update 2024-12-26 09:00:47

This commit is contained in:
actions-user 2024-12-26 09:00:47 +08:00
parent 92b32a8b8c
commit 650e7b1d2e
10 changed files with 134 additions and 35 deletions

View File

@ -6,7 +6,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-passwall
PKG_VERSION:=24.12.25
PKG_VERSION:=24.12.26
PKG_RELEASE:=1
PKG_CONFIG_DEPENDS:= \

View File

@ -4,7 +4,7 @@
module("luci.controller.passwall", package.seeall)
local api = require "luci.passwall.api"
local appname = "passwall" -- not available
local uci = luci.model.uci.cursor() -- in funtion index()
local uci = api.libuci -- in funtion index()
local http = require "luci.http"
local util = require "luci.util"
local i18n = require "luci.i18n"
@ -16,8 +16,9 @@ function index()
luci.sys.call('cp -f /usr/share/passwall/0_default_config /etc/config/passwall')
else return end
end
local api = require "luci.passwall.api"
local appname = "passwall" -- global definitions not available
local uci = luci.model.uci.cursor() -- in function index()
local uci = api.libuci -- in function index()
entry({"admin", "services", appname}).dependent = true
entry({"admin", "services", appname, "reset_config"}, call("reset_config")).leaf = true
entry({"admin", "services", appname, "show"}, call("show_menu")).leaf = true
@ -143,7 +144,7 @@ function socks_autoswitch_add_node()
table.insert(new_list, e.id)
end
end
uci:set_list(appname, id, "autoswitch_backup_node", new_list)
api.uci_set_list(uci, appname, id, "autoswitch_backup_node", new_list)
uci:commit(appname)
end
luci.http.redirect(api.url("socks_config", id))
@ -159,7 +160,7 @@ function socks_autoswitch_remove_node()
table.remove(new_list, i)
end
end
uci:set_list(appname, id, "autoswitch_backup_node", new_list)
api.uci_set_list(uci, appname, id, "autoswitch_backup_node", new_list)
uci:commit(appname)
end
luci.http.redirect(api.url("socks_config", id))
@ -346,7 +347,7 @@ end
function copy_node()
local section = luci.http.formvalue("section")
local uuid = api.gen_short_uuid()
uci:section(appname, "nodes", uuid)
api.uci_section(uci, appname, "nodes", uuid)
for k, v in pairs(uci:get_all(appname, section)) do
local filter = k:find("%.")
if filter and filter == 1 then
@ -370,7 +371,7 @@ function clear_all_nodes()
uci:delete(appname, '@global[0]', "udp_node")
uci:foreach(appname, "socks", function(t)
uci:delete(appname, t[".name"])
uci:set_list(appname, t[".name"], "autoswitch_backup_node", {})
api.uci_set_list(uci, appname, t[".name"], "autoswitch_backup_node", {})
end)
uci:foreach(appname, "haproxy_config", function(t)
uci:delete(appname, t[".name"])
@ -406,7 +407,7 @@ function delete_select_nodes()
table.remove(auto_switch_node_list, i)
end
end
uci:set_list(appname, t[".name"], "autoswitch_backup_node", auto_switch_node_list)
api.uci_set_list(uci, appname, t[".name"], "autoswitch_backup_node", auto_switch_node_list)
end)
uci:foreach(appname, "haproxy_config", function(t)
if t["lbss"] == w then

View File

@ -3,6 +3,7 @@ local com = require "luci.passwall.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,6 +31,52 @@ 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
end
function sh_uci_get(config, section, option)
exec_call(string.format("uci -q get %s.%s.%s", config, section, option))
exec_call(string.format("uci -q commit %s", config))
end
function sh_uci_set(config, section, option, val)
exec_call(string.format("uci -q set %s.%s.%s=\"%s\"", config, section, option, val))
exec_call(string.format("uci -q commit %s", config))
end
function sh_uci_del(config, section, option)
exec_call(string.format("uci -q delete %s.%s.%s", config, section, option))
exec_call(string.format("uci -q commit %s", config))
end
function sh_uci_add_list(config, section, option, val)
exec_call(string.format("uci -q del_list %s.%s.%s=\"%s\"", config, section, option, val))
exec_call(string.format("uci -q add_list %s.%s.%s=\"%s\"", config, section, option, val))
exec_call(string.format("uci -q commit %s", config))
end
function set_cache_var(key, val)
sys.call(string.format('/usr/share/passwall/app.sh set_cache_var %s "%s"', key, val))
end

View File

@ -1,6 +1,6 @@
local api = require "luci.passwall.api"
local appname = "passwall"
local uci = api.uci
local uci = api.libuci
local sys = api.sys
local fs = api.fs
local datatypes = api.datatypes
@ -46,7 +46,7 @@ local function restore_servers()
uci:commit(appname)
end
if dns_table and #dns_table > 0 then
uci:set_list("dhcp", "@dnsmasq[0]", "server", dns_table)
api.uci_set_list(uci, "dhcp", "@dnsmasq[0]", "server", dns_table)
uci:commit("dhcp")
end
end
@ -102,7 +102,7 @@ function logic_restart(var)
tinsert(dns_table, v)
end
end
uci:set_list("dhcp", "@dnsmasq[0]", "server", dns_table)
api.uci_set_list(uci, "dhcp", "@dnsmasq[0]", "server", dns_table)
uci:commit("dhcp")
end
sys.call("/etc/init.d/dnsmasq restart >/dev/null 2>&1")
@ -505,11 +505,14 @@ function add_rule(var)
end
if fwd_dns then
local sets = {
setflag_4 .. "passwall_chn"
setflag_4 .. "passwall_chn",
setflag_6 .. "passwall_chn6"
}
if CHN_LIST == "proxy" then
if NO_PROXY_IPV6 ~= "1" then
table.insert(sets, setflag_6 .. "passwall_chn6")
if NO_PROXY_IPV6 == "1" then
sets = {
setflag_4 .. "passwall_chn"
}
end
if REMOTE_FAKEDNS == "1" then
sets = {}

View File

@ -19,7 +19,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 = luci.model.uci.cursor()
local uci = api.libuci
uci:revert(appname)
local has_ss = api.is_finded("ss-redir")
@ -229,7 +229,7 @@ do
set = function(o)
for kk, vv in pairs(CONFIG) do
if (vv.remarks == id .. "备用节点的列表") then
uci:set_list(appname, id, "autoswitch_backup_node", vv.new_nodes)
api.uci_set_list(uci, appname, id, "autoswitch_backup_node", vv.new_nodes)
end
end
end
@ -300,8 +300,8 @@ do
if (vv.remarks == "Xray负载均衡节点[" .. node_id .. "]列表") then
uci:foreach(appname, "nodes", function(node2)
if node2[".name"] == node[".name"] then
local section = uci:section(appname, "nodes", node_id)
uci:set_list(appname, section, "balancing_node", vv.new_nodes)
local section = api.uci_section(uci, appname, "nodes", node_id)
api.uci_set_list(uci, appname, section, "balancing_node", vv.new_nodes)
end
end)
end
@ -1456,7 +1456,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_short_uuid())
local cfgid = api.uci_section(uci, appname, "nodes", api.gen_short_uuid())
for kkk, vvv in pairs(vv) do
uci:set(appname, cfgid, kkk, vvv)
-- sing-box 域名解析策略

