diff --git a/luci-app-passwall/Makefile b/luci-app-passwall/Makefile index 3997cd8b7..b83e4c1a4 100644 --- a/luci-app-passwall/Makefile +++ b/luci-app-passwall/Makefile @@ -1,5 +1,5 @@ # Copyright (C) 2018-2020 L-WRT Team -# Copyright (C) 2021-2023 xiaorouji +# Copyright (C) 2021-2025 xiaorouji # # This is free software, licensed under the GNU General Public License v3. diff --git a/luci-app-passwall/luasrc/controller/passwall.lua b/luci-app-passwall/luasrc/controller/passwall.lua index 620d8b0c3..8df6d62d0 100644 --- a/luci-app-passwall/luasrc/controller/passwall.lua +++ b/luci-app-passwall/luasrc/controller/passwall.lua @@ -1,10 +1,10 @@ -- Copyright (C) 2018-2020 L-WRT Team --- Copyright (C) 2021-2023 xiaorouji +-- Copyright (C) 2021-2025 xiaorouji module("luci.controller.passwall", package.seeall) local api = require "luci.passwall.api" -local appname = "passwall" -- not available -local uci = api.libuci -- in funtion index() +local appname = "passwall" -- not available +local uci = api.uci -- in funtion index() local fs = api.fs local http = require "luci.http" local util = require "luci.util" @@ -17,8 +17,8 @@ function index() else return end end local api = require "luci.passwall.api" - local appname = "passwall" -- global definitions not available - local uci = api.libuci -- in function index() + local appname = "passwall" -- global definitions not available + local uci = api.uci -- in function index() local fs = api.fs entry({"admin", "services", appname}).dependent = true entry({"admin", "services", appname, "reset_config"}, call("reset_config")).leaf = true @@ -110,7 +110,7 @@ end function show_menu() uci:delete(appname, "@global[0]", "hide_from_luci") - uci:commit(appname) + api.uci_save(uci, appname, true) luci.sys.call("rm -rf /tmp/luci-*") luci.sys.call("/etc/init.d/rpcd restart >/dev/null") luci.http.redirect(api.url()) @@ -118,7 +118,7 @@ end function hide_menu() uci:set(appname, "@global[0]", "hide_from_luci","1") - uci:commit(appname) + api.uci_save(uci, appname, true) luci.sys.call("rm -rf /tmp/luci-*") luci.sys.call("/etc/init.d/rpcd restart >/dev/null") luci.http.redirect(luci.dispatcher.build_url("admin", "status", "overview")) @@ -135,6 +135,7 @@ function socks_autoswitch_add_node() local id = luci.http.formvalue("id") local key = luci.http.formvalue("key") if id and id ~= "" and key and key ~= "" then + uci:set(appname, id, "enable_autoswitch", "1") local new_list = uci:get(appname, id, "autoswitch_backup_node") or {} for i = #new_list, 1, -1 do if (uci:get(appname, new_list[i], "remarks") or ""):find(key) then @@ -146,8 +147,8 @@ function socks_autoswitch_add_node() table.insert(new_list, e.id) end end - api.uci_set_list(uci, appname, id, "autoswitch_backup_node", new_list) - uci:commit(appname) + uci:set_list(appname, id, "autoswitch_backup_node", new_list) + api.uci_save(uci, appname) end luci.http.redirect(api.url("socks_config", id)) end @@ -156,14 +157,15 @@ function socks_autoswitch_remove_node() local id = luci.http.formvalue("id") local key = luci.http.formvalue("key") if id and id ~= "" and key and key ~= "" then + uci:set(appname, id, "enable_autoswitch", "1") local new_list = uci:get(appname, id, "autoswitch_backup_node") or {} for i = #new_list, 1, -1 do if (uci:get(appname, new_list[i], "remarks") or ""):find(key) then table.remove(new_list, i) end end - api.uci_set_list(uci, appname, id, "autoswitch_backup_node", new_list) - uci:commit(appname) + uci:set_list(appname, id, "autoswitch_backup_node", new_list) + api.uci_save(uci, appname) end luci.http.redirect(api.url("socks_config", id)) end @@ -353,7 +355,7 @@ function set_node() local protocol = luci.http.formvalue("protocol") local section = luci.http.formvalue("section") uci:set(appname, "@global[0]", protocol .. "_node", section) - uci:commit(appname) + api.uci_save(uci, appname, true) luci.sys.call("/etc/init.d/passwall restart > /dev/null 2>&1 &") luci.http.redirect(api.url("log")) end @@ -361,7 +363,7 @@ end function copy_node() local section = luci.http.formvalue("section") local uuid = api.gen_short_uuid() - api.uci_section(uci, appname, "nodes", uuid) + uci:section(appname, "nodes", uuid) for k, v in pairs(uci:get_all(appname, section)) do local filter = k:find("%.") if filter and filter == 1 then @@ -375,7 +377,7 @@ function copy_node() end uci:delete(appname, uuid, "add_from") uci:set(appname, uuid, "add_mode", 1) - uci:commit(appname) + api.uci_save(uci, appname) luci.http.redirect(api.url("node_config", uuid)) end @@ -385,7 +387,7 @@ function clear_all_nodes() uci:delete(appname, '@global[0]', "udp_node") uci:foreach(appname, "socks", function(t) uci:delete(appname, t[".name"]) - api.uci_set_list(uci, appname, t[".name"], "autoswitch_backup_node", {}) + uci:set_list(appname, t[".name"], "autoswitch_backup_node", {}) end) uci:foreach(appname, "haproxy_config", function(t) uci:delete(appname, t[".name"]) @@ -398,7 +400,7 @@ function clear_all_nodes() uci:delete(appname, node['.name']) end) - uci:commit(appname) + api.uci_save(uci, appname, true) luci.sys.call("/etc/init.d/" .. appname .. " stop") end @@ -421,7 +423,7 @@ function delete_select_nodes() table.remove(auto_switch_node_list, i) end end - api.uci_set_list(uci, appname, t[".name"], "autoswitch_backup_node", auto_switch_node_list) + uci:set_list(appname, t[".name"], "autoswitch_backup_node", auto_switch_node_list) end) uci:foreach(appname, "haproxy_config", function(t) if t["lbss"] == w then @@ -448,7 +450,7 @@ function delete_select_nodes() end) uci:delete(appname, w) end) - uci:commit(appname) + api.uci_save(uci, appname, true) luci.sys.call("/etc/init.d/" .. appname .. " restart > /dev/null 2>&1 &") end diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/socks_config.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/socks_config.lua index bc1ab22d8..1e70f23fa 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/socks_config.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/socks_config.lua @@ -123,6 +123,8 @@ for k, v in pairs(nodes_table) do socks_node:value(v.id, v["remark"]) end -m:append(Template(appname .. "/socks_auto_switch/footer")) +o = s:option(DummyValue, "btn", " ") +o.template = appname .. "/socks_auto_switch/btn" +o:depends("enable_autoswitch", true) return m diff --git a/luci-app-passwall/luasrc/passwall/api.lua b/luci-app-passwall/luasrc/passwall/api.lua index c866607ce..1dbeb84ad 100644 --- a/luci-app-passwall/luasrc/passwall/api.lua +++ b/luci-app-passwall/luasrc/passwall/api.lua @@ -3,6 +3,7 @@ local com = require "luci.passwall.com" bin = require "nixio".bin fs = require "nixio.fs" sys = require "luci.sys" +uci = require "luci.model.uci".cursor() libuci = require "uci".cursor() util = require "luci.util" datatypes = require "luci.cbi.datatypes" @@ -30,6 +31,10 @@ function log(...) end end +function is_js_luci() + return sys.call('[ -f "/www/luci-static/resources/uci.js" ]') == 0 +end + function uci_set_list(cursor, config, section, option, value) if config and section and option then if not value or #value == 0 then @@ -55,24 +60,48 @@ function uci_section(cursor, config, type, name, values) return stat and name end +function uci_save(cursor, config, commit, apply) + if is_js_luci() then + commit = true + if commit then + if apply then + cursor:commit(config) + else + sh_uci_commit(config) + end + end + else + cursor:save(config) + if commit then + cursor:commit(config) + if apply then + sys.call("/etc/init.d/" .. config .. " reload > /dev/null 2>&1 &") + end + end + end +end + function sh_uci_get(config, section, option) exec_call(string.format("uci -q get %s.%s.%s", config, section, option)) - exec_call(string.format("uci -q commit %s", config)) end -function sh_uci_set(config, section, option, val) +function sh_uci_set(config, section, option, val, commit) exec_call(string.format("uci -q set %s.%s.%s=\"%s\"", config, section, option, val)) - exec_call(string.format("uci -q commit %s", config)) + if commit then sh_uci_commit(config) end end -function sh_uci_del(config, section, option) +function sh_uci_del(config, section, option, commit) exec_call(string.format("uci -q delete %s.%s.%s", config, section, option)) - exec_call(string.format("uci -q commit %s", config)) + if commit then sh_uci_commit(config) end end -function sh_uci_add_list(config, section, option, val) +function sh_uci_add_list(config, section, option, val, commit) exec_call(string.format("uci -q del_list %s.%s.%s=\"%s\"", config, section, option, val)) exec_call(string.format("uci -q add_list %s.%s.%s=\"%s\"", config, section, option, val)) + if commit then sh_uci_commit(config) end +end + +function sh_uci_commit(config) exec_call(string.format("uci -q commit %s", config)) end @@ -175,7 +204,7 @@ end function curl_direct(url, file, args) --直连访问 - local chn_list = libuci:get(appname, "@global[0]", "chn_list") or "direct" + local chn_list = uci:get(appname, "@global[0]", "chn_list") or "direct" local Dns = (chn_list == "proxy") and "1.1.1.1" or "223.5.5.5" if not args then args = {} end local tmp_args = clone(args) @@ -419,30 +448,10 @@ function get_domain_from_url(url) return url end -function get_node_name(node_id) - local e - if type(node_id) == "table" then - e = node_id - else - e = libuci:get_all(appname, node_id) - end - if e then - if e.type and e.remarks then - if e.protocol and (e.protocol == "_balancing" or e.protocol == "_shunt" or e.protocol == "_iface") then - local type = e.type - if type == "sing-box" then type = "Sing-Box" end - local remark = "%s:[%s] " % {type .. " " .. i18n.translatef(e.protocol), e.remarks} - return remark - end - end - end - return "" -end - function get_valid_nodes() local show_node_info = uci_get_type("@global_other[0]", "show_node_info", "0") local nodes = {} - libuci:foreach(appname, "nodes", function(e) + uci:foreach(appname, "nodes", function(e) e.id = e[".name"] if e.type and e.remarks then if e.protocol and (e.protocol == "_balancing" or e.protocol == "_shunt" or e.protocol == "_iface") then @@ -539,7 +548,7 @@ function gen_short_uuid() end function uci_get_type(type, config, default) - local value = libuci:get(appname, type, config) or default + local value = uci:get(appname, type, config) or default if (value == nil or value == "") and (default and default ~= "") then value = default end diff --git a/luci-app-passwall/luasrc/passwall/server_app.lua b/luci-app-passwall/luasrc/passwall/server_app.lua index ef267c649..50357056b 100644 --- a/luci-app-passwall/luasrc/passwall/server_app.lua +++ b/luci-app-passwall/luasrc/passwall/server_app.lua @@ -3,7 +3,7 @@ local action = arg[1] local api = require "luci.passwall.api" local sys = api.sys -local uci = api.libuci +local uci = api.uci local jsonc = api.jsonc local CONFIG = "passwall_server" diff --git a/luci-app-passwall/luasrc/passwall/util_hysteria2.lua b/luci-app-passwall/luasrc/passwall/util_hysteria2.lua index 12afe6874..b818aadbf 100644 --- a/luci-app-passwall/luasrc/passwall/util_hysteria2.lua +++ b/luci-app-passwall/luasrc/passwall/util_hysteria2.lua @@ -1,6 +1,6 @@ module("luci.passwall.util_hysteria2", package.seeall) local api = require "luci.passwall.api" -local uci = api.libuci +local uci = api.uci local jsonc = api.jsonc function gen_config_server(node) diff --git a/luci-app-passwall/luasrc/passwall/util_naiveproxy.lua b/luci-app-passwall/luasrc/passwall/util_naiveproxy.lua index b6ef39b3b..ee095c1e6 100644 --- a/luci-app-passwall/luasrc/passwall/util_naiveproxy.lua +++ b/luci-app-passwall/luasrc/passwall/util_naiveproxy.lua @@ -1,6 +1,6 @@ module("luci.passwall.util_naiveproxy", package.seeall) local api = require "luci.passwall.api" -local uci = api.libuci +local uci = api.uci local jsonc = api.jsonc function gen_config(var) diff --git a/luci-app-passwall/luasrc/passwall/util_shadowsocks.lua b/luci-app-passwall/luasrc/passwall/util_shadowsocks.lua index 5e724e77b..e6080001b 100644 --- a/luci-app-passwall/luasrc/passwall/util_shadowsocks.lua +++ b/luci-app-passwall/luasrc/passwall/util_shadowsocks.lua @@ -1,6 +1,6 @@ module("luci.passwall.util_shadowsocks", package.seeall) local api = require "luci.passwall.api" -local uci = api.libuci +local uci = api.uci local jsonc = api.jsonc function gen_config_server(node) diff --git a/luci-app-passwall/luasrc/passwall/util_sing-box.lua b/luci-app-passwall/luasrc/passwall/util_sing-box.lua index e6cdbc7d3..bfa24b46c 100644 --- a/luci-app-passwall/luasrc/passwall/util_sing-box.lua +++ b/luci-app-passwall/luasrc/passwall/util_sing-box.lua @@ -1,6 +1,6 @@ module("luci.passwall.util_sing-box", package.seeall) local api = require "luci.passwall.api" -local uci = api.libuci +local uci = api.uci local sys = api.sys local jsonc = api.jsonc local appname = "passwall" diff --git a/luci-app-passwall/luasrc/passwall/util_trojan.lua b/luci-app-passwall/luasrc/passwall/util_trojan.lua index 31bd67a4a..848b689a5 100644 --- a/luci-app-passwall/luasrc/passwall/util_trojan.lua +++ b/luci-app-passwall/luasrc/passwall/util_trojan.lua @@ -1,6 +1,6 @@ module("luci.passwall.util_trojan", package.seeall) local api = require "luci.passwall.api" -local uci = api.libuci +local uci = api.uci local json = api.jsonc function gen_config_server(node) diff --git a/luci-app-passwall/luasrc/passwall/util_tuic.lua b/luci-app-passwall/luasrc/passwall/util_tuic.lua index be00dcb8c..e138b6da5 100644 --- a/luci-app-passwall/luasrc/passwall/util_tuic.lua +++ b/luci-app-passwall/luasrc/passwall/util_tuic.lua @@ -1,6 +1,6 @@ module("luci.passwall.util_tuic", package.seeall) local api = require "luci.passwall.api" -local uci = api.libuci +local uci = api.uci local json = api.jsonc function gen_config(var) diff --git a/luci-app-passwall/luasrc/passwall/util_xray.lua b/luci-app-passwall/luasrc/passwall/util_xray.lua index c3ac56c20..828b7681f 100644 --- a/luci-app-passwall/luasrc/passwall/util_xray.lua +++ b/luci-app-passwall/luasrc/passwall/util_xray.lua @@ -1,6 +1,6 @@ module("luci.passwall.util_xray", package.seeall) local api = require "luci.passwall.api" -local uci = api.libuci +local uci = api.uci local sys = api.sys local jsonc = api.jsonc local appname = "passwall" diff --git a/luci-app-passwall/luasrc/view/passwall/socks_auto_switch/footer.htm b/luci-app-passwall/luasrc/view/passwall/socks_auto_switch/btn.htm similarity index 63% rename from luci-app-passwall/luasrc/view/passwall/socks_auto_switch/footer.htm rename to luci-app-passwall/luasrc/view/passwall/socks_auto_switch/btn.htm index 067b97876..287c1d2f4 100644 --- a/luci-app-passwall/luasrc/view/passwall/socks_auto_switch/footer.htm +++ b/luci-app-passwall/luasrc/view/passwall/socks_auto_switch/btn.htm @@ -19,5 +19,7 @@ local api = require "luci.passwall.api" } //]]> - - \ No newline at end of file +
" data-index="<%=self.index%>" data-depends="<%=pcdata(self:deplist2json(section))%>"> + + +
\ No newline at end of file diff --git a/luci-app-passwall/root/usr/share/passwall/app.sh b/luci-app-passwall/root/usr/share/passwall/app.sh index eafa62591..9a1bd893a 100755 --- a/luci-app-passwall/root/usr/share/passwall/app.sh +++ b/luci-app-passwall/root/usr/share/passwall/app.sh @@ -1,6 +1,6 @@ #!/bin/sh # Copyright (C) 2018-2020 L-WRT Team -# Copyright (C) 2021-2023 xiaorouji +# Copyright (C) 2021-2025 xiaorouji . $IPKG_INSTROOT/lib/functions.sh . $IPKG_INSTROOT/lib/functions/service.sh diff --git a/luci-app-passwall/root/usr/share/passwall/haproxy.lua b/luci-app-passwall/root/usr/share/passwall/haproxy.lua index 7efaaeb78..67366ae1f 100644 --- a/luci-app-passwall/root/usr/share/passwall/haproxy.lua +++ b/luci-app-passwall/root/usr/share/passwall/haproxy.lua @@ -4,7 +4,7 @@ local api = require ("luci.passwall.api") local appname = "passwall" local fs = api.fs local jsonc = api.jsonc -local uci = api.libuci +local uci = api.uci local sys = api.sys local log = function(...) diff --git a/luci-app-passwall/root/usr/share/passwall/helper_chinadns_add.lua b/luci-app-passwall/root/usr/share/passwall/helper_chinadns_add.lua index 981578adb..061615370 100644 --- a/luci-app-passwall/root/usr/share/passwall/helper_chinadns_add.lua +++ b/luci-app-passwall/root/usr/share/passwall/helper_chinadns_add.lua @@ -21,7 +21,7 @@ local NFTFLAG = var["-NFTFLAG"] local REMOTE_FAKEDNS = var["-REMOTE_FAKEDNS"] local LOG_FILE = var["-LOG_FILE"] -local uci = api.libuci +local uci = api.uci local sys = api.sys local fs = api.fs local datatypes = api.datatypes diff --git a/luci-app-passwall/root/usr/share/passwall/helper_dnsmasq.lua b/luci-app-passwall/root/usr/share/passwall/helper_dnsmasq.lua index b168d73e1..165ed51fc 100644 --- a/luci-app-passwall/root/usr/share/passwall/helper_dnsmasq.lua +++ b/luci-app-passwall/root/usr/share/passwall/helper_dnsmasq.lua @@ -1,6 +1,6 @@ local api = require "luci.passwall.api" local appname = "passwall" -local uci = api.libuci +local uci = api.uci local sys = api.sys local fs = api.fs local datatypes = api.datatypes @@ -25,7 +25,7 @@ local function backup_servers() local DNSMASQ_DNS = uci:get("dhcp", "@dnsmasq[0]", "server") if DNSMASQ_DNS and #DNSMASQ_DNS > 0 then uci:set(appname, "@global[0]", "dnsmasq_servers", DNSMASQ_DNS) - uci:commit(appname) + api.uci_save(uci, appname, true) end end @@ -43,11 +43,11 @@ local function restore_servers() tinsert(dns_table, v) end uci:delete(appname, "@global[0]", "dnsmasq_servers") - uci:commit(appname) + api.uci_save(uci, appname, true) end if dns_table and #dns_table > 0 then - api.uci_set_list(uci, "dhcp", "@dnsmasq[0]", "server", dns_table) - uci:commit("dhcp") + uci:set_list("dhcp", "@dnsmasq[0]", "server", dns_table) + api.uci_save(uci, "dhcp", true) end end @@ -76,7 +76,7 @@ function stretch() end end uci:set("dhcp", "@dnsmasq[0]", "resolvfile", RESOLVFILE) - uci:commit("dhcp") + api.uci_save(uci, "dhcp", true) end end @@ -102,8 +102,8 @@ function logic_restart(var) tinsert(dns_table, v) end end - api.uci_set_list(uci, "dhcp", "@dnsmasq[0]", "server", dns_table) - uci:commit("dhcp") + uci:set_list("dhcp", "@dnsmasq[0]", "server", dns_table) + api.uci_save(uci, "dhcp", true) end sys.call("/etc/init.d/dnsmasq restart >/dev/null 2>&1") restore_servers() diff --git a/luci-app-passwall/root/usr/share/passwall/helper_smartdns_add.lua b/luci-app-passwall/root/usr/share/passwall/helper_smartdns_add.lua index 16e1419d9..ed0fa0bfc 100644 --- a/luci-app-passwall/root/usr/share/passwall/helper_smartdns_add.lua +++ b/luci-app-passwall/root/usr/share/passwall/helper_smartdns_add.lua @@ -28,7 +28,7 @@ local CACHE_FLAG = "smartdns_" .. FLAG local CACHE_DNS_PATH = CACHE_PATH .. "/" .. CACHE_FLAG local CACHE_DNS_FILE = CACHE_DNS_PATH .. ".conf" -local uci = api.libuci +local uci = api.uci local sys = api.sys local fs = api.fs local datatypes = api.datatypes diff --git a/luci-app-passwall/root/usr/share/passwall/rule_update.lua b/luci-app-passwall/root/usr/share/passwall/rule_update.lua index e399a70e8..f0ffc645e 100755 --- a/luci-app-passwall/root/usr/share/passwall/rule_update.lua +++ b/luci-app-passwall/root/usr/share/passwall/rule_update.lua @@ -2,7 +2,7 @@ local api = require ("luci.passwall.api") local name = api.appname -local uci = api.libuci +local uci = api.uci local sys = api.sys local jsonc = api.jsonc local fs = api.fs @@ -469,7 +469,7 @@ uci:set(name, "@global_rules[0]", "chnroute6_update", chnroute6_update) uci:set(name, "@global_rules[0]", "chnlist_update", chnlist_update) uci:set(name, "@global_rules[0]", "geoip_update", geoip_update) uci:set(name, "@global_rules[0]", "geosite_update", geosite_update) -uci:commit(name) +api.uci_save(uci, name, true) if reboot == 1 then if arg3 == "cron" then diff --git a/luci-app-passwall/root/usr/share/passwall/subscribe.lua b/luci-app-passwall/root/usr/share/passwall/subscribe.lua index 8f66cef70..696c18e78 100755 --- a/luci-app-passwall/root/usr/share/passwall/subscribe.lua +++ b/luci-app-passwall/root/usr/share/passwall/subscribe.lua @@ -1312,7 +1312,7 @@ local function truncate_nodes(add_from) end end end) - uci:commit(appname) + api.uci_save(uci, appname, true) end local function select_node(nodes, config) @@ -1464,7 +1464,7 @@ local function update_node(manual) end end end - uci:commit(appname) + api.uci_save(uci, appname, true) if next(CONFIG) then local nodes = {} @@ -1499,7 +1499,7 @@ local function update_node(manual) end ]]-- - uci:commit(appname) + api.uci_save(uci, appname, true) end if arg[3] == "cron" then diff --git a/patch-luci-app-passwall.patch b/patch-luci-app-passwall.patch index 5ecf502ee..af13fe1ec 100644 --- a/patch-luci-app-passwall.patch +++ b/patch-luci-app-passwall.patch @@ -1,5 +1,5 @@ diff --git a/luci-app-passwall/Makefile b/luci-app-passwall/Makefile -index 7b625ea..3997cd8 100644 +index 6653f5f..b83e4c1 100644 --- a/luci-app-passwall/Makefile +++ b/luci-app-passwall/Makefile @@ -144,7 +144,7 @@ config PACKAGE_$(PKG_NAME)_INCLUDE_V2ray_Geodata @@ -20,10 +20,10 @@ index 7b625ea..3997cd8 100644 define Package/$(PKG_NAME)/postrm diff --git a/luci-app-passwall/luasrc/controller/passwall.lua b/luci-app-passwall/luasrc/controller/passwall.lua -index 2ed0db4..620d8b0 100644 +index c01e5ef..8df6d62 100644 --- a/luci-app-passwall/luasrc/controller/passwall.lua +++ b/luci-app-passwall/luasrc/controller/passwall.lua -@@ -296,7 +296,7 @@ function connect_status() +@@ -298,7 +298,7 @@ function connect_status() url = "-x socks5h://" .. socks_server .. " " .. url end end