parent
300b6870bd
commit
e2d52df050
@ -3,7 +3,6 @@ local com = require "luci.passwall2.com"
|
|||||||
bin = require "nixio".bin
|
bin = require "nixio".bin
|
||||||
fs = require "nixio.fs"
|
fs = require "nixio.fs"
|
||||||
sys = require "luci.sys"
|
sys = require "luci.sys"
|
||||||
libuci = require "uci".cursor()
|
|
||||||
uci = require"luci.model.uci".cursor()
|
uci = require"luci.model.uci".cursor()
|
||||||
util = require "luci.util"
|
util = require "luci.util"
|
||||||
datatypes = require "luci.cbi.datatypes"
|
datatypes = require "luci.cbi.datatypes"
|
||||||
@ -30,33 +29,20 @@ function log(...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function uci_set_list(cursor, config, section, option, value)
|
function is_old_uci()
|
||||||
if config and section and option then
|
return sys.call("grep 'require \"uci\"' /usr/lib/lua/luci/model/uci.lua >/dev/null 2>&1") == 0
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function uci_save(cursor, config, commit, apply)
|
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
|
commit = true
|
||||||
if commit then
|
if commit then
|
||||||
if apply then
|
if apply then
|
||||||
@ -65,14 +51,6 @@ function uci_save(cursor, config, commit, apply)
|
|||||||
sh_uci_commit(config)
|
sh_uci_commit(config)
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ local ssub, slen, schar, sbyte, sformat, sgsub = string.sub, string.len, string.
|
|||||||
local split = api.split
|
local split = api.split
|
||||||
local jsonParse, jsonStringify = luci.jsonc.parse, luci.jsonc.stringify
|
local jsonParse, jsonStringify = luci.jsonc.parse, luci.jsonc.stringify
|
||||||
local base64Decode = api.base64Decode
|
local base64Decode = api.base64Decode
|
||||||
local uci = api.libuci
|
local uci = api.uci
|
||||||
local fs = api.fs
|
local fs = api.fs
|
||||||
uci:revert(appname)
|
uci:revert(appname)
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ do
|
|||||||
set = function(o)
|
set = function(o)
|
||||||
for kk, vv in pairs(CONFIG) do
|
for kk, vv in pairs(CONFIG) do
|
||||||
if (vv.remarks == id .. "备用节点的列表") then
|
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
|
end
|
||||||
end
|
end
|
||||||
@ -284,8 +284,8 @@ do
|
|||||||
if (vv.remarks == "Xray负载均衡节点[" .. node_id .. "]列表") then
|
if (vv.remarks == "Xray负载均衡节点[" .. node_id .. "]列表") then
|
||||||
uci:foreach(appname, "nodes", function(node2)
|
uci:foreach(appname, "nodes", function(node2)
|
||||||
if node2[".name"] == node[".name"] then
|
if node2[".name"] == node[".name"] then
|
||||||
local section = api.uci_section(uci, appname, "nodes", node_id)
|
local section = uci:section(appname, "nodes", node_id)
|
||||||
api.uci_set_list(uci, appname, section, "balancing_node", vv.new_nodes)
|
uci:set_list(appname, section, "balancing_node", vv.new_nodes)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@ -1423,7 +1423,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 = 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
|
for kkk, vvv in pairs(vv) do
|
||||||
uci:set(appname, cfgid, kkk, vvv)
|
uci:set(appname, cfgid, kkk, vvv)
|
||||||
-- sing-box 域名解析策略
|
-- sing-box 域名解析策略
|
||||||
|
Loading…
Reference in New Issue
Block a user