luci-app-passwall: sync upstream

last commit: 3f61880337
This commit is contained in:
gitea-action 2024-11-16 17:30:20 +08:00
parent a924744ac1
commit 8f0ae46d96
2 changed files with 96 additions and 90 deletions

View File

@ -22,30 +22,23 @@ function gen_outbound(flag, node, tag, proxy_table)
local result = nil local result = nil
if node and node ~= "nil" then if node and node ~= "nil" then
local node_id = node[".name"] local node_id = node[".name"]
if tag == nil then local node_remarks = node.remarks
tag = node_id
end
local proxy = 0 local proxy_tag = nil
local proxy_tag = "nil"
if proxy_table ~= nil and type(proxy_table) == "table" then if proxy_table ~= nil and type(proxy_table) == "table" then
proxy = proxy_table.proxy or 0 proxy_tag = proxy_table.tag or nil
proxy_tag = proxy_table.tag or "nil"
end
if node.type == "sing-box" then
proxy = 0
if proxy_tag ~= "nil" then
node.detour = proxy_tag
end
end end
if node.type ~= "sing-box" then if node.type ~= "sing-box" then
local config_tag = tag
if config_tag == nil then
config_tag = node_id
end
local relay_port = node.port local relay_port = node.port
new_port = get_new_port() new_port = get_new_port()
local config_file = string.format("%s_%s_%s.json", flag, tag, new_port) local config_file = string.format("%s_%s_%s.json", flag, config_tag, new_port)
if tag and node_id and tag ~= node_id then if config_tag and node_id and config_tag ~= node_id then
config_file = string.format("%s_%s_%s_%s.json", flag, tag, node_id, new_port) config_file = string.format("%s_%s_%s_%s.json", flag, config_tag, node_id, new_port)
end end
sys.call(string.format('/usr/share/%s/app.sh run_socks "%s"> /dev/null', sys.call(string.format('/usr/share/%s/app.sh run_socks "%s"> /dev/null',
appname, appname,
@ -55,7 +48,7 @@ function gen_outbound(flag, node, tag, proxy_table)
"127.0.0.1", --bind "127.0.0.1", --bind
new_port, --socks port new_port, --socks port
config_file, --config file config_file, --config file
(proxy == 1 and relay_port) and tostring(relay_port) or "" --relay port (proxy_tag and proxy_tag ~= "nil" and relay_port) and tostring(relay_port) or "" --relay port
) )
) )
) )
@ -64,11 +57,19 @@ function gen_outbound(flag, node, tag, proxy_table)
address = "127.0.0.1", address = "127.0.0.1",
port = new_port port = new_port
} }
else
if proxy_tag and proxy_tag ~= "nil" then
node.detour = proxy_tag
end
end
if tag == nil then
tag = node_id .. "_" .. node_remarks
end end
result = { result = {
_flag_tag = node_id, _id = node_id,
_flag_proxy = proxy, _flag = flag,
_flag_proxy_tag = proxy_tag, _flag_proxy_tag = proxy_tag,
tag = tag, tag = tag,
type = node.protocol, type = node.protocol,
@ -778,6 +779,7 @@ function gen_config(var)
local dns = nil local dns = nil
local inbounds = {} local inbounds = {}
local outbounds = {} local outbounds = {}
local COMMON = {}
local singbox_settings = uci:get_all(appname, "@global_singbox[0]") or {} local singbox_settings = uci:get_all(appname, "@global_singbox[0]") or {}
@ -797,7 +799,6 @@ function gen_config(var)
local experimental = nil local experimental = nil
local default_outTag = nil
if node_id then if node_id then
local node = uci:get_all(appname, node_id) local node = uci:get_all(appname, node_id)
if node then if node then
@ -1000,7 +1001,7 @@ function gen_config(var)
local proxy = preproxy_enabled and node[rule_name .. "_proxy_tag"] == preproxy_tag and _node_id ~= preproxy_node_id local proxy = preproxy_enabled and node[rule_name .. "_proxy_tag"] == preproxy_tag and _node_id ~= preproxy_node_id
local copied_outbound local copied_outbound
for index, value in ipairs(outbounds) do for index, value in ipairs(outbounds) do
if value["_flag_tag"] == _node_id and value["_flag_proxy_tag"] == preproxy_tag then if value["_id"] == _node_id and value["_flag_proxy_tag"] == preproxy_tag then
copied_outbound = api.clone(value) copied_outbound = api.clone(value)
break break
end end
@ -1036,23 +1037,23 @@ function gen_config(var)
}) })
end end
end end
local _outbound = gen_outbound(flag, _node, rule_name, { proxy = proxy and 1 or 0, tag = proxy and preproxy_tag or nil }) local outbound_tag = rule_name .. ":" .. _node.remarks
local _outbound = gen_outbound(flag, _node, outbound_tag, { tag = proxy and preproxy_tag or nil })
if _outbound then if _outbound then
set_outbound_detour(_node, _outbound, outbounds, rule_name) rule_outboundTag = set_outbound_detour(_node, _outbound, outbounds, outbound_tag)
table.insert(outbounds, _outbound) table.insert(outbounds, _outbound)
rule_outboundTag = rule_name
end end
end end
elseif _node.protocol == "_iface" then elseif _node.protocol == "_iface" then
if _node.iface then if _node.iface then
local _outbound = { local _outbound = {
type = "direct", type = "direct",
tag = rule_name, tag = rule_name .. ":" .. _node.remarks,
bind_interface = _node.iface, bind_interface = _node.iface,
routing_mark = 255, routing_mark = 255,
} }
table.insert(outbounds, _outbound) table.insert(outbounds, _outbound)
rule_outboundTag = rule_name rule_outboundTag = _outbound.tag
sys.call("touch /tmp/etc/passwall/iface/" .. _node.iface) sys.call("touch /tmp/etc/passwall/iface/" .. _node.iface)
end end
end end
@ -1211,8 +1212,7 @@ function gen_config(var)
end) end)
if default_outboundTag then if default_outboundTag then
route.final = default_outboundTag COMMON.default_outbound_tag = default_outboundTag
default_outTag = default_outboundTag
end end
for index, value in ipairs(rules) do for index, value in ipairs(rules) do
@ -1222,25 +1222,27 @@ function gen_config(var)
if node.iface then if node.iface then
local outbound = { local outbound = {
type = "direct", type = "direct",
tag = node_id, tag = node.remarks or node_id,
bind_interface = node.iface, bind_interface = node.iface,
routing_mark = 255, routing_mark = 255,
} }
table.insert(outbounds, outbound) table.insert(outbounds, outbound)
default_outTag = outbound.tag COMMON.default_outbound_tag = outbound.tag
route.final = default_outTag
sys.call("touch /tmp/etc/passwall/iface/" .. node.iface) sys.call("touch /tmp/etc/passwall/iface/" .. node.iface)
end end
else else
local outbound = gen_outbound(flag, node) local outbound = gen_outbound(flag, node)
if outbound then if outbound then
default_outTag = set_outbound_detour(node, outbound, outbounds) COMMON.default_outbound_tag = set_outbound_detour(node, outbound, outbounds)
table.insert(outbounds, outbound) table.insert(outbounds, outbound)
route.final = default_outTag
end end
end end
end end
if COMMON.default_outbound_tag then
route.final = COMMON.default_outbound_tag
end
if dns_listen_port then if dns_listen_port then
dns = { dns = {
servers = {}, servers = {},
@ -1265,6 +1267,8 @@ function gen_config(var)
server = dns_socks_address, server = dns_socks_address,
server_port = tonumber(dns_socks_port) server_port = tonumber(dns_socks_port)
}) })
else
default_outTag = COMMON.default_outbound_tag
end end
local remote_strategy = "prefer_ipv6" local remote_strategy = "prefer_ipv6"
@ -1406,7 +1410,7 @@ function gen_config(var)
} }
if value.outboundTag ~= "block" and value.outboundTag ~= "direct" then if value.outboundTag ~= "block" and value.outboundTag ~= "direct" then
dns_rule.server = "remote" dns_rule.server = "remote"
if value.outboundTag ~= "default" and remote_server.address then if value.outboundTag ~= COMMON.default_outbound_tag and remote_server.address then
local remote_dns_server = api.clone(remote_server) local remote_dns_server = api.clone(remote_server)
remote_dns_server.tag = value.outboundTag remote_dns_server.tag = value.outboundTag
remote_dns_server.detour = value.outboundTag remote_dns_server.detour = value.outboundTag