View File

@ -5,7 +5,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-passwall2
PKG_VERSION:=24.12.25
PKG_VERSION:=24.12.26
PKG_RELEASE:=1
PKG_CONFIG_DEPENDS:= \

View File

@ -3,7 +3,7 @@
module("luci.controller.passwall2", package.seeall)
local api = require "luci.passwall2.api"
local appname = api.appname -- not available
local uci = luci.model.uci.cursor() -- in funtion index()
local uci = api.libuci -- in funtion index()
local http = require "luci.http"
local util = require "luci.util"
local i18n = require "luci.i18n"
@ -14,8 +14,9 @@ function index()
luci.sys.call('cp -f /usr/share/passwall2/0_default_config /etc/config/passwall2')
else return end
end
local api = require "luci.passwall2.api"
local appname = "passwall2" -- global definitions not available
local uci = luci.model.uci.cursor() -- in function index()
local uci = api.libuci -- in function index()
entry({"admin", "services", appname}).dependent = true
entry({"admin", "services", appname, "reset_config"}, call("reset_config")).leaf = true
entry({"admin", "services", appname, "show"}, call("show_menu")).leaf = true
@ -134,7 +135,7 @@ function socks_autoswitch_add_node()
table.insert(new_list, e.id)
end
end
uci:set_list(appname, id, "autoswitch_backup_node", new_list)
api.uci_set_list(uci, appname, id, "autoswitch_backup_node", new_list)
uci:commit(appname)
end
luci.http.redirect(api.url("socks_config", id))
@ -150,7 +151,7 @@ function socks_autoswitch_remove_node()
table.remove(new_list, i)
end
end
uci:set_list(appname, id, "autoswitch_backup_node", new_list)
api.uci_set_list(uci, appname, id, "autoswitch_backup_node", new_list)
uci:commit(appname)
end
luci.http.redirect(api.url("socks_config", id))
@ -299,7 +300,7 @@ end
function copy_node()
local section = luci.http.formvalue("section")
local uuid = api.gen_short_uuid()
uci:section(appname, "nodes", uuid)
api.uci_section(uci, appname, "nodes", uuid)
for k, v in pairs(uci:get_all(appname, section)) do
local filter = k:find("%.")
if filter and filter == 1 then
@ -322,7 +323,7 @@ function clear_all_nodes()
uci:delete(appname, '@global[0]', "node")
uci:foreach(appname, "socks", function(t)
uci:delete(appname, t[".name"])
uci:set_list(appname, t[".name"], "autoswitch_backup_node", {})
api.uci_set_list(uci, appname, t[".name"], "autoswitch_backup_node", {})
end)
uci:foreach(appname, "haproxy_config", function(t)
uci:delete(appname, t[".name"])
@ -354,7 +355,7 @@ function delete_select_nodes()
table.remove(auto_switch_node_list, i)
end
end
uci:set_list(appname, t[".name"], "autoswitch_backup_node", auto_switch_node_list)
api.uci_set_list(uci, appname, t[".name"], "autoswitch_backup_node", auto_switch_node_list)
end)
uci:foreach(appname, "haproxy_config", function(t)
if t["lbss"] == w then

View File

@ -3,6 +3,7 @@ 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"
@ -29,6 +30,52 @@ 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
end
function sh_uci_get(config, section, option)
exec_call(string.format("uci -q get %s.%s.%s", config, section, option))
exec_call(string.format("uci -q commit %s", config))
end
function sh_uci_set(config, section, option, val)
exec_call(string.format("uci -q set %s.%s.%s=\"%s\"", config, section, option, val))
exec_call(string.format("uci -q commit %s", config))
end
function sh_uci_del(config, section, option)
exec_call(string.format("uci -q delete %s.%s.%s", config, section, option))
exec_call(string.format("uci -q commit %s", config))
end
function sh_uci_add_list(config, section, option, val)
exec_call(string.format("uci -q del_list %s.%s.%s=\"%s\"", config, section, option, val))
exec_call(string.format("uci -q add_list %s.%s.%s=\"%s\"", config, section, option, val))
exec_call(string.format("uci -q commit %s", config))
end
function set_cache_var(key, val)
sys.call(string.format('/usr/share/passwall2/app.sh set_cache_var %s "%s"', key, val))
end

View File

@ -1,6 +1,6 @@
local api = require "luci.passwall2.api"
local appname = "passwall2"
local uci = api.uci
local uci = api.libuci
local sys = api.sys
local fs = api.fs
local datatypes = api.datatypes
@ -46,7 +46,7 @@ local function restore_servers()
uci:commit(appname)
end
if dns_table and #dns_table > 0 then
uci:set_list("dhcp", "@dnsmasq[0]", "server", dns_table)
api.uci_set_list(uci, "dhcp", "@dnsmasq[0]", "server", dns_table)
uci:commit("dhcp")
end
end
@ -102,7 +102,7 @@ function logic_restart(var)
tinsert(dns_table, v)
end
end
uci:set_list("dhcp", "@dnsmasq[0]", "server", dns_table)
api.uci_set_list(uci, "dhcp", "@dnsmasq[0]", "server", dns_table)
uci:commit("dhcp")
end
sys.call("/etc/init.d/dnsmasq restart >/dev/null 2>&1")

View File

@ -19,7 +19,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 = luci.model.uci.cursor()
local uci = api.libuci
uci:revert(appname)
local has_ss = api.is_finded("ss-redir")
@ -213,7 +213,7 @@ do
set = function(o)
for kk, vv in pairs(CONFIG) do
if (vv.remarks == id .. "备用节点的列表") then
uci:set_list(appname, id, "autoswitch_backup_node", vv.new_nodes)
api.uci_set_list(uci, appname, id, "autoswitch_backup_node", vv.new_nodes)
end
end
end
@ -285,8 +285,8 @@ do
if (vv.remarks == "Xray负载均衡节点[" .. node_id .. "]列表") then
uci:foreach(appname, "nodes", function(node2)
if node2[".name"] == node[".name"] then
local section = uci:section(appname, "nodes", node_id)
uci:set_list(appname, section, "balancing_node", vv.new_nodes)
local section = api.uci_section(uci, appname, "nodes", node_id)
api.uci_set_list(uci, appname, section, "balancing_node", vv.new_nodes)
end
end)
end
@ -1427,7 +1427,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_short_uuid())
local cfgid = api.uci_section(uci, appname, "nodes", api.gen_short_uuid())
for kkk, vvv in pairs(vv) do
uci:set(appname, cfgid, kkk, vvv)
-- sing-box 域名解析策略