init : separate custom code

This commit is contained in:
bolvan
2019-05-24 08:27:25 +03:00
parent c1ca7fe367
commit eef294aada
6 changed files with 97 additions and 28 deletions

20
init.d/openwrt/custom Normal file
View 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
}

View File

@@ -11,12 +11,20 @@ TPWS_USER=daemon
# max wait time for the link local ipv6 on the LAN interface
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()
{
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
# uplink from isp, tunnelbroker, vpn, ...
@@ -239,10 +247,7 @@ zapret_apply_firewall()
create_ipset no-update
;;
custom)
# PLACEHOLDER
echo !!! NEED ATTENTION !!!
echo Configure iptables for required actions
echo Study how other sections work
existf zapret_custom_firewall && zapret_custom_firewall $1
;;
esac
}

View File

@@ -4,10 +4,8 @@ USE_PROCD=1
# after network
START=21
. /lib/functions/network.sh
ZAPRET_BASE=/opt/zapret
. "$ZAPRET_BASE/config"
. "$ZAPRET_BASE/init.d/openwrt/functions"
# !!!!! 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_HTTPS="--port=$TPPORT_HTTPS"
run_daemon()
{
# $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"
;;
custom)
# PLACEHOLDER
echo !!! NEED ATTENTION !!!
echo Start daemon\(s\)
echo Study how other sections work
existf zapret_custom_daemons && zapret_custom_daemons $1
;;
esac
}