parent
0b6acd7dc8
commit
a092986875
@ -5,7 +5,7 @@
|
|||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=luci-app-passwall2
|
PKG_NAME:=luci-app-passwall2
|
||||||
PKG_VERSION:=24.11.13
|
PKG_VERSION:=24.11.17
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=1
|
||||||
|
|
||||||
PKG_CONFIG_DEPENDS:= \
|
PKG_CONFIG_DEPENDS:= \
|
||||||
|
@ -53,7 +53,7 @@ o.rewrite_option = o.option
|
|||||||
o = s:option(Value, option_name("down_mbps"), translate("Max download Mbps"))
|
o = s:option(Value, option_name("down_mbps"), translate("Max download Mbps"))
|
||||||
o.rewrite_option = o.option
|
o.rewrite_option = o.option
|
||||||
|
|
||||||
o = s:option(Value, option_name("hop_interval"), translate("Hop Interval"))
|
o = s:option(Value, option_name("hop_interval"), translate("Hop Interval"), translate("Example:") .. "30s (≥5s)")
|
||||||
o.rewrite_option = o.option
|
o.rewrite_option = o.option
|
||||||
|
|
||||||
o = s:option(Value, option_name("recv_window"), translate("QUIC stream receive window"))
|
o = s:option(Value, option_name("recv_window"), translate("QUIC stream receive window"))
|
||||||
@ -62,7 +62,7 @@ o.rewrite_option = o.option
|
|||||||
o = s:option(Value, option_name("recv_window_conn"), translate("QUIC connection receive window"))
|
o = s:option(Value, option_name("recv_window_conn"), translate("QUIC connection receive window"))
|
||||||
o.rewrite_option = o.option
|
o.rewrite_option = o.option
|
||||||
|
|
||||||
o = s:option(Value, option_name("idle_timeout"), translate("Idle Timeout"))
|
o = s:option(Value, option_name("idle_timeout"), translate("Idle Timeout"), translate("Example:") .. "30s (4s-120s)")
|
||||||
o.rewrite_option = o.option
|
o.rewrite_option = o.option
|
||||||
|
|
||||||
o = s:option(Flag, option_name("disable_mtu_discovery"), translate("Disable MTU detection"))
|
o = s:option(Flag, option_name("disable_mtu_discovery"), translate("Disable MTU detection"))
|
||||||
|
@ -62,7 +62,14 @@ function gen_config(var)
|
|||||||
transport = {
|
transport = {
|
||||||
type = node.protocol or "udp",
|
type = node.protocol or "udp",
|
||||||
udp = {
|
udp = {
|
||||||
hopInterval = node.hysteria2_hop_interval and node.hysteria2_hop_interval .. "s" or "30s"
|
hopInterval = (function()
|
||||||
|
local HopIntervalStr = tostring(node.hysteria2_hop_interval or "30s")
|
||||||
|
local HopInterval = tonumber(HopIntervalStr:match("^%d+"))
|
||||||
|
if HopInterval and HopInterval >= 5 then
|
||||||
|
return tostring(HopInterval) .. "s"
|
||||||
|
end
|
||||||
|
return "30s"
|
||||||
|
end)(),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
obfs = (node.hysteria2_obfs) and {
|
obfs = (node.hysteria2_obfs) and {
|
||||||
@ -80,7 +87,14 @@ function gen_config(var)
|
|||||||
quic = {
|
quic = {
|
||||||
initStreamReceiveWindow = (node.hysteria2_recv_window) and tonumber(node.hysteria2_recv_window) or nil,
|
initStreamReceiveWindow = (node.hysteria2_recv_window) and tonumber(node.hysteria2_recv_window) or nil,
|
||||||
initConnReceiveWindow = (node.hysteria2_recv_window_conn) and tonumber(node.hysteria2_recv_window_conn) or nil,
|
initConnReceiveWindow = (node.hysteria2_recv_window_conn) and tonumber(node.hysteria2_recv_window_conn) or nil,
|
||||||
maxIdleTimeout = (node.hysteria2_idle_timeout) and tonumber(node.hysteria2_idle_timeout) or nil,
|
maxIdleTimeout = (function()
|
||||||
|
local timeoutStr = tostring(node.hysteria2_idle_timeout or "")
|
||||||
|
local timeout = tonumber(timeoutStr:match("^%d+"))
|
||||||
|
if timeout and timeout >= 4 and timeout <= 120 then
|
||||||
|
return tostring(timeout) .. "s"
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end)(),
|
||||||
disablePathMTUDiscovery = (node.hysteria2_disable_mtu_discovery) and true or false,
|
disablePathMTUDiscovery = (node.hysteria2_disable_mtu_discovery) and true or false,
|
||||||
},
|
},
|
||||||
bandwidth = (node.hysteria2_up_mbps or node.hysteria2_down_mbps) and {
|
bandwidth = (node.hysteria2_up_mbps or node.hysteria2_down_mbps) and {
|
||||||
|
@ -27,18 +27,9 @@ function gen_outbound(flag, node, tag, proxy_table)
|
|||||||
tag = node_id
|
tag = node_id
|
||||||
end
|
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
|
||||||
@ -56,7 +47,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
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -65,11 +56,15 @@ 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
|
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,
|
||||||
@ -776,6 +771,7 @@ function gen_config(var)
|
|||||||
local dns = nil
|
local dns = nil
|
||||||
local inbounds = {}
|
local inbounds = {}
|
||||||
local outbounds = {}
|
local outbounds = {}
|
||||||
|
local COMMON = {}
|
||||||
|
|
||||||
local CACHE_TEXT_FILE = CACHE_PATH .. "/cache_" .. flag .. ".txt"
|
local CACHE_TEXT_FILE = CACHE_PATH .. "/cache_" .. flag .. ".txt"
|
||||||
|
|
||||||
@ -866,8 +862,6 @@ function gen_config(var)
|
|||||||
table.insert(inbounds, inbound_tproxy)
|
table.insert(inbounds, inbound_tproxy)
|
||||||
end
|
end
|
||||||
|
|
||||||
local default_outTag = nil
|
|
||||||
|
|
||||||
if node then
|
if node then
|
||||||
if server_host and server_port then
|
if server_host and server_port then
|
||||||
node.address = server_host
|
node.address = server_host
|
||||||
@ -925,40 +919,16 @@ function gen_config(var)
|
|||||||
local rules = {}
|
local rules = {}
|
||||||
|
|
||||||
local preproxy_enabled = node.preproxy_enabled == "1"
|
local preproxy_enabled = node.preproxy_enabled == "1"
|
||||||
|
local preproxy_rule_name = "main"
|
||||||
local preproxy_tag = "main"
|
local preproxy_tag = "main"
|
||||||
local preproxy_node_id = node["main_node"]
|
local preproxy_node_id = node["main_node"]
|
||||||
local preproxy_node = preproxy_enabled and preproxy_node_id and uci:get_all(appname, preproxy_node_id) or nil
|
local preproxy_node = preproxy_enabled and preproxy_node_id and uci:get_all(appname, preproxy_node_id) or nil
|
||||||
|
if preproxy_node then
|
||||||
if preproxy_node_id and preproxy_node_id:find("Socks_") then
|
preproxy_tag = preproxy_tag .. ":" .. preproxy_node.remarks
|
||||||
local socks_id = preproxy_node_id:sub(1 + #"Socks_")
|
|
||||||
local socks_node = uci:get_all(appname, socks_id) or nil
|
|
||||||
if socks_node then
|
|
||||||
local _node = {
|
|
||||||
type = "sing-box",
|
|
||||||
protocol = "socks",
|
|
||||||
address = "127.0.0.1",
|
|
||||||
port = socks_node.port,
|
|
||||||
uot = "1",
|
|
||||||
}
|
|
||||||
local preproxy_outbound = gen_outbound(flag, _node, preproxy_tag)
|
|
||||||
if preproxy_outbound then
|
|
||||||
table.insert(outbounds, preproxy_outbound)
|
|
||||||
else
|
|
||||||
preproxy_enabled = false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif preproxy_node and api.is_normal_node(preproxy_node) then
|
|
||||||
local preproxy_outbound = gen_outbound(flag, preproxy_node, preproxy_tag)
|
|
||||||
if preproxy_outbound then
|
|
||||||
set_outbound_detour(preproxy_node, preproxy_outbound, outbounds, preproxy_tag)
|
|
||||||
table.insert(outbounds, preproxy_outbound)
|
|
||||||
else
|
|
||||||
preproxy_enabled = false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function gen_shunt_node(rule_name, _node_id)
|
local function gen_shunt_node(rule_name, _node_id)
|
||||||
if not rule_name then return nil, nil end
|
if not rule_name then return nil end
|
||||||
if not _node_id then _node_id = node[rule_name] or "nil" end
|
if not _node_id then _node_id = node[rule_name] or "nil" end
|
||||||
local rule_outboundTag
|
local rule_outboundTag
|
||||||
if _node_id == "_direct" then
|
if _node_id == "_direct" then
|
||||||
@ -980,27 +950,28 @@ function gen_config(var)
|
|||||||
}
|
}
|
||||||
local _outbound = gen_outbound(flag, _node, rule_name)
|
local _outbound = gen_outbound(flag, _node, rule_name)
|
||||||
if _outbound then
|
if _outbound then
|
||||||
|
_outbound.tag = _outbound.tag .. ":" .. _node.remarks
|
||||||
table.insert(outbounds, _outbound)
|
table.insert(outbounds, _outbound)
|
||||||
rule_outboundTag = rule_name
|
rule_outboundTag = _outbound.tag
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif _node_id ~= "nil" then
|
elseif _node_id ~= "nil" then
|
||||||
local _node = uci:get_all(appname, _node_id)
|
local _node = uci:get_all(appname, _node_id)
|
||||||
if not _node then return nil, nil end
|
if not _node then return nil end
|
||||||
|
|
||||||
if api.is_normal_node(_node) then
|
if api.is_normal_node(_node) then
|
||||||
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_rule_name 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
|
||||||
end
|
end
|
||||||
if copied_outbound then
|
if copied_outbound then
|
||||||
copied_outbound.tag = rule_name
|
copied_outbound.tag = rule_name .. ":" .. _node.remarks
|
||||||
table.insert(outbounds, copied_outbound)
|
table.insert(outbounds, copied_outbound)
|
||||||
rule_outboundTag = rule_name
|
rule_outboundTag = copied_outbound.tag
|
||||||
else
|
else
|
||||||
if proxy then
|
if proxy then
|
||||||
local pre_proxy = nil
|
local pre_proxy = nil
|
||||||
@ -1028,38 +999,45 @@ 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 = gen_outbound(flag, _node, rule_name, { tag = proxy and preproxy_tag or nil })
|
||||||
if _outbound then
|
if _outbound then
|
||||||
set_outbound_detour(_node, _outbound, outbounds, rule_name)
|
_outbound.tag = _outbound.tag .. ":" .. _node.remarks
|
||||||
|
rule_outboundTag = set_outbound_detour(_node, _outbound, outbounds, rule_name)
|
||||||
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/passwall2/iface/" .. _node.iface)
|
sys.call("touch /tmp/etc/passwall2/iface/" .. _node.iface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return rule_outboundTag
|
return rule_outboundTag
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if preproxy_node then
|
||||||
|
proxy_outboundTag = gen_shunt_node(preproxy_rule_name, preproxy_node_id)
|
||||||
|
if not proxy_outboundTag then
|
||||||
|
preproxy_node = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
--default_node
|
--default_node
|
||||||
local default_node_id = node.default_node or "_direct"
|
local default_node_id = node.default_node or "_direct"
|
||||||
local default_outboundTag = gen_shunt_node("default", default_node_id)
|
COMMON.default_outbound_tag = gen_shunt_node("default", default_node_id)
|
||||||
--shunt rule
|
--shunt rule
|
||||||
uci:foreach(appname, "shunt_rules", function(e)
|
uci:foreach(appname, "shunt_rules", function(e)
|
||||||
local outboundTag = gen_shunt_node(e[".name"])
|
local outboundTag = gen_shunt_node(e[".name"])
|
||||||
if outboundTag and e.remarks then
|
if outboundTag and e.remarks then
|
||||||
if outboundTag == "default" then
|
if outboundTag == "default" then
|
||||||
outboundTag = default_outboundTag
|
outboundTag = COMMON.default_outbound_tag
|
||||||
end
|
end
|
||||||
local protocols = nil
|
local protocols = nil
|
||||||
if e["protocol"] and e["protocol"] ~= "" then
|
if e["protocol"] and e["protocol"] ~= "" then
|
||||||
@ -1200,11 +1178,6 @@ function gen_config(var)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if default_outboundTag then
|
|
||||||
route.final = default_outboundTag
|
|
||||||
default_outTag = default_outboundTag
|
|
||||||
end
|
|
||||||
|
|
||||||
for index, value in ipairs(rules) do
|
for index, value in ipairs(rules) do
|
||||||
table.insert(route.rules, rules[index])
|
table.insert(route.rules, rules[index])
|
||||||
end
|
end
|
||||||
@ -1212,25 +1185,28 @@ 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/passwall2/iface/" .. node.iface)
|
sys.call("touch /tmp/etc/passwall2/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)
|
outbound.tag = outbound.tag .. ":" .. node.remarks
|
||||||
|
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 = {},
|
||||||
@ -1259,7 +1235,7 @@ function gen_config(var)
|
|||||||
address_strategy = "prefer_ipv4",
|
address_strategy = "prefer_ipv4",
|
||||||
strategy = remote_strategy,
|
strategy = remote_strategy,
|
||||||
address_resolver = "direct",
|
address_resolver = "direct",
|
||||||
detour = default_outTag,
|
detour = COMMON.default_outbound_tag,
|
||||||
}
|
}
|
||||||
|
|
||||||
if remote_dns_detour == "direct" then
|
if remote_dns_detour == "direct" then
|
||||||
@ -1367,7 +1343,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"
|
||||||
dns_rule.rewrite_ttl = 30
|
dns_rule.rewrite_ttl = 30
|
||||||
if value.outboundTag ~= "default" and remote_server.address and remote_dns_detour ~= "direct" then
|
if value.outboundTag ~= COMMON.default_outbound_tag and remote_server.address and remote_dns_detour ~= "direct" 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
|
||||||
|
@ -55,30 +55,15 @@ function gen_outbound(flag, node, tag, proxy_table)
|
|||||||
tag = node_id
|
tag = node_id
|
||||||
end
|
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
|
||||||
local relay_port = node.port
|
local relay_port = node.port
|
||||||
new_port = get_new_port()
|
new_port = get_new_port()
|
||||||
@ -94,7 +79,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
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -104,6 +89,16 @@ function gen_outbound(flag, node, tag, proxy_table)
|
|||||||
node.address = "127.0.0.1"
|
node.address = "127.0.0.1"
|
||||||
node.port = new_port
|
node.port = new_port
|
||||||
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
|
||||||
@ -131,8 +126,8 @@ function gen_outbound(flag, node, tag, proxy_table)
|
|||||||
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,
|
||||||
proxySettings = node.proxySettings or nil,
|
proxySettings = node.proxySettings or nil,
|
||||||
@ -389,7 +384,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"
|
||||||
}
|
}
|
||||||
@ -588,6 +582,7 @@ function gen_config(var)
|
|||||||
local outbounds = {}
|
local outbounds = {}
|
||||||
local routing = nil
|
local routing = nil
|
||||||
local observatory = nil
|
local observatory = nil
|
||||||
|
local COMMON = {}
|
||||||
|
|
||||||
local CACHE_TEXT_FILE = CACHE_PATH .. "/cache_" .. flag .. ".txt"
|
local CACHE_TEXT_FILE = CACHE_PATH .. "/cache_" .. flag .. ".txt"
|
||||||
|
|
||||||
@ -697,6 +692,7 @@ function gen_config(var)
|
|||||||
local blc_node = uci:get_all(appname, blc_node_id)
|
local blc_node = uci:get_all(appname, blc_node_id)
|
||||||
local outbound = gen_outbound(flag, blc_node, blc_node_tag, { fragment = xray_settings.fragment == "1" or nil, noise = xray_settings.noise == "1" or nil })
|
local outbound = gen_outbound(flag, blc_node, blc_node_tag, { fragment = xray_settings.fragment == "1" or nil, noise = xray_settings.noise == "1" or nil })
|
||||||
if outbound then
|
if outbound then
|
||||||
|
outbound.tag = outbound.tag .. ":" .. blc_node.remarks
|
||||||
table.insert(outbounds, outbound)
|
table.insert(outbounds, outbound)
|
||||||
valid_nodes[#valid_nodes + 1] = blc_node_tag
|
valid_nodes[#valid_nodes + 1] = blc_node_tag
|
||||||
end
|
end
|
||||||
@ -716,6 +712,7 @@ function gen_config(var)
|
|||||||
if fallback_node.protocol ~= "_balancing" then
|
if fallback_node.protocol ~= "_balancing" then
|
||||||
local outbound = gen_outbound(flag, fallback_node, fallback_node_id, { fragment = xray_settings.fragment == "1" or nil, noise = xray_settings.noise == "1" or nil })
|
local outbound = gen_outbound(flag, fallback_node, fallback_node_id, { fragment = xray_settings.fragment == "1" or nil, noise = xray_settings.noise == "1" or nil })
|
||||||
if outbound then
|
if outbound then
|
||||||
|
outbound.tag = outbound.tag .. ":" .. fallback_node.remarks
|
||||||
table.insert(outbounds, outbound)
|
table.insert(outbounds, outbound)
|
||||||
else
|
else
|
||||||
fallback_node_id = nil
|
fallback_node_id = nil
|
||||||
@ -750,7 +747,7 @@ function gen_config(var)
|
|||||||
end
|
end
|
||||||
if loopbackTag == nil or loopbackTag =="" then loopbackTag = _node[".name"] end
|
if loopbackTag == nil or loopbackTag =="" then loopbackTag = _node[".name"] end
|
||||||
local inboundTag = gen_loopback(loopbackTag, _node[".name"])
|
local inboundTag = gen_loopback(loopbackTag, _node[".name"])
|
||||||
table.insert(rules, { type = "field", inboundTag = { inboundTag }, balancerTag = balancerTag })
|
table.insert(rules, { inboundTag = { inboundTag }, balancerTag = balancerTag })
|
||||||
valid = true
|
valid = true
|
||||||
end
|
end
|
||||||
return valid
|
return valid
|
||||||
@ -790,9 +787,15 @@ function gen_config(var)
|
|||||||
node.port = server_port
|
node.port = server_port
|
||||||
end
|
end
|
||||||
if node.protocol == "_shunt" then
|
if node.protocol == "_shunt" then
|
||||||
local proxy_tag = "main"
|
local preproxy_enabled = node.preproxy_enabled == "1"
|
||||||
local proxy_node_id = node["main_node"]
|
local preproxy_rule_name = "main"
|
||||||
local proxy_node = node.preproxy_enabled == "1" and proxy_node_id or nil
|
local preproxy_tag = "main"
|
||||||
|
local preproxy_node_id = node["main_node"]
|
||||||
|
local preproxy_node = preproxy_enabled and preproxy_node_id and uci:get_all(appname, preproxy_node_id) or nil
|
||||||
|
if preproxy_node then
|
||||||
|
preproxy_tag = preproxy_tag .. ":" .. preproxy_node.remarks
|
||||||
|
end
|
||||||
|
|
||||||
local proxy_outboundTag, proxy_balancerTag
|
local proxy_outboundTag, proxy_balancerTag
|
||||||
|
|
||||||
local function gen_shunt_node(rule_name, _node_id)
|
local function gen_shunt_node(rule_name, _node_id)
|
||||||
@ -821,7 +824,7 @@ function gen_config(var)
|
|||||||
local outbound = gen_outbound(flag, _node, rule_name)
|
local outbound = gen_outbound(flag, _node, rule_name)
|
||||||
if outbound then
|
if outbound then
|
||||||
table.insert(outbounds, outbound)
|
table.insert(outbounds, outbound)
|
||||||
rule_outboundTag = rule_name
|
rule_outboundTag = outbound.tag
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif _node_id ~= "nil" then
|
elseif _node_id ~= "nil" then
|
||||||
@ -829,10 +832,9 @@ function gen_config(var)
|
|||||||
if not _node then return nil, nil end
|
if not _node then return nil, nil end
|
||||||
|
|
||||||
if api.is_normal_node(_node) then
|
if api.is_normal_node(_node) then
|
||||||
local _proxy_node = (proxy_node and proxy_node_id) and uci:get_all(appname, proxy_node_id) or nil
|
local use_proxy = preproxy_node and node[rule_name .. "_proxy_tag"] == preproxy_rule_name and _node_id ~= preproxy_node_id
|
||||||
local use_proxy = _proxy_node and node[rule_name .. "_proxy_tag"] == proxy_tag and _node_id ~= proxy_node_id
|
|
||||||
if use_proxy and proxy_balancerTag then
|
if use_proxy and proxy_balancerTag then
|
||||||
for _, blc_node_id in ipairs(_proxy_node.balancing_node) do
|
for _, blc_node_id in ipairs(preproxy_node.balancing_node) do
|
||||||
if _node_id == blc_node_id then
|
if _node_id == blc_node_id then
|
||||||
use_proxy = false
|
use_proxy = false
|
||||||
break
|
break
|
||||||
@ -841,13 +843,13 @@ function gen_config(var)
|
|||||||
end
|
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"] == proxy_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
|
||||||
end
|
end
|
||||||
if copied_outbound then
|
if copied_outbound then
|
||||||
copied_outbound.tag = rule_name
|
copied_outbound.tag = rule_name .. ":" .. _node.remarks
|
||||||
table.insert(outbounds, copied_outbound)
|
table.insert(outbounds, copied_outbound)
|
||||||
rule_outboundTag = rule_name
|
rule_outboundTag = rule_name
|
||||||
else
|
else
|
||||||
@ -866,31 +868,31 @@ 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 = proxy_outboundTag,
|
outboundTag = proxy_outboundTag,
|
||||||
balancerTag = proxy_balancerTag
|
balancerTag = proxy_balancerTag
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
local proxy_table = {
|
local proxy_table = {
|
||||||
proxy = use_proxy and 1 or 0,
|
tag = use_proxy and preproxy_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
|
||||||
end
|
proxy_table.fragment = true
|
||||||
if xray_settings.noise == "1" and not proxy_table.tag then
|
end
|
||||||
proxy_table.noise = true
|
if xray_settings.noise == "1" then
|
||||||
|
proxy_table.noise = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
local outbound = gen_outbound(flag, _node, rule_name, proxy_table)
|
local outbound = gen_outbound(flag, _node, rule_name, proxy_table)
|
||||||
if outbound then
|
if outbound then
|
||||||
set_outbound_detour(_node, outbound, outbounds, rule_name)
|
outbound.tag = outbound.tag .. ":" .. _node.remarks
|
||||||
|
rule_outboundTag = set_outbound_detour(_node, outbound, outbounds, rule_name)
|
||||||
if rule_name == "default" then
|
if rule_name == "default" then
|
||||||
table.insert(outbounds, 1, outbound)
|
table.insert(outbounds, 1, outbound)
|
||||||
else
|
else
|
||||||
table.insert(outbounds, outbound)
|
table.insert(outbounds, outbound)
|
||||||
end
|
end
|
||||||
rule_outboundTag = rule_name
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif _node.protocol == "_balancing" then
|
elseif _node.protocol == "_balancing" then
|
||||||
@ -930,16 +932,17 @@ function gen_config(var)
|
|||||||
return rule_outboundTag, rule_balancerTag
|
return rule_outboundTag, rule_balancerTag
|
||||||
end
|
end
|
||||||
|
|
||||||
--proxy_node
|
if preproxy_node then
|
||||||
if proxy_node then
|
proxy_outboundTag, proxy_balancerTag = gen_shunt_node(preproxy_rule_name, preproxy_node_id)
|
||||||
proxy_outboundTag, proxy_balancerTag = gen_shunt_node(proxy_tag, proxy_node_id)
|
if not proxy_outboundTag and not proxy_balancerTag then
|
||||||
if not proxy_outboundTag and not proxy_balancerTag then
|
preproxy_node = nil
|
||||||
proxy_node = nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--default_node
|
--default_node
|
||||||
local default_node_id = node.default_node or "_direct"
|
local default_node_id = node.default_node or "_direct"
|
||||||
local default_outboundTag, default_balancerTag = gen_shunt_node("default", default_node_id)
|
local default_outboundTag, default_balancerTag = 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 outboundTag, balancerTag = gen_shunt_node(e[".name"])
|
local outboundTag, balancerTag = gen_shunt_node(e[".name"])
|
||||||
@ -1005,8 +1008,7 @@ function gen_config(var)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
local rule = {
|
local rule = {
|
||||||
_flag = e.remarks,
|
ruleTag = e.remarks,
|
||||||
type = "field",
|
|
||||||
inboundTag = inboundTag,
|
inboundTag = inboundTag,
|
||||||
outboundTag = outboundTag,
|
outboundTag = outboundTag,
|
||||||
balancerTag = balancerTag,
|
balancerTag = balancerTag,
|
||||||
@ -1018,13 +1020,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
|
||||||
@ -1037,7 +1039,6 @@ function gen_config(var)
|
|||||||
if default_outboundTag or default_balancerTag then
|
if default_outboundTag or default_balancerTag then
|
||||||
table.insert(rules, {
|
table.insert(rules, {
|
||||||
_flag = "default",
|
_flag = "default",
|
||||||
type = "field",
|
|
||||||
outboundTag = default_outboundTag,
|
outboundTag = default_outboundTag,
|
||||||
balancerTag = default_balancerTag,
|
balancerTag = default_balancerTag,
|
||||||
network = "tcp,udp"
|
network = "tcp,udp"
|
||||||
@ -1054,18 +1055,19 @@ function gen_config(var)
|
|||||||
if node.balancing_node then
|
if node.balancing_node then
|
||||||
local valid = gen_balancer(node)
|
local valid = gen_balancer(node)
|
||||||
if valid then
|
if valid then
|
||||||
table.insert(rules, { type = "field", network = "tcp,udp", balancerTag = get_balancer_tag(node_id) })
|
table.insert(rules, { network = "tcp,udp", balancerTag = get_balancer_tag(node_id) })
|
||||||
end
|
end
|
||||||
routing = {
|
routing = {
|
||||||
balancers = balancers,
|
balancers = balancers,
|
||||||
rules = rules
|
rules = rules
|
||||||
}
|
}
|
||||||
|
COMMON.default_balancer_tag = get_balancer_tag(node_id)
|
||||||
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,
|
||||||
@ -1074,12 +1076,14 @@ function gen_config(var)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
table.insert(outbounds, outbound)
|
table.insert(outbounds, outbound)
|
||||||
|
COMMON.default_outbound_tag = outbound.tag
|
||||||
sys.call("touch /tmp/etc/passwall2/iface/" .. node.iface)
|
sys.call("touch /tmp/etc/passwall2/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
|
||||||
local default_outTag = set_outbound_detour(node, outbound, outbounds)
|
outbound.tag = outbound.tag .. ":" .. node.remarks
|
||||||
|
COMMON.default_outbound_tag = set_outbound_detour(node, outbound, outbounds)
|
||||||
table.insert(outbounds, outbound)
|
table.insert(outbounds, outbound)
|
||||||
routing = {
|
routing = {
|
||||||
domainStrategy = "AsIs",
|
domainStrategy = "AsIs",
|
||||||
@ -1087,9 +1091,8 @@ function gen_config(var)
|
|||||||
rules = {}
|
rules = {}
|
||||||
}
|
}
|
||||||
table.insert(routing.rules, {
|
table.insert(routing.rules, {
|
||||||
_flag = "default",
|
ruleTag = "default",
|
||||||
type = "field",
|
outboundTag = COMMON.default_outbound_tag,
|
||||||
outboundTag = default_outTag,
|
|
||||||
network = "tcp,udp"
|
network = "tcp,udp"
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
@ -1175,7 +1178,6 @@ function gen_config(var)
|
|||||||
table.insert(dns.servers, _remote_dns)
|
table.insert(dns.servers, _remote_dns)
|
||||||
if remote_dns_detour == "direct" then
|
if remote_dns_detour == "direct" then
|
||||||
table.insert(routing.rules, 1, {
|
table.insert(routing.rules, 1, {
|
||||||
type = "field",
|
|
||||||
ip = {
|
ip = {
|
||||||
_remote_dns_ip
|
_remote_dns_ip
|
||||||
},
|
},
|
||||||
@ -1233,7 +1235,6 @@ function gen_config(var)
|
|||||||
queryStrategy = (direct_dns_query_strategy and direct_dns_query_strategy ~= "") and direct_dns_query_strategy or "UseIP",
|
queryStrategy = (direct_dns_query_strategy and direct_dns_query_strategy ~= "") and direct_dns_query_strategy or "UseIP",
|
||||||
}
|
}
|
||||||
table.insert(routing.rules, 1, {
|
table.insert(routing.rules, 1, {
|
||||||
type = "field",
|
|
||||||
ip = {
|
ip = {
|
||||||
direct_dns_udp_server
|
direct_dns_udp_server
|
||||||
},
|
},
|
||||||
@ -1286,7 +1287,6 @@ function gen_config(var)
|
|||||||
settings = type_dns.settings
|
settings = type_dns.settings
|
||||||
})
|
})
|
||||||
table.insert(routing.rules, 1, {
|
table.insert(routing.rules, 1, {
|
||||||
type = "field",
|
|
||||||
inboundTag = {
|
inboundTag = {
|
||||||
"dns-in"
|
"dns-in"
|
||||||
},
|
},
|
||||||
@ -1295,13 +1295,8 @@ function gen_config(var)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local default_dns_flag = "remote"
|
local default_dns_flag = "remote"
|
||||||
if node_id and redir_port then
|
if not COMMON.default_outbound_tag or COMMON.default_outbound_tag == "direct" then
|
||||||
local node = uci:get_all(appname, node_id)
|
default_dns_flag = "direct"
|
||||||
if node.protocol == "_shunt" then
|
|
||||||
if node.default_node == "_direct" then
|
|
||||||
default_dns_flag = "direct"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if dns.servers and #dns.servers > 0 then
|
if dns.servers and #dns.servers > 0 then
|
||||||
@ -1482,6 +1477,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
|
||||||
@ -1733,7 +1735,6 @@ function gen_dns_config(var)
|
|||||||
_direct_dns.address = direct_dns_udp_server
|
_direct_dns.address = direct_dns_udp_server
|
||||||
_direct_dns.port = tonumber(direct_dns_udp_port) or 53
|
_direct_dns.port = tonumber(direct_dns_udp_port) or 53
|
||||||
table.insert(routing.rules, 1, {
|
table.insert(routing.rules, 1, {
|
||||||
type = "field",
|
|
||||||
ip = {
|
ip = {
|
||||||
direct_dns_udp_server
|
direct_dns_udp_server
|
||||||
},
|
},
|
||||||
@ -1803,7 +1804,6 @@ function gen_dns_config(var)
|
|||||||
})
|
})
|
||||||
|
|
||||||
table.insert(routing.rules, 1, {
|
table.insert(routing.rules, 1, {
|
||||||
type = "field",
|
|
||||||
inboundTag = {
|
inboundTag = {
|
||||||
"dns-in"
|
"dns-in"
|
||||||
},
|
},
|
||||||
@ -1811,7 +1811,6 @@ function gen_dns_config(var)
|
|||||||
})
|
})
|
||||||
|
|
||||||
table.insert(routing.rules, {
|
table.insert(routing.rules, {
|
||||||
type = "field",
|
|
||||||
inboundTag = {
|
inboundTag = {
|
||||||
"dns-in1"
|
"dns-in1"
|
||||||
},
|
},
|
||||||
|
@ -205,13 +205,16 @@ check_port_exists() {
|
|||||||
check_depends() {
|
check_depends() {
|
||||||
local depends
|
local depends
|
||||||
local tables=${1}
|
local tables=${1}
|
||||||
|
local file_path="/usr/lib/opkg/info"
|
||||||
|
local file_ext=".control"
|
||||||
|
[ -d "/lib/apk/packages" ] && file_path="/lib/apk/packages" && file_ext=".list"
|
||||||
if [ "$tables" == "iptables" ]; then
|
if [ "$tables" == "iptables" ]; then
|
||||||
for depends in "iptables-mod-tproxy" "iptables-mod-socket" "iptables-mod-iprange" "iptables-mod-conntrack-extra" "kmod-ipt-nat"; do
|
for depends in "iptables-mod-tproxy" "iptables-mod-socket" "iptables-mod-iprange" "iptables-mod-conntrack-extra" "kmod-ipt-nat"; do
|
||||||
[ -s "/usr/lib/opkg/info/${depends}.control" ] || echolog "$tables透明代理基础依赖 $depends 未安装..."
|
[ -s "${file_path}/${depends}${file_ext}" ] || echolog "$tables透明代理基础依赖 $depends 未安装..."
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
for depends in "kmod-nft-socket" "kmod-nft-tproxy" "kmod-nft-nat"; do
|
for depends in "kmod-nft-socket" "kmod-nft-tproxy" "kmod-nft-nat"; do
|
||||||
[ -s "/usr/lib/opkg/info/${depends}.control" ] || echolog "$tables透明代理基础依赖 $depends 未安装..."
|
[ -s "${file_path}/${depends}${file_ext}" ] || echolog "$tables透明代理基础依赖 $depends 未安装..."
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user