diff --git a/luci-app-passwall/luasrc/controller/passwall.lua b/luci-app-passwall/luasrc/controller/passwall.lua index 8061ceff1..d3761e44d 100644 --- a/luci-app-passwall/luasrc/controller/passwall.lua +++ b/luci-app-passwall/luasrc/controller/passwall.lua @@ -119,11 +119,19 @@ end function autoswitch_add_node() local key = luci.http.formvalue("key") if key and key ~= "" then - for k, e in ipairs(api.get_valid_nodes()) do - if e.node_type == "normal" and e["remark"]:find(key) then - luci.sys.call(string.format("uci -q del_list passwall.@auto_switch[0].tcp_node='%s' && uci -q add_list passwall.@auto_switch[0].tcp_node='%s'", e.id, e.id)) + local new_list = ucic:get(appname, "@auto_switch[0]", "tcp_node") or {} + for i = #new_list, 1, -1 do + if (ucic:get(appname, new_list[i], "remarks") or ""):find(key) then + table.remove(new_list, i) end end + for k, e in ipairs(api.get_valid_nodes()) do + if e.node_type == "normal" and e["remark"]:find(key) then + table.insert(new_list, e.id) + end + end + ucic:set_list(appname, "@auto_switch[0]", "tcp_node", new_list) + ucic:commit(appname) end luci.http.redirect(api.url("auto_switch")) end @@ -131,11 +139,14 @@ end function autoswitch_remove_node() local key = luci.http.formvalue("key") if key and key ~= "" then - for k, e in ipairs(ucic:get(appname, "@auto_switch[0]", "tcp_node") or {}) do - if e and (ucic:get(appname, e, "remarks") or ""):find(key) then - luci.sys.call(string.format("uci -q del_list passwall.@auto_switch[0].tcp_node='%s'", e)) + local new_list = ucic:get(appname, "@auto_switch[0]", "tcp_node") or {} + for i = #new_list, 1, -1 do + if (ucic:get(appname, new_list[i], "remarks") or ""):find(key) then + table.remove(new_list, i) end end + ucic:set_list(appname, "@auto_switch[0]", "tcp_node", new_list) + ucic:commit(appname) end luci.http.redirect(api.url("auto_switch")) end @@ -331,11 +342,12 @@ function delete_select_nodes() local ids = luci.http.formvalue("ids") local auto_switch_tcp_node_list = ucic:get(appname, "@auto_switch[0]", "tcp_node") or {} string.gsub(ids, '[^' .. "," .. ']+', function(w) - for k, v in ipairs(auto_switch_tcp_node_list) do - if v == w then - luci.sys.call(string.format("uci -q del_list passwall.@auto_switch[0].tcp_node='%s'", w)) + for i = #auto_switch_tcp_node_list, 1, -1 do + if w == auto_switch_tcp_node_list[i] then + table.remove(auto_switch_tcp_node_list, i) end end + ucic:set_list(appname, "@auto_switch[0]", "tcp_node", auto_switch_tcp_node_list) if (ucic:get(appname, "@global[0]", "tcp_node") or "nil") == w then ucic:set(appname, '@global[0]', "tcp_node", "nil") end