🌴 Sync 2026-10-12 12:02:15

This commit is contained in:
github-actions[bot] committed 2026-10-12 12:02:15 +08:00
1 parent 1b64546588
commit 887e5ac8e3
261 files changed
+52646 -35012

No files matched your search

@@ -9,60 +9,104 @@ local json = require "luci.jsonc"
local datatype = require "luci.cbi.datatypes"
local addr = arg[1]
if addr and not (datatype.hostname(addr) or datatype.ipaddr(addr)) then
os.exit(0)
end
local function fetch_connections(ip, port, passwd)
local raw = luci.sys.exec(string.format('curl -sL -m 3 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XGET http://"%s":"%s"/connections', passwd, ip, port))
if not raw or raw == "" then
return nil
end
return json.parse(raw)
end
local function print_connection(c)
print("id: "..(c.id))
print("start: "..(c.start))
print("download: "..fs.filesize(c.download))
print("upload: "..fs.filesize(c.upload))
print("rule: "..(c.rule))
print("rulePayload: "..(c.rulePayload))
print("chains: ")
for o = 1, #(c.chains) do
print(" "..o..": "..(c.chains[o]))
end
print("metadata: ")
print(" sourceIP: "..(c.metadata.sourceIP))
print(" sourcePort: "..(c.metadata.sourcePort))
print(" host: "..(c.metadata.host == "" and "Empty" or c.metadata.host))
print(" destinationIP: "..(c.metadata.destinationIP))
print(" destinationPort: "..(c.metadata.destinationPort))
print(" network: "..(c.metadata.network))
print(" type: "..(c.metadata.type))
print("")
end
local function scan_connections(ip, port, passwd)
local info = fetch_connections(ip, port, passwd)
if not info then
return false
end
local found = false
for i = 1, #(info.connections) do
local c = info.connections[i]
local host = (c.metadata.host == "" and "Empty" or c.metadata.host)
if (datatype.hostname(addr) and string.lower(addr) == host) or (datatype.ipaddr(addr) and addr == c.metadata.destinationIP) then
found = true
print_connection(c)
end
end
return found
end
local function dump_connections(info)
local conn_lines = {}
for i = 1, #(info.connections) do
local c = info.connections[i]
local host = (c.metadata.host == "" and "Empty" or c.metadata.host)
conn_lines[#conn_lines + 1] = string.format("%d. SourceIP:【%s】 - Host:【%s】 - DestinationIP:【%s】 - Network:【%s】 - RulePayload:【%s】 - Lastchain:【%s】\n",
i,
tostring(c.metadata.sourceIP),
tostring(host),
tostring(c.metadata.destinationIP),
tostring(c.metadata.network),
tostring(c.rulePayload),
tostring(c.chains and c.chains[1]))
end
if #conn_lines > 0 then
local existing = fs.readfile("/tmp/openclash_debug.log") or ""
fs.writefile("/tmp/openclash_debug.log", existing .. table.concat(conn_lines))
end
end
local function debug_getcon()
local info, ip, host, diag_info
ip = fs.lanip()
local ip = fs.lanip(true)
local port = fs.uci_get_config("config", "cn_port")
local passwd = fs.uci_get_config("config", "dashboard_password") or ""
if ip and port then
info = luci.sys.exec(string.format('curl -sL -m 3 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XGET http://"%s":"%s"/connections', passwd, ip, port))
if not ip or not port then
os.exit(0)
end
if not addr then
local info = fetch_connections(ip, port, passwd)
if info then
info = json.parse(info)
dump_connections(info)
end
if info then
local conn_lines = {}
for i = 1, #(info.connections) do
if info.connections[i].metadata.host == "" then
host = "Empty"
else
host = info.connections[i].metadata.host
end
if not addr then
conn_lines[#conn_lines + 1] = string.format("%d. SourceIP:【%s】 - Host:【%s】 - DestinationIP:【%s】 - Network:【%s】 - RulePayload:【%s】 - Lastchain:【%s】\n",
i,
tostring(info.connections[i].metadata.sourceIP),
tostring(host),
tostring(info.connections[i].metadata.destinationIP),
tostring(info.connections[i].metadata.network),
tostring(info.connections[i].rulePayload),
tostring(info.connections[i].chains and info.connections[i].chains[1]))
else
if datatype.hostname(addr) and string.lower(addr) == host or datatype.ipaddr(addr) and addr == (info.connections[i].metadata.destinationIP) then
print("id: "..(info.connections[i].id))
print("start: "..(info.connections[i].start))
print("download: "..fs.filesize(info.connections[i].download))
print("upload: "..fs.filesize(info.connections[i].upload))
print("rule: "..(info.connections[i].rule))
print("rulePayload: "..(info.connections[i].rulePayload))
print("chains: ")
for o = 1, #(info.connections[i].chains) do
print(" "..o..": "..(info.connections[i].chains[o]))
end
print("metadata: ")
print(" sourceIP: "..(info.connections[i].metadata.sourceIP))
print(" sourcePort: "..(info.connections[i].metadata.sourcePort))
print(" host: "..host)
print(" destinationIP: "..(info.connections[i].metadata.destinationIP))
print(" destinationPort: "..(info.connections[i].metadata.destinationPort))
print(" network: "..(info.connections[i].metadata.network))
print(" type: "..(info.connections[i].metadata.type))
print("")
end
end
end
if not addr and #conn_lines > 0 then
local existing = fs.readfile("/tmp/openclash_debug.log") or ""
fs.writefile("/tmp/openclash_debug.log", existing .. table.concat(conn_lines))
os.exit(0)
end
local found = scan_connections(ip, port, passwd)
if not found then
luci.sys.call(string.format('( (sleep 5) | nc %s 443 ) >/dev/null 2>&1 &', addr))
luci.sys.call(string.format('( (sleep 5) | openssl s_client -connect %s:443 -servername %s -quiet -no_ign_eof ) >/dev/null 2>&1 &', addr, addr))
local deadline = os.time() + 5
local polls = 0
while os.time() < deadline and not found and polls < 5 do
polls = polls + 1
found = scan_connections(ip, port, passwd)
if not found and polls < 5 then
luci.sys.call("sleep 1")
end
end
end