106 lines
2.5 KiB
Bash
106 lines
2.5 KiB
Bash
#!/bin/sh /etc/rc.common
|
|
|
|
USE_PROCD=1
|
|
START=99
|
|
STOP=01
|
|
|
|
PROG="/usr/sbin/fakehttp"
|
|
NAME="fakehttp"
|
|
|
|
service_triggers() {
|
|
procd_add_reload_trigger "${NAME}"
|
|
}
|
|
|
|
add_interface() {
|
|
local ifname="$1"
|
|
|
|
procd_append_param command "-i" "${ifname}"
|
|
procd_append_param netdev "${ifname}"
|
|
}
|
|
|
|
add_payload() {
|
|
local section="$1"
|
|
|
|
local enabled
|
|
config_get_bool enabled "${section}" "enabled" "0"
|
|
|
|
if [ "${enabled}" -eq "1" ]
|
|
then
|
|
local type payload
|
|
config_get type "${section}" "type" ""
|
|
config_get payload "${section}" "payload" ""
|
|
case "${type}" in
|
|
"http")
|
|
procd_append_param command "-h" "${payload}"
|
|
;;
|
|
"https")
|
|
procd_append_param command "-e" "${payload}"
|
|
;;
|
|
"binary")
|
|
procd_append_param command "-b" "${payload}"
|
|
;;
|
|
esac
|
|
fi
|
|
}
|
|
|
|
test_bool_then_append() {
|
|
local section="$1"
|
|
local config_option="$2"
|
|
local command_option="$3"
|
|
|
|
local tmp
|
|
config_get_bool tmp "${section}" "${config_option}" "0"
|
|
[ "${tmp}" -eq "1" ] && procd_append_param command "${command_option}"
|
|
}
|
|
|
|
test_number_then_append() {
|
|
local section="$1"
|
|
local config_option="$2"
|
|
local command_option="$3"
|
|
|
|
local tmp
|
|
config_get tmp "${section}" "${config_option}" "-1"
|
|
[ "${tmp}" -gt "0" ] && procd_append_param command "${command_option}" "${tmp}"
|
|
}
|
|
|
|
add_advanced() {
|
|
test_bool_then_append "advanced" "skip" "-f"
|
|
test_bool_then_append "advanced" "disable_estimation" "-g"
|
|
test_number_then_append "advanced" "pct" "-y"
|
|
test_number_then_append "advanced" "fwmark_bypassing" "-m"
|
|
test_number_then_append "advanced" "fwmark_handle" "-x"
|
|
test_number_then_append "advanced" "queue_number" "-n"
|
|
test_number_then_append "advanced" "repeat" "-r"
|
|
test_number_then_append "advanced" "ttl" "-t"
|
|
test_bool_then_append "advanced" "use_iptables" "-z"
|
|
}
|
|
|
|
fakehttp_instance() {
|
|
config_load "${NAME}"
|
|
|
|
local enabled
|
|
config_get_bool enabled "globals" "enabled" "0"
|
|
[ "${enabled}" -eq "1" ] || return 0
|
|
|
|
procd_open_instance
|
|
procd_set_param command "${PROG}"
|
|
config_list_foreach "globals" "interface" add_interface
|
|
test_bool_then_append "globals" "silent" "-s"
|
|
config_foreach add_payload "payload"
|
|
add_advanced
|
|
|
|
procd_set_param stdout 1
|
|
procd_set_param stderr 1
|
|
procd_set_param respawn
|
|
|
|
procd_close_instance
|
|
}
|
|
|
|
start_service() {
|
|
fakehttp_instance
|
|
}
|
|
|
|
reload_service() {
|
|
stop
|
|
start
|
|
} |