mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-10-31 20:35:13 +08:00
update 2026-08-10 20:55:22
This commit is contained in:
1 parent
caee61cc80
commit
ea41c17f86
1966 files changed
+1523197
-454
No files matched your search
@@ -111,34 +111,6 @@ for i, v in ipairs(cipherSuites) do
|
||||
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
|
||||
@@ -2023,6 +1995,7 @@ function gen_config(var)
|
||||
else default_dns_flag = "direct"
|
||||
end
|
||||
dns.final = default_dns_flag
|
||||
dns.strategy = default_dns_flag == "remote" and remote_strategy or direct_strategy
|
||||
|
||||
-- DNS in order of shunt
|
||||
if dns_domain_rules and #dns_domain_rules > 0 then
|
||||
@@ -2046,12 +2019,43 @@ function gen_config(var)
|
||||
dns_rule.server = nil
|
||||
end
|
||||
if value.outboundTag == "direct" then
|
||||
dns_rule.strategy = direct_strategy
|
||||
local block_rule
|
||||
if direct_strategy == "ipv4_only" then
|
||||
block_rule = api.clone(dns_rule)
|
||||
block_rule.query_type = { "AAAA" }
|
||||
elseif direct_strategy == "ipv6_only" then
|
||||
block_rule = api.clone(dns_rule)
|
||||
block_rule.query_type = { "A" }
|
||||
end
|
||||
if block_rule then
|
||||
block_rule.action = "predefined"
|
||||
block_rule.rcode = "NOERROR"
|
||||
block_rule.disable_cache = nil
|
||||
block_rule.server = nil
|
||||
table.insert(dns.rules, block_rule)
|
||||
end
|
||||
end
|
||||
if value.outboundTag ~= "block" and value.outboundTag ~= "direct" then
|
||||
dns_rule.server = "remote"
|
||||
dns_rule.rewrite_ttl = 30
|
||||
dns_rule.strategy = remote_strategy
|
||||
if true then
|
||||
local block_rule
|
||||
if remote_strategy == "ipv4_only" then
|
||||
block_rule = api.clone(dns_rule)
|
||||
block_rule.query_type = { "AAAA" }
|
||||
elseif remote_strategy == "ipv6_only" then
|
||||
block_rule = api.clone(dns_rule)
|
||||
block_rule.query_type = { "A" }
|
||||
end
|
||||
if block_rule then
|
||||
block_rule.action = "predefined"
|
||||
block_rule.rcode = "NOERROR"
|
||||
block_rule.disable_cache = nil
|
||||
block_rule.server = nil
|
||||
block_rule.rewrite_ttl = nil
|
||||
table.insert(dns.rules, block_rule)
|
||||
end
|
||||
end
|
||||
dns_rule.client_subnet = remote_dns_client_ip
|
||||
if value.outboundTag ~= COMMON.default_outbound_tag and remote_server.server and remote_dns_detour ~= "direct" then
|
||||
local remote_dns_server = api.clone(remote_server)
|
||||
@@ -2062,9 +2066,13 @@ function gen_config(var)
|
||||
end
|
||||
if value.fakedns then
|
||||
local fakedns_dns_rule = api.clone(dns_rule)
|
||||
fakedns_dns_rule.query_type = {
|
||||
"A", "AAAA"
|
||||
}
|
||||
if remote_strategy == "ipv4_only" then
|
||||
fakedns_dns_rule.query_type = { "A" }
|
||||
elseif remote_strategy == "ipv6_only" then
|
||||
fakedns_dns_rule.query_type = { "AAAA" }
|
||||
else
|
||||
fakedns_dns_rule.query_type = { "A", "AAAA" }
|
||||
end
|
||||
fakedns_dns_rule.server = fakedns_tag
|
||||
fakedns_dns_rule.disable_cache = true
|
||||
fakedns_dns_rule.client_subnet = nil
|
||||
@@ -2076,23 +2084,26 @@ function gen_config(var)
|
||||
end
|
||||
end
|
||||
if default_dns_flag == "remote" then
|
||||
local dns_rule_query_type = { "A", "AAAA" }
|
||||
if remote_strategy == "ipv4_only" then
|
||||
dns_rule_query_type = { "A" }
|
||||
elseif remote_strategy == "ipv6_only" then
|
||||
dns_rule_query_type = { "AAAA" }
|
||||
end
|
||||
if remote_dns_fake then
|
||||
-- When default is not direct and enable fakedns, default DNS use FakeDNS.
|
||||
local fakedns_dns_rule = {
|
||||
query_type = {
|
||||
"A", "AAAA"
|
||||
},
|
||||
query_type = dns_rule_query_type,
|
||||
server = fakedns_tag,
|
||||
disable_cache = true,
|
||||
rewrite_ttl = 30,
|
||||
strategy = remote_strategy,
|
||||
rewrite_ttl = 30
|
||||
}
|
||||
table.insert(dns.rules, fakedns_dns_rule)
|
||||
else
|
||||
local remote_dns_rule = {
|
||||
query_type = dns_rule_query_type,
|
||||
server = "remote",
|
||||
disable_cache = true,
|
||||
strategy = remote_strategy,
|
||||
}
|
||||
table.insert(dns.rules, remote_dns_rule)
|
||||
end
|
||||
@@ -2328,156 +2339,7 @@ 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,
|
||||
})
|
||||
|
||||
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)
|
||||
w = (w or ""):lower()
|
||||
table.insert(node_domain, w)
|
||||
end)
|
||||
if #node_domain > 0 then
|
||||
table.insert(dns.rules, {
|
||||
action = "route",
|
||||
server = "direct",
|
||||
domain = node_domain
|
||||
})
|
||||
end
|
||||
route.default_domain_resolver = {
|
||||
server = "direct",
|
||||
strategy = direct_strategy
|
||||
}
|
||||
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
|
||||
|
||||
|
||||
Reference in new issue
Block a user