luci-app-passwall: sync upstream
This commit is contained in:
parent
11a44f7946
commit
8cf18bbbbc
@ -49,7 +49,9 @@ o:depends({ [option_name("protocol")] = "_iface" })
|
|||||||
|
|
||||||
local nodes_table = {}
|
local nodes_table = {}
|
||||||
local balancers_table = {}
|
local balancers_table = {}
|
||||||
|
local fallback_table = {}
|
||||||
local iface_table = {}
|
local iface_table = {}
|
||||||
|
local is_balancer = nil
|
||||||
for k, e in ipairs(api.get_valid_nodes()) do
|
for k, e in ipairs(api.get_valid_nodes()) do
|
||||||
if e.node_type == "normal" then
|
if e.node_type == "normal" then
|
||||||
nodes_table[#nodes_table + 1] = {
|
nodes_table[#nodes_table + 1] = {
|
||||||
@ -63,6 +65,15 @@ for k, e in ipairs(api.get_valid_nodes()) do
|
|||||||
id = e[".name"],
|
id = e[".name"],
|
||||||
remark = e["remark"]
|
remark = e["remark"]
|
||||||
}
|
}
|
||||||
|
if e[".name"] ~= arg[1] then
|
||||||
|
fallback_table[#fallback_table + 1] = {
|
||||||
|
id = e[".name"],
|
||||||
|
remark = e["remark"],
|
||||||
|
fallback = e["fallback_node"]
|
||||||
|
}
|
||||||
|
else
|
||||||
|
is_balancer = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if e.protocol == "_iface" then
|
if e.protocol == "_iface" then
|
||||||
iface_table[#iface_table + 1] = {
|
iface_table[#iface_table + 1] = {
|
||||||
@ -90,23 +101,35 @@ for k, v in pairs(nodes_table) do o:value(v.id, v.remark) end
|
|||||||
local o = s:option(ListValue, option_name("balancingStrategy"), translate("Balancing Strategy"))
|
local o = s:option(ListValue, option_name("balancingStrategy"), translate("Balancing Strategy"))
|
||||||
o:depends({ [option_name("protocol")] = "_balancing" })
|
o:depends({ [option_name("protocol")] = "_balancing" })
|
||||||
o:value("random")
|
o:value("random")
|
||||||
|
o:value("roundRobin")
|
||||||
o:value("leastPing")
|
o:value("leastPing")
|
||||||
o:value("leastLoad")
|
o.default = "leastPing"
|
||||||
o.default = "leastLoad"
|
|
||||||
|
|
||||||
-- Fallback Node
|
-- Fallback Node
|
||||||
if api.compare_versions(api.get_app_version("xray"), ">=", "1.8.10") then
|
if api.compare_versions(api.get_app_version("xray"), ">=", "1.8.10") then
|
||||||
local o = s:option(ListValue, option_name("fallback_node"), translate("Fallback Node"))
|
local o = s:option(ListValue, option_name("fallback_node"), translate("Fallback Node"))
|
||||||
o:depends({ [option_name("protocol")] = "_balancing" })
|
o:depends({ [option_name("balancingStrategy")] = "leastPing" })
|
||||||
o:value("",translate("Null"))
|
o:value("",translate("Null"))
|
||||||
o.default = ""
|
o.default = ""
|
||||||
|
local function check_fallback_chain(fb)
|
||||||
|
for k, v in pairs(fallback_table) do
|
||||||
|
if v.fallback == fb then
|
||||||
|
fallback_table[k] = nil
|
||||||
|
check_fallback_chain(v.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- 检查fallback链,去掉会形成闭环的balancer节点
|
||||||
|
if is_balancer then
|
||||||
|
check_fallback_chain(arg[1])
|
||||||
|
end
|
||||||
|
for k, v in pairs(fallback_table) do o:value(v.id, v.remark) end
|
||||||
for k, v in pairs(nodes_table) do o:value(v.id, v.remark) end
|
for k, v in pairs(nodes_table) do o:value(v.id, v.remark) end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 探测地址
|
-- 探测地址
|
||||||
local o = s:option(Flag, option_name("useCustomProbeUrl"), translate("Use Custome Probe URL"), translate("By default the built-in probe URL will be used, enable this option to use a custom probe URL."))
|
local o = s:option(Flag, option_name("useCustomProbeUrl"), translate("Use Custome Probe URL"), translate("By default the built-in probe URL will be used, enable this option to use a custom probe URL."))
|
||||||
o:depends({ [option_name("balancingStrategy")] = "leastPing" })
|
o:depends({ [option_name("balancingStrategy")] = "leastPing" })
|
||||||
o:depends({ [option_name("balancingStrategy")] = "leastLoad" })
|
|
||||||
|
|
||||||
local o = s:option(Value, option_name("probeUrl"), translate("Probe URL"))
|
local o = s:option(Value, option_name("probeUrl"), translate("Probe URL"))
|
||||||
o:depends({ [option_name("useCustomProbeUrl")] = true })
|
o:depends({ [option_name("useCustomProbeUrl")] = true })
|
||||||
@ -116,7 +139,6 @@ o.description = translate("The URL used to detect the connection status.")
|
|||||||
-- 探测间隔
|
-- 探测间隔
|
||||||
local o = s:option(Value, option_name("probeInterval"), translate("Probe Interval"))
|
local o = s:option(Value, option_name("probeInterval"), translate("Probe Interval"))
|
||||||
o:depends({ [option_name("balancingStrategy")] = "leastPing" })
|
o:depends({ [option_name("balancingStrategy")] = "leastPing" })
|
||||||
o:depends({ [option_name("balancingStrategy")] = "leastLoad" })
|
|
||||||
o.default = "1m"
|
o.default = "1m"
|
||||||
o.description = translate("The interval between initiating probes. Every time this time elapses, a server status check is performed on a server. The time format is numbers + units, such as '10s', '2h45m', and the supported time units are <code>ns</code>, <code>us</code>, <code>ms</code>, <code>s</code>, <code>m</code>, <code>h</code>, which correspond to nanoseconds, microseconds, milliseconds, seconds, minutes, and hours, respectively.")
|
o.description = translate("The interval between initiating probes. Every time this time elapses, a server status check is performed on a server. The time format is numbers + units, such as '10s', '2h45m', and the supported time units are <code>ns</code>, <code>us</code>, <code>ms</code>, <code>s</code>, <code>m</code>, <code>h</code>, which correspond to nanoseconds, microseconds, milliseconds, seconds, minutes, and hours, respectively.")
|
||||||
|
|
||||||
|
@ -564,6 +564,8 @@ function gen_config(var)
|
|||||||
|
|
||||||
if node_id then
|
if node_id then
|
||||||
local node = uci:get_all(appname, node_id)
|
local node = uci:get_all(appname, node_id)
|
||||||
|
local balancers = {}
|
||||||
|
local rules = {}
|
||||||
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
|
||||||
@ -682,25 +684,32 @@ function gen_config(var)
|
|||||||
end
|
end
|
||||||
if is_new_node then
|
if is_new_node then
|
||||||
local fallback_node = uci:get_all(appname, fallback_node_id)
|
local fallback_node = uci:get_all(appname, fallback_node_id)
|
||||||
|
if fallback_node.protocol ~= "_balancing" then
|
||||||
local outbound = gen_outbound(flag, fallback_node, fallback_node_id, { fragment = xray_settings.fragment == "1" or nil })
|
local outbound = gen_outbound(flag, fallback_node, fallback_node_id, { fragment = xray_settings.fragment == "1" or nil })
|
||||||
if outbound then
|
if outbound then
|
||||||
table.insert(outbounds, outbound)
|
table.insert(outbounds, outbound)
|
||||||
else
|
else
|
||||||
fallback_node_id = nil
|
fallback_node_id = nil
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
local valid = gen_balancer(fallback_node)
|
||||||
|
if not valid then
|
||||||
|
fallback_node_id = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local balancer, rule
|
local valid = nil
|
||||||
if #valid_nodes > 0 then
|
if #valid_nodes > 0 then
|
||||||
local balancerTag = get_balancer_tag(_node[".name"])
|
local balancerTag = get_balancer_tag(_node[".name"])
|
||||||
balancer = {
|
table.insert(balancers, {
|
||||||
tag = balancerTag,
|
tag = balancerTag,
|
||||||
selector = valid_nodes,
|
selector = valid_nodes,
|
||||||
fallbackTag = fallback_node_id,
|
fallbackTag = fallback_node_id,
|
||||||
strategy = { type = _node.balancingStrategy or "random" }
|
strategy = { type = _node.balancingStrategy or "random" }
|
||||||
}
|
})
|
||||||
if _node.balancingStrategy == "leastPing" or _node.balancingStrategy == "leastLoad" then
|
if _node.balancingStrategy == "leastPing" then
|
||||||
if not observatory then
|
if not observatory then
|
||||||
observatory = {
|
observatory = {
|
||||||
subjectSelector = { "blc-" },
|
subjectSelector = { "blc-" },
|
||||||
@ -717,13 +726,10 @@ function gen_config(var)
|
|||||||
tag = loopbackTag,
|
tag = loopbackTag,
|
||||||
settings = { inboundTag = inboundTag }
|
settings = { inboundTag = inboundTag }
|
||||||
})
|
})
|
||||||
rule = {
|
table.insert(rules, { type = "field", inboundTag = { inboundTag }, balancerTag = balancerTag })
|
||||||
type = "field",
|
valid = true
|
||||||
inboundTag = { inboundTag },
|
|
||||||
balancerTag = balancerTag
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
return balancer, rule
|
return valid
|
||||||
end
|
end
|
||||||
|
|
||||||
local function set_outbound_detour(node, outbound, outbounds_table, shunt_rule_name)
|
local function set_outbound_detour(node, outbound, outbounds_table, shunt_rule_name)
|
||||||
@ -755,9 +761,6 @@ function gen_config(var)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if node.protocol == "_shunt" then
|
if node.protocol == "_shunt" then
|
||||||
local rules = {}
|
|
||||||
local balancers = {}
|
|
||||||
|
|
||||||
local preproxy_enabled = node.preproxy_enabled == "1"
|
local preproxy_enabled = node.preproxy_enabled == "1"
|
||||||
local preproxy_tag = "main"
|
local preproxy_tag = "main"
|
||||||
local preproxy_node_id = node["main_node"]
|
local preproxy_node_id = node["main_node"]
|
||||||
@ -793,11 +796,8 @@ function gen_config(var)
|
|||||||
end
|
end
|
||||||
elseif preproxy_node and preproxy_node.protocol == "_balancing" then
|
elseif preproxy_node and preproxy_node.protocol == "_balancing" then
|
||||||
preproxy_is_balancer = true
|
preproxy_is_balancer = true
|
||||||
local preproxy_balancer, preproxy_rule = gen_balancer(preproxy_node, preproxy_tag)
|
local valid = gen_balancer(preproxy_node, preproxy_tag)
|
||||||
if preproxy_balancer and preproxy_rule then
|
if not valid then
|
||||||
table.insert(balancers, preproxy_balancer)
|
|
||||||
table.insert(rules, preproxy_rule)
|
|
||||||
else
|
|
||||||
preproxy_enabled = false
|
preproxy_enabled = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -913,11 +913,9 @@ function gen_config(var)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if is_new_balancer then
|
if is_new_balancer then
|
||||||
local balancer, rule = gen_balancer(_node)
|
local valid = gen_balancer(_node)
|
||||||
if balancer then
|
if valid then
|
||||||
table.insert(balancers, balancer)
|
rule_balancerTag = get_balancer_tag(_node_id)
|
||||||
table.insert(rules, rule)
|
|
||||||
rule_balancerTag = balancer.tag
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif _node.protocol == "_iface" then
|
elseif _node.protocol == "_iface" then
|
||||||
@ -1043,13 +1041,13 @@ function gen_config(var)
|
|||||||
}
|
}
|
||||||
elseif node.protocol == "_balancing" then
|
elseif node.protocol == "_balancing" then
|
||||||
if node.balancing_node then
|
if node.balancing_node then
|
||||||
local balancer, rule = gen_balancer(node)
|
local valid = gen_balancer(node)
|
||||||
|
if valid then
|
||||||
|
table.insert(rules, { type = "field", network = "tcp,udp", balancerTag = get_balancer_tag(node_id) })
|
||||||
|
end
|
||||||
routing = {
|
routing = {
|
||||||
balancers = { balancer },
|
balancers = balancers,
|
||||||
rules = {
|
rules = rules
|
||||||
{ type = "field", network = "tcp,udp", balancerTag = balancer.tag },
|
|
||||||
rule
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
elseif node.protocol == "_iface" then
|
elseif node.protocol == "_iface" then
|
||||||
|
Loading…
Reference in New Issue
Block a user