|
@ -14,11 +14,17 @@ get_config() { |
|
|
config_get server $1 server |
|
|
config_get server $1 server |
|
|
config_get server_port $1 server_port |
|
|
config_get server_port $1 server_port |
|
|
config_get local_port $1 local_port |
|
|
config_get local_port $1 local_port |
|
|
config_get password $1 password |
|
|
|
|
|
config_get timeout $1 timeout |
|
|
config_get timeout $1 timeout |
|
|
|
|
|
config_get password $1 password |
|
|
config_get encrypt_method $1 encrypt_method |
|
|
config_get encrypt_method $1 encrypt_method |
|
|
config_get ignore_list $1 ignore_list |
|
|
config_get ignore_list $1 ignore_list |
|
|
config_get udp_relay $1 udp_relay |
|
|
|
|
|
|
|
|
config_get udp_mode $1 udp_mode |
|
|
|
|
|
config_get udp_server $1 udp_server |
|
|
|
|
|
config_get udp_server_port $1 udp_server_port |
|
|
|
|
|
config_get udp_local_port $1 udp_local_port |
|
|
|
|
|
config_get udp_timeout $1 udp_timeout |
|
|
|
|
|
config_get udp_password $1 udp_password |
|
|
|
|
|
config_get udp_encrypt_method $1 udp_encrypt_method |
|
|
config_get_bool tunnel_enable $1 tunnel_enable |
|
|
config_get_bool tunnel_enable $1 tunnel_enable |
|
|
config_get tunnel_port $1 tunnel_port |
|
|
config_get tunnel_port $1 tunnel_port |
|
|
config_get tunnel_forward $1 tunnel_forward |
|
|
config_get tunnel_forward $1 tunnel_forward |
|
@ -27,6 +33,8 @@ get_config() { |
|
|
config_get wan_bp_ip $1 wan_bp_ip |
|
|
config_get wan_bp_ip $1 wan_bp_ip |
|
|
config_get wan_fw_ip $1 wan_fw_ip |
|
|
config_get wan_fw_ip $1 wan_fw_ip |
|
|
config_get ipt_ext $1 ipt_ext |
|
|
config_get ipt_ext $1 ipt_ext |
|
|
|
|
|
: ${timeout:=60} |
|
|
|
|
|
: ${udp_timeout:=60} |
|
|
: ${tunnel_port:=5300} |
|
|
: ${tunnel_port:=5300} |
|
|
: ${tunnel_forward:=8.8.4.4:53} |
|
|
: ${tunnel_forward:=8.8.4.4:53} |
|
|
} |
|
|
} |
|
@ -45,6 +53,8 @@ start_rules() { |
|
|
/usr/bin/ss-rules \ |
|
|
/usr/bin/ss-rules \ |
|
|
-s "$server" \ |
|
|
-s "$server" \ |
|
|
-l "$local_port" \ |
|
|
-l "$local_port" \ |
|
|
|
|
|
-S "$udp_server" \ |
|
|
|
|
|
-L "$udp_local_port" \ |
|
|
-i "$ignore_list" \ |
|
|
-i "$ignore_list" \ |
|
|
-a "$ac_args" \ |
|
|
-a "$ac_args" \ |
|
|
-b "$wan_bp_ip" \ |
|
|
-b "$wan_bp_ip" \ |
|
@ -55,17 +65,48 @@ start_rules() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
start_redir() { |
|
|
start_redir() { |
|
|
service_start /usr/bin/ss-redir \ |
|
|
|
|
|
-c "$CONFIG_FILE" $udp |
|
|
|
|
|
|
|
|
cat <<-EOF >$CONFIG_FILE |
|
|
|
|
|
{ |
|
|
|
|
|
"server": "$server", |
|
|
|
|
|
"server_port": $server_port, |
|
|
|
|
|
"local_address": "0.0.0.0", |
|
|
|
|
|
"local_port": $local_port, |
|
|
|
|
|
"password": "$password", |
|
|
|
|
|
"timeout": $timeout, |
|
|
|
|
|
"method": "$encrypt_method" |
|
|
|
|
|
} |
|
|
|
|
|
EOF |
|
|
|
|
|
if [ "$udp_mode" = 2 ]; then |
|
|
|
|
|
/usr/bin/ss-redir \ |
|
|
|
|
|
-c $CONFIG_FILE \ |
|
|
|
|
|
-f /var/run/ss-redir_t.pid |
|
|
|
|
|
cat <<-EOF >$CONFIG_FILE |
|
|
|
|
|
{ |
|
|
|
|
|
"server": "$udp_server", |
|
|
|
|
|
"server_port": $udp_server_port, |
|
|
|
|
|
"local_address": "0.0.0.0", |
|
|
|
|
|
"local_port": $udp_local_port, |
|
|
|
|
|
"password": "$udp_password", |
|
|
|
|
|
"timeout": $udp_timeout, |
|
|
|
|
|
"method": "$udp_encrypt_method" |
|
|
|
|
|
} |
|
|
|
|
|
EOF |
|
|
|
|
|
fi |
|
|
|
|
|
/usr/bin/ss-redir \ |
|
|
|
|
|
-c $CONFIG_FILE \ |
|
|
|
|
|
-f /var/run/ss-redir.pid \ |
|
|
|
|
|
$udp |
|
|
return $? |
|
|
return $? |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
start_tunnel() { |
|
|
start_tunnel() { |
|
|
service_start /usr/bin/ss-tunnel \ |
|
|
|
|
|
-c "$CONFIG_FILE" \ |
|
|
|
|
|
-l "$tunnel_port" \ |
|
|
|
|
|
-L "$tunnel_forward" \ |
|
|
|
|
|
-u |
|
|
|
|
|
|
|
|
: ${udp:="-u"} |
|
|
|
|
|
/usr/bin/ss-tunnel \ |
|
|
|
|
|
-c $CONFIG_FILE \ |
|
|
|
|
|
-l $tunnel_port \ |
|
|
|
|
|
-L $tunnel_forward \ |
|
|
|
|
|
-f /var/run/ss-tunnel.pid \ |
|
|
|
|
|
$udp |
|
|
return $? |
|
|
return $? |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -73,25 +114,26 @@ rules() { |
|
|
config_load shadowsocks-libev |
|
|
config_load shadowsocks-libev |
|
|
config_foreach get_config shadowsocks-libev |
|
|
config_foreach get_config shadowsocks-libev |
|
|
[ "$enable" = 1 ] || exit 0 |
|
|
[ "$enable" = 1 ] || exit 0 |
|
|
[ "$udp_relay" = 1 ] && udp="-u" |
|
|
|
|
|
mkdir -p $(dirname $CONFIG_FILE) |
|
|
|
|
|
|
|
|
mkdir -p /var/run /var/etc |
|
|
|
|
|
|
|
|
: ${server:?} |
|
|
: ${server:?} |
|
|
: ${server_port:?} |
|
|
: ${server_port:?} |
|
|
: ${local_port:?} |
|
|
: ${local_port:?} |
|
|
: ${password:?} |
|
|
: ${password:?} |
|
|
: ${encrypt_method:?} |
|
|
: ${encrypt_method:?} |
|
|
cat <<-EOF >$CONFIG_FILE |
|
|
|
|
|
{ |
|
|
|
|
|
"server": "$server", |
|
|
|
|
|
"server_port": $server_port, |
|
|
|
|
|
"local_address": "0.0.0.0", |
|
|
|
|
|
"local_port": $local_port, |
|
|
|
|
|
"password": "$password", |
|
|
|
|
|
"timeout": $timeout, |
|
|
|
|
|
"method": "$encrypt_method" |
|
|
|
|
|
} |
|
|
|
|
|
EOF |
|
|
|
|
|
|
|
|
case $udp_mode in |
|
|
|
|
|
1) udp="-u" |
|
|
|
|
|
;; |
|
|
|
|
|
2) |
|
|
|
|
|
udp="-U" |
|
|
|
|
|
: ${udp_server:?} |
|
|
|
|
|
: ${udp_server_port:?} |
|
|
|
|
|
: ${udp_local_port:?} |
|
|
|
|
|
: ${udp_password:?} |
|
|
|
|
|
: ${udp_encrypt_method:?} |
|
|
|
|
|
;; |
|
|
|
|
|
esac |
|
|
|
|
|
|
|
|
start_rules |
|
|
start_rules |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -109,7 +151,6 @@ start() { |
|
|
|
|
|
|
|
|
stop() { |
|
|
stop() { |
|
|
/usr/bin/ss-rules -f |
|
|
/usr/bin/ss-rules -f |
|
|
service_stop /usr/bin/ss-redir |
|
|
|
|
|
service_stop /usr/bin/ss-tunnel |
|
|
|
|
|
rm -f $CONFIG_FILE |
|
|
|
|
|
|
|
|
killall -q -9 ss-redir |
|
|
|
|
|
killall -q -9 ss-tunnel |
|
|
} |
|
|
} |