mirror of
https://github.com/bol-van/zapret.git
synced 2025-04-19 21:42:59 +03:00
init : separate custom code
This commit is contained in:
parent
c1ca7fe367
commit
eef294aada
@ -359,6 +359,32 @@ IFACE_WAN=eth1
|
|||||||
/opt/zapret/init.d/sysv/zapret start-daemons
|
/opt/zapret/init.d/sysv/zapret start-daemons
|
||||||
/opt/zapret/init.d/sysv/zapret stop-daemons
|
/opt/zapret/init.d/sysv/zapret stop-daemons
|
||||||
|
|
||||||
|
Вариант custom
|
||||||
|
--------------
|
||||||
|
|
||||||
|
custom код вынесен в отдельный shell include
|
||||||
|
/opt/zapret/init.d/sysv/custom
|
||||||
|
или
|
||||||
|
/opt/zapret/init.d/openwrt/custom
|
||||||
|
|
||||||
|
Нужно свой код вписать в функции :
|
||||||
|
zapret_custom_daemons
|
||||||
|
zapret_custom_firewall
|
||||||
|
|
||||||
|
В этом файле пишите ваш код, пользуясь хелперами из "functions" или "zapret".
|
||||||
|
Смотрите как там сделано добавление iptables или запуск демонов.
|
||||||
|
Используя хелпер функции, вы избавитесь от необходимости учитывать все возможные случаи
|
||||||
|
типа наличия/отсутствия ipv6, является ли система роутером, имена интерфейсов, ...
|
||||||
|
Хелперы это учитывают , вам нужно сосредоточиться лишь на фильтрах iptables и
|
||||||
|
параметрах демонов.
|
||||||
|
|
||||||
|
Код для openwrt и sysv немного отличается. В sysv нужно обрабатывать и запуск, и остановку.
|
||||||
|
Запуск это или остановка передается в параметре $1 (0 или 1).
|
||||||
|
В openwrt за остановку демонов отвечает procd, а firewall вычищается при "fw3 restart",
|
||||||
|
потому нет необходимости реализоввать логику останова.
|
||||||
|
|
||||||
|
При апгрейде нужно сохранить лишь custom, другие файлы править не надо.
|
||||||
|
|
||||||
Пример установки на debian-подобную систему
|
Пример установки на debian-подобную систему
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
|
|
||||||
|
20
init.d/openwrt/custom
Normal file
20
init.d/openwrt/custom
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# this script contain your special code to launch daemons and configure firewall
|
||||||
|
# use helpers from "functions" file and "zapret" init script
|
||||||
|
# in case of upgrade keep this file only, do not modify others
|
||||||
|
|
||||||
|
zapret_custom_daemons()
|
||||||
|
{
|
||||||
|
# PLACEHOLDER
|
||||||
|
echo !!! NEED ATTENTION !!!
|
||||||
|
echo Start daemon\(s\)
|
||||||
|
echo Study how other sections work
|
||||||
|
|
||||||
|
run_daemon 1 /bin/sleep 20
|
||||||
|
}
|
||||||
|
zapret_custom_firewall()
|
||||||
|
{
|
||||||
|
# PLACEHOLDER
|
||||||
|
echo !!! NEED ATTENTION !!!
|
||||||
|
echo Configure iptables for required actions
|
||||||
|
echo Study how other sections work
|
||||||
|
}
|
@ -11,12 +11,20 @@ TPWS_USER=daemon
|
|||||||
# max wait time for the link local ipv6 on the LAN interface
|
# max wait time for the link local ipv6 on the LAN interface
|
||||||
LINKLOCAL_WAIT_SEC=5
|
LINKLOCAL_WAIT_SEC=5
|
||||||
|
|
||||||
IPSET_CR=$ZAPRET_BASE/ipset/create_ipset.sh
|
IPSET_CR="$ZAPRET_BASE/ipset/create_ipset.sh"
|
||||||
|
|
||||||
|
CUSTOM_SCRIPT="$ZAPRET_BASE/init.d/openwrt/custom"
|
||||||
|
[ -f "$CUSTOM_SCRIPT" ] && . "$CUSTOM_SCRIPT"
|
||||||
|
|
||||||
exists()
|
exists()
|
||||||
{
|
{
|
||||||
which $1 >/dev/null 2>/dev/null
|
which "$1" >/dev/null 2>/dev/null
|
||||||
}
|
}
|
||||||
|
existf()
|
||||||
|
{
|
||||||
|
type "$1" >/dev/null 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# can be multiple ipv6 outgoing interfaces
|
# can be multiple ipv6 outgoing interfaces
|
||||||
# uplink from isp, tunnelbroker, vpn, ...
|
# uplink from isp, tunnelbroker, vpn, ...
|
||||||
@ -239,10 +247,7 @@ zapret_apply_firewall()
|
|||||||
create_ipset no-update
|
create_ipset no-update
|
||||||
;;
|
;;
|
||||||
custom)
|
custom)
|
||||||
# PLACEHOLDER
|
existf zapret_custom_firewall && zapret_custom_firewall $1
|
||||||
echo !!! NEED ATTENTION !!!
|
|
||||||
echo Configure iptables for required actions
|
|
||||||
echo Study how other sections work
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,8 @@ USE_PROCD=1
|
|||||||
# after network
|
# after network
|
||||||
START=21
|
START=21
|
||||||
|
|
||||||
. /lib/functions/network.sh
|
|
||||||
|
|
||||||
ZAPRET_BASE=/opt/zapret
|
ZAPRET_BASE=/opt/zapret
|
||||||
. "$ZAPRET_BASE/config"
|
. "$ZAPRET_BASE/init.d/openwrt/functions"
|
||||||
|
|
||||||
# !!!!! in openwrt firewall rules are configured separately
|
# !!!!! in openwrt firewall rules are configured separately
|
||||||
|
|
||||||
@ -31,7 +29,6 @@ TPWS_OPT_BASE6_PRE="--user=$TPWS_USER --bind-linklocal=prefer --bind-wait-ifup=3
|
|||||||
TPWS_OPT_BASE_HTTP="--port=$TPPORT_HTTP"
|
TPWS_OPT_BASE_HTTP="--port=$TPPORT_HTTP"
|
||||||
TPWS_OPT_BASE_HTTPS="--port=$TPPORT_HTTPS"
|
TPWS_OPT_BASE_HTTPS="--port=$TPPORT_HTTPS"
|
||||||
|
|
||||||
|
|
||||||
run_daemon()
|
run_daemon()
|
||||||
{
|
{
|
||||||
# $1 - daemon string id or number. can use 1,2,3,...
|
# $1 - daemon string id or number. can use 1,2,3,...
|
||||||
@ -81,10 +78,7 @@ start_service() {
|
|||||||
run_daemon 1 $NFQWS "$NFQWS_OPT_BASE $NFQWS_OPT"
|
run_daemon 1 $NFQWS "$NFQWS_OPT_BASE $NFQWS_OPT"
|
||||||
;;
|
;;
|
||||||
custom)
|
custom)
|
||||||
# PLACEHOLDER
|
existf zapret_custom_daemons && zapret_custom_daemons $1
|
||||||
echo !!! NEED ATTENTION !!!
|
|
||||||
echo Start daemon\(s\)
|
|
||||||
echo Study how other sections work
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
24
init.d/sysv/custom
Normal file
24
init.d/sysv/custom
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# this script contain your special code to launch daemons and configure firewall
|
||||||
|
# use helpers from "functions" file
|
||||||
|
# in case of upgrade keep this file only, do not modify others
|
||||||
|
|
||||||
|
zapret_custom_daemons()
|
||||||
|
{
|
||||||
|
# $1 - 1 - run, 0 - stop
|
||||||
|
|
||||||
|
# PLACEHOLDER
|
||||||
|
echo !!! NEED ATTENTION !!!
|
||||||
|
echo Start daemon\(s\)
|
||||||
|
echo Study how other sections work
|
||||||
|
|
||||||
|
do_daemon $1 1 /bin/sleep 20
|
||||||
|
}
|
||||||
|
zapret_custom_firewall()
|
||||||
|
{
|
||||||
|
# $1 - 1 - run, 0 - stop
|
||||||
|
|
||||||
|
# PLACEHOLDER
|
||||||
|
echo !!! NEED ATTENTION !!!
|
||||||
|
echo Configure iptables for required actions
|
||||||
|
echo Study how other sections work
|
||||||
|
}
|
@ -6,17 +6,17 @@
|
|||||||
|
|
||||||
PIDDIR=/var/run
|
PIDDIR=/var/run
|
||||||
|
|
||||||
IPSET_CR=$ZAPRET_BASE/ipset/create_ipset.sh
|
IPSET_CR="$ZAPRET_BASE/ipset/create_ipset.sh"
|
||||||
|
|
||||||
WS_USER=tpws
|
WS_USER=tpws
|
||||||
|
|
||||||
QNUM=200
|
QNUM=200
|
||||||
NFQWS=$ZAPRET_BASE/nfq/nfqws
|
NFQWS="$ZAPRET_BASE/nfq/nfqws"
|
||||||
NFQWS_OPT_BASE="--qnum=$QNUM --user=$WS_USER"
|
NFQWS_OPT_BASE="--qnum=$QNUM --user=$WS_USER"
|
||||||
|
|
||||||
TPPORT_HTTP=1188
|
TPPORT_HTTP=1188
|
||||||
TPPORT_HTTPS=1189
|
TPPORT_HTTPS=1189
|
||||||
TPWS=$ZAPRET_BASE/tpws/tpws
|
TPWS="$ZAPRET_BASE/tpws/tpws"
|
||||||
TPWS_HOSTLIST=$ZAPRET_BASE/ipset/zapret-hosts.txt.gz
|
TPWS_HOSTLIST=$ZAPRET_BASE/ipset/zapret-hosts.txt.gz
|
||||||
[ -f "$TPWS_HOSTLIST" ] || TPWS_HOSTLIST=$ZAPRET_BASE/ipset/zapret-hosts-user.txt
|
[ -f "$TPWS_HOSTLIST" ] || TPWS_HOSTLIST=$ZAPRET_BASE/ipset/zapret-hosts-user.txt
|
||||||
TPWS_OPT_BASE="--user=$WS_USER --bind-addr=127.0.0.1"
|
TPWS_OPT_BASE="--user=$WS_USER --bind-addr=127.0.0.1"
|
||||||
@ -33,9 +33,16 @@ TPWS_OPT_BASE_HTTPS="--port=$TPPORT_HTTPS"
|
|||||||
# max wait time for the link local ipv6 on the LAN interface
|
# max wait time for the link local ipv6 on the LAN interface
|
||||||
LINKLOCAL_WAIT_SEC=5
|
LINKLOCAL_WAIT_SEC=5
|
||||||
|
|
||||||
|
CUSTOM_SCRIPT="$ZAPRET_BASE/init.d/sysv/custom"
|
||||||
|
[ -f "$CUSTOM_SCRIPT" ] && . "$CUSTOM_SCRIPT"
|
||||||
|
|
||||||
exists()
|
exists()
|
||||||
{
|
{
|
||||||
which $1 >/dev/null 2>/dev/null
|
which "$1" >/dev/null 2>/dev/null
|
||||||
|
}
|
||||||
|
existf()
|
||||||
|
{
|
||||||
|
type "$1" >/dev/null 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
on_off_function()
|
on_off_function()
|
||||||
@ -365,10 +372,7 @@ zapret_do_firewall()
|
|||||||
[ "$1" != "1" ] || create_ipset
|
[ "$1" != "1" ] || create_ipset
|
||||||
;;
|
;;
|
||||||
custom)
|
custom)
|
||||||
# PLACEHOLDER
|
existf zapret_custom_firewall && zapret_custom_firewall $1
|
||||||
echo !!! NEED ATTENTION !!!
|
|
||||||
echo Configure iptables for required actions
|
|
||||||
echo Study how other sections work
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@ -400,11 +404,7 @@ zapret_do_daemons()
|
|||||||
do_nfqws $1 1 "$NFQWS_OPT"
|
do_nfqws $1 1 "$NFQWS_OPT"
|
||||||
;;
|
;;
|
||||||
custom)
|
custom)
|
||||||
# PLACEHOLDER
|
existf zapret_custom_daemons && zapret_custom_daemons $1
|
||||||
echo !!! NEED ATTENTION !!!
|
|
||||||
echo Start daemon\(s\)
|
|
||||||
echo Study how other sections work
|
|
||||||
do_daemon $1 1 /bin/sleep 20
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user