From f152d28d69ae257e0f1693d5db73130fd30a84f9 Mon Sep 17 00:00:00 2001 From: xiaorouji <60100640+xiaorouji@users.noreply.github.com> Date: Wed, 30 Aug 2023 00:56:28 +0800 Subject: [PATCH] luci: update subscribe script --- .../root/usr/share/passwall2/subscribe.lua | 84 ++++++++++--------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/luci-app-passwall2/root/usr/share/passwall2/subscribe.lua b/luci-app-passwall2/root/usr/share/passwall2/subscribe.lua index 64e16ffda..70763fd23 100755 --- a/luci-app-passwall2/root/usr/share/passwall2/subscribe.lua +++ b/luci-app-passwall2/root/usr/share/passwall2/subscribe.lua @@ -121,6 +121,9 @@ do set = function(o, server) uci:set(appname, t[".name"], option, server) o.newNodeId = server + end, + delete = function(o) + uci:delete(appname, t[".name"]) end } end) @@ -140,6 +143,9 @@ do set = function(o, server) uci:set(appname, t[".name"], option, server) o.newNodeId = server + end, + delete = function(o) + uci:delete(appname, t[".name"]) end } end) @@ -228,15 +234,20 @@ do for k, e in pairs(rules) do local _node_id = node[e[".name"]] or nil - CONFIG[#CONFIG + 1] = { - log = false, - currentNode = _node_id and uci:get_all(appname, _node_id) or nil, - remarks = "分流" .. e.remarks .. "节点", - set = function(o, server) - uci:set(appname, node_id, e[".name"], server) - o.newNodeId = server - end - } + if _node_id and api.parseURL(_node_id) then + else + CONFIG[#CONFIG + 1] = { + log = false, + currentNode = _node_id and uci:get_all(appname, _node_id) or nil, + remarks = "分流" .. e.remarks .. "节点", + set = function(o, server) + if not server then server = "nil" end + uci:set(appname, node_id, e[".name"], server) + o.newNodeId = server + end + } + end + end elseif node.protocol and node.protocol == '_balancing' then local node_id = node[".name"] @@ -288,7 +299,8 @@ do end end else - if v.currentNode == nil then + if v.currentNode == nil and v.delete then + v.delete() CONFIG[k] = nil end end @@ -810,23 +822,13 @@ local function truncate_nodes(add_from) end local function select_node(nodes, config) - local server if config.currentNode then - -- 特别优先级 分流 + 备注 - if config.currentNode.protocol and config.currentNode.protocol == '_shunt' then + local server + -- 特别优先级 cfgid + if config.currentNode[".name"] then for index, node in pairs(nodes) do - if node.remarks == config.currentNode.remarks then - log('更新【' .. config.remarks .. '】分流匹配节点:' .. node.remarks) - server = node[".name"] - break - end - end - end - -- 特别优先级 负载均衡 + 备注 - if config.currentNode.protocol and config.currentNode.protocol == '_balancing' then - for index, node in pairs(nodes) do - if node.remarks == config.currentNode.remarks then - log('更新【' .. config.remarks .. '】负载均衡匹配节点:' .. node.remarks) + if node[".name"] == config.currentNode[".name"] then + log('更新【' .. config.remarks .. '】匹配节点:' .. node.remarks) server = node[".name"] break end @@ -912,24 +914,26 @@ local function select_node(nodes, config) end end end - end - -- 还不行 随便找一个 - if not server then - local nodes_table = {} - for k, e in ipairs(api.get_valid_nodes()) do - if e.node_type == "normal" then - nodes_table[#nodes_table + 1] = e + -- 还不行 随便找一个 + if not server then + local nodes_table = {} + for k, e in ipairs(api.get_valid_nodes()) do + if e.node_type == "normal" then + nodes_table[#nodes_table + 1] = e + end + end + if #nodes_table > 0 then + if config.log == nil or config.log == true then + log('【' .. config.remarks .. '】' .. '无法找到最匹配的节点,当前已更换为:' .. nodes_table[1].remarks) + end + server = nodes_table[1][".name"] end end - if #nodes_table > 0 then - if config.log == nil or config.log == true then - log('【' .. config.remarks .. '】' .. '无法找到最匹配的节点,当前已更换为:' .. nodes_table[1].remarks) - end - server = nodes_table[1][".name"] + if server then + config.set(config, server) end - end - if server then - config.set(config, server) + else + config.set(config, nil) end end