1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00

Track is shadowsocks is up or not

This commit is contained in:
Ycarus 2018-05-09 11:15:43 +02:00
parent 0e22cbd6b2
commit 0387798d74
6 changed files with 146 additions and 12 deletions

View file

@ -1,12 +1,14 @@
#!/bin/sh /etc/rc.common
#
# Copyright (C) 2017 Yousong Zhou <yszhou4tech@gmail.com>
# Copyright (C) 2018 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
#
# This is free software, licensed under the GNU General Public License v3.
# See /LICENSE for more information.
#
USE_PROCD=1
EXTRA_COMMANDS="rules_up rules_down"
START=99
ss_confdir=/var/etc/shadowsocks-libev
@ -169,9 +171,17 @@ ss_xxx() {
fi
}
ss_rules_restart() {
local cfg="$1"
local cfgtype="$2"
eval "$("validate_${cfgtype}_section" "$cfg" ss_validate_mklocal)"
"validate_${cfgtype}_section" "$cfg" || return 1
ss_rules_cb
}
ss_rules_cb() {
local cfgserver server
if [ "$cfgtype" = ss_redir ]; then
config_get cfgserver "$cfg" server
config_get server "$cfgserver" server
@ -194,7 +204,6 @@ ss_rules() {
local local_port_tcp local_port_udp
local args
local ss_redir_servers4 dst_ips_bypass4 dst_ips_forward4 src_ips_bypass4 src_ips_forward4 src_ips_checkdst4
[ -x "$bin" ] || return 1
config_get cfgtype "$cfg" TYPE
[ "$cfgtype" = ss_rules ] || return 1
@ -307,6 +316,30 @@ stop_service() {
rm -rf "$ss_confdir"
}
_rules_status() {
[ -n "$(iptables -t nat -L | grep ss_rules_forward)" ] && return 1
return 0
}
rules_up() {
_rules_status || return 0
config_load shadowsocks-libev
for cfgtype in ss_redir; do
config_foreach ss_rules_restart "$cfgtype" "$cfgtype"
done
ss_rules
ss_rules6
}
rules_down() {
_rules_status && return 0
local bin="$ss_bindir/ss-rules"
[ -x "$bin" ] && "$bin" -f
local bin6="$ss_bindir/ss-rules6"
[ -x "$bin6" ] && "$bin6" -f
}
service_triggers() {
procd_add_reload_interface_trigger wan*
procd_add_reload_trigger shadowsocks-libev