parent
ab971e5e1e
commit
b175eb2d1e
@ -289,7 +289,7 @@ function connect_status()
|
|||||||
local socks_server = api.get_cache_var("GLOBAL_TCP_SOCKS_server")
|
local socks_server = api.get_cache_var("GLOBAL_TCP_SOCKS_server")
|
||||||
|
|
||||||
-- 兼容 curl 8.6 time_starttransfer 错误
|
-- 兼容 curl 8.6 time_starttransfer 错误
|
||||||
local curl_ver = luci.sys.exec("curl -V 2>/dev/null | head -n 1 | awk '{print $2}' | cut -d. -f1,2 | tr -d ' \n'") or "0"
|
local curl_ver = api.get_bin_version_cache("/usr/bin/curl", "-V 2>/dev/null | head -n 1 | awk '{print $2}' | cut -d. -f1,2 | tr -d ' \n'") or "0"
|
||||||
url = (curl_ver == "8.6") and "-w %{http_code}:%{time_appconnect} https://" .. url
|
url = (curl_ver == "8.6") and "-w %{http_code}:%{time_appconnect} https://" .. url
|
||||||
or "-w %{http_code}:%{time_starttransfer} http://" .. url
|
or "-w %{http_code}:%{time_starttransfer} http://" .. url
|
||||||
|
|
||||||
@ -302,7 +302,7 @@ function connect_status()
|
|||||||
url = "-x socks5h://" .. socks_server .. " " .. url
|
url = "-x socks5h://" .. socks_server .. " " .. url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local result = luci.sys.exec('curl --connect-timeout 3 -o /dev/null -I -sk ' .. url)
|
local result = luci.sys.exec('/usr/bin/curl --connect-timeout 3 -o /dev/null -I -sk ' .. url)
|
||||||
local code = tonumber(luci.sys.exec("echo -n '" .. result .. "' | awk -F ':' '{print $1}'") or "0")
|
local code = tonumber(luci.sys.exec("echo -n '" .. result .. "' | awk -F ':' '{print $1}'") or "0")
|
||||||
if code ~= 0 then
|
if code ~= 0 then
|
||||||
local use_time = luci.sys.exec("echo -n '" .. result .. "' | awk -F ':' '{print $2}'")
|
local use_time = luci.sys.exec("echo -n '" .. result .. "' | awk -F ':' '{print $2}'")
|
||||||
|
@ -580,7 +580,7 @@ function clone(org)
|
|||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_bin_version_cache(file, cmd)
|
function get_bin_version_cache(file, cmd)
|
||||||
sys.call("mkdir -p /tmp/etc/passwall_tmp")
|
sys.call("mkdir -p /tmp/etc/passwall_tmp")
|
||||||
if fs.access(file) then
|
if fs.access(file) then
|
||||||
chmod_755(file)
|
chmod_755(file)
|
||||||
|
@ -14,6 +14,15 @@ config_n_get() {
|
|||||||
echo "${ret:=$3}"
|
echo "${ret:=$3}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lua_api() {
|
||||||
|
local func=${1}
|
||||||
|
[ -z "${func}" ] && {
|
||||||
|
echo "nil"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
echo $(lua -e "local api = require 'luci.passwall.api' print(api.${func})")
|
||||||
|
}
|
||||||
|
|
||||||
test_url() {
|
test_url() {
|
||||||
local url=$1
|
local url=$1
|
||||||
local try=1
|
local try=1
|
||||||
@ -74,14 +83,17 @@ url_test_node() {
|
|||||||
fi
|
fi
|
||||||
sleep 1s
|
sleep 1s
|
||||||
# 兼容 curl 8.6 time_starttransfer 错误
|
# 兼容 curl 8.6 time_starttransfer 错误
|
||||||
local curl_ver=$(curl -V 2>/dev/null | head -n 1 | awk '{print $2}' | cut -d. -f1,2 | tr -d ' \n')
|
local _cmd="-V 2>/dev/null | head -n 1 | awk '{print \$2}' | cut -d. -f1,2 | tr -d ' \\n'"
|
||||||
|
local _curl="/usr/bin/curl"
|
||||||
|
local curl_ver=$(lua_api "get_bin_version_cache(\"${_curl}\", \"${_cmd}\")")
|
||||||
|
|
||||||
local curl_arg="-w %{http_code}:%{time_starttransfer} http://"
|
local curl_arg="-w %{http_code}:%{time_starttransfer} http://"
|
||||||
[ "${curl_ver}" = "8.6" ] && curl_arg="-w %{http_code}:%{time_appconnect} https://"
|
[ "${curl_ver}" = "8.6" ] && curl_arg="-w %{http_code}:%{time_appconnect} https://"
|
||||||
|
|
||||||
local chn_list=$(config_n_get @global[0] chn_list direct)
|
local chn_list=$(config_n_get @global[0] chn_list direct)
|
||||||
local probeUrl="www.google.com/generate_204"
|
local probeUrl="www.google.com/generate_204"
|
||||||
[ "${chn_list}" = "proxy" ] && probeUrl="www.baidu.com"
|
[ "${chn_list}" = "proxy" ] && probeUrl="www.baidu.com"
|
||||||
result=$(curl --connect-timeout 3 -o /dev/null -I -skL -x $curlx ${curl_arg}${probeUrl})
|
result=$(${_curl} --connect-timeout 3 -o /dev/null -I -skL -x ${curlx} ${curl_arg}${probeUrl})
|
||||||
pgrep -af "url_test_${node_id}" | awk '! /test\.sh/{print $1}' | xargs kill -9 >/dev/null 2>&1
|
pgrep -af "url_test_${node_id}" | awk '! /test\.sh/{print $1}' | xargs kill -9 >/dev/null 2>&1
|
||||||
rm -rf "/tmp/etc/${CONFIG}/url_test_${node_id}.json"
|
rm -rf "/tmp/etc/${CONFIG}/url_test_${node_id}.json"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user