Merge commit 'ee5048aa89'
This commit is contained in:
commit
b2630653f7
3 changed files with 156 additions and 4 deletions
106
fakehttp/files/fakehttp.init
Normal file
106
fakehttp/files/fakehttp.init
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
#!/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 type
|
||||
config_get type "${section}" "type" ""
|
||||
|
||||
case "${type}" in
|
||||
"h")
|
||||
local hostname
|
||||
config_get hostname "${section}" "hostname" ""
|
||||
procd_append_param command "-h" "${hostname}"
|
||||
;;
|
||||
"e")
|
||||
local hostname
|
||||
config_get hostname "${section}" "hostname" ""
|
||||
procd_append_param command "-e" "${hostname}"
|
||||
;;
|
||||
"b")
|
||||
local file
|
||||
config_get file "${section}" "file" ""
|
||||
procd_append_param command "-b" "${file}"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue