mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-16 21:43:33 +08:00
🎄 Sync 2026-08-10 20:58:00
This commit is contained in:
1 parent
f93918f4ae
commit
e68eb29c6f
37 files changed
+318
-551
No files matched your search
@@ -51,35 +51,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 = {
|
||||
address = str
|
||||
}
|
||||
if _a.protocol == "udp" then
|
||||
result_dns_server.address = _a.hostname
|
||||
end
|
||||
if _a.port then
|
||||
result_dns_server.port = _a.port
|
||||
else
|
||||
if _a.protocol == "https" then
|
||||
result_dns_server.port = 443
|
||||
else
|
||||
result_dns_server.port = 53
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return result_dns_server
|
||||
end
|
||||
|
||||
function gen_outbound(flag, node, tag, proxy_table)
|
||||
local result = nil
|
||||
if node then
|
||||
@@ -2186,157 +2157,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 default_dns_udp_server = var["default_dns_udp_server"]
|
||||
local default_dns_udp_port = var["default_dns_udp_port"]
|
||||
|
||||
local queryStrategy = "UseIP"
|
||||
local dns = {
|
||||
tag = "dns-global-direct",
|
||||
disableCache = false,
|
||||
disableFallback = true,
|
||||
disableFallbackIfMatch = true,
|
||||
queryStrategy = queryStrategy,
|
||||
servers = {}
|
||||
}
|
||||
local inbounds = {}
|
||||
local outbounds = {}
|
||||
local routing = {
|
||||
rules = {}
|
||||
}
|
||||
|
||||
table.insert(outbounds, {
|
||||
tag = "direct",
|
||||
protocol = "freedom",
|
||||
settings = {
|
||||
domainStrategy = queryStrategy
|
||||
},
|
||||
streamSettings = {
|
||||
sockopt = {
|
||||
mark = 255
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if default_dns_udp_server then
|
||||
table.insert(dns.servers, {
|
||||
tag = "default",
|
||||
address = default_dns_udp_server,
|
||||
port = tonumber(default_dns_udp_port) or 53,
|
||||
queryStrategy = queryStrategy,
|
||||
})
|
||||
end
|
||||
|
||||
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
|
||||
dns_server[dns].tag = dns
|
||||
dns_server[dns].queryStrategy = queryStrategy
|
||||
dns_server[dns].address = new_dns_server.address
|
||||
dns_server[dns].port = new_dns_server.port
|
||||
dns_server[dns].finalQuery = true
|
||||
if not dns_server[dns].domains then
|
||||
dns_server[dns].domains = {}
|
||||
end
|
||||
table.insert(dns_server[dns].domains, domain)
|
||||
end
|
||||
end
|
||||
end)
|
||||
for k, v in pairs(dns_server) do
|
||||
table.insert(dns.servers, v)
|
||||
table.insert(routing.rules, {
|
||||
inboundTag = {
|
||||
v.tag
|
||||
},
|
||||
outboundTag = "direct"
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
if direct_dns_udp_server then
|
||||
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, "full:" .. w)
|
||||
end)
|
||||
if #node_domain > 0 then
|
||||
table.insert(dns.servers, {
|
||||
tag = "dns-in-vpslist",
|
||||
address = direct_dns_udp_server,
|
||||
port = tonumber(direct_dns_udp_port) or 53,
|
||||
queryStrategy = queryStrategy,
|
||||
domains = node_domain,
|
||||
finalQuery = true,
|
||||
disableCache = false,
|
||||
serveStale = true,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(inbounds, {
|
||||
tag = "dns-in",
|
||||
listen = "127.0.0.1",
|
||||
port = tonumber(dns_listen_port),
|
||||
protocol = "dokodemo-door",
|
||||
settings = {
|
||||
address = "0.0.0.0",
|
||||
network = "tcp,udp"
|
||||
}
|
||||
})
|
||||
|
||||
table.insert(outbounds, {
|
||||
tag = "dns-out",
|
||||
protocol = "dns",
|
||||
proxySettings = {
|
||||
tag = "direct"
|
||||
},
|
||||
settings = {
|
||||
address = direct_dns_udp_server,
|
||||
port = tonumber(direct_dns_udp_port) or 53,
|
||||
network = "udp",
|
||||
nonIPQuery = "skip",
|
||||
blockTypes = {
|
||||
65
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
table.insert(routing.rules, {
|
||||
inboundTag = {
|
||||
"dns-in"
|
||||
},
|
||||
outboundTag = "dns-out"
|
||||
})
|
||||
|
||||
local config = {
|
||||
log = {
|
||||
dnsLog = true,
|
||||
loglevel = "debug"
|
||||
},
|
||||
dns = dns,
|
||||
inbounds = inbounds,
|
||||
outbounds = outbounds,
|
||||
routing = routing
|
||||
}
|
||||
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
|
||||
|
||||
if arg[1] then
|
||||
|
||||
Reference in new issue
Block a user