update 2026-08-15 04:24:58

This commit is contained in:
action committed 2026-08-15 04:24:58 +08:00
1 parent a59171002f
commit c9ba9e3a54
1983 files changed
+619 -1523517

No files matched your search

@@ -7,23 +7,22 @@ require 'luci.util'
require 'luci.jsonc'
require 'luci.sys'
local api = require "luci.passwall.api"
local appname = api.appname
local c_config = api.c_config
local datatypes = require "luci.cbi.datatypes"
local datatypes = api.datatypes
loadfile("/usr/share/" .. appname .. "/clash_subconverter.lua")()
loadfile("/usr/share/passwall/clash_subconverter.lua")()
local split = api.split
local base64Decode = api.base64Decode
local jsonParse, jsonStringify = api.jsonc.parse, api.jsonc.stringify
local UrlEncode, UrlDecode = api.UrlEncode, api.UrlDecode
local fs = api.fs
local uci, uci_get, uci_set, uci_del, uci_foreach, uci_save = api.uci, api.uci_get_c, api.uci_set_c, api.uci_del_c, api.uci_foreach_c, api.uci_save_c
-- these global functions are accessed all the time by the event handler
-- so caching them is worth the effort
local tinsert = table.insert
local ssub, slen, schar, sbyte, sformat, sgsub = string.sub, string.len, string.char, string.byte, string.format, string.gsub
local split = api.split
local jsonParse, jsonStringify = luci.jsonc.parse, luci.jsonc.stringify
local base64Decode = api.base64Decode
local UrlEncode = api.UrlEncode
local UrlDecode = api.UrlDecode
local uci = api.uci
local fs = api.fs
local has_ss_rust = api.is_finded("sslocal")
local has_ssr = api.is_finded("ssr-local") and api.is_finded("ssr-redir")
@@ -31,9 +30,9 @@ local has_singbox = api.finded_com("sing-box")
local has_xray = api.finded_com("xray")
local has_hysteria2 = api.finded_com("hysteria")
local DEFAULT_ALLOWINSECURE = true
local DEFAULT_FILTER_KEYWORD_MODE = uci:get(c_config, "@global_subscribe[0]", "filter_keyword_mode") or "0"
local DEFAULT_FILTER_KEYWORD_DISCARD_LIST = uci:get(c_config, "@global_subscribe[0]", "filter_discard_list") or {}
local DEFAULT_FILTER_KEYWORD_KEEP_LIST = uci:get(c_config, "@global_subscribe[0]", "filter_keep_list") or {}
local DEFAULT_FILTER_KEYWORD_MODE = uci_get("@global_subscribe[0]", "filter_keyword_mode") or "0"
local DEFAULT_FILTER_KEYWORD_DISCARD_LIST = uci_get("@global_subscribe[0]", "filter_discard_list") or {}
local DEFAULT_FILTER_KEYWORD_KEEP_LIST = uci_get("@global_subscribe[0]", "filter_keep_list") or {}
-- 取节点使用core类型(节点订阅页面未设置时,自动取默认)
local DEFAULT_SS_TYPE = api.get_core("ss_type", {{has_ss_rust,"shadowsocks-rust"},{has_singbox,"sing-box"},{has_xray,"xray"}})
local DEFAULT_TROJAN_TYPE = api.get_core("trojan_type", {{has_singbox,"sing-box"},{has_xray,"xray"}})
@@ -142,13 +141,13 @@ do
local szType = "@global[0]"
local option = protocol .. "_node"
local node_id = uci:get(c_config, szType, option)
local node_id = uci_get(szType, option)
CONFIG[#CONFIG + 1] = {
log = true,
remarks = name .. "节点",
currentNode = node_id and uci:get_all(c_config, node_id) or nil,
currentNode = node_id and uci_get(node_id) or nil,
set = function(o, server)
uci:set(c_config, szType, option, server)
uci_set(szType, option, server)
o.newNodeId = server
end
}
@@ -159,7 +158,7 @@ do
if true then
local i = 0
local option = "node"
uci:foreach(c_config, "socks", function(t)
uci_foreach("socks", function(t)
i = i + 1
local id = t[".name"]
local node_id = t[option]
@@ -167,14 +166,14 @@ do
log = true,
id = id,
remarks = "Socks节点列表[" .. i .. "]",
currentNode = node_id and uci:get_all(c_config, node_id) or nil,
currentNode = node_id and uci_get(node_id) or nil,
set = function(o, server)
if not server or server == "" then
if #nodes_table > 0 then
server = nodes_table[1][".name"]
end
end
uci:set(c_config, t[".name"], option, server)
uci_set(t[".name"], option, server)
o.newNodeId = server
end
}
@@ -184,7 +183,7 @@ do
local newNodes = {}
for k, asb_node_id in ipairs(t.autoswitch_backup_node) do
if asb_node_id then
local currentNode = uci:get_all(c_config, asb_node_id) or {}
local currentNode = uci_get(asb_node_id) or {}
if currentNode[".type"] == "nodes" then
currentNodes[#currentNodes + 1] = {
log = true,
@@ -206,7 +205,7 @@ do
set = function(o, newNodes)
if o then
if not newNodes then newNodes = o.newNodes end
uci:set_list(c_config, id, "autoswitch_backup_node", newNodes or {})
uci_set(id, "autoswitch_backup_node", newNodes or {})
end
end
}
@@ -222,25 +221,25 @@ do
local ip, port = str:match("^([%d%.]+):(%d+)$")
return ip and datatypes.ipaddr(ip) and tonumber(port) and tonumber(port) <= 65535
end
uci:foreach(c_config, "haproxy_config", function(t)
uci_foreach("haproxy_config", function(t)
i = i + 1
local node_id = t[option]
CONFIG[#CONFIG + 1] = {
log = true,
id = t[".name"],
remarks = "HAProxy负载均衡节点列表[" .. i .. "]",
currentNode = node_id and uci:get_all(c_config, node_id) or nil,
currentNode = node_id and uci_get(node_id) or nil,
set = function(o, server)
-- 如果当前 lbss 值不是 ip:port 格式,才进行修改
if not is_ip_port(t[option]) then
uci:set(c_config, t[".name"], option, server)
uci_set(t[".name"], option, server)
o.newNodeId = server
end
end,
delete = function(o)
-- 如果当前 lbss 值不是 ip:port 格式,才进行删除
if not is_ip_port(t[option]) then
uci:delete(c_config, t[".name"])
uci_del(t[".name"])
end
end
}
@@ -250,7 +249,7 @@ do
if true then
local i = 0
local options = {"tcp", "udp"}
uci:foreach(c_config, "acl_rule", function(t)
uci_foreach("acl_rule", function(t)
i = i + 1
for index, value in ipairs(options) do
local option = value .. "_node"
@@ -259,9 +258,9 @@ do
log = true,
id = t[".name"],
remarks = "访问控制列表[" .. i .. "]",
currentNode = node_id and uci:get_all(c_config, node_id) or nil,
currentNode = node_id and uci_get(node_id) or nil,
set = function(o, server)
uci:set(c_config, t[".name"], option, server)
uci_set(t[".name"], option, server)
o.newNodeId = server
end
}
@@ -269,11 +268,11 @@ do
end)
end
uci:foreach(c_config, "nodes", function(node)
uci_foreach("nodes", function(node)
local node_id = node[".name"]
if node.protocol and node.protocol == '_shunt' then
local rules = {}
uci:foreach(c_config, "shunt_rules", function(e)
uci_foreach("shunt_rules", function(e)
if e[".name"] and e.remarks then
table.insert(rules, e)
table.insert(rules, {
@@ -294,7 +293,7 @@ do
for k, e in pairs(rules) do
local _node_id = node[e[".name"]] or nil
if _node_id then
local section = uci:get_all(c_config, _node_id) or {}
local section = uci_get(_node_id) or {}
if section[".type"] == "nodes" then
CONFIG[#CONFIG + 1] = {
log = false,
@@ -302,7 +301,7 @@ do
remarks = "分流" .. e.remarks .. "节点",
set = function(o, server)
if not server then server = "" end
uci:set(c_config, node_id, e[".name"], server)
uci_set(node_id, e[".name"], server)
o.newNodeId = server
end
}
@@ -319,7 +318,7 @@ do
log = true,
node = b_node_id,
currentNode = (function()
local section = uci:get_all(c_config, b_node_id) or {}
local section = uci_get(b_node_id) or {}
if section[".type"] == "socks" then
return { Socks = b_node_id }
end
@@ -341,15 +340,15 @@ do
set = function(o, newNodes)
if o then
if not newNodes then newNodes = o.newNodes end
uci:set_list(c_config, node_id, "balancing_node", newNodes or {})
uci_set(node_id, "balancing_node", newNodes or {})
end
end
}
--后备节点
local currentNode = uci:get_all(c_config, node_id) or nil
local currentNode = uci_get(node_id) or nil
if currentNode and currentNode.fallback_node then
local section = uci:get_all(c_config, currentNode.fallback_node) or {}
local section = uci_get(currentNode.fallback_node) or {}
if section[".type"] == "nodes" then
CONFIG[#CONFIG + 1] = {
log = true,
@@ -357,11 +356,11 @@ do
remarks = "Xray负载均衡节点[" .. node_id .. "]后备节点",
currentNode = section,
set = function(o, server)
uci:set(c_config, node_id, "fallback_node", server)
uci_set(node_id, "fallback_node", server)
o.newNodeId = server
end,
delete = function(o)
uci:delete(c_config, node_id, "fallback_node")
uci_del(node_id, "fallback_node")
end
}
end
@@ -376,7 +375,7 @@ do
log = true,
node = u_node_id,
currentNode = (function()
local section = uci:get_all(c_config, u_node_id) or {}
local section = uci_get(u_node_id) or {}
if section[".type"] == "socks" then
return { Socks = u_node_id }
end
@@ -398,47 +397,47 @@ do
set = function(o, newNodes)
if o then
if not newNodes then newNodes = o.newNodes end
uci:set_list(c_config, node_id, "urltest_node", newNodes or {})
uci_set(node_id, "urltest_node", newNodes or {})
end
end
}
else
--前置代理节点
local currentNode = uci:get_all(c_config, node_id) or nil
local currentNode = uci_get(node_id) or nil
if currentNode and currentNode.preproxy_node then
local section = uci:get_all(c_config, currentNode.preproxy_node) or {}
local section = uci_get(currentNode.preproxy_node) or {}
if section[".type"] == "nodes" then
CONFIG[#CONFIG + 1] = {
log = true,
id = node_id,
remarks = "节点[" .. node_id .. "]前置代理节点",
currentNode = uci:get_all(c_config, currentNode.preproxy_node) or nil,
currentNode = uci_get(currentNode.preproxy_node) or nil,
set = function(o, server)
uci:set(c_config, node_id, "preproxy_node", server)
uci_set(node_id, "preproxy_node", server)
o.newNodeId = server
end,
delete = function(o)
uci:delete(c_config, node_id, "preproxy_node")
uci_del(node_id, "preproxy_node")
end
}
end
end
--落地节点
local currentNode = uci:get_all(c_config, node_id) or nil
local currentNode = uci_get(node_id) or nil
if currentNode and currentNode.to_node then
local section = uci:get_all(c_config, currentNode.to_node) or {}
local section = uci_get(currentNode.to_node) or {}
if section[".type"] == "nodes" then
CONFIG[#CONFIG + 1] = {
log = true,
id = node_id,
remarks = "节点[" .. node_id .. "]落地节点",
currentNode = uci:get_all(c_config, currentNode.to_node) or nil,
currentNode = uci_get(currentNode.to_node) or nil,
set = function(o, server)
uci:set(c_config, node_id, "to_node", server)
uci_set(node_id, "to_node", server)
o.newNodeId = server
end,
delete = function(o)
uci:delete(c_config, node_id, "to_node")
uci_del(node_id, "to_node")
end
}
end
@@ -1757,19 +1756,19 @@ local function truncate_nodes(group)
end
end
end
uci:foreach(c_config, "nodes", function(node)
uci_foreach("nodes", function(node)
if node.add_mode == "2" then
if (not group) or (group:lower() == (node.group or ""):lower()) then
uci:delete(c_config, node['.name'])
uci_del(node['.name'])
end
end
end)
uci:foreach(c_config, "subscribe_list", function(o)
uci_foreach("subscribe_list", function(o)
if (not group) or (group:lower() == (o.remark or ""):lower()) then
uci:delete(c_config, o['.name'], "md5")
uci_del(o['.name'], "md5")
end
end)
api.uci_save(uci, c_config, true)
uci_save(true)
end
local function select_node(nodes, config, parentConfig)
@@ -1908,10 +1907,10 @@ local function update_node(manual)
end
if manual == 0 and next(group) then
uci:foreach(c_config, "nodes", function(node)
uci_foreach("nodes", function(node)
-- 如果未发现新节点或手动导入的节点就不要删除了...
if node.add_mode == "2" and (node.group and group[node.group:lower()] == true) then
uci:delete(c_config, node['.name'])
uci_del(node['.name'])
end
end)
end
@@ -1924,9 +1923,9 @@ local function update_node(manual)
-- Subscription Group Chain Agent
local function valid_chain_node(node)
if not node then return "" end
local cp = uci:get(c_config, node, "chain_proxy") or ""
local am = uci:get(c_config, node, "add_mode") or "0"
chain_node_type = (cp == "" and am ~= "2") and (uci:get(c_config, node, "type") or "") or ""
local cp = uci_get(node, "chain_proxy") or ""
local am = uci_get(node, "add_mode") or "0"
chain_node_type = (cp == "" and am ~= "2") and (uci_get(node, "type") or "") or ""
if chain_node_type ~= "Xray" and chain_node_type ~= "sing-box" then
chain_node_type = ""
return ""
@@ -1948,19 +1947,19 @@ local function update_node(manual)
local cfgid = uci:section(c_config, "nodes", api.gen_random_char())
for kkk, vvv in pairs(vv) do
if type(vvv) == "table" and next(vvv) ~= nil then
uci:set_list(c_config, cfgid, kkk, vvv)
uci_set(cfgid, kkk, vvv)
else
if kkk ~= "group" or vvv ~= "default" then
uci:set(c_config, cfgid, kkk, vvv)
uci_set(cfgid, kkk, vvv)
end
-- sing-box/xray 节点域名解析
if kkk == "type" and (vvv == "Xray" or vvv == "sing-box") then
if domain_resolver then
uci:set(c_config, cfgid, "domain_resolver", domain_resolver)
uci_set(cfgid, "domain_resolver", domain_resolver)
if domain_resolver_dns then
uci:set(c_config, cfgid, "domain_resolver_dns", domain_resolver_dns)
uci_set(cfgid, "domain_resolver_dns", domain_resolver_dns)
elseif domain_resolver_dns_https then
uci:set(c_config, cfgid, "domain_resolver_dns_https", domain_resolver_dns_https)
uci_set(cfgid, "domain_resolver_dns_https", domain_resolver_dns_https)
end
end
if domain_strategy then
@@ -1969,20 +1968,20 @@ local function update_node(manual)
local map = { UseIPv4v6 = "prefer_ipv4", UseIPv6v4 = "prefer_ipv6", UseIPv4 = "ipv4_only", UseIPv6 = "ipv6_only" }
ds = map[ds] or ""
end
uci:set(c_config, cfgid, "domain_strategy", ds)
uci_set(cfgid, "domain_strategy", ds)
end
end
-- 订阅组链式代理
if chain_node_type ~= "" and kkk == "type" and (vvv == "Xray" or vvv == "sing-box") then
if preproxy_node_group ~="" then
uci:set(c_config, cfgid, "chain_proxy", "1")
uci:set(c_config, cfgid, "preproxy_node", preproxy_node_group)
uci_set(cfgid, "chain_proxy", "1")
uci_set(cfgid, "preproxy_node", preproxy_node_group)
elseif to_node_group ~= "" then
uci:set(c_config, cfgid, "chain_proxy", "2")
uci:set(c_config, cfgid, "to_node", to_node_group)
uci_set(cfgid, "chain_proxy", "2")
uci_set(cfgid, "to_node", to_node_group)
elseif outbound_iface_group ~= "" then
uci:set(c_config, cfgid, "chain_proxy", "3")
uci:set(c_config, cfgid, "outbound_iface", outbound_iface_group)
uci_set(cfgid, "chain_proxy", "3")
uci_set(cfgid, "outbound_iface", outbound_iface_group)
end
end
end
@@ -1993,16 +1992,16 @@ local function update_node(manual)
for cfgid, info in pairs(subscribe_info) do
for key, value in pairs(info) do
if value ~= "" then
uci:set(c_config, cfgid, key, value)
uci_set(cfgid, key, value)
else
uci:delete(c_config, cfgid, key)
uci_del(cfgid, key)
end
end
end
if next(CONFIG) then
local nodes = {}
uci:foreach(c_config, "nodes", function(node)
uci_foreach("nodes", function(node)
nodes[#nodes + 1] = node
end)
@@ -2021,16 +2020,16 @@ local function update_node(manual)
end
end
api.uci_save(uci, c_config, true)
uci_save(true)
if arg[3] == "cron" then
if not fs.access("/var/lock/" .. c_config .. ".lock") then
luci.sys.call("touch /tmp/lock/" .. c_config .. "_cron.lock")
if not fs.access(api.LOCK_PREFIX .. ".lock") then
luci.sys.call("touch %s_cron.lock" % api.LOCK_PREFIX)
end
end
if manual ~= 1 then
luci.sys.call("/etc/init.d/" .. appname .. " restart > /dev/null 2>&1 &")
luci.sys.call("/etc/init.d/passwall restart > /dev/null 2>&1 &")
end
end
@@ -2134,10 +2133,10 @@ local execute = function()
local fail_list = {}
if arg[2] ~= "all" then
string.gsub(arg[2], '[^' .. "," .. ']+', function(w)
subscribe_list[#subscribe_list + 1] = uci:get_all(c_config, w) or {}
subscribe_list[#subscribe_list + 1] = uci_get(w) or {}
end)
else
uci:foreach(c_config, "subscribe_list", function(o)
uci_foreach("subscribe_list", function(o)
subscribe_list[#subscribe_list + 1] = o
end)
end
@@ -2183,7 +2182,7 @@ local execute = function()
raw_data = parseClashNode(raw_data)
subscribe_info[cfgid] = parse_clash_sub_info(headers)
parse_link(raw_data, "2", remark, value)
uci:set(c_config, cfgid, "md5", new_md5)
uci_set(cfgid, "md5", new_md5)
end
else
fail_list[#fail_list + 1] = value
@@ -2206,8 +2205,8 @@ local execute = function()
end
local function check_instance(action)
local sub_lock = "/var/lock/" .. appname .. "_subscribe.lock"
local rule_lock = "/var/lock/" .. appname .. "_rule_update.lock"
local sub_lock = api.LOCK_PREFIX .. "_subscribe.lock"
local rule_lock = api.LOCK_PREFIX .. "_rule_update.lock"
if action == "start" then
math.randomseed(os.time() + math.floor(os.clock() * 1000))