From e21b60d6c72cbfa471f684078a6844291b3d4b48 Mon Sep 17 00:00:00 2001 From: xiaorouji <60100640+xiaorouji@users.noreply.github.com> Date: Sun, 7 May 2023 01:34:57 +0800 Subject: [PATCH] luci: use short UUID The amount of data is not large, maybe not repeat. --- luci-app-passwall/luasrc/controller/passwall.lua | 2 +- luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua | 4 ++-- .../luasrc/model/cbi/passwall/client/haproxy.lua | 2 +- .../luasrc/model/cbi/passwall/client/node_list.lua | 2 +- luci-app-passwall/luasrc/passwall/api.lua | 4 ++++ luci-app-passwall/luasrc/passwall/util_xray.lua | 4 ++-- luci-app-passwall/root/usr/share/passwall/subscribe.lua | 2 +- 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/luci-app-passwall/luasrc/controller/passwall.lua b/luci-app-passwall/luasrc/controller/passwall.lua index 3bca32c84..1065fe8a7 100644 --- a/luci-app-passwall/luasrc/controller/passwall.lua +++ b/luci-app-passwall/luasrc/controller/passwall.lua @@ -290,7 +290,7 @@ end function copy_node() local section = luci.http.formvalue("section") - local uuid = api.gen_uuid() + local uuid = api.gen_short_uuid() ucic:section(appname, "nodes", uuid) for k, v in pairs(ucic:get_all(appname, section)) do local filter = k:find("%.") diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua index 7d1e16f2a..22d01ec2b 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua @@ -155,7 +155,7 @@ if (has_v2ray or has_xray) and #nodes_table > 0 then end if #normal_list > 0 then for k, v in pairs(shunt_list) do - local vid = v.id:sub(1, 8) + local vid = v.id -- shunt node type, V2ray or Xray local type = s:taboption("Main", ListValue, vid .. "-type", translate("Type")) if has_v2ray then @@ -513,7 +513,7 @@ s.anonymous = true s.addremove = true s.template = "cbi/tblsection" function s.create(e, t) - TypedSection.create(e, api.gen_uuid()) + TypedSection.create(e, api.gen_short_uuid()) end o = s:option(DummyValue, "status", translate("Status")) diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/haproxy.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/haproxy.lua index 7c6b03be1..416fbd53a 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/haproxy.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/haproxy.lua @@ -76,7 +76,7 @@ s.anonymous = true s.addremove = true s.create = function(e, t) - TypedSection.create(e, api.gen_uuid()) + TypedSection.create(e, api.gen_short_uuid()) end s.remove = function(self, section) diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_list.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_list.lua index 3ae17a53c..d2a721d54 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_list.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_list.lua @@ -26,7 +26,7 @@ s.addremove = true s.template = "cbi/tblsection" s.extedit = api.url("node_config", "%s") function s.create(e, t) - local uuid = api.gen_uuid() + local uuid = api.gen_short_uuid() t = uuid TypedSection.create(e, t) luci.http.redirect(e.extedit:format(t)) diff --git a/luci-app-passwall/luasrc/passwall/api.lua b/luci-app-passwall/luasrc/passwall/api.lua index 319928d43..604816526 100644 --- a/luci-app-passwall/luasrc/passwall/api.lua +++ b/luci-app-passwall/luasrc/passwall/api.lua @@ -365,6 +365,10 @@ function gen_uuid(format) return uuid end +function gen_short_uuid() + return sys.exec("echo -n $(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 8)") +end + function uci_get_type(type, config, default) local value = uci:get_first(appname, type, config, default) or sys.exec("echo -n $(uci -q get " .. appname .. ".@" .. type .."[0]." .. config .. ")") if (value == nil or value == "") and (default and default ~= "") then diff --git a/luci-app-passwall/luasrc/passwall/util_xray.lua b/luci-app-passwall/luasrc/passwall/util_xray.lua index 9cf130e4a..f5eb180ed 100644 --- a/luci-app-passwall/luasrc/passwall/util_xray.lua +++ b/luci-app-passwall/luasrc/passwall/util_xray.lua @@ -602,7 +602,7 @@ function gen_config(var) end local function get_balancer_tag(_node_id) - return "balancer-" .. _node_id:sub(1, 8) + return "balancer-" .. _node_id end local function gen_balancer(_node, loopbackTag) @@ -611,7 +611,7 @@ function gen_config(var) local valid_nodes = {} for i = 1, length do local blc_node_id = blc_nodes[i] - local blc_node_tag = "blc-" .. blc_node_id:sub(1, 8) + 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 diff --git a/luci-app-passwall/root/usr/share/passwall/subscribe.lua b/luci-app-passwall/root/usr/share/passwall/subscribe.lua index 17bdfba66..838256e0d 100755 --- a/luci-app-passwall/root/usr/share/passwall/subscribe.lua +++ b/luci-app-passwall/root/usr/share/passwall/subscribe.lua @@ -1059,7 +1059,7 @@ local function update_node(manual) local remark = v["remark"] local list = v["list"] for _, vv in ipairs(list) do - local cfgid = uci:section(appname, "nodes", api.gen_uuid()) + local cfgid = uci:section(appname, "nodes", api.gen_short_uuid()) for kkk, vvv in pairs(vv) do uci:set(appname, cfgid, kkk, vvv) end