From ce124906100506874c025d24506a7e51dd343920 Mon Sep 17 00:00:00 2001 From: action Date: Sun, 9 Aug 2026 12:59:02 +0800 Subject: [PATCH] update 2026-08-09 12:59:02 --- .../luasrc/model/cbi/passwall/client/acl.lua | 6 ++-- .../cbi/passwall/client/node_subscribe.lua | 11 +++--- .../root/etc/uci-defaults/luci-passwall | 10 ++++++ .../root/usr/share/passwall/app.sh | 35 +++++++++--------- .../root/usr/share/passwall/rule_update.lua | 2 +- .../root/usr/share/passwall/tasks.sh | 3 +- .../luasrc/controller/passwall2.lua | 36 +++++++++---------- .../luasrc/model/cbi/passwall2/client/acl.lua | 7 ++-- .../model/cbi/passwall2/client/global.lua | 7 ++-- .../model/cbi/passwall2/client/haproxy.lua | 5 ++- .../cbi/passwall2/client/node_subscribe.lua | 11 +++--- .../model/cbi/passwall2/client/other.lua | 5 ++- .../model/cbi/passwall2/server/index.lua | 7 ++-- .../model/cbi/passwall2/server/type/ray.lua | 2 +- .../cbi/passwall2/server/type/sing-box.lua | 2 +- luci-app-passwall2/luasrc/passwall2/api.lua | 7 ++-- .../root/usr/share/passwall2/subscribe.lua | 10 +++--- 17 files changed, 85 insertions(+), 81 deletions(-) diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/acl.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/acl.lua index e3f3d9a1..cc1edcf4 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/acl.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/acl.lua @@ -23,8 +23,10 @@ s.anonymous = true s.addremove = true s.extedit = api.url("acl_config", "%s") function s.create(e, t) - t = TypedSection.create(e, t) - luci.http.redirect(e.extedit:format(t)) + local uuid = api.gen_short_uuid(5) + uuid = "acl_" .. uuid + TypedSection.create(e, uuid) + luci.http.redirect(e.extedit:format(uuid)) end function s.remove(e, t) sys.call("rm -rf /tmp/etc/passwall_tmp/dns_" .. t .. "*") diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe.lua index 5d8ad73d..49b8cf88 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe.lua @@ -138,11 +138,12 @@ s.template = "cbi/tblsection" s.extedit = api.url("node_subscribe_config", "%s") function s.create(e, t) m.no_commit = true - local id = TypedSection.create(e, t) - uci:set(appname, id, "hysteria_up_mbps", "100") - uci:set(appname, id, "hysteria_down_mbps", "100") - api.uci_save(uci, appname) - luci.http.redirect(e.extedit:format(id)) + local uuid = api.gen_short_uuid(5) + uuid = "sub_" .. uuid + TypedSection.create(e, uuid) + m:set(uuid, "hysteria_up_mbps", "100") + m:set(uuid, "hysteria_down_mbps", "100") + luci.http.redirect(e.extedit:format(uuid)) end o = s:option(Value, "remark", translate("Remarks")) diff --git a/luci-app-passwall/root/etc/uci-defaults/luci-passwall b/luci-app-passwall/root/etc/uci-defaults/luci-passwall index c1212a54..dfe5c602 100755 --- a/luci-app-passwall/root/etc/uci-defaults/luci-passwall +++ b/luci-app-passwall/root/etc/uci-defaults/luci-passwall @@ -55,6 +55,16 @@ for sid in $(uci show passwall | grep "=socks" | awk -F '.' '{print $2}' | awk - unset sid new_id fi done +for sid in $(uci show passwall | grep "@acl_rule" | cut -d '.' -sf 2 | cut -d '=' -sf 1); do + new_id="acl_$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5)" + uci -q rename passwall.${sid}="${new_id}" + unset sid new_id +done +for sid in $(uci show passwall | grep "@subscribe_list" | cut -d '.' -sf 2 | cut -d '=' -sf 1); do + new_id="sub_$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5)" + uci -q rename passwall.${sid}="${new_id}" + unset sid new_id +done uci -q commit passwall diff --git a/luci-app-passwall/root/usr/share/passwall/app.sh b/luci-app-passwall/root/usr/share/passwall/app.sh index 9eba10e2..ad8ceb2f 100755 --- a/luci-app-passwall/root/usr/share/passwall/app.sh +++ b/luci-app-passwall/root/usr/share/passwall/app.sh @@ -1050,9 +1050,6 @@ socks_node_switch() { LOG_FILE="/dev/null" run_socks flag=$flag node=$new_node bind=$bind socks_port=$port config_file=$config_file http_port=$http_port http_config_file=$http_config_file log_file=$log_file set_cache_var "${flag}" "$new_node" - local ENABLED_DEFAULT_ACL=$(get_cache_var "ENABLED_DEFAULT_ACL") - local ENABLED_ACLS=$(get_cache_var "ENABLED_ACLS") - [ "$ENABLED_DEFAULT_ACL" != "1" ] && [ "$ENABLED_ACLS" != "1" ] && return local USE_TABLES=$(get_cache_var "USE_TABLES") [ -n "$USE_TABLES" ] && source $APP_PATH/${USE_TABLES}.sh filter_direct_node_list } @@ -1147,14 +1144,13 @@ start_crontab() { # ===== subscribe ===== local TMP_SUB_PATH=$TMP_PATH/sub_crontabs mkdir -p "$TMP_SUB_PATH" - local item cfgid remark sub_update_week_mode sub_update_time_mode + local item remark sub_update_week_mode sub_update_time_mode for item in $(uci show ${CONFIG} | grep "=subscribe_list" | cut -d '.' -sf 2 | cut -d '=' -sf 1); do sub_update_week_mode=$(config_n_get $item update_week_mode) if [ -n "$sub_update_week_mode" ]; then - cfgid=$(uci show ${CONFIG}.$item | head -n 1 | cut -d '.' -sf 2 | cut -d '=' -sf 1) remark=$(config_n_get "$item" remark) sub_update_time_mode=$(config_n_get $item update_time_mode) - echo "$cfgid" >> "$TMP_SUB_PATH/${sub_update_week_mode}_${sub_update_time_mode}" + echo "$item" >> "$TMP_SUB_PATH/${sub_update_week_mode}_${sub_update_time_mode}" echolog "配置定时任务:自动更新【$remark】订阅。" fi done @@ -1511,8 +1507,13 @@ start_haproxy() { acl_app() { local items=$(uci show ${CONFIG} | grep "=acl_rule" | cut -d '.' -sf 2 | cut -d '=' -sf 1) - [ -n "$items" ] && { - local item + if [ -z "$items" ]; then + ENABLED_ACLS=0 + set_cache_var ENABLED_ACLS $ENABLED_ACLS + return + else + local has_enabled + local sid local socks_port redir_port dns_port dnsmasq_port chinadns_port local msg msg2 socks_port=11100 @@ -1520,10 +1521,10 @@ acl_app() { dns_port=11300 dnsmasq_port=${GLOBAL_DNSMASQ_PORT:-11400} chinadns_port=11500 - for item in $items; do - local sid=$(uci -q show "${CONFIG}.${item}" | grep "=acl_rule" | awk -F '=' '{print $1}' | awk -F '.' '{print $2}') + for sid in $items; do [ "$(config_n_get $sid enabled)" = "1" ] || continue - eval $(uci -q show "${CONFIG}.${item}" | cut -d'.' -sf 3-) + has_enabled=1 + eval $(uci -q show "${CONFIG}.${sid}" | cut -d'.' -sf 3-) log=${log:-0} loglevel=${loglevel:-warning} @@ -1846,7 +1847,11 @@ acl_app() { unset _china_ng_listen _chinadns_local_dns _direct_dns_mode chinadns_ng_default_tag dnsmasq_filter_proxy_ipv6 remote_fakedns force_https_soa use_fakedns done unset socks_port redir_port dns_port dnsmasq_port chinadns_port - } + [ -n "${has_enabled}" ] || { + ENABLED_ACLS=0 + set_cache_var ENABLED_ACLS $ENABLED_ACLS + } + fi } start() { @@ -1903,8 +1908,7 @@ start() { local cfgids item for item in $(uci show ${CONFIG} | grep "=subscribe_list" | cut -d '.' -sf 2 | cut -d '=' -sf 1); do if [ "$(config_n_get "$item" boot_update 0)" = "1" ]; then - local cfgid=$(uci show ${CONFIG}.$item | head -n 1 | cut -d '.' -sf 2 | cut -d '=' -sf 1) - cfgids="${cfgids:+$cfgids,}$cfgid" + cfgids="${cfgids:+$cfgids,}$item" fi done [ -n "$cfgids" ] && { @@ -1994,9 +1998,6 @@ get_config() { done } ENABLED_ACLS=$(config_t_get global acl_enable 0) - [ "$ENABLED_ACLS" = 1 ] && { - [ "$(uci show ${CONFIG} | grep "@acl_rule" | grep "enabled='1'" | wc -l)" = 0 ] && ENABLED_ACLS=0 - } set_cache_var ENABLED_DEFAULT_ACL $ENABLED_DEFAULT_ACL set_cache_var ENABLED_ACLS $ENABLED_ACLS 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 53db2e1d..e236d425 100755 --- a/luci-app-passwall/root/usr/share/passwall/rule_update.lua +++ b/luci-app-passwall/root/usr/share/passwall/rule_update.lua @@ -533,7 +533,7 @@ local function fetch_geofile(geo_name, geo_type, url) local tmp_path = "/tmp/" .. geo_name local asset_path = asset_location .. geo_name local down_filename = url:match("^.*/([^/?#]+)") - local sha_url = url:gsub(down_filename, down_filename .. ".sha256sum") + local sha_url = url:gsub((down_filename:gsub("(%W)", "%%%1")), down_filename .. ".sha256sum") local sha_path = tmp_path .. ".sha256sum" local function verify_sha256(sha_file) diff --git a/luci-app-passwall/root/usr/share/passwall/tasks.sh b/luci-app-passwall/root/usr/share/passwall/tasks.sh index 25d2320e..f696e13e 100755 --- a/luci-app-passwall/root/usr/share/passwall/tasks.sh +++ b/luci-app-passwall/root/usr/share/passwall/tasks.sh @@ -41,10 +41,9 @@ do for item in $(uci show ${CONFIG} | grep "=subscribe_list" | cut -d '.' -sf 2 | cut -d '=' -sf 1); do sub_update_week_mode=$(config_n_get $item update_week_mode) if [ -n "$sub_update_week_mode" ]; then - cfgid=$(uci show ${CONFIG}.$item | head -n 1 | cut -d '.' -sf 2 | cut -d '=' -sf 1) remark=$(config_n_get $item remark) sub_update_interval_mode=$(config_n_get $item update_interval_mode) - echo "$cfgid" >> $TMP_SUB_PATH/${sub_update_week_mode}_${sub_update_interval_mode} + echo "$item" >> $TMP_SUB_PATH/${sub_update_week_mode}_${sub_update_interval_mode} fi done diff --git a/luci-app-passwall2/luasrc/controller/passwall2.lua b/luci-app-passwall2/luasrc/controller/passwall2.lua index 41e31611..cfd5fae2 100644 --- a/luci-app-passwall2/luasrc/controller/passwall2.lua +++ b/luci-app-passwall2/luasrc/controller/passwall2.lua @@ -393,22 +393,22 @@ end function add_node() local redirect = http.formvalue("redirect") - local uuid = api.gen_short_uuid() - uci:section(appname, "nodes", uuid) + local uid = api.gen_random_char() + uci:section(appname, "nodes", uid) local group = http.formvalue("group") if group and group ~= "default" then - uci:set(appname, uuid, "group", group) + uci:set(appname, uid, "group", group) end - uci:set(appname, uuid, "type", "Xray") + uci:set(appname, uid, "type", "Xray") if redirect == "1" then api.uci_save(uci, appname) - http.redirect(api.url("node_config", uuid)) + http.redirect(api.url("node_config", uid)) else api.uci_save(uci, appname, true, true) - http_write_json({result = uuid}) + http_write_json({result = uid}) end end @@ -423,17 +423,17 @@ end function copy_node() local section = http.formvalue("section") - local uuid = api.gen_short_uuid() - uci:section(appname, "nodes", uuid) + local uid = api.gen_random_char() + uci:section(appname, "nodes", uid) for k, v in pairs(uci:get_all(appname, section)) do if not k:match("^%.") and k ~= "group" then if k == "remarks" then v = (v or "") .. "(1)" end - uci:set(appname, uuid, k, v) + uci:set(appname, uid, k, v) end end - uci:set(appname, uuid, "add_mode", 1) + uci:set(appname, uid, "add_mode", 1) api.uci_save(uci, appname) - http.redirect(api.url("node_config", uuid)) + http.redirect(api.url("node_config", uid)) end function clear_all_nodes() @@ -999,29 +999,29 @@ function add_shunt_rule() local add_name = http.formvalue("add_name") local redirect = http.formvalue("redirect") - local uuid = add_name + local uid = add_name if add_name then - local has = uci:get(appname, uuid) + local has = uci:get(appname, uid) if has then http_write_json_error({ message = "This ID already exists." }) return end else - uuid = api.gen_short_uuid() + uid = api.gen_random_char() end - uci:section(appname, "shunt_rules", uuid) + uci:section(appname, "shunt_rules", uid) local group = http.formvalue("group") if group and group ~= "default" then - uci:set(appname, uuid, "group", group) + uci:set(appname, uid, "group", group) end if redirect == "1" then api.uci_save(uci, appname) - http.redirect(api.url("shunt_rules", uuid)) + http.redirect(api.url("shunt_rules", uid)) else api.uci_save(uci, appname) - http_write_json_ok({uuid = uuid, redirect_url = api.url("shunt_rules", uuid)}) + http_write_json_ok({uid = uid, redirect_url = api.url("shunt_rules", uid)}) end end diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl.lua index 979e5580..f24e2b50 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl.lua @@ -23,10 +23,9 @@ s.anonymous = true s.addremove = true s.extedit = api.url("acl_config", "%s") function s.create(e, t) - local uuid = api.gen_short_uuid(5) - uuid = "acl_" .. uuid - TypedSection.create(e, uuid) - luci.http.redirect(e.extedit:format(uuid)) + local uid = "acl_" .. api.gen_random_char(5) + TypedSection.create(e, uid) + luci.http.redirect(e.extedit:format(uid)) end ---- Enable diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/global.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/global.lua index 7ecd709d..634ff768 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/global.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/global.lua @@ -326,10 +326,9 @@ s2.anonymous = true s2.addremove = true s2.extedit = api.url("socks_config", "%s") function s2.create(e, t) - local uuid = api.gen_short_uuid(5) - uuid = "socks_" .. uuid - TypedSection.create(e, uuid) - luci.http.redirect(e.extedit:format(uuid)) + local uid = "socks_" .. api.gen_random_char(5) + TypedSection.create(e, uid) + luci.http.redirect(e.extedit:format(uid)) end o = s2:option(DummyValue, "status", translate("Status")) diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/haproxy.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/haproxy.lua index d6f14020..a1ce99f7 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/haproxy.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/haproxy.lua @@ -113,9 +113,8 @@ s.anonymous = true s.addremove = true s.create = function(e, t) - local uuid = api.gen_short_uuid(5) - uuid = "haproxy_" .. uuid - TypedSection.create(e, uuid) + local uid = "haproxy_" .. api.gen_random_char(5) + TypedSection.create(e, uid) end s.remove = function(self, section) diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_subscribe.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_subscribe.lua index 66df5407..3f7e7c68 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_subscribe.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_subscribe.lua @@ -134,12 +134,11 @@ s.sortable = true s.template = "cbi/tblsection" s.extedit = api.url("node_subscribe_config", "%s") function s.create(e, t) - local uuid = api.gen_short_uuid(5) - uuid = "sub_" .. uuid - TypedSection.create(e, uuid) - m:set(uuid, "hysteria_up_mbps", "100") - m:set(uuid, "hysteria_down_mbps", "100") - luci.http.redirect(e.extedit:format(uuid)) + local uid = "sub_" .. api.gen_random_char(5) + TypedSection.create(e, uid) + m:set(uid, "hysteria_up_mbps", "100") + m:set(uid, "hysteria_down_mbps", "100") + luci.http.redirect(e.extedit:format(uid)) end o = s:option(Value, "remark", translate("Remarks")) diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/other.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/other.lua index 74cc6f14..1a91208c 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/other.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/other.lua @@ -263,9 +263,8 @@ if has_xray then s_xray_noise.addremove = true s_xray_noise.create = function(e, t) - local uuid = api.gen_short_uuid(5) - uuid = "xray_noise_" .. uuid - TypedSection.create(e, uuid) + local uid = "xray_noise_" .. api.gen_random_char(5) + TypedSection.create(e, uid) end s_xray_noise.remove = function(self, section) diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/index.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/index.lua index 33f24596..ef9ba277 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/index.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/index.lua @@ -21,10 +21,9 @@ t.sortable = true t.template = "cbi/tblsection" t.extedit = api.url("server_user", "%s") function t.create(e, t) - local uuid = api.gen_uuid() - t = uuid - TypedSection.create(e, t) - luci.http.redirect(e.extedit:format(t)) + local uid = api.gen_random_char() + TypedSection.create(e, uid) + luci.http.redirect(e.extedit:format(uid)) end function t.remove(e, t) e.map.proceed = true diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/ray.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/ray.lua index 09dd948d..11bfc669 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/ray.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/ray.lua @@ -111,7 +111,7 @@ o:depends({ [_n("protocol")] = "socks" }) o = s:option(DynamicList, _n("uuid"), translate("ID") .. "/" .. translate("Password")) for i = 1, 3 do - o:value(api.gen_uuid(1)) + o:value(api.gen_uuid()) end o:depends({ [_n("protocol")] = "vmess" }) o:depends({ [_n("protocol")] = "vless" }) diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/sing-box.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/sing-box.lua index 8f906243..d0f01773 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/sing-box.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/sing-box.lua @@ -235,7 +235,7 @@ o:depends({ [_n("protocol")] = "shadowsocks" }) o = s:option(DynamicList, _n("uuid"), translate("ID") .. "/" .. translate("Password")) for i = 1, 3 do - o:value(api.gen_uuid(1)) + o:value(api.gen_uuid()) end o:depends({ [_n("protocol")] = "vmess" }) o:depends({ [_n("protocol")] = "vless" }) diff --git a/luci-app-passwall2/luasrc/passwall2/api.lua b/luci-app-passwall2/luasrc/passwall2/api.lua index f11ef1a7..5437f4f7 100644 --- a/luci-app-passwall2/luasrc/passwall2/api.lua +++ b/luci-app-passwall2/luasrc/passwall2/api.lua @@ -669,15 +669,12 @@ function get_full_node_remarks(n) return remarks end -function gen_uuid(format) +function gen_uuid() local uuid = sys.exec("echo -n $(cat /proc/sys/kernel/random/uuid)") - if format == nil then - uuid = string.gsub(uuid, "-", "") - end return uuid end -function gen_short_uuid(length) +function gen_random_char(length) if not length then length = 8 end return sys.exec("echo -n $(head /dev/urandom | tr -dc A-Za-z0-9 | head -c %s)" % length) end diff --git a/luci-app-passwall2/root/usr/share/passwall2/subscribe.lua b/luci-app-passwall2/root/usr/share/passwall2/subscribe.lua index 97cf756b..91bd534c 100755 --- a/luci-app-passwall2/root/usr/share/passwall2/subscribe.lua +++ b/luci-app-passwall2/root/usr/share/passwall2/subscribe.lua @@ -168,9 +168,9 @@ do local flag = i18n.translatef("Socks node list [%s]", i) .. " " .. i18n.translatef("Backup node list") local currentNodes = {} local newNodes = {} - for k, asb_node in ipairs(t.autoswitch_backup_node) do - if asb_node then - local currentNode = uci:get_all(appname, asb_node) or {} + for k, asb_node_id in ipairs(t.autoswitch_backup_node) do + if asb_node_id then + local currentNode = uci:get_all(appname, asb_node_id) or {} if currentNode[".type"] == "nodes" then currentNodes[#currentNodes + 1] = { log = true, @@ -277,7 +277,7 @@ do for k, e in pairs(rules) do local _node_id = node[e[".name"]] or nil if _node_id then - local section = uci:get_all(appname, node_id) or {} + local section = uci:get_all(appname, _node_id) or {} if section[".type"] == "nodes" then CONFIG[#CONFIG + 1] = { log = false, @@ -2274,7 +2274,7 @@ local function update_node(manual) chain_node_type = (outbound_iface_group ~= "") and "iface" or chain_node_type end for _, vv in ipairs(list) do - local cfgid = uci:section(appname, "nodes", api.gen_short_uuid()) + local cfgid = uci:section(appname, "nodes", api.gen_random_char()) for kkk, vvv in pairs(vv) do if type(vvv) == "table" and next(vvv) ~= nil then uci:set_list(appname, cfgid, kkk, vvv)