update 2026-10-11 00:49:02
marry-jell / merge (push) Canceled after 0s

This commit is contained in:
action committed 2026-10-11 00:49:02 +08:00
1 parent 54d5be6086
commit 7ae707aaa6
8 files changed
+112 -64

No files matched your search

@@ -381,35 +381,36 @@ function connect_status()
local e = {}
e.use_time = ""
local url = http.formvalue("url")
if not url or url == "" then
http_write_json(e)
return
end
local aliyun = string.find(url, "aliyun")
local chn_list = uci_get("@global[0]", "chn_list") or "direct"
local gfw_list = uci_get("@global[0]", "use_gfw_list") or "1"
local proxy_mode = uci_get("@global[0]", "tcp_proxy_mode") or "proxy"
local localhost_proxy = uci_get("@global[0]", "localhost_proxy") or "1"
local socks_server = (localhost_proxy == "0") and api.get_cache_var("GLOBAL_SOCKS_server") or ""
url = "-w %{http_code}:%{time_pretransfer} " .. url
local curl_args = "-w '%{http_code}:%{time_pretransfer}:%{time_starttransfer}' " .. util.shellquote(url)
if socks_server and socks_server ~= "" then
if (chn_list == "proxy" and gfw_list == "0" and proxy_mode ~= "proxy" and aliyun ~= nil) or (chn_list == "0" and gfw_list == "0" and proxy_mode == "proxy") then
-- 中国列表+阿里 or 全局
url = "-x socks5h://" .. socks_server .. " " .. url
curl_args = "-x " .. util.shellquote("socks5h://" .. socks_server) .. " " .. curl_args
elseif aliyun == nil then
-- 其他代理模式+阿里以外网站
url = "-x socks5h://" .. socks_server .. " " .. url
curl_args = "-x " .. util.shellquote("socks5h://" .. socks_server) .. " " .. curl_args
end
end
local result = luci.sys.exec('/usr/bin/curl --connect-timeout 3 --max-time 5 -o /dev/null -I -sk ' .. url)
local code = tonumber(luci.sys.exec("echo -n '" .. result .. "' | awk -F ':' '{print $1}'") or "0")
if code ~= 0 then
local use_time_str = luci.sys.exec("echo -n '" .. result .. "' | awk -F ':' '{print $2}'")
local use_time = tonumber(use_time_str)
if use_time then
if use_time_str:find("%.") then
e.use_time = string.format("%.2f", use_time * 1000)
else
e.use_time = string.format("%.2f", use_time / 1000)
end
e.ping_type = "curl"
end
local result = luci.sys.exec('curl_result=$(/usr/bin/curl --connect-timeout 3 --max-time 5 -o /dev/null -I -sk ' .. curl_args .. '); [ $? -eq 0 ] && printf "%s" "$curl_result"')
local code, pretransfer, starttransfer = result:match("^%s*(%d+):([%d%.]+):([%d%.]+)%s*$")
code, pretransfer, starttransfer = tonumber(code), tonumber(pretransfer), tonumber(starttransfer)
if code and code > 0 then e.http_code = code end
-- A completed HTTP response, including 4xx/5xx, confirms homepage connectivity.
if code and code >= 200 and code < 600 and pretransfer and pretransfer >= 0 and starttransfer and starttransfer > 0 and starttransfer >= pretransfer then
-- HTTP request latency excludes connection and TLS handshakes.
e.use_time = string.format("%.2f", (starttransfer - pretransfer) * 1000)
e.handshake_time = string.format("%.2f", pretransfer * 1000)
e.ping_type = "curl"
end
http_write_json(e)
end
@@ -438,17 +439,13 @@ function urltest_node()
local e = {}
e.index = index
local result = luci.sys.exec("/usr/share/passwall/test.sh url_test_node " .. util.shellquote(id or ""))
local code = tonumber(luci.sys.exec("echo -n '" .. result .. "' | awk -F ':' '{print $1}'") or "0")
if code ~= 0 then
local use_time_str = luci.sys.exec("echo -n '" .. result .. "' | awk -F ':' '{print $2}'")
local use_time = tonumber(use_time_str)
if use_time then
if use_time_str:find("%.") then
e.use_time = string.format("%.2f", use_time * 1000)
else
e.use_time = string.format("%.2f", use_time / 1000)
end
end
local code, pretransfer, starttransfer = result:match("^%s*(%d+):([%d%.]+):([%d%.]+)%s*$")
code, pretransfer, starttransfer = tonumber(code), tonumber(pretransfer), tonumber(starttransfer)
if code and code > 0 then e.http_code = code end
if code and code >= 200 and code < 600 and pretransfer and pretransfer >= 0 and starttransfer and starttransfer > 0 and starttransfer >= pretransfer then
-- Keep node test parsing independent from the homepage test.
e.use_time = string.format("%.2f", (starttransfer - pretransfer) * 1000)
e.handshake_time = string.format("%.2f", pretransfer * 1000)
end
http_write_json(e)
end