提交 cec0ab41 编写于 作者: W William Chan 提交者: coolsnowwolf

luci-app-ssr-plus: added try count (#2706)

有时候只不过是短暂性的无法访问, 多尝试一次就可以.
所以增加尝试次数, 默认每秒钟检查一次.
上级 aeceaafa
...@@ -10,10 +10,10 @@ uci:foreach(shadowsocksr, "servers", function(s) ...@@ -10,10 +10,10 @@ uci:foreach(shadowsocksr, "servers", function(s)
end end
end) end)
local key_table = {} local key_table = {}
for key,_ in pairs(server_table) do for key,_ in pairs(server_table) do
table.insert(key_table,key) table.insert(key_table,key)
end end
table.sort(key_table) table.sort(key_table)
...@@ -38,6 +38,11 @@ o.datatype = "uinteger" ...@@ -38,6 +38,11 @@ o.datatype = "uinteger"
o:depends("enable_switch", "1") o:depends("enable_switch", "1")
o.default = 5 o.default = 5
o = s:option(Value, "switch_try_count", translate("Check Try Count"))
o.datatype = "uinteger"
o:depends("enable_switch", "1")
o.default = 3
-- [[ SOCKS5 Proxy ]]-- -- [[ SOCKS5 Proxy ]]--
if nixio.fs.access("/usr/bin/ssr-local") then if nixio.fs.access("/usr/bin/ssr-local") then
s = m:section(TypedSection, "socks5_proxy", translate("SOCKS5 Proxy")) s = m:section(TypedSection, "socks5_proxy", translate("SOCKS5 Proxy"))
......
...@@ -320,6 +320,9 @@ msgstr "自动切换检查周期(秒)" ...@@ -320,6 +320,9 @@ msgstr "自动切换检查周期(秒)"
msgid "Check timout(second)" msgid "Check timout(second)"
msgstr "切换检查超时时间(秒)" msgstr "切换检查超时时间(秒)"
msgid "Check Try Count"
msgstr "切换检查重试次数"
msgid "Enable Process Deamon" msgid "Enable Process Deamon"
msgstr "启用进程自动守护" msgstr "启用进程自动守护"
......
...@@ -9,6 +9,7 @@ config global ...@@ -9,6 +9,7 @@ config global
option enable_switch '1' option enable_switch '1'
option switch_timeout '5' option switch_timeout '5'
option switch_time '667' option switch_time '667'
option switch_try_count '3'
config socks5_proxy config socks5_proxy
option server 'nil' option server 'nil'
......
...@@ -35,31 +35,39 @@ CURRENT_SERVER=$DEFAULT_SERVER ...@@ -35,31 +35,39 @@ CURRENT_SERVER=$DEFAULT_SERVER
#判断代理是否正常 #判断代理是否正常
check_proxy() { check_proxy() {
/usr/bin/ssr-check www.google.com 80 $switch_time 1 local result=0
if [ "$?" == "0" ]; then local try_count=$(uci_get_by_type global switch_try_count 3)
return 0 for i in $(seq 1 $try_count)
else do
/usr/bin/ssr-check www.baidu.com 80 $switch_time 1 /usr/bin/ssr-check www.google.com 80 $switch_time 1
if [ "$?" == "0" ]; then if [ "$?" == "0" ]; then
#goole不通baidu通则不正常 # echo "$(date "+%Y-%m-%d %H:%M:%S") Check Google Proxy Success, count=$i" >> /tmp/ssrplus.log
return 1 result=0
else break
return 2 else
fi # echo "$(date "+%Y-%m-%d %H:%M:%S") Check Google Proxy Fail, count=$i" >> /tmp/ssrplus.log
fi /usr/bin/ssr-check www.baidu.com 80 $switch_time 1
return 0 if [ "$?" == "0" ]; then
result=1
else
result=2
fi
fi
sleep 1;
done
return $result;
} }
test_proxy() { test_proxy() {
local servername=$(uci_get_by_name $1 server) local servername=$(uci_get_by_name $1 server)
local serverport=$(uci_get_by_name $1 server_port) local serverport=$(uci_get_by_name $1 server_port)
ret=$(ping -c 3 $servername | grep 'loss' | awk -F ',' '{ print $3 }' | awk -F "%" '{ print $1 }') ret=$(ping -c 3 $servername | grep 'loss' | awk -F ',' '{ print $3 }' | awk -F "%" '{ print $1 }')
[ -z "$ret" ] && return 1 [ -z "$ret" ] && return 1
[ "$ret" -gt "50" ] && return 1 [ "$ret" -gt "50" ] && return 1
ipset add ss_spec_wan_ac $servername 2>/dev/null ipset add ss_spec_wan_ac $servername 2>/dev/null
ret=$? ret=$?
/usr/bin/ssr-check $servername $serverport $switch_time /usr/bin/ssr-check $servername $serverport $switch_time
local ret2=$? local ret2=$?
if [ "$ret" = "0" ] ;then if [ "$ret" = "0" ] ;then
ipset del ss_spec_wan_ac $servername 2>/dev/null ipset del ss_spec_wan_ac $servername 2>/dev/null
...@@ -81,7 +89,7 @@ local servername=$(uci_get_by_name $1 server) ...@@ -81,7 +89,7 @@ local servername=$(uci_get_by_name $1 server)
local serverport=$(uci_get_by_name $1 server_port) local serverport=$(uci_get_by_name $1 server_port)
ipset add ss_spec_wan_ac $servername 2>/dev/null ipset add ss_spec_wan_ac $servername 2>/dev/null
ret=$? ret=$?
/usr/bin/ssr-check $servername $serverport $switch_time /usr/bin/ssr-check $servername $serverport $switch_time
local ret2=$? local ret2=$?
if [ "$ret" = "0" ] ;then if [ "$ret" = "0" ] ;then
ipset del ss_spec_wan_ac $servername 2>/dev/null ipset del ss_spec_wan_ac $servername 2>/dev/null
...@@ -117,12 +125,12 @@ start() { ...@@ -117,12 +125,12 @@ start() {
[ $(uci_get_by_name $DEFAULT_SERVER kcp_enable) = "1" ] && return 1 [ $(uci_get_by_name $DEFAULT_SERVER kcp_enable) = "1" ] && return 1
while [ "1" = "1" ] #死循环 while [ "1" = "1" ] #死循环
do do
sleep $cycle_time sleep $cycle_time
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S") LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
#判断当前代理是否为缺省服务器 #判断当前代理是否为缺省服务器
if [ "$CURRENT_SERVER" != "$DEFAULT_SERVER" ] ;then if [ "$CURRENT_SERVER" != "$DEFAULT_SERVER" ] ;then
#echo "not default proxy" #echo "not default proxy"
...@@ -134,7 +142,7 @@ do ...@@ -134,7 +142,7 @@ do
echo "$(date "+%Y-%m-%d %H:%M:%S") Main server is avilable." >> /tmp/ssrplus.log echo "$(date "+%Y-%m-%d %H:%M:%S") Main server is avilable." >> /tmp/ssrplus.log
#缺省服务器正常,切换回来 #缺省服务器正常,切换回来
CURRENT_SERVER=$DEFAULT_SERVER CURRENT_SERVER=$DEFAULT_SERVER
switch_proxy $CURRENT_SERVER switch_proxy $CURRENT_SERVER
echo "$(date "+%Y-%m-%d %H:%M:%S") switch to default ["$(uci_get_by_name $CURRENT_SERVER server)"] proxy!" >> /tmp/ssrplus.log echo "$(date "+%Y-%m-%d %H:%M:%S") switch to default ["$(uci_get_by_name $CURRENT_SERVER server)"] proxy!" >> /tmp/ssrplus.log
continue continue
else else
...@@ -143,14 +151,14 @@ do ...@@ -143,14 +151,14 @@ do
fi fi
#判断当前代理是否正常 #判断当前代理是否正常
check_proxy check_proxy
current_ret=$? current_ret=$?
if [ "$current_ret" = "1" ] ;then if [ "$current_ret" = "1" ] ;then
#当前代理错误,判断有无可用的服务器 #当前代理错误,判断有无可用的服务器
#echo "current error" #echo "current error"
echo "$(date "+%Y-%m-%d %H:%M:%S") Current server error, try to switch another server." >> /tmp/ssrplus.log echo "$(date "+%Y-%m-%d %H:%M:%S") Current server error, try to switch another server." >> /tmp/ssrplus.log
select_proxy select_proxy
if [ "$ENABLE_SERVER" != nil ] ;then if [ "$ENABLE_SERVER" != nil ] ;then
#有其他服务器可用,进行切换 #有其他服务器可用,进行切换
...@@ -162,11 +170,11 @@ do ...@@ -162,11 +170,11 @@ do
echo "$(date "+%Y-%m-%d %H:%M:%S") ShadowsocksR server switch OK" >> /tmp/ssrplus.log echo "$(date "+%Y-%m-%d %H:%M:%S") ShadowsocksR server switch OK" >> /tmp/ssrplus.log
else else
switch_proxy $CURRENT_SERVER switch_proxy $CURRENT_SERVER
normal_flag=1 normal_flag=1
echo "$(date "+%Y-%m-%d %H:%M:%S") Try restart current server." >> /tmp/ssrplus.log echo "$(date "+%Y-%m-%d %H:%M:%S") Try restart current server." >> /tmp/ssrplus.log
fi fi
else else
normal_flag=0 normal_flag=0
echo "$(date "+%Y-%m-%d %H:%M:%S") ShadowsocksR No Problem." >> /tmp/ssrplus.log echo "$(date "+%Y-%m-%d %H:%M:%S") ShadowsocksR No Problem." >> /tmp/ssrplus.log
fi fi
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册