luci: fix auto switch when use shunt node #2474
This commit is contained in:
parent
b53d790c8b
commit
c8701a112a
@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk
|
|||||||
|
|
||||||
PKG_NAME:=luci-app-passwall
|
PKG_NAME:=luci-app-passwall
|
||||||
PKG_VERSION:=4.63
|
PKG_VERSION:=4.63
|
||||||
PKG_RELEASE:=3
|
PKG_RELEASE:=4
|
||||||
|
|
||||||
PKG_CONFIG_DEPENDS:= \
|
PKG_CONFIG_DEPENDS:= \
|
||||||
CONFIG_PACKAGE_$(PKG_NAME)_Iptables_Transparent_Proxy \
|
CONFIG_PACKAGE_$(PKG_NAME)_Iptables_Transparent_Proxy \
|
||||||
|
@ -84,21 +84,39 @@ s:tab("Main", translate("Main"))
|
|||||||
o = s:taboption("Main", Flag, "enabled", translate("Main switch"))
|
o = s:taboption("Main", Flag, "enabled", translate("Main switch"))
|
||||||
o.rmempty = false
|
o.rmempty = false
|
||||||
|
|
||||||
---- TCP Node
|
local auto_switch_tip
|
||||||
tcp_node = s:taboption("Main", ListValue, "tcp_node", "<a style='color: red'>" .. translate("TCP Node") .. "</a>")
|
local auto_switch_flag
|
||||||
tcp_node.description = ""
|
local current_tcp_node = luci.sys.exec(string.format("[ -f '/tmp/etc/%s/id/TCP' ] && echo -n $(cat /tmp/etc/%s/id/TCP)", appname, appname))
|
||||||
local current_node = luci.sys.exec(string.format("[ -f '/tmp/etc/%s/id/TCP' ] && echo -n $(cat /tmp/etc/%s/id/TCP)", appname, appname))
|
if current_tcp_node and current_tcp_node ~= "" and current_tcp_node ~= "nil" then
|
||||||
if current_node and current_node ~= "" and current_node ~= "nil" then
|
local n = uci:get_all(appname, current_tcp_node)
|
||||||
local n = uci:get_all(appname, current_node)
|
|
||||||
if n then
|
if n then
|
||||||
if tonumber(m:get("@auto_switch[0]", "enable") or 0) == 1 then
|
if tonumber(m:get("@auto_switch[0]", "enable") or 0) == 1 then
|
||||||
local remarks = api.get_full_node_remarks(n)
|
auto_switch_flag = ""
|
||||||
local url = api.url("node_config", current_node)
|
if n.protocol == "_shunt" then
|
||||||
tcp_node.description = tcp_node.description .. translatef("Current node: %s", string.format('<a href="%s">%s</a>', url, remarks)) .. "<br />"
|
local shunt_logic = tonumber(m:get("@auto_switch[0]", "shunt_logic"))
|
||||||
|
if shunt_logic == 1 then
|
||||||
|
auto_switch_flag = "default"
|
||||||
|
elseif shunt_logic == 2 then
|
||||||
|
auto_switch_flag = "main"
|
||||||
|
end
|
||||||
|
current_tcp_node = luci.sys.exec(string.format("[ -f '/tmp/etc/%s/id/TCP_%s' ] && echo -n $(cat /tmp/etc/%s/id/TCP_%s)", appname, auto_switch_flag, appname, auto_switch_flag))
|
||||||
|
if current_tcp_node and current_tcp_node ~= "" and current_tcp_node ~= "nil" then
|
||||||
|
n = uci:get_all(appname, current_tcp_node)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local remarks = api.get_node_remarks(n)
|
||||||
|
local url = api.url("node_config", n[".name"])
|
||||||
|
auto_switch_tip = translatef("Current node: %s", string.format('<a href="%s">%s</a>', url, remarks)) .. "<br />"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---- TCP Node
|
||||||
|
tcp_node = s:taboption("Main", ListValue, "tcp_node", "<a style='color: red'>" .. translate("TCP Node") .. "</a>")
|
||||||
tcp_node:value("nil", translate("Close"))
|
tcp_node:value("nil", translate("Close"))
|
||||||
|
if auto_switch_flag == "" and auto_switch_tip then
|
||||||
|
tcp_node.description = auto_switch_tip
|
||||||
|
end
|
||||||
|
|
||||||
---- UDP Node
|
---- UDP Node
|
||||||
udp_node = s:taboption("Main", ListValue, "udp_node", "<a style='color: red'>" .. translate("UDP Node") .. "</a>")
|
udp_node = s:taboption("Main", ListValue, "udp_node", "<a style='color: red'>" .. translate("UDP Node") .. "</a>")
|
||||||
@ -145,12 +163,14 @@ if (has_v2ray or has_xray) and #nodes_table > 0 then
|
|||||||
end
|
end
|
||||||
type.cfgvalue = get_cfgvalue(v.id, "type")
|
type.cfgvalue = get_cfgvalue(v.id, "type")
|
||||||
type.write = get_write(v.id, "type")
|
type.write = get_write(v.id, "type")
|
||||||
|
|
||||||
-- pre-proxy
|
-- pre-proxy
|
||||||
o = s:taboption("Main", Flag, vid .. "-preproxy_enabled", translate("Preproxy"))
|
o = s:taboption("Main", Flag, vid .. "-preproxy_enabled", translate("Preproxy"))
|
||||||
o:depends("tcp_node", v.id)
|
o:depends("tcp_node", v.id)
|
||||||
o.rmempty = false
|
o.rmempty = false
|
||||||
o.cfgvalue = get_cfgvalue(v.id, "preproxy_enabled")
|
o.cfgvalue = get_cfgvalue(v.id, "preproxy_enabled")
|
||||||
o.write = get_write(v.id, "preproxy_enabled")
|
o.write = get_write(v.id, "preproxy_enabled")
|
||||||
|
|
||||||
o = s:taboption("Main", ListValue, vid .. "-main_node", string.format('<a style="color:red">%s</a>', translate("Preproxy Node")), translate("Set the node to be used as a pre-proxy. Each rule (including <code>Default</code>) has a separate switch that controls whether this rule uses the pre-proxy or not."))
|
o = s:taboption("Main", ListValue, vid .. "-main_node", string.format('<a style="color:red">%s</a>', translate("Preproxy Node")), translate("Set the node to be used as a pre-proxy. Each rule (including <code>Default</code>) has a separate switch that controls whether this rule uses the pre-proxy or not."))
|
||||||
o:depends(vid .. "-preproxy_enabled", "1")
|
o:depends(vid .. "-preproxy_enabled", "1")
|
||||||
for k1, v1 in pairs(balancing_list) do
|
for k1, v1 in pairs(balancing_list) do
|
||||||
@ -161,6 +181,10 @@ if (has_v2ray or has_xray) and #nodes_table > 0 then
|
|||||||
end
|
end
|
||||||
o.cfgvalue = get_cfgvalue(v.id, "main_node")
|
o.cfgvalue = get_cfgvalue(v.id, "main_node")
|
||||||
o.write = get_write(v.id, "main_node")
|
o.write = get_write(v.id, "main_node")
|
||||||
|
if auto_switch_flag == "main" and auto_switch_tip then
|
||||||
|
o.description = auto_switch_tip
|
||||||
|
end
|
||||||
|
|
||||||
if (has_v2ray and has_xray) or (v.type == "V2ray" and not has_v2ray) or (v.type == "Xray" and not has_xray) then
|
if (has_v2ray and has_xray) or (v.type == "V2ray" and not has_v2ray) or (v.type == "Xray" and not has_xray) then
|
||||||
type:depends("tcp_node", v.id)
|
type:depends("tcp_node", v.id)
|
||||||
else
|
else
|
||||||
@ -209,6 +233,9 @@ if (has_v2ray or has_xray) and #nodes_table > 0 then
|
|||||||
for k1, v1 in pairs(normal_list) do
|
for k1, v1 in pairs(normal_list) do
|
||||||
o:value(v1.id, v1.remark)
|
o:value(v1.id, v1.remark)
|
||||||
end
|
end
|
||||||
|
if auto_switch_flag == "default" and auto_switch_tip then
|
||||||
|
o.description = auto_switch_tip
|
||||||
|
end
|
||||||
|
|
||||||
local id = "default_proxy_tag"
|
local id = "default_proxy_tag"
|
||||||
o = s:taboption("Main", ListValue, vid .. "-" .. id, string.format('* <a style="color:red">%s</a>', translate("Default Preproxy")), translate("When using, localhost will connect this node first and then use this node to connect the default node."))
|
o = s:taboption("Main", ListValue, vid .. "-" .. id, string.format('* <a style="color:red">%s</a>', translate("Default Preproxy")), translate("When using, localhost will connect this node first and then use this node to connect the default node."))
|
||||||
|
@ -322,7 +322,7 @@ function get_valid_nodes()
|
|||||||
return nodes
|
return nodes
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_full_node_remarks(n)
|
function get_node_remarks(n)
|
||||||
local remarks = ""
|
local remarks = ""
|
||||||
if n then
|
if n then
|
||||||
if n.protocol and (n.protocol == "_balancing" or n.protocol == "_shunt" or n.protocol == "_iface") then
|
if n.protocol and (n.protocol == "_balancing" or n.protocol == "_shunt" or n.protocol == "_iface") then
|
||||||
@ -340,7 +340,17 @@ function get_full_node_remarks(n)
|
|||||||
end
|
end
|
||||||
type2 = type2 .. " " .. protocol
|
type2 = type2 .. " " .. protocol
|
||||||
end
|
end
|
||||||
remarks = "%s:[%s] %s:%s" % {type2, n.remarks, n.address, n.port}
|
remarks = "%s:[%s]" % {type2, n.remarks}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return remarks
|
||||||
|
end
|
||||||
|
|
||||||
|
function get_full_node_remarks(n)
|
||||||
|
local remarks = get_node_remarks(n)
|
||||||
|
if #remarks > 0 then
|
||||||
|
if n.address and n.port then
|
||||||
|
remarks = remarks .. " " .. n.address .. ":" .. n.port
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return remarks
|
return remarks
|
||||||
|
@ -896,8 +896,8 @@ node_switch() {
|
|||||||
echo $new_node > $TMP_ID_PATH/${FLAG}
|
echo $new_node > $TMP_ID_PATH/${FLAG}
|
||||||
|
|
||||||
[ "$shunt_logic" != "0" ] && [ "$(config_n_get $new_node protocol nil)" = "_shunt" ] && {
|
[ "$shunt_logic" != "0" ] && [ "$(config_n_get $new_node protocol nil)" = "_shunt" ] && {
|
||||||
echo $(config_n_get $new_node default_node nil) > $TMP_ID_PATH/${1}_default
|
echo $(config_n_get $new_node default_node nil) > $TMP_ID_PATH/${FLAG}_default
|
||||||
echo $(config_n_get $new_node main_node nil) > $TMP_ID_PATH/${1}_main
|
echo $(config_n_get $new_node main_node nil) > $TMP_ID_PATH/${FLAG}_main
|
||||||
uci commit $CONFIG
|
uci commit $CONFIG
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user