luci-app-passwall2: sync upstream

last commit: 1cdf6f4d8c
This commit is contained in:
gitea-action 2025-01-03 17:00:20 +08:00
parent 300b6870bd
commit e2d52df050
2 changed files with 16 additions and 38 deletions

View File

@ -3,7 +3,6 @@ local com = require "luci.passwall2.com"
bin = require "nixio".bin
fs = require "nixio.fs"
sys = require "luci.sys"
libuci = require "uci".cursor()
uci = require"luci.model.uci".cursor()
util = require "luci.util"
datatypes = require "luci.cbi.datatypes"
@ -30,33 +29,20 @@ function log(...)
end
end
function uci_set_list(cursor, config, section, option, value)
if config and section and option then
if not value or #value == 0 then
return cursor:delete(config, section, option)
end
return cursor:set(
config, section, option,
( type(value) == "table" and value or { value } )
)
end
return false
end
function uci_section(cursor, config, type, name, values)
local stat = true
if name then
stat = cursor:set(config, name, type)
else
name = cursor:add(config, type)
stat = name and true
end
return stat and name
function is_old_uci()
return sys.call("grep 'require \"uci\"' /usr/lib/lua/luci/model/uci.lua >/dev/null 2>&1") == 0
end
function uci_save(cursor, config, commit, apply)
if is_js_luci() then
if is_old_uci() then
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
else
commit = true
if commit then
if apply then
@ -65,14 +51,6 @@ function uci_save(cursor, config, commit, apply)
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

View File

@ -17,7 +17,7 @@ local ssub, slen, schar, sbyte, sformat, sgsub = string.sub, string.len, string.
local split = api.split
local jsonParse, jsonStringify = luci.jsonc.parse, luci.jsonc.stringify
local base64Decode = api.base64Decode
local uci = api.libuci
local uci = api.uci
local fs = api.fs
uci:revert(appname)
@ -212,7 +212,7 @@ do
set = function(o)
for kk, vv in pairs(CONFIG) do
if (vv.remarks == id .. "备用节点的列表") then
api.uci_set_list(uci, appname, id, "autoswitch_backup_node", vv.new_nodes)
uci:set_list(appname, id, "autoswitch_backup_node", vv.new_nodes)
end
end
end
@ -284,8 +284,8 @@ do
if (vv.remarks == "Xray负载均衡节点[" .. node_id .. "]列表") then
uci:foreach(appname, "nodes", function(node2)
if node2[".name"] == node[".name"] then
local section = api.uci_section(uci, appname, "nodes", node_id)
api.uci_set_list(uci, appname, section, "balancing_node", vv.new_nodes)
local section = uci:section(appname, "nodes", node_id)
uci:set_list(appname, section, "balancing_node", vv.new_nodes)
end
end)
end
@ -1423,7 +1423,7 @@ local function update_node(manual)
local remark = v["remark"]
local list = v["list"]
for _, vv in ipairs(list) do
local cfgid = api.uci_section(uci, appname, "nodes", api.gen_short_uuid())
local cfgid = uci:section(appname, "nodes", api.gen_short_uuid())
for kkk, vvv in pairs(vv) do
uci:set(appname, cfgid, kkk, vvv)
-- sing-box 域名解析策略