View File

@ -50,44 +50,31 @@ function gen_outbound(flag, node, tag, proxy_table)
local result = nil local result = nil
if node and node ~= "nil" then if node and node ~= "nil" then
local node_id = node[".name"] local node_id = node[".name"]
if tag == nil then local node_remarks = node.remarks
tag = node_id
end
local proxy = 0 local proxy_tag = nil
local proxy_tag = "nil"
local fragment = nil local fragment = nil
local noise = nil local noise = nil
if proxy_table ~= nil and type(proxy_table) == "table" then if proxy_table ~= nil and type(proxy_table) == "table" then
proxy = proxy_table.proxy or 0 proxy_tag = proxy_table.tag or nil
proxy_tag = proxy_table.tag or "nil"
fragment = proxy_table.fragment or nil fragment = proxy_table.fragment or nil
noise = proxy_table.noise or nil noise = proxy_table.noise or nil
end end
if node.type == "Xray" then
if node.flow == "xtls-rprx-vision" then
else
proxy = 0
if proxy_tag ~= "nil" then
node.proxySettings = {
tag = proxy_tag,
transportLayer = true
}
end
end
end
if node.type ~= "Xray" then if node.type ~= "Xray" then
if node.type == "Socks" then if node.type == "Socks" then
node.protocol = "socks" node.protocol = "socks"
node.transport = "tcp" node.transport = "tcp"
else else
local config_tag = tag
if config_tag == nil then
config_tag = node_id
end
local relay_port = node.port local relay_port = node.port
new_port = get_new_port() new_port = get_new_port()
local config_file = string.format("%s_%s_%s.json", flag, tag, new_port) local config_file = string.format("%s_%s_%s.json", flag, config_tag, new_port)
if tag and node_id and tag ~= node_id then if config_tag and node_id and config_tag ~= node_id then
config_file = string.format("%s_%s_%s_%s.json", flag, tag, node_id, new_port) config_file = string.format("%s_%s_%s_%s.json", flag, config_tag, node_id, new_port)
end end
sys.call(string.format('/usr/share/%s/app.sh run_socks "%s"> /dev/null', sys.call(string.format('/usr/share/%s/app.sh run_socks "%s"> /dev/null',
appname, appname,
@ -97,7 +84,7 @@ function gen_outbound(flag, node, tag, proxy_table)
"127.0.0.1", --bind "127.0.0.1", --bind
new_port, --socks port new_port, --socks port
config_file, --config file config_file, --config file
(proxy == 1 and relay_port) and tostring(relay_port) or "" --relay port (proxy_tag and proxy_tag ~= "nil" and relay_port) and tostring(relay_port) or "" --relay port
) )
)) ))
node = {} node = {}
@ -107,6 +94,16 @@ function gen_outbound(flag, node, tag, proxy_table)
node.port = new_port node.port = new_port
end end
node.stream_security = "none" node.stream_security = "none"
else
if node.flow == "xtls-rprx-vision" then
else
if proxy_tag and proxy_tag ~= "nil" then
node.proxySettings = {
tag = proxy_tag,
transportLayer = true
}
end
end
end end
if node.type == "Xray" then if node.type == "Xray" then
@ -142,9 +139,13 @@ function gen_outbound(flag, node, tag, proxy_table)
node.wireguard_reserved = #bytes > 0 and bytes or nil node.wireguard_reserved = #bytes > 0 and bytes or nil
end end
if tag == nil then
tag = node_id .. "_" .. node_remarks
end
result = { result = {
_flag_tag = node_id, _id = node_id,
_flag_proxy = proxy, _flag = flag,
_flag_proxy_tag = proxy_tag, _flag_proxy_tag = proxy_tag,
tag = tag, tag = tag,
proxySettings = node.proxySettings or nil, proxySettings = node.proxySettings or nil,
@ -450,7 +451,6 @@ function gen_config_server(node)
domainStrategy = "IPOnDemand", domainStrategy = "IPOnDemand",
rules = { rules = {
{ {
type = "field",
ip = {"10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"}, ip = {"10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"},
outboundTag = (node.accept_lan == nil or node.accept_lan == "0") and "blocked" or "direct" outboundTag = (node.accept_lan == nil or node.accept_lan == "0") and "blocked" or "direct"
} }
@ -641,6 +641,7 @@ function gen_config(var)
local observatory = nil local observatory = nil
local inbounds = {} local inbounds = {}
local outbounds = {} local outbounds = {}
local COMMON = {}
local xray_settings = uci:get_all(appname, "@global_xray[0]") or {} local xray_settings = uci:get_all(appname, "@global_xray[0]") or {}
@ -817,7 +818,7 @@ function gen_config(var)
end end
end end
local inbound_tag = gen_loopback(loopback_tag, loopback_dst) local inbound_tag = gen_loopback(loopback_tag, loopback_dst)
table.insert(rules, { type = "field", inboundTag = { inbound_tag }, balancerTag = balancer_tag }) table.insert(rules, { inboundTag = { inbound_tag }, balancerTag = balancer_tag })
return balancer_tag return balancer_tag
end end
@ -897,7 +898,7 @@ function gen_config(var)
if use_proxy and proxy_balancer_tag and proxy_nodes[_node_id] then use_proxy = false end if use_proxy and proxy_balancer_tag and proxy_nodes[_node_id] then use_proxy = false end
local copied_outbound local copied_outbound
for index, value in ipairs(outbounds) do for index, value in ipairs(outbounds) do
if value["_flag_tag"] == _node_id and value["_flag_proxy_tag"] == (use_proxy and proxy_tag or "nil") then if value["_id"] == _node_id and value["_flag_proxy_tag"] == (use_proxy and proxy_tag or nil) then
copied_outbound = api.clone(value) copied_outbound = api.clone(value)
break break
end end
@ -923,23 +924,23 @@ function gen_config(var)
_node.address = "127.0.0.1" _node.address = "127.0.0.1"
_node.port = new_port _node.port = new_port
table.insert(rules, 1, { table.insert(rules, 1, {
type = "field",
inboundTag = {"proxy_" .. rule_name}, inboundTag = {"proxy_" .. rule_name},
outboundTag = not proxy_balancer_tag and proxy_tag or nil, outboundTag = not proxy_balancer_tag and proxy_tag or nil,
balancerTag = proxy_balancer_tag balancerTag = proxy_balancer_tag
}) })
end end
local proxy_table = { local proxy_table = {
proxy = use_proxy and 1 or 0,
tag = use_proxy and proxy_tag or nil tag = use_proxy and proxy_tag or nil
} }
if xray_settings.fragment == "1" and not proxy_table.tag then if not proxy_table.tag then
proxy_table.fragment = true if xray_settings.fragment == "1" then
proxy_table.fragment = true
end
if xray_settings.noise == "1" then
proxy_table.noise = true
end
end end
if xray_settings.noise == "1" and not proxy_table.tag then local outbound = gen_outbound(flag, _node, rule_name .. ":" .. _node.remarks, proxy_table)
proxy_table.noise = true
end
local outbound = gen_outbound(flag, _node, rule_name, proxy_table)
local outbound_tag local outbound_tag
if outbound then if outbound then
set_outbound_detour(_node, outbound, outbounds, rule_name) set_outbound_detour(_node, outbound, outbounds, rule_name)
@ -997,6 +998,8 @@ function gen_config(var)
--default_node --default_node
local default_node_id = node.default_node or "_direct" local default_node_id = node.default_node or "_direct"
local default_outbound_tag, default_balancer_tag = gen_shunt_node("default", default_node_id) local default_outbound_tag, default_balancer_tag = gen_shunt_node("default", default_node_id)
COMMON.default_outbound_tag = default_outbound_tag
COMMON.default_balancer_tag = default_balancer_tag
--shunt rule --shunt rule
uci:foreach(appname, "shunt_rules", function(e) uci:foreach(appname, "shunt_rules", function(e)
local outbound_tag, balancer_tag = gen_shunt_node(e[".name"]) local outbound_tag, balancer_tag = gen_shunt_node(e[".name"])
@ -1055,8 +1058,7 @@ function gen_config(var)
end) end)
end end
local rule = { local rule = {
_flag = e.remarks, ruleTag = e.remarks,
type = "field",
inboundTag = inbound_tag, inboundTag = inbound_tag,
outboundTag = outbound_tag, outboundTag = outbound_tag,
balancerTag = balancer_tag, balancerTag = balancer_tag,
@ -1068,13 +1070,13 @@ function gen_config(var)
} }
if domains then if domains then
local _rule = api.clone(rule) local _rule = api.clone(rule)
_rule["_flag"] = _rule["_flag"] .. "_domains" _rule.ruleTag = _rule.ruleTag .. " Domains"
_rule.domains = domains _rule.domains = domains
table.insert(rules, _rule) table.insert(rules, _rule)
end end
if ip then if ip then
local _rule = api.clone(rule) local _rule = api.clone(rule)
_rule["_flag"] = _rule["_flag"] .. "_ip" _rule.ruleTag = _rule.ruleTag .. " IP"
_rule.ip = ip _rule.ip = ip
table.insert(rules, _rule) table.insert(rules, _rule)
end end
@ -1087,7 +1089,6 @@ function gen_config(var)
--[[ --[[
if default_outbound_tag or default_balancer_tag then if default_outbound_tag or default_balancer_tag then
table.insert(rules, { table.insert(rules, {
type = "field",
outboundTag = default_outbound_tag, outboundTag = default_outbound_tag,
balancerTag = default_balancer_tag, balancerTag = default_balancer_tag,
network = "tcp,udp" network = "tcp,udp"
@ -1105,18 +1106,19 @@ function gen_config(var)
if node.balancing_node then if node.balancing_node then
local balancer_tag = gen_balancer(node) local balancer_tag = gen_balancer(node)
if balancer_tag then if balancer_tag then
table.insert(rules, { type = "field", network = "tcp,udp", balancerTag = balancer_tag }) table.insert(rules, { network = "tcp,udp", balancerTag = balancer_tag })
end end
routing = { routing = {
balancers = balancers, balancers = balancers,
rules = rules rules = rules
} }
COMMON.default_balancer_tag = balancer_tag
end end
elseif node.protocol == "_iface" then elseif node.protocol == "_iface" then
if node.iface then if node.iface then
local outbound = { local outbound = {
protocol = "freedom", protocol = "freedom",
tag = "outbound", tag = node.remarks or node_id,
streamSettings = { streamSettings = {
sockopt = { sockopt = {
mark = 255, mark = 255,
@ -1125,12 +1127,13 @@ function gen_config(var)
} }
} }
table.insert(outbounds, outbound) table.insert(outbounds, outbound)
COMMON.default_outbound_tag = outbound.tag
sys.call("touch /tmp/etc/passwall/iface/" .. node.iface) sys.call("touch /tmp/etc/passwall/iface/" .. node.iface)
end end
else else
local outbound = gen_outbound(flag, node, nil, { fragment = xray_settings.fragment == "1" or nil, noise = xray_settings.fragment == "1" or nil }) local outbound = gen_outbound(flag, node, nil, { fragment = xray_settings.fragment == "1" or nil, noise = xray_settings.fragment == "1" or nil })
if outbound then if outbound then
set_outbound_detour(node, outbound, outbounds) COMMON.default_outbound_tag = set_outbound_detour(node, outbound, outbounds)
table.insert(outbounds, outbound) table.insert(outbounds, outbound)
end end
routing = { routing = {
@ -1231,12 +1234,8 @@ function gen_config(var)
} }
}) })
else else
if node_id and tcp_redir_port then if COMMON.default_outbound_tag then
dns_outbound_tag = node_id dns_outbound_tag = COMMON.default_outbound_tag
local node = uci:get_all(appname, node_id)
if node.protocol == "_shunt" then
dns_outbound_tag = "default"
end
end end
end end
@ -1268,7 +1267,6 @@ function gen_config(var)
}) })
table.insert(routing.rules, 1, { table.insert(routing.rules, 1, {
type = "field",
inboundTag = { inboundTag = {
"dns-in" "dns-in"
}, },
@ -1276,7 +1274,6 @@ function gen_config(var)
}) })
end end
table.insert(rules, { table.insert(rules, {
type = "field",
inboundTag = { inboundTag = {
"dns-in1" "dns-in1"
}, },
@ -1288,7 +1285,6 @@ function gen_config(var)
}) })
if _remote_dns_host then if _remote_dns_host then
table.insert(rules, { table.insert(rules, {
type = "field",
inboundTag = { inboundTag = {
"dns-in1" "dns-in1"
}, },
@ -1301,7 +1297,6 @@ function gen_config(var)
end end
if remote_dns_doh_ip then if remote_dns_doh_ip then
table.insert(rules, { table.insert(rules, {
type = "field",
inboundTag = { inboundTag = {
"dns-in1" "dns-in1"
}, },
@ -1409,6 +1404,13 @@ function gen_config(var)
protocol = "blackhole", protocol = "blackhole",
tag = "blackhole" tag = "blackhole"
}) })
for index, value in ipairs(config.outbounds) do
for k, v in pairs(config.outbounds[index]) do
if k:find("_") == 1 then
config.outbounds[index][k] = nil
end
end
end
return jsonc.stringify(config, 1) return jsonc.stringify(config, 1)
end end
end end