mirror of https://github.com/bol-van/zapret/
committed by
GitHub
5 changed files with 128 additions and 3 deletions
@ -0,0 +1,4 @@ |
|||||
|
config zapret tpws |
||||
|
option opts "--split-pos=2" |
||||
|
option pidfile "tpws.pid" |
||||
|
option port "8088" |
@ -0,0 +1,19 @@ |
|||||
|
#!/bin/sh |
||||
|
|
||||
|
ZAPRET=/etc/init.d/zapret |
||||
|
|
||||
|
check_lan() |
||||
|
{ |
||||
|
IS_LAN= |
||||
|
[ -n "$OPENWRT_LAN" ] || OPENWRT_LAN=lan |
||||
|
for lan in $OPENWRT_LAN; do |
||||
|
[ "$INTERFACE" = "$lan" ] && { |
||||
|
IS_LAN=1 |
||||
|
break |
||||
|
} |
||||
|
done |
||||
|
} |
||||
|
|
||||
|
|
||||
|
[ -n "$INTERFACE" ] && check_lan && [ -n "$IS_LAN" ] && [ "$ACTION" = ifup -o "$ACTION" = ifupdate ] && [ $ZAPRET stop ] && [ $ZAPRET start ] |
||||
|
[ -n "$INTERFACE" ] && [ -n "$IS_LAN" ] && [ "$ACTION" = ifdown ] && [ $ZAPRET stop ] |
@ -0,0 +1,90 @@ |
|||||
|
#!/bin/sh /etc/rc.common |
||||
|
|
||||
|
USE_PROCD=1 |
||||
|
# after network |
||||
|
START=21 |
||||
|
|
||||
|
CONFIGURATION=zapret |
||||
|
PIDDIR=/var/run |
||||
|
|
||||
|
|
||||
|
load_fw_rules() |
||||
|
{ |
||||
|
json_add_object "" |
||||
|
json_add_string type redirect |
||||
|
json_add_string name "Transparent Proxy Redirect HTTP" |
||||
|
json_add_string src lan |
||||
|
json_add_string proto tcp |
||||
|
json_add_string dest_port "$1" |
||||
|
json_add_string src_dip "!$2" |
||||
|
json_add_string dest_ip "$2" |
||||
|
json_add_string src_dport "80" |
||||
|
json_add_string dest lan |
||||
|
json_close_object |
||||
|
|
||||
|
json_add_object "" |
||||
|
json_add_string type redirect |
||||
|
json_add_string name "Transparent Proxy Redirect HTTPS" |
||||
|
json_add_string src lan |
||||
|
json_add_string proto tcp |
||||
|
json_add_string dest_port "$1" |
||||
|
json_add_string src_dip "!$2" |
||||
|
json_add_string dest_ip "$2" |
||||
|
json_add_string src_dport "443" |
||||
|
json_add_string dest lan |
||||
|
json_close_object |
||||
|
} |
||||
|
|
||||
|
start_service() |
||||
|
{ |
||||
|
echo "Starting Zapret service" |
||||
|
config_load "$CONFIGURATION" |
||||
|
|
||||
|
local opts |
||||
|
local pid |
||||
|
local lanaddr |
||||
|
local lport |
||||
|
|
||||
|
config_get opts tpws opts |
||||
|
config_get pid tpws pid |
||||
|
config_get lport tpws port |
||||
|
config_load "network" |
||||
|
config_get lanaddr lan ipaddr |
||||
|
|
||||
|
procd_open_instance |
||||
|
|
||||
|
procd_set_param command "/opt/zapret/tpws/tpws" |
||||
|
procd_append_param command "--port=$lport" |
||||
|
procd_append_param command "--user=nobody" |
||||
|
procd_append_param command "--bind-addr=$lanaddr" |
||||
|
procd_append_param command "--bind-wait-ifup=30" |
||||
|
procd_append_param command "--bind-wait-ip=10" |
||||
|
procd_append_param command "$opts" |
||||
|
|
||||
|
procd_set_param file /etc/config/zapret |
||||
|
procd_set_param pidfile "$PIDDIR/$pid" |
||||
|
procd_set_param netdev "br-lan" |
||||
|
|
||||
|
procd_open_data |
||||
|
|
||||
|
json_add_array firewall |
||||
|
load_fw_rules "$lport" "$lanaddr" |
||||
|
json_close_array |
||||
|
|
||||
|
procd_close_data |
||||
|
|
||||
|
procd_close_instance |
||||
|
} |
||||
|
|
||||
|
stop_service() |
||||
|
{ |
||||
|
# this procedure is called from stop() |
||||
|
# stop() already stop daemons |
||||
|
procd_set_config_changed firewall |
||||
|
echo "STOP Zapret service" |
||||
|
} |
||||
|
|
||||
|
service_started() |
||||
|
{ |
||||
|
procd_set_config_changed firewall |
||||
|
} |
Loading…
Reference in new issue