mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Update shadowsocks luci interface
This commit is contained in:
parent
69275038c5
commit
95288f3b1d
14 changed files with 982 additions and 676 deletions
|
@ -1,7 +1,6 @@
|
|||
#!/bin/sh /etc/rc.common
|
||||
#
|
||||
# Copyright (C) 2017 Yousong Zhou <yszhou4tech@gmail.com>
|
||||
# Copyright (C) 2018 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
|
||||
# Copyright (C) 2017-2019 Yousong Zhou <yszhou4tech@gmail.com>
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v3.
|
||||
# See /LICENSE for more information.
|
||||
|
@ -9,30 +8,10 @@
|
|||
|
||||
USE_PROCD=1
|
||||
EXTRA_COMMANDS="rules_up rules_down rules_exist"
|
||||
START=98
|
||||
START=99
|
||||
|
||||
ss_confdir=/var/etc/shadowsocks-libev
|
||||
ss_bindir=/usr/bin
|
||||
q='"'
|
||||
|
||||
ss_mkjson() {
|
||||
echo "{" >"$confjson"
|
||||
if ss_mkjson_ "$@" >>$confjson; then
|
||||
sed -i -e '/^\s*$/d' -e '2,$s/^/\t/' -e '$s/,$//' "$confjson"
|
||||
echo "}" >>"$confjson"
|
||||
else
|
||||
rm -f "$confjson"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
ss_mkjson_() {
|
||||
local func
|
||||
|
||||
for func in "$@"; do
|
||||
"$func" || return 1
|
||||
done
|
||||
}
|
||||
|
||||
ss_mkjson_server_conf() {
|
||||
local cfgserver
|
||||
|
@ -47,159 +26,52 @@ ss_mkjson_server_conf() {
|
|||
|
||||
ss_mkjson_server_conf_() {
|
||||
[ -n "$server_port" ] || return 1
|
||||
password="${password//\"/\\\"}"
|
||||
key="$(echo $key | sed 's/+/-/g; s/\//_/g;')"
|
||||
[ "$method" = "none" -a -z "$key" ] && key=""
|
||||
[ "$ebpf" = 1 ] && {
|
||||
key=""
|
||||
method="none"
|
||||
}
|
||||
cat <<-EOF
|
||||
${server:+${q}server${q}: ${q}$server${q},}
|
||||
"server_port": $server_port,
|
||||
${method:+${q}method${q}: ${q}$method${q},}
|
||||
${key:+${q}key${q}: ${q}$key${q},}
|
||||
${password:+${q}password${q}: ${q}$password${q},}
|
||||
EOF
|
||||
}
|
||||
|
||||
ss_mkjson_common_conf() {
|
||||
[ "$ipv6_first" = 0 ] && ipv6_first=false || ipv6_first=true
|
||||
[ "$fast_open" = 0 ] && fast_open=false || fast_open=true
|
||||
[ "$no_delay" = 0 ] && no_delay=false || no_delay=true
|
||||
[ "$reuse_port" = 0 ] && reuse_port=false || reuse_port=true
|
||||
[ "$mptcp" = 0 ] && mptcp=false || mptcp=true
|
||||
[ "$syslog" = 0 ] && syslog=false || syslog=true
|
||||
[ "$ebpf" = 0 ] && ebpf=false || ebpf=true
|
||||
cat <<-EOF
|
||||
"use_syslog": $syslog,
|
||||
"ipv6_first": $ipv6_first,
|
||||
"fast_open": $fast_open,
|
||||
"no_delay": $no_delay,
|
||||
"mptcp": $mptcp,
|
||||
"ebpf": $ebpf,
|
||||
"reuse_port": $reuse_port,
|
||||
${local_address:+${q}local_address${q}: ${q}$local_address${q},}
|
||||
${local_port:+${q}local_port${q}: $local_port,}
|
||||
${mode:+${q}mode${q}: ${q}$mode${q},}
|
||||
${mtu:+${q}mtu${q}: $mtu,}
|
||||
${timeout:+${q}timeout${q}: $timeout,}
|
||||
${user:+${q}user${q}: ${q}$user${q},}
|
||||
EOF
|
||||
[ -z "$server" ] || json_add_string server "$server"
|
||||
json_add_int server_port "$server_port"
|
||||
[ -z "$method" ] || json_add_string method "$method"
|
||||
[ -z "$key" ] || json_add_string key "$key"
|
||||
[ -z "$password" ] || json_add_string password "$password"
|
||||
[ -z "$plugin" ] || json_add_string plugin "$plugin"
|
||||
[ -z "$plugin_opts" ] || json_add_string plugin_opts "$plugin_opts"
|
||||
if [ "$obfs" = 1; then
|
||||
if [ "$obfs_plugin" = "obfs" ]; then
|
||||
obfs_options="obfs=$obfs_type"
|
||||
[ -z "$obfs_host" ] || obfs_options="$obfs_options;obfs-host=$obfs_host"
|
||||
[ -z "$obfs_uri" ] || obfs_options="$obfs_options;obfs-uri=$obfs_uri"
|
||||
[ "$fast_open" = 1 ] && obfs_options="$obfs_options;fast-open"
|
||||
[ "$mptcp" = 1 ] && obfs_options="$obfs_options;mptcp"
|
||||
[ -z "$timeout" ] || obfs_options="$obfs_options;t=$timeout"
|
||||
json_add_string plugin "/usr/bin/obfs-local"
|
||||
json_add_string plugin_opts "$obfs_options"
|
||||
fi
|
||||
if [ "$obfs_plugin" = "v2ray" ]; then
|
||||
obfs_options="loglevel=default"
|
||||
[ "$obfs_type" = "tls" ] && obfs_options="tls"
|
||||
[ -z "$obfs_host" ] || obfs_options="$obfs_options;host=$obfs_host"
|
||||
[ -z "$obfs_uri" ] || obfs_options="$obfs_options;path=$obfs_uri"
|
||||
[ "$fast_open" = 1 ] && obfs_options="$obfs_options;fast-open"
|
||||
json_add_string plugin "/usr/bin/v2ray-plugin"
|
||||
json_add_string plugin_opts "$obfs_options"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
ss_mkjson_ss_local_conf() {
|
||||
ss_mkjson_server_conf
|
||||
[ "$obfs" = 0 ] && obfs=false || obfs=true
|
||||
if $obfs; then
|
||||
if [ "$obfs_plugin" = "obfs" ]; then
|
||||
obfs_options="obfs=$obfs_type"
|
||||
[ -z "$obfs_host" ] || obfs_options="$obfs_options;obfs-host=$obfs_host"
|
||||
[ -z "$obfs_uri" ] || obfs_options="$obfs_options;obfs-uri=$obfs_uri"
|
||||
[ "$fast_open" = true ] && obfs_options="$obfs_options;fast-open"
|
||||
[ "$mptcp" = true ] && obfs_options="$obfs_options;mptcp"
|
||||
[ -z "$timeout" ] || obfs_options="$obfs_options;t=$timeout"
|
||||
cat <<-EOF
|
||||
${obfs:+${q}plugin${q}: ${q}/usr/bin/obfs-local${q},${q}plugin_opts${q}: ${q}$obfs_options${q},}
|
||||
EOF
|
||||
fi
|
||||
if [ "$obfs_plugin" = "v2ray" ]; then
|
||||
obfs_options="loglevel=default"
|
||||
[ "$obfs_type" = "tls" ] && obfs_options="tls"
|
||||
[ -z "$obfs_host" ] || obfs_options="$obfs_options;host=$obfs_host"
|
||||
[ -z "$obfs_uri" ] || obfs_options="$obfs_options;path=$obfs_uri"
|
||||
[ "$fast_open" = true ] && obfs_options="$obfs_options;fast-open"
|
||||
cat <<-EOF
|
||||
${obfs:+${q}plugin${q}: ${q}/usr/bin/v2ray-plugin${q},${q}plugin_opts${q}: ${q}$obfs_options${q},}
|
||||
EOF
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
ss_mkjson_ss_redir_conf() {
|
||||
ss_mkjson_server_conf || return 1
|
||||
[ "$disable_sni" = 0 ] && disable_sni=false || disable_sni=true
|
||||
cat <<-EOF
|
||||
"disable_sni": $disable_sni,
|
||||
EOF
|
||||
[ "$obfs" = 0 ] && obfs=false || obfs=true
|
||||
if $obfs; then
|
||||
if [ "$obfs_plugin" = "obfs" ]; then
|
||||
obfs_options="obfs=$obfs_type"
|
||||
[ -z "$obfs_host" ] || obfs_options="$obfs_options;obfs-host=$obfs_host"
|
||||
[ -z "$obfs_uri" ] || obfs_options="$obfs_options;obfs-uri=$obfs_uri"
|
||||
[ "$fast_open" = true ] && obfs_options="$obfs_options;fast-open"
|
||||
[ "$mptcp" = true ] && obfs_options="$obfs_options;mptcp"
|
||||
[ -z "$timeout" ] || obfs_options="$obfs_options;t=$timeout"
|
||||
cat <<-EOF
|
||||
${obfs:+${q}plugin${q}: ${q}/usr/bin/obfs-local${q},${q}plugin_opts${q}: ${q}$obfs_options${q},}
|
||||
EOF
|
||||
fi
|
||||
if [ "$obfs_plugin" = "v2ray" ]; then
|
||||
obfs_options="loglevel=default"
|
||||
[ "$obfs_type" = "tls" ] && obfs_options="tls"
|
||||
[ -z "$obfs_host" ] || obfs_options="$obfs_options;host=$obfs_host"
|
||||
[ -z "$obfs_uri" ] || obfs_options="$obfs_options;path=$obfs_uri"
|
||||
[ "$fast_open" = true ] && obfs_options="$obfs_options;fast-open"
|
||||
cat <<-EOF
|
||||
${obfs:+${q}plugin${q}: ${q}/usr/bin/v2ray-plugin${q},${q}plugin_opts${q}: ${q}$obfs_options${q},}
|
||||
EOF
|
||||
fi
|
||||
fi
|
||||
ss_mkjson_server_conf
|
||||
}
|
||||
|
||||
ss_mkjson_ss_server_conf() {
|
||||
ss_mkjson_server_conf_
|
||||
[ "$obfs" = 0 ] && obfs=false || obfs=true
|
||||
if $obfs; then
|
||||
if [ "$obfs_plugin" = "obfs" ]; then
|
||||
obfs_options="obfs=$obfs_type"
|
||||
[ "$fast_open" = true ] && obfs_options="$obfs_options;fast-open"
|
||||
[ "$mptcp" = true ] && obfs_options="$obfs_options;mptcp"
|
||||
[ -z "$timeout" ] || obfs_options="$obfs_options;t=$timeout"
|
||||
cat <<-EOF
|
||||
${obfs:+${q}plugin${q}: ${q}/usr/bin/obfs-server${q},${q}plugin_opts${q}: ${q}$obfs_options${q},}
|
||||
EOF
|
||||
fi
|
||||
if [ "$obfs_plugin" = "v2ray" ]; then
|
||||
obfs_options="server"
|
||||
[ "$obfs_type" = "tls" ] && obfs_options="tls"
|
||||
[ "$fast_open" = true ] && obfs_options="$obfs_options;fast-open"
|
||||
cat <<-EOF
|
||||
${obfs:+${q}plugin${q}: ${q}/usr/bin/v2ray-plugin${q},${q}plugin_opts${q}: ${q}$obfs_options${q},}
|
||||
EOF
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
ss_mkjson_ss_tunnel_conf() {
|
||||
ss_mkjson_server_conf || return 1
|
||||
[ -n "$tunnel_address" ] || return 1
|
||||
cat <<-EOF
|
||||
${tunnel_address:+${q}tunnel_address${q}: ${q}$tunnel_address${q},}
|
||||
EOF
|
||||
[ "$obfs" = 0 ] && obfs=false || obfs=true
|
||||
if $obfs; then
|
||||
if [ "$obfs_plugin" = "obfs" ]; then
|
||||
obfs_options="obfs=$obfs_type"
|
||||
[ -z "$obfs_host" ] || obfs_options="$obfs_options;obfs-host=$obfs_host"
|
||||
[ -z "$obfs_uri" ] || obfs_options="$obfs_options;obfs-uri=$obfs_uri"
|
||||
[ -z "$timeout" ] || obfs_options="$obfs_options;t=$timeout"
|
||||
cat <<-EOF
|
||||
${obfs:+${q}plugin${q}: ${q}/usr/bin/obfs-local${q},${q}plugin_opts${q}: ${q}$obfs_options${q},}
|
||||
EOF
|
||||
fi
|
||||
if [ "$obfs_plugin" = "v2ray" ]; then
|
||||
obfs_options="loglevel=default"
|
||||
[ "$obfs_type" = "tls" ] && obfs_options="tls"
|
||||
[ -z "$obfs_host" ] || obfs_options="$obfs_options;host=$obfs_host"
|
||||
[ -z "$obfs_uri" ] || obfs_options="$obfs_options;path=$obfs_uri"
|
||||
[ "$fast_open" = true ] && obfs_options="$obfs_options;fast-open"
|
||||
cat <<-EOF
|
||||
${obfs:+${q}plugin${q}: ${q}/usr/bin/v2ray-plugin${q},${q}plugin_opts${q}: ${q}$obfs_options${q},}
|
||||
EOF
|
||||
fi
|
||||
fi
|
||||
json_add_string tunnel_address "$tunnel_address"
|
||||
}
|
||||
|
||||
ss_xxx() {
|
||||
|
@ -210,25 +82,33 @@ ss_xxx() {
|
|||
|
||||
[ -x "$bin" ] || return
|
||||
eval "$("validate_${cfgtype}_section" "$cfg" ss_validate_mklocal)"
|
||||
"validate_${cfgtype}_section" "$cfg" || return 1
|
||||
"validate_${cfgtype}_section" "$cfg" || return
|
||||
[ "$disabled" = 0 ] || return
|
||||
|
||||
if ss_mkjson \
|
||||
ss_mkjson_common_conf \
|
||||
ss_mkjson_${cfgtype}_conf \
|
||||
; then
|
||||
procd_open_instance "$cfgtype.$cfg"
|
||||
procd_set_param command "$bin" -c "$confjson"
|
||||
[ "$verbose" = 0 ] || procd_append_param command -v
|
||||
[ "$no_delay" = 0 ] || procd_append_param command --no-delay
|
||||
[ -z "$bind_address" ] || procd_append_param command -b "$bind_address"
|
||||
[ -z "$manager_address" ] || procd_append_param command --manager-address "$manager_address"
|
||||
procd_set_param file "$confjson"
|
||||
procd_set_param limits nofile="512000 512000"
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
ss_rules_cb
|
||||
fi
|
||||
json_init
|
||||
ss_mkjson_${cfgtype}_conf || return
|
||||
json_add_boolean use_syslog 1
|
||||
json_add_boolean ipv6_first "$ipv6_first"
|
||||
json_add_boolean fast_open "$fast_open"
|
||||
json_add_boolean reuse_port "$reuse_port"
|
||||
json_add_boolean no_delay "$no_delay"
|
||||
json_add_boolean mptcp "$mptcp"
|
||||
[ -z "$local_address" ] || json_add_string local_address "$local_address"
|
||||
[ -z "$local_port" ] || json_add_int local_port "$local_port"
|
||||
[ -z "$mode" ] || json_add_string mode "$mode"
|
||||
[ -z "$mtu" ] || json_add_int mtu "$mtu"
|
||||
[ -z "$timeout" ] || json_add_int timeout "$timeout"
|
||||
[ -z "$user" ] || json_add_string user "$user"
|
||||
json_dump -i >"$confjson"
|
||||
|
||||
procd_open_instance "$cfgtype.$cfg"
|
||||
procd_set_param command "$bin" -c "$confjson"
|
||||
[ "$verbose" = 0 ] || procd_append_param command -v
|
||||
[ -z "$bind_address" ] || procd_append_param command -b "$bind_address"
|
||||
procd_set_param file "$confjson"
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
ss_rules_cb
|
||||
}
|
||||
|
||||
ss_rules_restart() {
|
||||
|
@ -242,17 +122,16 @@ ss_rules_restart() {
|
|||
|
||||
ss_rules_cb() {
|
||||
local cfgserver server
|
||||
|
||||
if [ "$cfgtype" = ss_redir ]; then
|
||||
config_get cfgserver "$cfg" server
|
||||
config_get server "$cfgserver" server
|
||||
ss_redir_servers="$ss_redir_servers $server"
|
||||
if [ "$mode" = "tcp_only" -o "$mode" = "tcp_and_udp" ]; then
|
||||
if [ "$mode" = tcp_only -o "$mode" = "tcp_and_udp" ]; then
|
||||
eval "ss_rules_redir_tcp_$cfg=$local_port"
|
||||
eval "ss_rules6_redir_tcp_$cfg=$local_port"
|
||||
fi
|
||||
if [ "$mode" = "udp_only" -o "$mode" = "tcp_and_udp" ]; then
|
||||
if [ "$mode" = udp_only -o "$mode" = "tcp_and_udp" ]; then
|
||||
eval "ss_rules_redir_udp_$cfg=$local_port"
|
||||
eval "ss_rules6_redir_udp_$cfg=$local_port"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
@ -263,79 +142,31 @@ ss_rules() {
|
|||
local cfgtype
|
||||
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
|
||||
"$bin" -f
|
||||
"$bin" -6 -f
|
||||
|
||||
config_get cfgtype "$cfg" TYPE
|
||||
[ "$cfgtype" = ss_rules ] || return 1
|
||||
|
||||
eval "$(validate_ss_rules_section "$cfg" ss_validate_mklocal)"
|
||||
validate_ss_rules_section "$cfg" || return 1
|
||||
[ "$disabled" = 0 ] || return 1
|
||||
[ "$disabled" = 0 ] || return 0
|
||||
|
||||
eval local_port_tcp="\$ss_rules_redir_tcp_$redir_tcp"
|
||||
eval local_port_udp="\$ss_rules_redir_udp_$redir_udp"
|
||||
[ -n "$local_port_tcp" -o -n "$local_port_udp" ] || return 1
|
||||
ss_redir_servers4="$(echo "$ss_redir_servers" | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | sort -u)"
|
||||
|
||||
ss_redir_servers="$(echo "$ss_redir_servers" | tr ' ' '\n' | sort -u)"
|
||||
[ "$dst_forward_recentrst" = 0 ] || args="$args --dst-forward-recentrst"
|
||||
|
||||
dst_ips_bypass4="$(echo "$dst_ips_bypass" | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | sort -u)"
|
||||
dst_ips_forward4="$(echo "$dst_ips_forward" | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | sort -u)"
|
||||
src_ips_bypass4="$(echo "$src_ips_bypass" | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | sort -u)"
|
||||
src_ips_forward4="$(echo "$src_ips_forward" | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | sort -u)"
|
||||
src_ips_checkdst4="$(echo "$src_ips_checkdst" | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | sort -u)"
|
||||
|
||||
"$bin" \
|
||||
-s "$ss_redir_servers4" \
|
||||
-l "$local_port_tcp" \
|
||||
-L "$local_port_udp" \
|
||||
--src-default "$src_default" \
|
||||
--dst-default "$dst_default" \
|
||||
--local-default "$local_default" \
|
||||
--dst-bypass-file "$dst_ips_bypass_file" \
|
||||
--dst-forward-file "$dst_ips_forward_file" \
|
||||
--dst-bypass "$dst_ips_bypass4" \
|
||||
--dst-forward "$dst_ips_forward4" \
|
||||
--src-bypass "$src_ips_bypass4" \
|
||||
--src-forward "$src_ips_forward4" \
|
||||
--src-checkdst "$src_ips_checkdst4" \
|
||||
--ifnames "$ifnames" \
|
||||
--ipt-extra "$ipt_args" \
|
||||
$args \
|
||||
|| "$bin" -f
|
||||
ss_rules_call
|
||||
ss_rules_call -6
|
||||
}
|
||||
|
||||
ss_rules6() {
|
||||
local cfg="ss_rules"
|
||||
local bin="$ss_bindir/ss-rules6"
|
||||
local cfgtype
|
||||
local local_port_tcp local_port_udp
|
||||
local args
|
||||
local ss_redir_servers6 dst_ips_bypass6 dst_ips_forward6 src_ips_bypass6 src_ips_forward6 src_ips_checkdst6
|
||||
|
||||
[ -x "$bin" ] || return 1
|
||||
config_get cfgtype "$cfg" TYPE
|
||||
[ "$cfgtype" = ss_rules ] || return 1
|
||||
|
||||
eval "$(validate_ss_rules_section "$cfg" ss_validate_mklocal)"
|
||||
validate_ss_rules_section "$cfg" || return 1
|
||||
[ "$disabled" = 0 ] || return 1
|
||||
|
||||
eval local_port_tcp="\$ss_rules6_redir_tcp_$redir_tcp"
|
||||
eval local_port_udp="\$ss_rules6_redir_udp_$redir_udp"
|
||||
[ -n "$local_port_tcp" -o -n "$local_port_udp" ] || return 1
|
||||
ss_redir_servers6="$(echo "$ss_redir_servers" | grep -o '\([0-9a-fA-F]\{0,4\}:\)\{1,7\}[0-9a-fA-F]\{0,4\}' | sort -u)"
|
||||
|
||||
[ "$dst_forward_recentrst" = 0 ] || args="$args --dst-forward-recentrst"
|
||||
|
||||
dst_ips_bypass6="$(echo "$dst_ips_bypass" | grep -o '\([0-9a-fA-F]\{0,4\}:\)\{1,7\}[0-9a-fA-F]\{0,4\}' | sort -u)"
|
||||
dst_ips_forward6="$(echo "$dst_ips_forward" | grep -o '\([0-9a-fA-F]\{0,4\}:\)\{1,7\}[0-9a-fA-F]\{0,4\}' | sort -u)"
|
||||
src_ips_bypass6="$(echo "$src_ips_bypass" | grep -o '\([0-9a-fA-F]\{0,4\}:\)\{1,7\}[0-9a-fA-F]\{0,4\}' | sort -u)"
|
||||
src_ips_forward6="$(echo "$src_ips_forward" | grep -o '\([0-9a-fA-F]\{0,4\}:\)\{1,7\}[0-9a-fA-F]\{0,4\}' | sort -u)"
|
||||
src_ips_checkdst6="$(echo "$src_ips_checkdst" | grep -o '\([0-9a-fA-F]\{0,4\}:\)\{1,7\}[0-9a-fA-F]\{0,4\}' | sort -u)"
|
||||
|
||||
"$bin" \
|
||||
-s "$ss_redir_servers6" \
|
||||
ss_rules_call() {
|
||||
"$bin" "$@" \
|
||||
-s "$ss_redir_servers" \
|
||||
-l "$local_port_tcp" \
|
||||
-L "$local_port_udp" \
|
||||
--src-default "$src_default" \
|
||||
|
@ -343,15 +174,15 @@ ss_rules6() {
|
|||
--local-default "$local_default" \
|
||||
--dst-bypass-file "$dst_ips_bypass_file" \
|
||||
--dst-forward-file "$dst_ips_forward_file" \
|
||||
--dst-bypass "$dst_ips_bypass6" \
|
||||
--dst-forward "$dst_ips_forward6" \
|
||||
--src-bypass "$src_ips_bypass6" \
|
||||
--src-forward "$src_ips_forward6" \
|
||||
--src-checkdst "$src_ips_checkdst6" \
|
||||
--dst-bypass "$dst_ips_bypass" \
|
||||
--dst-forward "$dst_ips_forward" \
|
||||
--src-bypass "$src_ips_bypass" \
|
||||
--src-forward "$src_ips_forward" \
|
||||
--src-checkdst "$src_ips_checkdst" \
|
||||
--ifnames "$ifnames" \
|
||||
--ipt-extra "$ipt_args" \
|
||||
$args \
|
||||
|| "$bin" -f
|
||||
|| "$bin" "$@" -f
|
||||
}
|
||||
|
||||
start_service() {
|
||||
|
@ -362,19 +193,17 @@ start_service() {
|
|||
for cfgtype in ss_local ss_redir ss_server ss_tunnel; do
|
||||
config_foreach ss_xxx "$cfgtype" "$cfgtype"
|
||||
done
|
||||
rules_up
|
||||
# Add rule to match traffic marked by firewall for bypass
|
||||
ip rule add prio 1 fwmark 0x539 lookup 991337 > /dev/null 2>&1
|
||||
ss_rules
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
rules_down
|
||||
rm -rf "$ss_confdir"
|
||||
}
|
||||
local bin="$ss_bindir/ss-rules"
|
||||
|
||||
reload_service() {
|
||||
stop
|
||||
start
|
||||
[ -x "$bin" ] && {
|
||||
"$bin" -f
|
||||
"$bin" -6 -f
|
||||
}
|
||||
rm -rf "$ss_confdir"
|
||||
}
|
||||
|
||||
rules_exist() {
|
||||
|
@ -407,9 +236,8 @@ rules_down() {
|
|||
[ -x "$bin6" ] && "$bin6" -f >/dev/null 2>&1
|
||||
}
|
||||
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_interface_trigger wan*
|
||||
procd_add_reload_interface_trigger wan
|
||||
procd_add_reload_trigger shadowsocks-libev
|
||||
procd_open_validate
|
||||
validate_server_section
|
||||
|
@ -439,7 +267,7 @@ validate_common_server_options_() {
|
|||
local cfgtype="$1"; shift
|
||||
local cfg="$1"; shift
|
||||
local func="$1"; shift
|
||||
local stream_methods='"none", "table", "rc4", "rc4-md5", "aes-128-cfb", "aes-192-cfb", "aes-256-cfb", "aes-128-ctr", "aes-192-ctr", "aes-256-ctr", "bf-cfb", "camellia-128-cfb", "camellia-192-cfb", "camellia-256-cfb", "salsa20", "chacha20", "chacha20-ietf"'
|
||||
local stream_methods='"table", "rc4", "rc4-md5", "aes-128-cfb", "aes-192-cfb", "aes-256-cfb", "aes-128-ctr", "aes-192-ctr", "aes-256-ctr", "bf-cfb", "camellia-128-cfb", "camellia-192-cfb", "camellia-256-cfb", "salsa20", "chacha20", "chacha20-ietf"'
|
||||
local aead_methods='"aes-128-gcm", "aes-192-gcm", "aes-256-gcm", "chacha20-ietf-poly1305", "xchacha20-ietf-poly1305"'
|
||||
|
||||
"${func:-ss_validate}" "$cfgtype" "$cfg" "$@" \
|
||||
|
@ -448,7 +276,12 @@ validate_common_server_options_() {
|
|||
'server_port:port' \
|
||||
'password:string' \
|
||||
'key:string' \
|
||||
"method:or($stream_methods, $aead_methods)"
|
||||
"method:or($stream_methods, $aead_methods)" \
|
||||
'plugin:string' \
|
||||
'plugin_opts:string' \
|
||||
'obfs:bool:0' \
|
||||
'obfs_plugin:or("v2ray","obfs-simple"):v2ray' \
|
||||
'obfs_type:or("http","tls"):http'
|
||||
}
|
||||
|
||||
validate_common_client_options_() {
|
||||
|
@ -468,36 +301,25 @@ validate_common_options_() {
|
|||
'fast_open:bool:0' \
|
||||
'ipv6_first:bool:0' \
|
||||
'no_delay:bool:0' \
|
||||
'reuse_port:bool:0' \
|
||||
'mptcp:bool:0' \
|
||||
'ebpf:bool:0' \
|
||||
'reuse_port:bool:0' \
|
||||
'verbose:bool:0' \
|
||||
'mode:or("tcp_only", "udp_only", "tcp_and_udp"):tcp_only' \
|
||||
'mtu:uinteger' \
|
||||
'timeout:uinteger' \
|
||||
'user:string' \
|
||||
'obfs:bool:0' \
|
||||
'obfs_plugin:or("v2ray","obfs-simple"):v2ray' \
|
||||
'obfs_type:or("http","tls"):http'
|
||||
'user:string'
|
||||
}
|
||||
|
||||
validate_server_section() {
|
||||
validate_common_server_options_ server "$1" "${2}"
|
||||
validate_common_server_options_ server "$1" "$2"
|
||||
}
|
||||
|
||||
validate_ss_local_section() {
|
||||
validate_common_client_options_ ss_local "$1" \
|
||||
"${2}" \
|
||||
'obfs_host:string' \
|
||||
'obfs_uri:string'
|
||||
validate_common_client_options_ ss_local "$1" "$2"
|
||||
}
|
||||
|
||||
validate_ss_redir_section() {
|
||||
validate_common_client_options_ ss_redir "$1" \
|
||||
"${2}" \
|
||||
'disable_sni:bool:0' \
|
||||
'obfs_host:string' \
|
||||
'obfs_uri:string'
|
||||
validate_common_client_options_ ss_redir "$1" "$2"
|
||||
}
|
||||
|
||||
validate_ss_rules_section() {
|
||||
|
@ -505,13 +327,13 @@ validate_ss_rules_section() {
|
|||
'disabled:bool:0' \
|
||||
'redir_tcp:uci("shadowsocks-libev", "@ss_redir")' \
|
||||
'redir_udp:uci("shadowsocks-libev", "@ss_redir")' \
|
||||
'src_ips_bypass:or(ip4addr,cidr4,ip6addr,cidr6)' \
|
||||
'src_ips_forward:or(ip4addr,cidr4,ip6addr,cidr6)' \
|
||||
'src_ips_checkdst:or(ip4addr,cidr4,ip6addr,cidr6)' \
|
||||
'src_ips_bypass:or(ipaddr,cidr)' \
|
||||
'src_ips_forward:or(ipaddr,cidr)' \
|
||||
'src_ips_checkdst:or(ipaddr,cidr)' \
|
||||
'dst_ips_bypass_file:file' \
|
||||
'dst_ips_bypass:or(ip4addr,cidr4,ip6addr,cidr6)' \
|
||||
'dst_ips_bypass:or(ipaddr,cidr)' \
|
||||
'dst_ips_forward_file:file' \
|
||||
'dst_ips_forward:or(ip4addr,cidr4,ip6addr,cidr6)' \
|
||||
'dst_ips_forward:or(ipaddr,cidr)' \
|
||||
'src_default:or("bypass", "forward", "checkdst"):checkdst' \
|
||||
'dst_default:or("bypass", "forward"):bypass' \
|
||||
'local_default:or("bypass", "forward", "checkdst"):bypass' \
|
||||
|
@ -523,13 +345,12 @@ validate_ss_rules_section() {
|
|||
validate_ss_server_section() {
|
||||
validate_common_server_options_ ss_server "$1" \
|
||||
validate_common_options_ \
|
||||
"${2}" \
|
||||
'bind_address:ipaddr' \
|
||||
'manager_address:host'
|
||||
"$2" \
|
||||
'bind_address:ipaddr'
|
||||
}
|
||||
|
||||
validate_ss_tunnel_section() {
|
||||
validate_common_client_options_ ss_tunnel "$1" \
|
||||
"${2}" \
|
||||
"$2" \
|
||||
'tunnel_address:regex(".+\:[0-9]+")'
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue