luci: use short UUID

The amount of data is not large, maybe not repeat.
This commit is contained in:
xiaorouji 2023-05-07 01:34:57 +08:00 committed by sbwml
parent d85a74ded8
commit e21b60d6c7
7 changed files with 12 additions and 8 deletions

View File

@ -290,7 +290,7 @@ end
function copy_node() function copy_node()
local section = luci.http.formvalue("section") local section = luci.http.formvalue("section")
local uuid = api.gen_uuid() local uuid = api.gen_short_uuid()
ucic:section(appname, "nodes", uuid) ucic:section(appname, "nodes", uuid)
for k, v in pairs(ucic:get_all(appname, section)) do for k, v in pairs(ucic:get_all(appname, section)) do
local filter = k:find("%.") local filter = k:find("%.")

View File

@ -155,7 +155,7 @@ if (has_v2ray or has_xray) and #nodes_table > 0 then
end end
if #normal_list > 0 then if #normal_list > 0 then
for k, v in pairs(shunt_list) do 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 -- shunt node type, V2ray or Xray
local type = s:taboption("Main", ListValue, vid .. "-type", translate("Type")) local type = s:taboption("Main", ListValue, vid .. "-type", translate("Type"))
if has_v2ray then if has_v2ray then
@ -513,7 +513,7 @@ s.anonymous = true
s.addremove = true s.addremove = true
s.template = "cbi/tblsection" s.template = "cbi/tblsection"
function s.create(e, t) function s.create(e, t)
TypedSection.create(e, api.gen_uuid()) TypedSection.create(e, api.gen_short_uuid())
end end
o = s:option(DummyValue, "status", translate("Status")) o = s:option(DummyValue, "status", translate("Status"))

View File

@ -76,7 +76,7 @@ s.anonymous = true
s.addremove = true s.addremove = true
s.create = function(e, t) s.create = function(e, t)
TypedSection.create(e, api.gen_uuid()) TypedSection.create(e, api.gen_short_uuid())
end end
s.remove = function(self, section) s.remove = function(self, section)

View File

@ -26,7 +26,7 @@ s.addremove = true
s.template = "cbi/tblsection" s.template = "cbi/tblsection"
s.extedit = api.url("node_config", "%s") s.extedit = api.url("node_config", "%s")
function s.create(e, t) function s.create(e, t)
local uuid = api.gen_uuid() local uuid = api.gen_short_uuid()
t = uuid t = uuid
TypedSection.create(e, t) TypedSection.create(e, t)
luci.http.redirect(e.extedit:format(t)) luci.http.redirect(e.extedit:format(t))

View File

@ -365,6 +365,10 @@ function gen_uuid(format)
return uuid return uuid
end 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) 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 .. ")") 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 if (value == nil or value == "") and (default and default ~= "") then

View File

@ -602,7 +602,7 @@ function gen_config(var)
end end
local function get_balancer_tag(_node_id) local function get_balancer_tag(_node_id)
return "balancer-" .. _node_id:sub(1, 8) return "balancer-" .. _node_id
end end
local function gen_balancer(_node, loopbackTag) local function gen_balancer(_node, loopbackTag)
@ -611,7 +611,7 @@ function gen_config(var)
local valid_nodes = {} local valid_nodes = {}
for i = 1, length do for i = 1, length do
local blc_node_id = blc_nodes[i] 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 local is_new_blc_node = true
for _, outbound in ipairs(outbounds) do for _, outbound in ipairs(outbounds) do
if outbound.tag == blc_node_tag then if outbound.tag == blc_node_tag then

View File

@ -1059,7 +1059,7 @@ local function update_node(manual)
local remark = v["remark"] local remark = v["remark"]
local list = v["list"] local list = v["list"]
for _, vv in ipairs(list) do 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 for kkk, vvv in pairs(vv) do
uci:set(appname, cfgid, kkk, vvv) uci:set(appname, cfgid, kkk, vvv)
end end