85 lines
2.3 KiB
Plaintext
Raw Normal View History

2016-02-15 16:34:45 +03:00
#!/bin/sh /etc/rc.common
USE_PROCD=1
# after network
START=21
2019-05-06 16:02:22 +03:00
ZAPRET_BASE=/opt/zapret
2019-05-24 08:27:25 +03:00
. "$ZAPRET_BASE/init.d/openwrt/functions"
2019-05-03 12:44:43 +03:00
2019-05-06 16:02:22 +03:00
# !!!!! in openwrt firewall rules are configured separately
2019-05-03 12:44:43 +03:00
PIDDIR=/var/run
2016-02-15 16:34:45 +03:00
QNUM=200
2019-05-20 10:53:20 +03:00
NFQWS_USER=daemon
2019-05-24 08:37:50 +03:00
NFQWS="$ZAPRET_BASE/nfq/nfqws"
2019-05-20 10:53:20 +03:00
NFQWS_OPT_BASE="--qnum=$QNUM --user=$NFQWS_USER"
2019-05-03 12:44:43 +03:00
2019-05-13 18:27:16 +03:00
TPWS_USER=daemon
2019-05-05 23:35:10 +03:00
TPPORT_HTTP=1188
TPPORT_HTTPS=1189
2019-05-24 08:37:50 +03:00
TPWS="$ZAPRET_BASE/tpws/tpws"
2019-05-24 08:46:10 +03:00
TPWS_HOSTLIST="$ZAPRET_BASE/ipset/zapret-hosts.txt.gz"
[ -f "$TPWS_HOSTLIST" ] || TPWS_HOSTLIST="$ZAPRET_BASE/ipset/zapret-hosts-user.txt"
2019-05-05 23:35:10 +03:00
TPWS_OPT_BASE="--user=$TPWS_USER --bind-addr=127.0.0.1"
2019-05-13 18:27:16 +03:00
TPWS_OPT_BASE6="--user=$TPWS_USER --bind-addr=::1"
# first wait for lan to ifup, then wait for bind-wait-ip-linklocal seconds for link local address and bind-wait-ip for any ipv6 as the worst case
TPWS_OPT_BASE6_PRE="--user=$TPWS_USER --bind-linklocal=prefer --bind-wait-ifup=30 --bind-wait-ip=30 --bind-wait-ip-linklocal=3"
2019-05-13 18:27:16 +03:00
TPWS_OPT_BASE_HTTP="--port=$TPPORT_HTTP"
TPWS_OPT_BASE_HTTPS="--port=$TPPORT_HTTPS"
2016-02-15 16:34:45 +03:00
2019-05-03 12:44:43 +03:00
run_daemon()
{
# $1 - daemon string id or number. can use 1,2,3,...
# $2 - daemon
# $3 - daemon args
# use $PIDDIR/$DAEMONBASE$1.pid as pidfile
local DAEMONBASE=$(basename $2)
echo "Starting daemon $1: $2 $3"
procd_open_instance
procd_set_param command $2 $3
procd_set_param pidfile $PIDDIR/$DAEMONBASE$1.pid
procd_close_instance
}
2019-05-13 18:27:16 +03:00
run_tpws()
{
2019-05-14 23:14:14 +03:00
[ "$DISABLE_IPV4" = "1" ] || run_daemon $1 $TPWS "$TPWS_OPT_BASE $2"
[ "$DISABLE_IPV6" = "1" ] || {
2019-05-13 18:27:16 +03:00
run_daemon $((60+$1)) $TPWS "$TPWS_OPT_BASE6 $2"
network_get_device DEVICE lan
[ -n "$DEVICE" ] && run_daemon $((660+$1)) $TPWS "$TPWS_OPT_BASE6_PRE --bind-iface6=$DEVICE $2"
}
}
stop_tpws()
{
2019-05-14 23:14:14 +03:00
[ "$DISABLE_IPV4" = "1" ] || stop_daemon $1 $TPWS
[ "$DISABLE_IPV6" = "1" ] || {
2019-05-13 18:27:16 +03:00
stop_daemon $((60+$1)) $TPWS
stop_daemon $((660+$1)) $TPWS
}
}
2019-05-03 12:44:43 +03:00
start_service() {
case "${MODE}" in
tpws_hostlist)
2019-05-13 18:27:16 +03:00
run_tpws 1 "$TPWS_OPT_BASE_HTTP $TPWS_OPT_HTTP --hostlist=$TPWS_HOSTLIST"
;;
2019-05-05 23:35:10 +03:00
tpws_ipset|tpws_all)
2019-05-13 18:27:16 +03:00
run_tpws 1 "$TPWS_OPT_BASE_HTTP $TPWS_OPT_HTTP"
;;
2019-05-05 23:35:10 +03:00
tpws_ipset_https|tpws_all_https)
2019-05-13 18:27:16 +03:00
run_tpws 1 "$TPWS_OPT_BASE_HTTP $TPWS_OPT_HTTP"
run_tpws 2 "$TPWS_OPT_BASE_HTTPS $TPWS_OPT_HTTPS"
;;
2019-05-23 19:33:13 +03:00
nfqws_ipset|nfqws_ipset_https|nfqws_all|nfqws_all_https)
2019-05-13 18:27:16 +03:00
run_daemon 1 $NFQWS "$NFQWS_OPT_BASE $NFQWS_OPT"
;;
2016-12-09 16:33:29 +03:00
custom)
2019-05-24 08:27:25 +03:00
existf zapret_custom_daemons && zapret_custom_daemons $1
2019-05-13 18:27:16 +03:00
;;
2016-02-15 16:34:45 +03:00
esac
}