mirror of
https://github.com/bol-van/zapret.git
synced 2025-04-19 21:42:59 +03:00
sysv init : more code dedup
This commit is contained in:
parent
8d182f0692
commit
cc006c2337
@ -37,6 +37,20 @@ exists()
|
|||||||
which $1 >/dev/null 2>/dev/null
|
which $1 >/dev/null 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
on_off_function()
|
||||||
|
{
|
||||||
|
# $1 : function name on
|
||||||
|
# $2 : function name off
|
||||||
|
# $3 : 0 - off, 1 - on
|
||||||
|
local F="$1"
|
||||||
|
[ "$3" = "1" ] || F="$2"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
"$F" $@
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ipt()
|
ipt()
|
||||||
{
|
{
|
||||||
iptables -C $@ 2>/dev/null || iptables -I $@
|
iptables -C $@ 2>/dev/null || iptables -I $@
|
||||||
@ -47,13 +61,7 @@ ipt_del()
|
|||||||
}
|
}
|
||||||
ipt_add_del()
|
ipt_add_del()
|
||||||
{
|
{
|
||||||
if [ "$1" = "1" ]; then
|
on_off_function ipt ipt_del $@
|
||||||
shift
|
|
||||||
ipt $@
|
|
||||||
else
|
|
||||||
shift
|
|
||||||
ipt_del $@
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
ipt6()
|
ipt6()
|
||||||
{
|
{
|
||||||
@ -65,13 +73,7 @@ ipt6_del()
|
|||||||
}
|
}
|
||||||
ipt6_add_del()
|
ipt6_add_del()
|
||||||
{
|
{
|
||||||
if [ "$1" = "1" ]; then
|
on_off_function ipt6 ipt6_del $@
|
||||||
shift
|
|
||||||
ipt6 $@
|
|
||||||
else
|
|
||||||
shift
|
|
||||||
ipt6_del $@
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# there's no route_localnet for ipv6
|
# there's no route_localnet for ipv6
|
||||||
@ -254,6 +256,12 @@ stop_daemon()
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
do_daemon()
|
||||||
|
{
|
||||||
|
# $1 - 1 - run, 0 - stop
|
||||||
|
on_off_function run_daemon stop_daemon $@
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
prepare_tpws()
|
prepare_tpws()
|
||||||
{
|
{
|
||||||
@ -283,6 +291,11 @@ stop_tpws()
|
|||||||
[ -n "$IFACE_LAN" ] && stop_daemon $((660+$1)) $TPWS
|
[ -n "$IFACE_LAN" ] && stop_daemon $((660+$1)) $TPWS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
do_tpws()
|
||||||
|
{
|
||||||
|
# $1 - 1 - run, 0 - stop
|
||||||
|
on_off_function run_tpws stop_tpws $@
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
create_ipset()
|
create_ipset()
|
||||||
@ -360,52 +373,42 @@ zapret_unapply_firewall()
|
|||||||
zapret_do_firewall 0 $@
|
zapret_do_firewall 0 $@
|
||||||
}
|
}
|
||||||
|
|
||||||
zapret_run_daemons()
|
zapret_do_daemons()
|
||||||
{
|
{
|
||||||
|
# $1 - 1 - run, 0 - stop
|
||||||
|
|
||||||
case "${MODE}" in
|
case "${MODE}" in
|
||||||
tpws_hostlist)
|
tpws_hostlist)
|
||||||
run_tpws 1 "$TPWS_OPT_BASE_HTTP $TPWS_OPT_HTTP --hostlist=$TPWS_HOSTLIST"
|
do_tpws $1 1 "$TPWS_OPT_BASE_HTTP $TPWS_OPT_HTTP --hostlist=$TPWS_HOSTLIST"
|
||||||
;;
|
;;
|
||||||
tpws_ipset)
|
tpws_ipset)
|
||||||
run_tpws 1 "$TPWS_OPT_BASE_HTTP $TPWS_OPT_HTTP"
|
do_tpws $1 1 "$TPWS_OPT_BASE_HTTP $TPWS_OPT_HTTP"
|
||||||
;;
|
;;
|
||||||
tpws_ipset_https|tpws_all_https)
|
tpws_ipset_https|tpws_all_https)
|
||||||
run_tpws 1 "$TPWS_OPT_BASE_HTTP $TPWS_OPT_HTTP"
|
do_tpws $1 1 "$TPWS_OPT_BASE_HTTP $TPWS_OPT_HTTP"
|
||||||
run_tpws 2 "$TPWS_OPT_BASE_HTTPS $TPWS_OPT_HTTPS"
|
do_tpws $1 2 "$TPWS_OPT_BASE_HTTPS $TPWS_OPT_HTTPS"
|
||||||
;;
|
;;
|
||||||
tpws_all)
|
tpws_all)
|
||||||
run_tpws 1 "$TPWS_OPT_BASE_HTTP $TPWS_OPT_HTTP"
|
do_tpws $1 1 "$TPWS_OPT_BASE_HTTP $TPWS_OPT_HTTP"
|
||||||
;;
|
;;
|
||||||
nfqws_ipset|nfqws_ipset_https|nfqws_all|nfqws_all_https)
|
nfqws_ipset|nfqws_ipset_https|nfqws_all|nfqws_all_https)
|
||||||
run_daemon 1 $NFQWS "$NFQWS_OPT_BASE $NFQWS_OPT"
|
do_daemon $1 1 $NFQWS "$NFQWS_OPT_BASE $NFQWS_OPT"
|
||||||
;;
|
;;
|
||||||
custom)
|
custom)
|
||||||
# PLACEHOLDER
|
# PLACEHOLDER
|
||||||
echo !!! NEED ATTENTION !!!
|
echo !!! NEED ATTENTION !!!
|
||||||
echo Start daemon\(s\)
|
echo Start daemon\(s\)
|
||||||
echo Study how other sections work
|
echo Study how other sections work
|
||||||
run_daemon 1 /bin/sleep 20
|
do_daemon $1 1 /bin/sleep 20
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
zapret_run_daemons()
|
||||||
|
{
|
||||||
|
zapret_do_daemons 1 $@
|
||||||
|
}
|
||||||
zapret_stop_daemons()
|
zapret_stop_daemons()
|
||||||
{
|
{
|
||||||
case "${MODE}" in
|
zapret_do_daemons 0 $@
|
||||||
tpws_hostlist|tpws_all|tpws_ipset)
|
|
||||||
stop_tpws 1
|
|
||||||
;;
|
|
||||||
tpws_ipset_https|tpws_all_https)
|
|
||||||
stop_tpws 1
|
|
||||||
stop_tpws 2
|
|
||||||
;;
|
|
||||||
nfqws_ipset|nfqws_ipset_https|nfqws_all|nfqws_all_https)
|
|
||||||
stop_daemon 1 $NFQWS
|
|
||||||
;;
|
|
||||||
custom)
|
|
||||||
# PLACEHOLDER
|
|
||||||
echo !!! NEED ATTENTION !!!
|
|
||||||
echo Stop daemon\(s\) previously started.
|
|
||||||
echo Study how other sections work.
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user