mirror of
https://github.com/bol-van/zapret.git
synced 2024-11-27 04:30:53 +03:00
101 lines
2.3 KiB
Bash
Executable File
101 lines
2.3 KiB
Bash
Executable File
#!/bin/sh /etc/rc.common
|
|
|
|
USE_PROCD=1
|
|
# after network
|
|
START=21
|
|
|
|
|
|
SCRIPT=$(readlink /etc/init.d/zapret)
|
|
if [ -n "$SCRIPT" ]; then
|
|
EXEDIR=$(dirname "$SCRIPT")
|
|
ZAPRET_BASE=$(readlink -f "$EXEDIR/../..")
|
|
else
|
|
ZAPRET_BASE=/opt/zapret
|
|
fi
|
|
. "$ZAPRET_BASE/init.d/openwrt/functions"
|
|
|
|
|
|
# !!!!! in openwrt firewall rules are configured separately
|
|
|
|
PIDDIR=/var/run
|
|
|
|
QNUM=200
|
|
NFQWS_USER=daemon
|
|
NFQWS="$ZAPRET_BASE/nfq/nfqws"
|
|
NFQWS_OPT_BASE="--qnum=$QNUM --user=$NFQWS_USER"
|
|
|
|
TPWS_USER=daemon
|
|
TPPORT=988
|
|
TPWS="$ZAPRET_BASE/tpws/tpws"
|
|
TPWS_LOCALHOST4=127.0.0.127
|
|
HOSTLIST="$ZAPRET_BASE/ipset/zapret-hosts.txt.gz"
|
|
[ -f "$HOSTLIST" ] || HOSTLIST="$ZAPRET_BASE/ipset/zapret-hosts.txt"
|
|
[ -f "$HOSTLIST" ] || HOSTLIST="$ZAPRET_BASE/ipset/zapret-hosts-user.txt"
|
|
TPWS_OPT_BASE="--user=$TPWS_USER --port=$TPPORT"
|
|
TPWS_OPT_BASE4="--bind-addr=$TPWS_LOCALHOST4"
|
|
TPWS_OPT_BASE6="--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="--bind-linklocal=prefer --bind-wait-ifup=30 --bind-wait-ip=30 --bind-wait-ip-linklocal=3"
|
|
|
|
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
|
|
}
|
|
|
|
run_tpws()
|
|
{
|
|
[ "$DISABLE_IPV4" = "1" ] && [ "$DISABLE_IPV6" = "1" ] && return 0
|
|
|
|
local OPT="$TPWS_OPT_BASE"
|
|
local DEVICE
|
|
|
|
[ "$DISABLE_IPV4" = "1" ] || OPT="$OPT $TPWS_OPT_BASE4"
|
|
[ "$DISABLE_IPV6" = "1" ] || {
|
|
OPT="$OPT $TPWS_OPT_BASE6"
|
|
network_get_device DEVICE lan
|
|
[ -n "$DEVICE" ] && OPT="$OPT --bind-iface6=$DEVICE $TPWS_OPT_BASE6_PRE"
|
|
}
|
|
run_daemon $1 $TPWS "$OPT $2"
|
|
}
|
|
stop_tpws()
|
|
{
|
|
stop_daemon $1 $TPWS
|
|
}
|
|
|
|
|
|
filter_apply_hostlist_target()
|
|
{
|
|
# $1 - var name of tpws or nfqws params
|
|
[ "$MODE_FILTER" = "hostlist" ] && eval $1="\"\$$1 --hostlist=$HOSTLIST\""
|
|
}
|
|
|
|
|
|
start_service() {
|
|
local opt
|
|
|
|
case "${MODE}" in
|
|
tpws)
|
|
opt="$TPWS_OPT"
|
|
filter_apply_hostlist_target opt
|
|
run_tpws 1 "$opt"
|
|
;;
|
|
nfqws)
|
|
opt="$NFQWS_OPT_BASE $NFQWS_OPT_DESYNC"
|
|
filter_apply_hostlist_target opt
|
|
run_daemon 1 $NFQWS "$opt"
|
|
;;
|
|
custom)
|
|
existf zapret_custom_daemons && zapret_custom_daemons $1
|
|
;;
|
|
esac
|
|
}
|