🎨 Sync 2026-04-10 15:34:26

This commit is contained in:
github-actions[bot] committed 2026-04-10 15:34:26 +08:00
1 parent 9b1a57d792
commit 42174fc0b0
66 files changed
+6841 -2210

No files matched your search

@@ -91,6 +91,34 @@ local function convert_geofile()
convert(GEO_VAR.IP_PATH, "geoip", GEO_VAR.IP_TAGS)
end
function parseDNS(str)
local result_dns_server
-- [proto]://[ip]
-- [proto]://[ip]:[port]
-- https://[ip]/[path]
-- https://[ip]:[port]/[path]
local _a = api.parseURL(str)
if _a then
if _a.protocol == "tcp" or _a.protocol == "udp" or _a.protocol == "https" then
result_dns_server = {
type = _a.protocol,
server = _a.hostname
}
if _a.port then
result_dns_server.server_port = _a.port
else
if _a.protocol == "https" then
result_dns_server.server_port = 443
else
result_dns_server.server_port = 53
end
end
result_dns_server.path = _a.pathname
end
end
return result_dns_server
end
function gen_outbound(flag, node, tag, proxy_table)
local result = nil
if node then
@@ -1754,6 +1782,13 @@ function gen_config(var)
tag = "local"
})
local direct_strategy = "prefer_ipv6"
if direct_dns_query_strategy == "UseIPv4" then
direct_strategy = "ipv4_only"
elseif direct_dns_query_strategy == "UseIPv6" then
direct_strategy = "ipv6_only"
end
if dns_listen_port then
local dns_host = ""
if flag == "global" then
@@ -1891,13 +1926,6 @@ function gen_config(var)
})
end
direct_strategy = "prefer_ipv6"
if direct_dns_query_strategy == "UseIPv4" then
direct_strategy = "ipv4_only"
elseif direct_dns_query_strategy == "UseIPv6" then
direct_strategy = "ipv6_only"
end
local server_port = tonumber(direct_dns_udp_port) or 53
table.insert(dns.servers, {
@@ -2229,7 +2257,155 @@ function gen_proto_config(var)
return jsonc.stringify(config, 1)
end
function gen_front_dns_config(var)
local dns_listen_port = var["dns_listen_port"]
local direct_dns_udp_server = var["direct_dns_udp_server"]
local direct_dns_udp_port = var["direct_dns_udp_port"]
local direct_dns_query_strategy = var["direct_dns_query_strategy"]
local default_dns_udp_server = var["default_dns_udp_server"]
local default_dns_udp_port = var["default_dns_udp_port"]
local dns = {
servers = {},
rules = {}
}
local inbounds = {}
local outbounds = {}
local route = {}
local direct_strategy = "prefer_ipv6"
if direct_dns_query_strategy == "UseIPv4" then
direct_strategy = "ipv4_only"
elseif direct_dns_query_strategy == "UseIPv6" then
direct_strategy = "ipv6_only"
end
table.insert(outbounds, {
type = "direct",
tag = "direct",
routing_mark = 255,
domain_resolver = {
server = "direct",
strategy = direct_strategy
}
})
local direct_dns_shunt = uci:get(appname, "@global[0]", "direct_dns_shunt") or ""
if #direct_dns_shunt > 0 then
local dns_server = {}
string.gsub(direct_dns_shunt, '[^' .. "\r\n" .. ']+', function(w)
if w:find("#") == 1 then return end
local domain = sys.exec(string.format("echo -n $(echo %s | awk -F ' ' '{print $1}')", w))
local dns = sys.exec(string.format("echo -n $(echo %s | awk -F ' ' '{print $2}')", w))
if domain ~= "" and dns ~= "" then
local new_dns_server = parseDNS(dns)
if new_dns_server then
if not dns_server[dns] then
dns_server[dns] = {}
end
if not dns_server[dns].server then
dns_server[dns].server = new_dns_server
dns_server[dns].server.tag = dns
dns_server[dns].server.detour = "direct"
end
if not dns_server[dns].rule then
dns_server[dns].rule = {
action = "route",
server = dns,
domain = {},
domain_suffix = {},
domain_keyword = {}
}
end
if domain:find("full:") == 1 then
table.insert(dns_server[dns].rule.domain, domain:sub(1 + #"full:"))
elseif domain:find("domain:") == 1 then
table.insert(dns_server[dns].rule.domain_suffix, domain:sub(1 + #"domain:"))
else
table.insert(dns_server[dns].rule.domain_keyword, domain)
end
end
end
end)
for k, v in pairs(dns_server) do
table.insert(dns.servers, v.server)
if #v.rule.domain == 0 then v.rule.domain = nil end
if #v.rule.domain_suffix == 0 then v.rule.domain_suffix = nil end
if #v.rule.domain_keyword == 0 then v.rule.domain_keyword = nil end
table.insert(dns.rules, v.rule)
end
end
if direct_dns_udp_server then
table.insert(dns.servers, {
tag = "direct",
type = "udp",
server = direct_dns_udp_server,
server_port = tonumber(direct_dns_udp_port) or 53,
detour = "direct"
})
local node_domain = {}
local nodes_domain_text = sys.exec('uci show passwall2 | grep ".address=" | cut -d "\'" -f 2 | grep "[a-zA-Z]$" | sort -u')
string.gsub(nodes_domain_text, '[^' .. "\r\n" .. ']+', function(w)
table.insert(node_domain, w)
end)
if #node_domain > 0 then
table.insert(dns.rules, {
action = "route",
server = "direct",
domain = node_domain
})
end
end
if default_dns_udp_server then
table.insert(dns.servers, {
tag = "default",
type = "udp",
server = default_dns_udp_server,
server_port = tonumber(default_dns_udp_port) or 53,
detour = "direct"
})
dns.final = "default"
else
dns.final = "direct"
end
local dns_in_inbound = {
type = "direct",
tag = "dns-in",
listen = "127.0.0.1",
listen_port = tonumber(dns_listen_port),
}
table.insert(inbounds, dns_in_inbound)
route.rules = {}
table.insert(route.rules, {
action = "hijack-dns",
inbound = dns_in_inbound.tag
})
table.insert(route.rules, {
action = "sniff",
inbound = dns_in_inbound.tag
})
route.final = "direct"
local config = {
log = {
disabled = true,
level = "debug",
timestamp = true,
},
dns = dns,
inbounds = inbounds,
outbounds = outbounds,
route = route
}
return jsonc.stringify(config, 1)
end
_G.gen_config = gen_config
_G.gen_front_dns_config = gen_front_dns_config
_G.gen_proto_config = gen_proto_config
_G.geo_convert_srs = geo_convert_srs