mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-16 21:43:33 +08:00
🦄 Sync 2026-04-11 02:41:05
This commit is contained in:
1 parent
c6d54c1769
commit
f118665d70
9 files changed
+203
-66
No files matched your search
@@ -12,7 +12,8 @@ local local_version = api.get_app_version("sing-box"):match("[^v]+")
|
||||
local version_ge_1_13_0 = api.compare_versions(local_version, ">=", "1.13.0")
|
||||
|
||||
local GLOBAL = {
|
||||
DNS_SERVER = {}
|
||||
DNS_SERVER = {},
|
||||
VPS_EXCLUDE = {}
|
||||
}
|
||||
|
||||
local GEO_VAR = {
|
||||
@@ -159,7 +160,6 @@ function gen_outbound(flag, node, tag, proxy_table)
|
||||
}
|
||||
|
||||
if api.datatypes.hostname(node.address) and node.domain_resolver and (node.domain_resolver_dns or node.domain_resolver_dns_https) then
|
||||
local dns_tag = node_id .. "_dns"
|
||||
local dns_proto = node.domain_resolver
|
||||
local server_address
|
||||
local server_port
|
||||
@@ -168,12 +168,8 @@ function gen_outbound(flag, node, tag, proxy_table)
|
||||
local _a = api.parseURL(node.domain_resolver_dns_https)
|
||||
if _a then
|
||||
server_address = _a.hostname
|
||||
if _a.port then
|
||||
server_port = _a.port
|
||||
else
|
||||
server_port = 443
|
||||
end
|
||||
server_path = _a.pathname
|
||||
server_port = _a.port or 443
|
||||
server_path = _a.pathname or ""
|
||||
end
|
||||
else
|
||||
server_address = node.domain_resolver_dns
|
||||
@@ -184,19 +180,28 @@ function gen_outbound(flag, node, tag, proxy_table)
|
||||
server_port = tonumber(split[#split])
|
||||
end
|
||||
end
|
||||
GLOBAL.DNS_SERVER[node_id] = {
|
||||
server = {
|
||||
tag = dns_tag,
|
||||
type = dns_proto,
|
||||
server = server_address,
|
||||
server_port = server_port,
|
||||
path = server_path,
|
||||
domain_resolver = "direct",
|
||||
detour = "direct"
|
||||
},
|
||||
domain = node.address
|
||||
}
|
||||
result.domain_resolver.server = dns_tag
|
||||
local dns_key = dns_proto .. "|" .. tostring(server_address) .. "|" .. tostring(server_port) .. "|" .. tostring(server_path or "")
|
||||
if not GLOBAL.DNS_SERVER[dns_key] then
|
||||
GLOBAL.DNS_SERVER[dns_key] = {
|
||||
server = {
|
||||
tag = "dns-node-" .. api.gen_short_uuid(),
|
||||
type = dns_proto,
|
||||
server = server_address,
|
||||
server_port = server_port,
|
||||
path = server_path,
|
||||
domain_resolver = "direct",
|
||||
detour = "direct"
|
||||
},
|
||||
domain = {}
|
||||
}
|
||||
end
|
||||
local exists
|
||||
for _, d in ipairs(GLOBAL.DNS_SERVER[dns_key].domain) do
|
||||
if d == node.address then exists = true; break end
|
||||
end
|
||||
if not exists then table.insert(GLOBAL.DNS_SERVER[dns_key].domain, node.address) end
|
||||
result.domain_resolver.server = GLOBAL.DNS_SERVER[dns_key].server.tag
|
||||
GLOBAL.VPS_EXCLUDE[node.address] = true
|
||||
end
|
||||
|
||||
local tls = nil
|
||||
@@ -1766,12 +1771,8 @@ function gen_config(var)
|
||||
remote_server.type = "h3"
|
||||
end
|
||||
remote_server.server = _a.hostname
|
||||
if _a.port then
|
||||
remote_server.server_port = _a.port
|
||||
else
|
||||
remote_server.server_port = 443
|
||||
end
|
||||
remote_server.path = _a.pathname
|
||||
remote_server.server_port = _a.port or 443
|
||||
remote_server.path = _a.pathname or ""
|
||||
end
|
||||
if remote_dns_doh_ip and remote_dns_doh_host ~= remote_dns_doh_ip and not api.is_ip(remote_dns_doh_host) then
|
||||
local domains = {}
|
||||
@@ -1825,9 +1826,11 @@ function gen_config(var)
|
||||
|
||||
if direct_dns_udp_server or direct_dns_tcp_server then
|
||||
local domain = {}
|
||||
local nodes_domain_text = sys.exec('uci show passwall | grep ".address=" | cut -d "\'" -f 2 | grep "[a-zA-Z]$" | sort -u')
|
||||
local nodes_domain_text = sys.exec([[uci show passwall | sed -n "s/.*\.address='\([^']*\)'/\1/p" | sort -u]])
|
||||
string.gsub(nodes_domain_text, '[^' .. "\r\n" .. ']+', function(w)
|
||||
table.insert(domain, w)
|
||||
if w and w ~= "" and api.datatypes.hostname(w) and not GLOBAL.VPS_EXCLUDE[w] then
|
||||
table.insert(domain, w)
|
||||
end
|
||||
end)
|
||||
if #domain > 0 then
|
||||
table.insert(dns_domain_rules, 1, {
|
||||
@@ -1970,9 +1973,11 @@ function gen_config(var)
|
||||
for i, v in pairs(GLOBAL.DNS_SERVER) do
|
||||
table.insert(dns.servers, v.server)
|
||||
if not dns.rules then dns.rules = {} end
|
||||
table.insert(dns.rules, {
|
||||
table.insert(dns.rules, 1, {
|
||||
action = "route",
|
||||
server = v.server.tag,
|
||||
disable_cache = false,
|
||||
rewrite_ttl = 30,
|
||||
domain = v.domain,
|
||||
})
|
||||
end
|
||||
|
||||
@@ -8,7 +8,8 @@ local fs = api.fs
|
||||
|
||||
local GLOBAL = {
|
||||
DNS_SERVER = {},
|
||||
DNS_HOSTNAME = {}
|
||||
DNS_HOSTNAME = {},
|
||||
VPS_EXCLUDE = {}
|
||||
}
|
||||
|
||||
local xray_version = api.get_app_version("xray")
|
||||
@@ -405,7 +406,6 @@ function gen_outbound(flag, node, tag, proxy_table)
|
||||
end
|
||||
|
||||
if api.datatypes.hostname(node.address) and node.domain_resolver and (node.domain_resolver_dns or node.domain_resolver_dns_https) then
|
||||
local dns_tag = node_id .. "_dns"
|
||||
local dns_proto = node.domain_resolver
|
||||
local config_address
|
||||
local config_port
|
||||
@@ -413,20 +413,14 @@ function gen_outbound(flag, node, tag, proxy_table)
|
||||
local _a = api.parseURL(node.domain_resolver_dns_https)
|
||||
if _a then
|
||||
config_address = node.domain_resolver_dns_https
|
||||
if _a.port then
|
||||
config_port = _a.port
|
||||
else
|
||||
config_port = 443
|
||||
end
|
||||
if _a.hostname then
|
||||
if api.datatypes.hostname(_a.hostname) then
|
||||
GLOBAL.DNS_HOSTNAME[_a.hostname] = true
|
||||
end
|
||||
config_port = _a.port or 443
|
||||
if _a.hostname and api.datatypes.hostname(_a.hostname) then
|
||||
GLOBAL.DNS_HOSTNAME[_a.hostname] = true
|
||||
end
|
||||
end
|
||||
else
|
||||
local server_address = node.domain_resolver_dns
|
||||
local config_port = 53
|
||||
config_port = 53
|
||||
local split = api.split(server_address, ":")
|
||||
if #split > 1 then
|
||||
server_address = split[1]
|
||||
@@ -437,13 +431,27 @@ function gen_outbound(flag, node, tag, proxy_table)
|
||||
config_address = dns_proto .. "://" .. server_address .. ":" .. config_port
|
||||
end
|
||||
end
|
||||
GLOBAL.DNS_SERVER[node_id] = {
|
||||
tag = dns_tag,
|
||||
queryStrategy = node.domain_strategy or "UseIP",
|
||||
address = config_address,
|
||||
port = config_port,
|
||||
domains = {"full:" .. node.address}
|
||||
}
|
||||
local dns_key = dns_proto .. "|" .. config_address .. "|" .. tostring(config_port)
|
||||
if not GLOBAL.DNS_SERVER[dns_key] then
|
||||
GLOBAL.DNS_SERVER[dns_key] = {
|
||||
tag = "dns-node-" .. api.gen_short_uuid(),
|
||||
queryStrategy = node.domain_strategy or "UseIP",
|
||||
address = config_address,
|
||||
port = config_port,
|
||||
finalQuery = true,
|
||||
disableCache = false,
|
||||
serveStale = true,
|
||||
serveExpiredTTL = 30,
|
||||
domains = {}
|
||||
}
|
||||
end
|
||||
local exists
|
||||
local domain = "full:" .. node.address
|
||||
for _, d in ipairs(GLOBAL.DNS_SERVER[dns_key].domains) do
|
||||
if d == domain then exists = true; break end
|
||||
end
|
||||
if not exists then table.insert(GLOBAL.DNS_SERVER[dns_key].domains, domain) end
|
||||
GLOBAL.VPS_EXCLUDE[node.address] = true
|
||||
end
|
||||
end
|
||||
return result
|
||||
@@ -1509,7 +1517,8 @@ function gen_config(var)
|
||||
disableFallbackIfMatch = true,
|
||||
servers = {},
|
||||
clientIp = (remote_dns_client_ip and remote_dns_client_ip ~= "") and remote_dns_client_ip or nil,
|
||||
queryStrategy = "UseIP"
|
||||
queryStrategy = "UseIP",
|
||||
useSystemHosts = true
|
||||
}
|
||||
|
||||
local _direct_dns = {
|
||||
@@ -1521,9 +1530,11 @@ function gen_config(var)
|
||||
|
||||
if direct_dns_udp_server or direct_dns_tcp_server then
|
||||
local domain = {}
|
||||
local nodes_domain_text = sys.exec('uci show passwall | grep ".address=" | cut -d "\'" -f 2 | grep "[a-zA-Z]$" | sort -u')
|
||||
local nodes_domain_text = sys.exec([[uci show passwall | sed -n "s/.*\.\(address\|download_address\)='\([^']*\)'/\2/p" | sort -u]])
|
||||
string.gsub(nodes_domain_text, '[^' .. "\r\n" .. ']+', function(w)
|
||||
table.insert(domain, w)
|
||||
if w and w ~= "" and api.datatypes.hostname(w) and not GLOBAL.VPS_EXCLUDE[w] then
|
||||
table.insert(domain, "full:" .. w)
|
||||
end
|
||||
end)
|
||||
if #domain > 0 then
|
||||
table.insert(dns_domain_rules, 1, {
|
||||
@@ -1763,9 +1774,10 @@ function gen_config(var)
|
||||
if #node_dns > 0 and #dns.servers < 1 then
|
||||
dns.servers = { "localhost" }
|
||||
end
|
||||
local idx = dns_listen_port and 2 or 1
|
||||
for i = #node_dns, 1, -1 do
|
||||
local value = node_dns[i]
|
||||
table.insert(routing.rules, 1, {
|
||||
table.insert(routing.rules, idx, {
|
||||
inboundTag = {
|
||||
value.server.tag
|
||||
},
|
||||
@@ -1784,7 +1796,7 @@ function gen_config(var)
|
||||
queryStrategy = "UseIPv4",
|
||||
domains = hostname
|
||||
})
|
||||
table.insert(routing.rules, 1, {
|
||||
table.insert(routing.rules, idx, {
|
||||
inboundTag = { "bootstrap" },
|
||||
outboundTag = "direct"
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user