From 192c81d8dff6dc5597154007a1b8ce80971ecdc3 Mon Sep 17 00:00:00 2001 From: kenzok8 Date: Mon, 18 Nov 2024 20:41:06 +0800 Subject: [PATCH] update 2024-11-18 20:41:06 --- luci-app-passwall2/Makefile | 4 +-- .../luasrc/passwall2/util_sing-box.lua | 29 ++++++++----------- .../luasrc/passwall2/util_xray.lua | 23 +++++++-------- 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/luci-app-passwall2/Makefile b/luci-app-passwall2/Makefile index 579aacaf5..52ec5c668 100644 --- a/luci-app-passwall2/Makefile +++ b/luci-app-passwall2/Makefile @@ -5,8 +5,8 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-passwall2 -PKG_VERSION:=24.11.17 -PKG_RELEASE:=2 +PKG_VERSION:=24.11.18 +PKG_RELEASE:=1 PKG_CONFIG_DEPENDS:= \ CONFIG_PACKAGE_$(PKG_NAME)_Iptables_Transparent_Proxy \ diff --git a/luci-app-passwall2/luasrc/passwall2/util_sing-box.lua b/luci-app-passwall2/luasrc/passwall2/util_sing-box.lua index 26590fb41..20650ff6d 100644 --- a/luci-app-passwall2/luasrc/passwall2/util_sing-box.lua +++ b/luci-app-passwall2/luasrc/passwall2/util_sing-box.lua @@ -918,14 +918,9 @@ function gen_config(var) if node.protocol == "_shunt" then local rules = {} - local preproxy_enabled = node.preproxy_enabled == "1" - local preproxy_rule_name = "main" - 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 preproxy_rule_name = node.preproxy_enabled == "1" and "main" or nil + local preproxy_tag = preproxy_rule_name + local preproxy_node_id = preproxy_rule_name and node["main_node"] or nil local function gen_shunt_node(rule_name, _node_id) if not rule_name then return nil end @@ -950,7 +945,6 @@ function gen_config(var) } local _outbound = gen_outbound(flag, _node, rule_name) if _outbound then - _outbound.tag = _outbound.tag .. ":" .. _node.remarks table.insert(outbounds, _outbound) rule_outboundTag = _outbound.tag end @@ -960,10 +954,10 @@ function gen_config(var) if not _node then return nil end if api.is_normal_node(_node) then - local proxy = preproxy_enabled and node[rule_name .. "_proxy_tag"] == preproxy_rule_name and _node_id ~= preproxy_node_id + local use_proxy = preproxy_tag and node[rule_name .. "_proxy_tag"] == preproxy_rule_name and _node_id ~= preproxy_node_id local copied_outbound for index, value in ipairs(outbounds) do - if value["_id"] == _node_id and value["_flag_proxy_tag"] == preproxy_tag then + if value["_id"] == _node_id and value["_flag_proxy_tag"] == (use_proxy and preproxy_tag or nil) then copied_outbound = api.clone(value) break end @@ -973,7 +967,7 @@ function gen_config(var) table.insert(outbounds, copied_outbound) rule_outboundTag = copied_outbound.tag else - if proxy then + if use_proxy then local pre_proxy = nil if _node.type ~= "sing-box" then pre_proxy = true @@ -999,7 +993,8 @@ function gen_config(var) }) end end - local _outbound = gen_outbound(flag, _node, rule_name, { tag = proxy and preproxy_tag or nil }) + + local _outbound = gen_outbound(flag, _node, rule_name, { tag = use_proxy and preproxy_tag or nil }) if _outbound then _outbound.tag = _outbound.tag .. ":" .. _node.remarks rule_outboundTag = set_outbound_detour(_node, _outbound, outbounds, rule_name) @@ -1023,10 +1018,10 @@ function gen_config(var) return rule_outboundTag end - if preproxy_node then - proxy_outboundTag = gen_shunt_node(preproxy_rule_name, preproxy_node_id) - if not proxy_outboundTag then - preproxy_node = nil + if preproxy_tag and preproxy_node_id then + local preproxy_outboundTag = gen_shunt_node(preproxy_rule_name, preproxy_node_id) + if preproxy_outboundTag then + preproxy_tag = preproxy_outboundTag end end --default_node diff --git a/luci-app-passwall2/luasrc/passwall2/util_xray.lua b/luci-app-passwall2/luasrc/passwall2/util_xray.lua index 816fa4ef6..b482126ac 100644 --- a/luci-app-passwall2/luasrc/passwall2/util_xray.lua +++ b/luci-app-passwall2/luasrc/passwall2/util_xray.lua @@ -756,16 +756,15 @@ function gen_config(var) end -- new balancer local blc_nodes = _node.balancing_node - local length = #blc_nodes local valid_nodes = {} - for i = 1, length do + for i = 1, #blc_nodes do local blc_node_id = blc_nodes[i] local blc_node_tag = "blc-" .. blc_node_id local is_new_blc_node = true for _, outbound in ipairs(outbounds) do - if outbound.tag == blc_node_tag then + if outbound.tag:find("^" .. blc_node_tag) == 1 then is_new_blc_node = false - valid_nodes[#valid_nodes + 1] = blc_node_tag + valid_nodes[#valid_nodes + 1] = outbound.tag break end end @@ -775,7 +774,7 @@ function gen_config(var) if outbound then outbound.tag = outbound.tag .. ":" .. blc_node.remarks table.insert(outbounds, outbound) - valid_nodes[#valid_nodes + 1] = blc_node_tag + valid_nodes[#valid_nodes + 1] = outbound.tag end end end @@ -1050,6 +1049,7 @@ function gen_config(var) local domain_table = { shunt_rule_name = e[".name"], outboundTag = outboundTag, + balancerTag = balancerTag, domain = {}, } domains = {} @@ -1058,7 +1058,7 @@ function gen_config(var) table.insert(domains, w) table.insert(domain_table.domain, w) end) - if outboundTag and outboundTag ~= "nil" then + if (outboundTag and outboundTag ~= "nil") or (balancerTag and balancerTag ~= "nil") then table.insert(dns_domain_rules, api.clone(domain_table)) end if #domains == 0 then domains = nil end @@ -1107,16 +1107,15 @@ function gen_config(var) end end end) ---[[ - if default_outboundTag or default_balancerTag then + + if default_balancerTag then table.insert(rules, { - _flag = "default", - outboundTag = default_outboundTag, + ruleTag = "default", balancerTag = default_balancerTag, network = "tcp,udp" }) end -]] + routing = { domainStrategy = node.domainStrategy or "AsIs", domainMatcher = node.domainMatcher or "hybrid", @@ -1395,7 +1394,7 @@ function gen_config(var) --按分流顺序DNS if dns_domain_rules and #dns_domain_rules > 0 then for index, value in ipairs(dns_domain_rules) do - if value.outboundTag and value.domain then + if value.domain and (value.outboundTag or value.balancerTag) then local dns_server = nil if value.outboundTag == "direct" then dns_server = api.clone(_direct_dns)