diff --git a/dae/Makefile b/dae/Makefile
index 63769afc..b16764a5 100644
--- a/dae/Makefile
+++ b/dae/Makefile
@@ -10,7 +10,7 @@ PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_PROTO:=git
-PKG_SOURCE_VERSION:=e31cf617518ac7f3658084e9ec2035e3b53dc08a
+PKG_SOURCE_VERSION:=6fcf2e6fc520e0b312200d6fa5c59a4464b191bd
PKG_SOURCE_URL:=https://github.com/olicesx/dae.git
PKG_MIRROR_HASH:=skip
diff --git a/doc/lucky1.png b/doc/lucky1.png
new file mode 100644
index 00000000..a5b41b6e
Binary files /dev/null and b/doc/lucky1.png differ
diff --git a/doc/lucky2.png b/doc/lucky2.png
new file mode 100644
index 00000000..ba4c026f
Binary files /dev/null and b/doc/lucky2.png differ
diff --git a/doc/lucky3.png b/doc/lucky3.png
new file mode 100644
index 00000000..6fa7982f
Binary files /dev/null and b/doc/lucky3.png differ
diff --git a/doc/taskplan1.png b/doc/taskplan1.png
deleted file mode 100644
index 1f8db7be..00000000
Binary files a/doc/taskplan1.png and /dev/null differ
diff --git a/doc/taskplan2.png b/doc/taskplan2.png
deleted file mode 100644
index edb45d6d..00000000
Binary files a/doc/taskplan2.png and /dev/null differ
diff --git a/doc/taskplan3.png b/doc/taskplan3.png
deleted file mode 100644
index d4794702..00000000
Binary files a/doc/taskplan3.png and /dev/null differ
diff --git a/doc/view.png b/doc/view.png
deleted file mode 100644
index 169e112f..00000000
Binary files a/doc/view.png and /dev/null differ
diff --git a/doc/view2.png b/doc/view2.png
deleted file mode 100644
index 9058c632..00000000
Binary files a/doc/view2.png and /dev/null differ
diff --git a/luci-app-passwall2/Makefile b/luci-app-passwall2/Makefile
index 8ff63f32..39720f18 100644
--- a/luci-app-passwall2/Makefile
+++ b/luci-app-passwall2/Makefile
@@ -6,7 +6,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-passwall2
-PKG_VERSION:=26.8.10
+PKG_VERSION:=26.8.14
PKG_RELEASE:=1
PKG_PO_VERSION:=$(PKG_VERSION)
diff --git a/luci-app-passwall2/luasrc/controller/passwall2.lua b/luci-app-passwall2/luasrc/controller/passwall2.lua
index 470111cb..6ca80d12 100644
--- a/luci-app-passwall2/luasrc/controller/passwall2.lua
+++ b/luci-app-passwall2/luasrc/controller/passwall2.lua
@@ -4,6 +4,8 @@
module("luci.controller.passwall2", package.seeall)
local api = require "luci.passwall2.api"
local appname = api.appname -- not available
+local c_config = api.c_config -- not available
+local s_config = api.s_config -- not available
local uci = api.uci -- in funtion index()
local http = require "luci.http"
local util = require "luci.util"
@@ -20,12 +22,14 @@ function index()
end
local api = require "luci.passwall2.api"
local appname = api.appname -- global definitions not available
+ local c_config = api.c_config -- not available
+ local s_config = api.s_config -- not available
local uci = api.uci -- in function index()
entry({"admin", "services", appname}).dependent = true
entry({"admin", "services", appname, "show"}, call("show_menu")).leaf = true
entry({"admin", "services", appname, "hide"}, call("hide_menu")).leaf = true
local e
- if uci:get(appname, "@global[0]", "hide_from_luci") ~= "1" then
+ if uci:get(c_config, "@global[0]", "hide_from_luci") ~= "1" then
e = entry({"admin", "services", appname}, alias("admin", "services", appname, "settings"), _("PassWall 2"), 0)
else
e = entry({"admin", "services", appname}, alias("admin", "services", appname, "settings"), nil, 0)
@@ -137,7 +141,7 @@ local function http_write_json_error(data)
end
function reset_config()
- uci:revert(appname)
+ uci:revert(c_config)
luci.sys.call("echo '' > /tmp/log/passwall2.log")
luci.sys.call('/etc/init.d/passwall2 stop')
luci.sys.call('[ -f "/usr/share/passwall2/0_default_config" ] && cp -f /usr/share/passwall2/0_default_config /etc/config/passwall2')
@@ -145,14 +149,14 @@ function reset_config()
end
function show_menu()
- api.sh_uci_del(appname, "@global[0]", "hide_from_luci", true)
+ api.sh_uci_del(c_config, "@global[0]", "hide_from_luci", true)
luci.sys.call("rm -rf /tmp/luci-*")
luci.sys.call("/etc/init.d/rpcd restart >/dev/null")
http.redirect(api.url())
end
function hide_menu()
- api.sh_uci_set(appname, "@global[0]", "hide_from_luci", "1", true)
+ api.sh_uci_set(c_config, "@global[0]", "hide_from_luci", "1", true)
luci.sys.call("rm -rf /tmp/luci-*")
luci.sys.call("/etc/init.d/rpcd restart >/dev/null")
http.redirect(luci.dispatcher.build_url("admin", "status", "overview"))
@@ -188,10 +192,10 @@ function socks_autoswitch_add_node()
local id = http.formvalue("id")
local key = http.formvalue("key")
if id and id ~= "" and key and key ~= "" then
- uci:set(appname, id, "enable_autoswitch", "1")
- local new_list = uci:get(appname, id, "autoswitch_backup_node") or {}
+ uci:set(c_config, id, "enable_autoswitch", "1")
+ local new_list = uci:get(c_config, id, "autoswitch_backup_node") or {}
for i = #new_list, 1, -1 do
- if (uci:get(appname, new_list[i], "remarks") or ""):find(key) then
+ if (uci:get(c_config, new_list[i], "remarks") or ""):find(key) then
table.remove(new_list, i)
end
end
@@ -200,8 +204,8 @@ 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_save(uci, appname)
+ uci:set_list(c_config, id, "autoswitch_backup_node", new_list)
+ api.uci_save(uci, c_config)
end
http.redirect(api.url("socks_config", id))
end
@@ -210,15 +214,15 @@ function socks_autoswitch_remove_node()
local id = http.formvalue("id")
local key = http.formvalue("key")
if id and id ~= "" and key and key ~= "" then
- uci:set(appname, id, "enable_autoswitch", "1")
- local new_list = uci:get(appname, id, "autoswitch_backup_node") or {}
+ uci:set(c_config, id, "enable_autoswitch", "1")
+ local new_list = uci:get(c_config, id, "autoswitch_backup_node") or {}
for i = #new_list, 1, -1 do
- if (uci:get(appname, new_list[i], "remarks") or ""):find(key) then
+ if (uci:get(c_config, new_list[i], "remarks") or ""):find(key) then
table.remove(new_list, i)
end
end
- uci:set_list(appname, id, "autoswitch_backup_node", new_list)
- api.uci_save(uci, appname)
+ uci:set_list(c_config, id, "autoswitch_backup_node", new_list)
+ api.uci_save(uci, c_config)
end
http.redirect(api.url("socks_config", id))
end
@@ -309,7 +313,7 @@ function socks_status()
local id = http.formvalue("id")
e.index = index
e.socks_status = luci.sys.call(string.format("/bin/busybox top -bn1 | grep -v -E 'grep|acl/|acl_' | grep '%s/bin/' | grep '%s' > /dev/null", appname, id)) == 0
- local use_http = uci:get(appname, id, "http_port") or 0
+ local use_http = uci:get(c_config, id, "http_port") or 0
e.use_http = 0
if tonumber(use_http) > 0 then
e.use_http = 1
@@ -379,9 +383,9 @@ function update_config()
local data_t = jsonParse(data) or {}
if next(data_t) then
for k, v in pairs(data_t) do
- uci:set(appname, id, k, v)
+ uci:set(c_config, id, k, v)
end
- api.uci_save(uci, appname)
+ api.uci_save(uci, c_config)
http_write_json_ok()
return
end
@@ -393,20 +397,20 @@ function add_node()
local redirect = http.formvalue("redirect")
local uid = api.gen_random_char()
- uci:section(appname, "nodes", uid)
+ uci:section(c_config, "nodes", uid)
local group = http.formvalue("group")
if group and group ~= "default" then
- uci:set(appname, uid, "group", group)
+ uci:set(c_config, uid, "group", group)
end
- uci:set(appname, uid, "type", "Xray")
+ uci:set(c_config, uid, "type", "Xray")
if redirect == "1" then
- api.uci_save(uci, appname)
+ api.uci_save(uci, c_config)
http.redirect(api.url("node_config", uid))
else
- api.uci_save(uci, appname, true, true)
+ api.uci_save(uci, c_config, true, true)
http_write_json({result = uid})
end
end
@@ -415,67 +419,67 @@ function set_node()
local type = http.formvalue("type")
local config = http.formvalue("config")
local section = http.formvalue("section")
- uci:set(appname, type, config, section)
- api.uci_save(uci, appname, true, true)
+ uci:set(c_config, type, config, section)
+ api.uci_save(uci, c_config, true, true)
http.redirect(api.url("log"))
end
function copy_node()
local section = http.formvalue("section")
local uid = api.gen_random_char()
- uci:section(appname, "nodes", uid)
- for k, v in pairs(uci:get_all(appname, section)) do
+ uci:section(c_config, "nodes", uid)
+ for k, v in pairs(uci:get_all(c_config, section)) do
if not k:match("^%.") and k ~= "group" then
if k == "remarks" then v = (v or "") .. "(1)" end
- uci:set(appname, uid, k, v)
+ uci:set(c_config, uid, k, v)
end
end
- uci:set(appname, uid, "add_mode", 1)
- api.uci_save(uci, appname)
+ uci:set(c_config, uid, "add_mode", 1)
+ api.uci_save(uci, c_config)
http.redirect(api.url("node_config", uid))
end
function clear_all_nodes()
- uci:set(appname, '@global[0]', "enabled", "0")
- uci:set(appname, '@global[0]', "socks_enabled", "0")
- uci:set(appname, '@global_haproxy[0]', "balancing_enable", "0")
- 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", {})
+ uci:set(c_config, '@global[0]', "enabled", "0")
+ uci:set(c_config, '@global[0]', "socks_enabled", "0")
+ uci:set(c_config, '@global_haproxy[0]', "balancing_enable", "0")
+ uci:delete(c_config, '@global[0]', "node")
+ uci:foreach(c_config, "socks", function(t)
+ uci:delete(c_config, t[".name"])
+ uci:set_list(c_config, t[".name"], "autoswitch_backup_node", {})
end)
- uci:foreach(appname, "haproxy_config", function(t)
- uci:delete(appname, t[".name"])
+ uci:foreach(c_config, "haproxy_config", function(t)
+ uci:delete(c_config, t[".name"])
end)
- uci:foreach(appname, "acl_rule", function(t)
- uci:delete(appname, t[".name"], "node")
+ uci:foreach(c_config, "acl_rule", function(t)
+ uci:delete(c_config, t[".name"], "node")
end)
- uci:foreach(appname, "nodes", function(node)
- uci:delete(appname, node['.name'])
+ uci:foreach(c_config, "nodes", function(node)
+ uci:delete(c_config, node['.name'])
end)
- uci:foreach(appname, "subscribe_list", function(t)
- uci:delete(appname, t[".name"], "md5")
- uci:delete(appname, t[".name"], "chain_proxy")
- uci:delete(appname, t[".name"], "preproxy_node")
- uci:delete(appname, t[".name"], "to_node")
+ uci:foreach(c_config, "subscribe_list", function(t)
+ uci:delete(c_config, t[".name"], "md5")
+ uci:delete(c_config, t[".name"], "chain_proxy")
+ uci:delete(c_config, t[".name"], "preproxy_node")
+ uci:delete(c_config, t[".name"], "to_node")
end)
- api.uci_save(uci, appname, true, true)
+ api.uci_save(uci, c_config, true, true)
end
function delete_select_nodes()
local ids = http.formvalue("ids")
local redirect = http.formvalue("redirect")
string.gsub(ids, '[^' .. "," .. ']+', function(w)
- if (uci:get(appname, "@global[0]", "node") or "") == w then
- uci:delete(appname, '@global[0]', "node")
+ if (uci:get(c_config, "@global[0]", "node") or "") == w then
+ uci:delete(c_config, '@global[0]', "node")
end
- uci:foreach(appname, "socks", function(t)
+ uci:foreach(c_config, "socks", function(t)
if t["node"] == w then
- uci:delete(appname, t[".name"])
+ uci:delete(c_config, t[".name"])
end
local changed = false
- local auto_switch_node_list = uci:get(appname, t[".name"], "autoswitch_backup_node") or {}
+ local auto_switch_node_list = uci:get(c_config, t[".name"], "autoswitch_backup_node") or {}
for i = #auto_switch_node_list, 1, -1 do
if w == auto_switch_node_list[i] then
table.remove(auto_switch_node_list, i)
@@ -483,31 +487,31 @@ function delete_select_nodes()
end
end
if changed then
- uci:set_list(appname, t[".name"], "autoswitch_backup_node", auto_switch_node_list)
+ uci:set_list(c_config, t[".name"], "autoswitch_backup_node", auto_switch_node_list)
end
end)
- uci:foreach(appname, "haproxy_config", function(t)
+ uci:foreach(c_config, "haproxy_config", function(t)
if t["lbss"] == w then
- uci:delete(appname, t[".name"])
+ uci:delete(c_config, t[".name"])
end
end)
- uci:foreach(appname, "acl_rule", function(t)
+ uci:foreach(c_config, "acl_rule", function(t)
if t["node"] == w then
- uci:delete(appname, t[".name"], "node")
+ uci:delete(c_config, t[".name"], "node")
end
end)
- uci:foreach(appname, "nodes", function(t)
+ uci:foreach(c_config, "nodes", function(t)
if t["preproxy_node"] == w then
- uci:delete(appname, t[".name"], "preproxy_node")
- uci:delete(appname, t[".name"], "chain_proxy")
+ uci:delete(c_config, t[".name"], "preproxy_node")
+ uci:delete(c_config, t[".name"], "chain_proxy")
end
if t["to_node"] == w then
- uci:delete(appname, t[".name"], "to_node")
- uci:delete(appname, t[".name"], "chain_proxy")
+ uci:delete(c_config, t[".name"], "to_node")
+ uci:delete(c_config, t[".name"], "chain_proxy")
end
local list_name = t["urltest_node"] and "urltest_node" or (t["balancing_node"] and "balancing_node")
if list_name then
- local nodes = uci:get_list(appname, t[".name"], list_name)
+ local nodes = uci:get_list(c_config, t[".name"], list_name)
if nodes then
local changed = false
local new_nodes = {}
@@ -519,48 +523,48 @@ function delete_select_nodes()
end
end
if changed then
- uci:set_list(appname, t[".name"], list_name, new_nodes)
+ uci:set_list(c_config, t[".name"], list_name, new_nodes)
end
end
end
if t["fallback_node"] == w then
- uci:delete(appname, t[".name"], "fallback_node")
+ uci:delete(c_config, t[".name"], "fallback_node")
end
end)
- uci:foreach(appname, "subscribe_list", function(t)
+ uci:foreach(c_config, "subscribe_list", function(t)
if t["preproxy_node"] == w then
- uci:delete(appname, t[".name"], "preproxy_node")
- uci:delete(appname, t[".name"], "chain_proxy")
+ uci:delete(c_config, t[".name"], "preproxy_node")
+ uci:delete(c_config, t[".name"], "chain_proxy")
end
if t["to_node"] == w then
- uci:delete(appname, t[".name"], "to_node")
- uci:delete(appname, t[".name"], "chain_proxy")
+ uci:delete(c_config, t[".name"], "to_node")
+ uci:delete(c_config, t[".name"], "chain_proxy")
end
end)
- if (uci:get(appname, w, "add_mode") or "0") == "2" then
- local group = uci:get(appname, w, "group") or ""
+ if (uci:get(c_config, w, "add_mode") or "0") == "2" then
+ local group = uci:get(c_config, w, "group") or ""
if group ~= "" then
- uci:foreach(appname, "subscribe_list", function(t)
+ uci:foreach(c_config, "subscribe_list", function(t)
if t["remark"] == group then
- uci:delete(appname, t[".name"], "md5")
+ uci:delete(c_config, t[".name"], "md5")
end
end)
end
end
- uci:delete(appname, w)
+ uci:delete(c_config, w)
end)
if redirect == "1" then
- api.uci_save(uci, appname)
+ api.uci_save(uci, c_config)
http.redirect(api.url("node_list"))
else
- api.uci_save(uci, appname, true, true)
+ api.uci_save(uci, c_config, true, true)
end
end
function get_node()
local id = http.formvalue("id")
local result = {}
- local show_node_info = api.uci_get_type("global_other", "show_node_info", "0")
+ local show_node_info = uci:get(c_config, "@global_other[0]", "show_node_info") or "0"
local function add_is_ipv6_key(o)
if o and o.address and show_node_info == "1" then
@@ -573,12 +577,12 @@ function get_node()
end
if id then
- result = uci:get_all(appname, id)
+ result = uci:get_all(c_config, id)
add_is_ipv6_key(result)
else
local default_nodes = {}
local other_nodes = {}
- uci:foreach(appname, "nodes", function(t)
+ uci:foreach(c_config, "nodes", function(t)
add_is_ipv6_key(t)
if not t.group or t.group == "" then
default_nodes[#default_nodes + 1] = t
@@ -597,12 +601,12 @@ function reassign_group()
local group = http.formvalue("group") or "default"
for id in ids:gmatch("([^,]+)") do
if group ~="" and group ~= "default" then
- api.sh_uci_set(appname, id, "group", group)
+ api.sh_uci_set(c_config, id, "group", group)
else
- api.sh_uci_del(appname, id, "group")
+ api.sh_uci_del(c_config, id, "group")
end
end
- api.sh_uci_commit(appname)
+ api.sh_uci_commit(c_config)
http_write_json({ status = "ok" })
end
@@ -610,7 +614,7 @@ function save_node_list_opt()
local option = http.formvalue("option") or ""
local value = http.formvalue("value") or ""
if option ~= "" then
- api.sh_uci_set(appname, "@global_other[0]", option, value, true)
+ api.sh_uci_set(c_config, "@global_other[0]", option, value, true)
end
http_write_json({ status = "ok" })
end
@@ -632,7 +636,7 @@ function rollback_rules()
return
end
local bak_dir = "/tmp/bak_v2ray/"
- local geo_dir = (uci:get(appname, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/")
+ local geo_dir = (uci:get(c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/")
fs.move(bak_dir .. arg_type .. ".dat", geo_dir .. arg_type .. ".dat")
fs.rmdir(bak_dir)
http_write_json_ok()
@@ -645,9 +649,9 @@ function server_update_config()
local data_t = jsonParse(data) or {}
if next(data_t) then
for k, v in pairs(data_t) do
- uci:set(appname .. "_server", id, k, v)
+ uci:set(c_config .. "_server", id, k, v)
end
- api.uci_save(uci, appname .. "_server")
+ api.uci_save(uci, c_config .. "_server")
http_write_json_ok()
return
end
@@ -758,7 +762,7 @@ function restore_backup()
fp:write(decoded)
fp:close()
if chunk_index + 1 == total_chunks then
- uci:revert(appname)
+ uci:revert(c_config)
api.sys.call("echo '' > /tmp/log/passwall2.log")
api.log(0, string.format(" * PassWall2 %s", i18n.translate("Configuration file uploaded successfully…")))
local temp_dir = '/tmp/passwall2_bak'
@@ -801,7 +805,7 @@ function geo_view()
end
local function get_rules(str, type)
local rules_id = {}
- uci:foreach(appname, "shunt_rules", function(s)
+ uci:foreach(c_config, "shunt_rules", function(s)
local list
if type == "geoip" then list = s.ip_list else list = s.domain_list end
for line in string.gmatch((list or ""), "[^\r\n]+") do
@@ -818,7 +822,7 @@ function geo_view()
end)
return rules_id
end
- local geo_dir = (uci:get(appname, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/")
+ local geo_dir = (uci:get(c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/")
local geosite_path = geo_dir .. "/geosite.dat"
local geoip_path = geo_dir .. "/geoip.dat"
local geo_type, file_path, cmd
@@ -890,13 +894,13 @@ function subscribe_manual()
http_write_json({ success = false, msg = "Missing section or URL, skip." })
return
end
- local uci_url = api.sh_uci_get(appname, section, "url")
+ local uci_url = api.sh_uci_get(c_config, section, "url")
if not uci_url or uci_url == "" then
http_write_json({ success = false, msg = i18n.translate("Please save and apply before manually subscribing.") })
return
end
if uci_url ~= current_url then
- api.sh_uci_set(appname, section, "url", current_url, true)
+ api.sh_uci_set(c_config, section, "url", current_url, true)
end
luci.sys.call("lua /usr/share/" .. appname .. "/subscribe.lua start " .. section .. " manual >/dev/null 2>&1 &")
http_write_json({ success = true, msg = "Subscribe triggered." })
@@ -913,7 +917,7 @@ function subscribe_manual_all()
local url_list = util.split(urls, ",")
-- Check if there are any unsaved configurations.
for i, section in ipairs(section_list) do
- local uci_url = api.sh_uci_get(appname, section, "url")
+ local uci_url = api.sh_uci_get(c_config, section, "url")
if not uci_url or uci_url == "" then
http_write_json({ success = false, msg = i18n.translate("Please save and apply before manually subscribing.") })
return
@@ -922,9 +926,9 @@ function subscribe_manual_all()
-- Save URLs that have changed.
for i, section in ipairs(section_list) do
local current_url = url_list[i] or ""
- local uci_url = api.sh_uci_get(appname, section, "url")
+ local uci_url = api.sh_uci_get(c_config, section, "url")
if current_url ~= "" and uci_url ~= current_url then
- api.sh_uci_set(appname, section, "url", current_url, true)
+ api.sh_uci_set(c_config, section, "url", current_url, true)
end
end
luci.sys.call("lua /usr/share/" .. appname .. "/subscribe.lua start all manual >/dev/null 2>&1 &")
@@ -935,10 +939,10 @@ function flush_set()
local redirect = http.formvalue("redirect") or "0"
local reload = http.formvalue("reload") or "0"
if reload == "1" then
- uci:set(appname, '@global[0]', "flush_set", "1")
- api.uci_save(uci, appname, true, true)
+ uci:set(c_config, '@global[0]', "flush_set", "1")
+ api.uci_save(uci, c_config, true, true)
else
- api.sh_uci_set(appname, "@global[0]", "flush_set", "1", true)
+ api.sh_uci_set(c_config, "@global[0]", "flush_set", "1", true)
end
if redirect == "1" then
http.redirect(api.url("log"))
@@ -947,9 +951,9 @@ end
function fetch_certsha256()
local id = http.formvalue("id") or ""
- local address = (id ~= "") and uci:get(appname, id, "address") or ""
- local port = (id ~= "") and uci:get(appname, id, "port") or 0
- local sni = (id ~= "") and uci:get(appname, id, "tls_serverName") or ""
+ local address = (id ~= "") and uci:get(c_config, id, "address") or ""
+ local port = (id ~= "") and uci:get(c_config, id, "port") or 0
+ local sni = (id ~= "") and uci:get(c_config, id, "tls_serverName") or ""
sni = (sni ~= "") and sni or address
if address == "" or port == 0 then
http_write_json_error()
@@ -964,11 +968,11 @@ function get_shunt_rules()
local result = {}
if id then
- result = uci:get_all(appname, id)
+ result = uci:get_all(c_config, id)
else
local default_items = {}
local other_items = {}
- uci:foreach(appname, "shunt_rules", function(t)
+ uci:foreach(c_config, "shunt_rules", function(t)
if not t.group or t.group == "" then
default_items[#default_items + 1] = t
else
@@ -987,7 +991,7 @@ function add_shunt_rule()
local uid = add_name
if add_name then
- local has = uci:get(appname, uid)
+ local has = uci:get(c_config, uid)
if has then
http_write_json_error({ message = i18n.translate("This ID already exists.") })
return
@@ -995,18 +999,18 @@ function add_shunt_rule()
else
uid = api.gen_random_char()
end
- uci:section(appname, "shunt_rules", uid)
+ uci:section(c_config, "shunt_rules", uid)
local group = http.formvalue("group")
if group and group ~= "default" then
- uci:set(appname, uid, "group", group)
+ uci:set(c_config, uid, "group", group)
end
if redirect == "1" then
- api.uci_save(uci, appname)
+ api.uci_save(uci, c_config)
http.redirect(api.url("shunt_rules", uid))
else
- api.uci_save(uci, appname)
+ api.uci_save(uci, c_config)
http_write_json_ok({uid = uid, redirect_url = api.url("shunt_rules", uid)})
end
end
@@ -1015,17 +1019,17 @@ function delete_select_shunt_rules()
local ids = http.formvalue("ids")
local redirect = http.formvalue("redirect")
string.gsub(ids, '[^' .. "," .. ']+', function(w)
- uci:foreach(appname, "nodes", function(s)
+ uci:foreach(c_config, "nodes", function(s)
if s["protocol"] and s["protocol"] == "_shunt" then
- uci:delete(appname, s[".name"], w)
+ uci:delete(c_config, s[".name"], w)
end
end)
- uci:delete(appname, w)
+ uci:delete(c_config, w)
end)
if redirect == "1" then
- api.uci_save(uci, appname)
+ api.uci_save(uci, c_config)
http.redirect(api.url("rule"))
else
- api.uci_save(uci, appname, true, true)
+ api.uci_save(uci, c_config, true, true)
end
end
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl.lua
index f24e2b50..49b5e9aa 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl.lua
@@ -1,22 +1,16 @@
local api = require "luci.passwall2.api"
-local appname = api.appname
-local sys = api.sys
-
api.set_default_cbi()
-m = Map(appname)
-api.set_apply_on_parse(m)
+m = Map()
-s = m:section(TypedSection, "global", translate("ACLs"), "" .. translate("ACLs is a tools which used to designate specific IP proxy mode.") .. "")
-s.anonymous = true
+s = m:section(NamedSection, "@global[0]", "global", translate("ACLs"), "" .. translate("ACLs is a tools which used to designate specific IP proxy mode.") .. "")
o = s:option(Flag, "acl_enable", translate("Main switch"))
o.rmempty = false
o.default = false
-- [[ ACLs Settings ]]--
-local cfgname = "acl_rule"
-s = m:section(TypedSection, cfgname)
+s = m:section(TypedSection, "acl_rule")
s.template = "cbi/tblsection"
s.sortable = true
s.anonymous = true
@@ -38,7 +32,7 @@ o = s:option(Value, "remarks", translate("Remarks"))
o.rmempty = true
local mac_t = {}
-sys.net.mac_hints(function(e, t)
+api.sys.net.mac_hints(function(e, t)
mac_t[e] = {
ip = t,
mac = e
@@ -81,9 +75,6 @@ i.cfgvalue = function(t, n)
return translate("No Proxy")
end
-local sortable = Template(appname .. "/cbi/sortable")
-sortable.api = api
-sortable.target_cfgname = cfgname
-m:append(sortable)
+m:appendTemplate("/cbi/sortable", {sectiontype = s.sectiontype})
return api.return_map(m)
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl_config.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl_config.lua
index 1272d660..860488b6 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl_config.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl_config.lua
@@ -1,18 +1,13 @@
local api = require "luci.passwall2.api"
-local appname = api.appname
-
api.set_default_cbi()
-m = Map(appname)
-api.set_apply_on_parse(m)
+m = Map()
if not arg[1] or not m:get(arg[1]) then
luci.http.redirect(api.url("acl"))
end
-m:append(Template(appname .. "/cbi/nodes_listvalue_com"))
-
-local sys = api.sys
+m:appendTemplate("/cbi/nodes_listvalue_com")
local port_validate = function(self, value, t)
return value:gsub("-", ":")
@@ -44,6 +39,7 @@ local doh_validate = function(self, value, t)
end
return nil, translate("DoH request address") .. " " .. translate("Format must be:") .. " URL,IP"
end
+
-- [[ ACLs Settings ]]--
s = m:section(NamedSection, arg[1], translate("ACLs"), translate("ACLs"))
s.addremove = false
@@ -73,7 +69,7 @@ o.validate = function(self, value, section)
end
local mac_t = {}
-sys.net.mac_hints(function(e, t)
+api.sys.net.mac_hints(function(e, t)
mac_t[#mac_t + 1] = {
ip = t,
mac = e
@@ -181,7 +177,7 @@ o:depends("mode", "1")
o.validate = port_validate
o = s:option(DummyValue, "_hide_node_option", "")
-o.template = "passwall2/cbi/hidevalue"
+o.template = m:template_path("/cbi/hidevalue")
o.value = "1"
o:depends("mode", "0")
o:depends({ tcp_no_redir_ports = "1:65535", udp_no_redir_ports = "1:65535" })
@@ -199,13 +195,13 @@ else
o.group = {}
end
o:depends({ _hide_node_option = "1", ['!reverse'] = true })
-o.template = appname .. "/cbi/nodes_listvalue"
+o.template = m:template_path("/cbi/nodes_listvalue")
current_node_id = o:formvalue(arg[1])
if not current_node_id then
- current_node_id = m.uci:get(appname, arg[1], "node")
+ current_node_id = m:get(arg[1], "node")
end
-current_node = current_node_id and m.uci:get_all(appname, current_node_id) or {}
+current_node = current_node_id and m:get(current_node_id) or {}
o = s:option(Flag, "log", translate("Enable Node Log"))
o:depends({ _hide_node_option = "1", ['!reverse'] = true })
@@ -259,7 +255,7 @@ end
o:depends({ _hide_node_option = "1", ['!reverse'] = true })
o = s:option(DummyValue, "_hide_dns_option", "")
-o.template = "passwall2/cbi/hidevalue"
+o.template = m:template_path("/cbi/hidevalue")
o.value = "1"
o:depends({ node = "" })
if GLOBAL_ENABLED == "1" and NODE then
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/app_update.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/app_update.lua
index 462046e3..3fb4f5cc 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/app_update.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/app_update.lua
@@ -1,21 +1,14 @@
local api = require "luci.passwall2.api"
-local com = require "luci.passwall2.com"
-local appname = api.appname
-
api.set_default_cbi()
-m = Map(appname)
-api.set_apply_on_parse(m)
+local com = require "luci.passwall2.com"
+
+m = Map()
-- [[ App Settings ]]--
-s = m:section(TypedSection, "global_app", translate("App Update"))
-s.anonymous = true
+s = m:section(NamedSection, "@global_app[0]", "global_app", translate("App Update"))
-local app_version = Template(appname .. "/app_update/app_version")
-app_version.api = api
-app_version.config = m.config
-app_version.com = com
-s:append(app_version)
+s:appendTemplate("/app_update/app_version", {com = com})
local k, v
for k, v in pairs(com) do
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/geoview.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/geoview.lua
index abd9c1f1..234aad26 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/geoview.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/geoview.lua
@@ -1,16 +1,18 @@
local api = require "luci.passwall2.api"
-local appname = api.appname
local fs = api.fs
local uci = api.uci
-local geo_dir = (uci:get(appname, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/")
+local geo_dir = (uci:get(api.c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/")
local geosite_path = geo_dir .. "/geosite.dat"
local geoip_path = geo_dir .. "/geoip.dat"
if fs.access(geosite_path) and fs.access(geoip_path) then
- f = SimpleForm(appname)
+ f = SimpleForm(api.c_config)
f.reset = false
f.submit = false
- f:append(Template(appname .. "/rule/geoview"))
+
+ local obj = Template(api.appname .. "/rule/geoview")
+ obj.api = api
+ f:append(obj)
end
-return f
\ No newline at end of file
+return f
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/global.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/global.lua
index c62432ed..d6d2ede9 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/global.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/global.lua
@@ -1,15 +1,12 @@
api = require "luci.passwall2.api"
-appname = api.appname
datatypes = api.datatypes
has_singbox = api.finded_com("sing-box")
has_xray = api.finded_com("xray")
-
api.set_default_cbi()
-m = Map(appname)
-api.set_apply_on_parse(m)
+m = Map()
-m:append(Template(appname .. "/cbi/nodes_listvalue_com"))
+m:appendTemplate("/cbi/nodes_listvalue_com")
nodes_table = {}
for k, e in ipairs(api.get_valid_nodes()) do
@@ -40,7 +37,7 @@ for k, v in pairs(nodes_table) do
end
local socks_list = {}
-m.uci:foreach(appname, "socks", function(s)
+m:foreach("socks", function(s)
if s.enabled == "1" and s.node then
socks_list[#socks_list + 1] = {
id = s[".name"],
@@ -72,13 +69,9 @@ local doh_validate = function(self, value, t)
return nil, translate("DoH request address") .. " " .. translate("Format must be:") .. " URL,IP"
end
-m:append(Template(appname .. "/global/status"))
+m:appendTemplate("/global/status")
-global_cfgid = (m:get("@global[0]") or {})[".name"] or ""
-
-s = m:section(TypedSection, "global")
-s.anonymous = true
-s.addremove = false
+s = m:section(NamedSection, "@global[0]", "global")
s:tab("Main", translate("Main"))
@@ -88,12 +81,12 @@ o.rmempty = false
---- Node
o = s:taboption("Main", ListValue, "node", "" .. translate("Node") .. "")
-o.template = appname .. "/cbi/nodes_listvalue"
+o.template = m:template_path("/cbi/nodes_listvalue")
o:value("", translate("Close"))
o.group = {""}
-current_node_id = m.uci:get(appname, global_cfgid, "node")
-current_node = current_node_id and m.uci:get_all(appname, current_node_id) or {}
+current_node_id = m:get(s.section, "node")
+current_node = current_node_id and m:get(current_node_id) or {}
-- Shunt Start
if (has_singbox or has_xray) and #nodes_table > 0 then
@@ -101,7 +94,7 @@ if (has_singbox or has_xray) and #nodes_table > 0 then
if current_node.protocol == "_shunt" then
local shunt_lua = loadfile("/usr/lib/lua/luci/model/cbi/passwall2/client/include/shunt_options.lua")
setfenv(shunt_lua, getfenv(1))(m, s, {
- s_cfgid = s:cfgsections()[1],
+ s_cfgid = s.section,
node_id = current_node_id,
node = current_node,
socks_list = socks_list,
@@ -245,7 +238,7 @@ o = s:taboption("DNS", TextValue, "dns_hosts", translate("Domain Override"))
o.rows = 5
o.wrap = "off"
o.remove = function(self, section)
- local node_value = s.fields["node"]:formvalue(global_cfgid)
+ local node_value = s.fields["node"]:formvalue(section)
if node_value then
local node_t = m:get(node_value) or {}
if node_t.type == "Xray" or node_t.type == "sing-box" then
@@ -297,11 +290,11 @@ o:depends("log_node", "1")
s:tab("faq", "FAQ")
o = s:taboption("faq", DummyValue, "")
-o.template = appname .. "/global/faq"
+o.template = m:template_path("/global/faq")
s:tab("maintain", translate("Maintain"))
o = s:taboption("maintain", DummyValue, "")
-o.template = appname .. "/global/backup"
+o.template = m:template_path("/global/backup")
-- [[ Socks Server ]]--
o = s:taboption("Main", Flag, "socks_enabled", "Socks " .. translate("Main switch"))
@@ -330,7 +323,7 @@ o.default = 1
o.rmempty = false
o = s2:option(ListValue, "node", translate("Socks Node"))
-o.template = appname .. "/cbi/nodes_listvalue"
+o.template = m:template_path("/cbi/nodes_listvalue")
o.group = {}
o = s2:option(DummyValue, "now_node", translate("Current Node"))
@@ -346,7 +339,7 @@ o.cfgvalue = function(_, n)
end
local n = 1
-m.uci:foreach(appname, "socks", function(s)
+m:foreach("socks", function(s)
if s[".name"] == section then
return false
end
@@ -382,11 +375,6 @@ for k, v in pairs(nodes_table) do
end
end
-local footer = Template(appname .. "/global/footer")
-footer.api = api
-footer.global_cfgid = global_cfgid
-footer.shunt_list = api.jsonc.stringify(shunt_list)
-
-m:append(footer)
+m:appendTemplate("/global/footer", {shunt_list = api.jsonc.stringify(shunt_list)})
return api.return_map(m)
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/haproxy.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/haproxy.lua
index a1ce99f7..dbaf3965 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/haproxy.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/haproxy.lua
@@ -1,7 +1,6 @@
local api = require "luci.passwall2.api"
-local appname = api.appname
local datatypes = api.datatypes
-local net = require "luci.model.network".init()
+api.set_default_cbi()
local nodes_table = {}
for k, e in ipairs(api.get_valid_nodes()) do
@@ -15,18 +14,14 @@ for k, e in ipairs(api.get_valid_nodes()) do
end
end
-api.set_default_cbi()
+m = Map()
-m = Map(appname)
-api.set_apply_on_parse(m)
-
-m:append(Template(appname .. "/cbi/nodes_value_com"))
+m:appendTemplate("/cbi/nodes_value_com")
-- [[ Haproxy Settings ]]--
-s = m:section(TypedSection, "global_haproxy", translate("Basic Settings"))
-s.anonymous = true
+s = m:section(NamedSection, "@global_haproxy[0]", "global_haproxy", translate("Basic Settings"))
-s:append(Template(appname .. "/haproxy/status"))
+s:appendTemplate("/haproxy/status")
---- Balancing Enable
o = s:option(Flag, "balancing_enable", translate("Enable Load Balancing"))
@@ -69,9 +64,9 @@ o:depends("balancing_enable", true)
---- Health Check Type
o = s:option(ListValue, "health_check_type", translate("Health Check Type"))
-o.default = "passwall_logic"
+o.default = "script_logic"
o:value("tcp", "TCP")
-o:value("passwall_logic", translate("URL Test") .. string.format("(passwall %s)", translate("Inner implement")))
+o:value("script_logic", translate("URL Test") .. string.format("(passwall2 %s)", translate("Inner implement")))
o:depends("balancing_enable", true)
---- Passwall Inner implement Probe URL
@@ -85,7 +80,7 @@ o:value("https://connectivitycheck.platform.hicloud.com/generate_204", "HiCloud
o:value("https://wifi.vivo.com.cn/generate_204", "VIVO (CN)")
o.default = o.keylist[3]
o.description = translate("The URL used to detect the connection status.")
-o:depends("health_check_type", "passwall_logic")
+o:depends("health_check_type", "script_logic")
---- Health Check Inter
o = s:option(Value, "health_check_inter", translate("Health Check Inter"))
@@ -99,11 +94,10 @@ o.rawhtml = true
o.cfgvalue = function(t, n)
return string.format('%s', translate("When the URL test is used, the load balancing node will be converted into a Socks node. when node list set customizing, must be a Socks node, otherwise the health check will be invalid."))
end
-o:depends("health_check_type", "passwall_logic")
+o:depends("health_check_type", "script_logic")
-- [[ Balancing Settings ]]--
-local cfgname = "haproxy_config"
-s = m:section(TypedSection, cfgname, translate("Node List"))
+s = m:section(TypedSection, "haproxy_config", translate("Node List"))
s.description = "" ..
translate("Add a node, Export Of Multi WAN Only support Multi Wan. Load specific gravity range 1-256. Multiple primary servers can be load balanced, standby will only be enabled when the primary server is offline! Multiple groups can be set, Haproxy port same one for each group.") .. "
" ..
translate("Note that the node configuration parameters for load balancing must be consistent when use TCP health check type, otherwise it cannot be used normally!") .. ""
@@ -132,7 +126,7 @@ o.rmempty = false
---- Node Address
o = s:option(Value, "lbss", translate("Node Address"))
-o.template = appname .. "/cbi/nodes_value"
+o.template = m:template_path("/cbi/nodes_value")
o.group = {}
for k, v in pairs(nodes_table) do
o:value(v.id, v.remarks)
@@ -180,11 +174,8 @@ o:value(0, translate("Primary"))
o:value(1, translate("Standby"))
o.rmempty = false
-local sortable = Template(appname .. "/cbi/sortable")
-sortable.api = api
-sortable.target_cfgname = cfgname
-m:append(sortable)
+m:appendTemplate("/cbi/sortable", {sectiontype = s.sectiontype})
-m:append(Template(appname .. "/haproxy/js"))
+m:appendTemplate("/haproxy/js")
return api.return_map(m)
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/include/shunt_options.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/include/shunt_options.lua
index 6e23ae6a..15e17eb1 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/include/shunt_options.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/include/shunt_options.lua
@@ -9,7 +9,7 @@ local current_node_id = data.node_id
local node_list = data.node_list or api.get_node_list()
local groups = {}
-m.uci:foreach(appname, "shunt_rules", function(s)
+m:foreach("shunt_rules", function(s)
if s.group and s.group ~= "" then
groups[s.group] = true
end
@@ -123,7 +123,7 @@ end
local shunt_group_val = m:get(current_node_id, "shunt_group") or ""
shunt_group_val = shunt_group_val:lower()
local shunt_rules = {}
-m.uci:foreach(appname, "shunt_rules", function(e)
+m:foreach("shunt_rules", function(e)
local group = e.group or ""
group = group:lower()
if group == shunt_group_val then
@@ -146,7 +146,7 @@ table.insert(shunt_rules, {
})
s2 = m:section(Table, shunt_rules, " ")
-s2.config = appname
+s2.config = m.config
s2.sectiontype = "shunt_option_list"
o = s2:option(DummyValue, "remarks", translate("Rule"))
@@ -160,7 +160,7 @@ o.cfgvalue = function(self, section)
end
_node = s2:option(Value, "_node", translate("Node"))
-_node.template = appname .. "/cbi/nodes_listvalue"
+_node.template = m:template_path("/cbi/nodes_listvalue")
_node.group = {"","","",""}
_node:value("", translate("Close (Not use)"))
_node:value("_default", translate("Use default node"))
@@ -192,7 +192,7 @@ end
proxy_tag_node = s2:option(ListValue, "_proxy_tag", string.format('%s',
translate("Set the node to be used as a pre-proxy.") .. "\n" .. translate("Each rule has a separate switch that controls whether this rule uses the pre-proxy or not."),
translate("Preproxy")))
-proxy_tag_node.template = appname .. "/cbi/nodes_listvalue"
+proxy_tag_node.template = m:template_path("/cbi/nodes_listvalue")
proxy_tag_node.group = {""}
proxy_tag_node:value("", translate("Close (Not use)"))
proxy_tag_node.cfgvalue = function(self, section)
@@ -217,10 +217,4 @@ for k1, v1 in pairs(node_list) do
end
end
-local footer = Template(appname .. "/include/shunt_options")
-footer.api = api
-footer.config = m.config
-footer.id = current_node_id
-footer.s_cfgid = s_cfgid or current_node_id
-footer.normal_list = api.jsonc.stringify(node_list.normal_list)
-m:append(footer)
+m:appendTemplate("/include/shunt_options", {id = current_node_id, s_cfgid = s_cfgid or current_node_id, normal_list = api.jsonc.stringify(node_list.normal_list)})
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_config.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_config.lua
index ead7043f..3bbe3cb0 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_config.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_config.lua
@@ -1,30 +1,22 @@
api = require "luci.passwall2.api"
-appname = api.appname
-
api.set_default_cbi()
-m = Map(appname, translate("Node Config"))
+m = Map()
m.redirect = api.url()
-api.set_apply_on_parse(m)
if not arg[1] or not m:get(arg[1]) then
luci.http.redirect(api.url("node_list"))
end
fs = require "nixio.fs"
-formvalue_key = "cbid." .. appname .. "." .. arg[1] .. "."
+formvalue_key = "cbid." .. m.config .. "." .. arg[1] .. "."
-local header = Template(appname .. "/node_config/header")
-header.api = api
-header.config = m.config
-header.section = arg[1]
-m:append(header)
-
-m:append(Template(appname .. "/cbi/nodes_multivalue_com"))
-m:append(Template(appname .. "/cbi/nodes_listvalue_com"))
+m:appendTemplate("/node_config/header", {section = arg[1]})
+m:appendTemplate("/cbi/nodes_multivalue_com")
+m:appendTemplate("/cbi/nodes_listvalue_com")
groups = {}
-m.uci:foreach(appname, "nodes", function(s)
+m:foreach("nodes", function(s)
if s[".name"] ~= arg[1] then
if s.group and s.group ~= "" then
groups[s.group] = true
@@ -32,13 +24,13 @@ m.uci:foreach(appname, "nodes", function(s)
end
end)
-s = m:section(NamedSection, arg[1], "nodes", "")
+s = m:section(NamedSection, arg[1], "nodes", translate("Node Config"))
s.addremove = false
s.dynamic = false
o = s:option(DummyValue, "passwall2", " ")
o.rawhtml = true
-o.template = "passwall2/node_config/link_share_man"
+o.template = m:template_path("/node_config/link_share_man")
o.value = arg[1]
o = s:option(Value, "remarks", translate("Node Remarks"))
@@ -67,10 +59,10 @@ o.write = function(self, section, value)
m:set(section, self.option, value)
end
-local types_dir = "/usr/lib/lua/luci/model/cbi/passwall2/client/type/"
+local types_dir = "/usr/lib/lua/luci/model/cbi/" .. api.appname .. "/client/type/"
s.val = {}
-s.val["type"] = m.uci:get(appname, arg[1], "type")
-s.val["protocol"] = m.uci:get(appname, arg[1], "protocol")
+s.val["type"] = m:get(arg[1], "type")
+s.val["protocol"] = m:get(arg[1], "protocol")
if luci.http.formvalue("cbi.submit") == "1" then
local formvalue_type = luci.http.formvalue(formvalue_key .. "type")
@@ -92,10 +84,6 @@ for index, value in ipairs(type_table) do
setfenv(p_func, getfenv(1))(m, s)
end
-local footer = Template(appname .. "/node_config/footer")
-footer.api = api
-footer.config = m.config
-footer.section = arg[1]
-m:append(footer)
+m:appendTemplate("/node_config/footer", {section = arg[1]})
return api.return_map(m)
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_list.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_list.lua
index fed50b6e..af15398a 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_list.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_list.lua
@@ -1,14 +1,10 @@
local api = require "luci.passwall2.api"
-local appname = api.appname
-
api.set_default_cbi()
-m = Map(appname)
-api.set_apply_on_parse(m)
+m = Map()
-- [[ Other Settings ]]--
-s = m:section(TypedSection, "global_other")
-s.anonymous = true
+s = m:section(NamedSection, "@global_other[0]", "global_other")
o = s:option(ListValue, "auto_detection_time", translate("Automatic detection delay"))
o:value("0", translate("Close"))
@@ -29,10 +25,7 @@ o:value("https://wifi.vivo.com.cn/generate_204", "VIVO (CN)")
o.default = o.keylist[3]
if true then
- local o = Template(appname .. "/node_list/node_list")
- o.map = m
- o.api = api
- m:append(o)
+ m:appendTemplate("/node_list/node_list")
if luci.http.formvalue("cbi.submit") == "1" then
local group_order = {}
@@ -45,7 +38,7 @@ if true then
new_order[#new_order + 1] = w
end)
for idx, name in ipairs(new_order) do
- m.uci:reorder(appname, name, idx - 1)
+ m.uci:reorder(m.config, name, idx - 1)
end
end
end
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_subscribe.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_subscribe.lua
index 3f7e7c68..4d401b0e 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_subscribe.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_subscribe.lua
@@ -1,6 +1,6 @@
local api = require "luci.passwall2.api"
-local appname = api.appname
-local uci = api.uci
+api.set_default_cbi()
+
local has_ss_rust = api.is_finded("sslocal")
local has_singbox = api.finded_com("sing-box")
local has_xray = api.finded_com("xray")
@@ -38,20 +38,16 @@ if has_hysteria2 then
table.insert(hysteria2_type, s)
end
-api.set_default_cbi()
-
-m = Map(appname)
-api.set_apply_on_parse(m)
+m = Map()
function m.on_before_save(self)
- self.uci:foreach(appname, "subscribe_list", function(e)
+ self:foreach("subscribe_list", function(e)
self:del(e[".name"], "md5")
end)
end
-- [[ Subscribe Settings ]]--
-s = m:section(TypedSection, "global_subscribe", "")
-s.anonymous = true
+s = m:section(NamedSection, "@global_subscribe[0]", "global_subscribe")
o = s:option(ListValue, "filter_keyword_mode", translate("Filter keyword Mode"))
o:value("0", translate("Close"))
@@ -126,8 +122,7 @@ o.cfgvalue = function(self, section)
translate("Manual subscription All"))
end
-local cfgname = "subscribe_list"
-s = m:section(TypedSection, cfgname, "", "" .. translate("When adding a new subscription, please save and apply before manually subscribing. If you only change the subscription URL, you can subscribe manually, and the system will save it automatically.") .. "")
+s = m:section(TypedSection, "subscribe_list", "", "" .. translate("When adding a new subscription, please save and apply before manually subscribing. If you only change the subscription URL, you can subscribe manually, and the system will save it automatically.") .. "")
s.addremove = true
s.anonymous = true
s.sortable = true
@@ -150,7 +145,7 @@ o.validate = function(self, value, section)
return nil, translate("Remark cannot be empty.")
end
local duplicate = false
- m.uci:foreach(appname, cfgname, function(e)
+ m:foreach(s.sectiontype, function(e)
if e[".name"] ~= section and e["remark"] and e["remark"]:lower() == value:lower() then
duplicate = true
return false
@@ -164,9 +159,9 @@ end
o.write = function(self, section, value)
local old = m:get(section, self.option) or ""
if old ~= value then
- m.uci:foreach(appname, "nodes", function(e)
+ m:foreach("nodes", function(e)
if e["group"] and e["group"]:lower() == old:lower() then
- m.uci:set(appname, e[".name"], "group", value)
+ m:set(e[".name"], "group", value)
end
if e["protocol"] and (e["protocol"] == "_balancing" or e["protocol"] == "_urltest") and e["node_group"] then
local gs = ""
@@ -178,7 +173,7 @@ o.write = function(self, section, value)
end
end
gs = api.trim(gs)
- m.uci:set(appname, e[".name"], "node_group", gs)
+ m:set(e[".name"], "node_group", gs)
end
end)
end
@@ -196,7 +191,7 @@ o.cfgvalue = function(t, n)
end
str = str ~= "" and "
" .. str or ""
local num = 0
- m.uci:foreach(appname, "nodes", function(s)
+ m:foreach("nodes", function(s)
if s["group"] and s["group"]:lower() == remark:lower() then
num = num + 1
end
@@ -225,11 +220,8 @@ o.cfgvalue = function(self, section)
section, translate("Manual subscription"))
end
-local sortable = Template(appname .. "/cbi/sortable")
-sortable.api = api
-sortable.target_cfgname = cfgname
-m:append(sortable)
+m:appendTemplate("/cbi/sortable", {sectiontype = s.sectiontype})
-m:append(Template(appname .. "/node_subscribe/js"))
+m:appendTemplate("/node_subscribe/js")
return api.return_map(m)
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_subscribe_config.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_subscribe_config.lua
index 0ea1e64e..aba243cc 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_subscribe_config.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_subscribe_config.lua
@@ -1,11 +1,8 @@
local api = require "luci.passwall2.api"
-local appname = api.appname
-
api.set_default_cbi()
-m = Map(appname)
+m = Map()
m.redirect = api.url("node_subscribe")
-api.set_apply_on_parse(m)
if not arg[1] or not m:get(arg[1]) then
luci.http.redirect(m.redirect)
@@ -15,7 +12,7 @@ function m.on_before_save(self)
self:del(arg[1], "md5")
end
-m:append(Template(appname .. "/cbi/nodes_listvalue_com"))
+m:appendTemplate("/cbi/nodes_listvalue_com")
local has_ss_rust = api.is_finded("sslocal")
local has_singbox = api.finded_com("sing-box")
@@ -79,7 +76,7 @@ o.validate = function(self, value, section)
return nil, translate("Remark cannot be empty.")
end
local duplicate = false
- m.uci:foreach(appname, "subscribe_list", function(e)
+ m:foreach("subscribe_list", function(e)
if e[".name"] ~= section and e["remark"] and e["remark"]:lower() == value:lower() then
duplicate = true
return false
@@ -93,9 +90,9 @@ end
o.write = function(self, section, value)
local old = m:get(section, self.option) or ""
if old ~= value then
- m.uci:foreach(appname, "nodes", function(e)
+ m:foreach("nodes", function(e)
if e["group"] and e["group"]:lower() == old:lower() then
- m.uci:set(appname, e[".name"], "group", value)
+ self:set(e[".name"], "group", value)
end
if e["protocol"] and (e["protocol"] == "_balancing" or e["protocol"] == "_urltest") and e["node_group"] then
local gs = ""
@@ -107,7 +104,7 @@ o.write = function(self, section, value)
end
end
gs = api.trim(gs)
- m.uci:set(appname, e[".name"], "node_group", gs)
+ self:set(e[".name"], "node_group", gs)
end
end)
end
@@ -298,13 +295,13 @@ descrStr = translate(descrStr) .. "
" .. translate("Only support a layer of p
o1 = s:option(ListValue, "preproxy_node", translate("Preproxy Node"))
o1:depends({ ["chain_proxy"] = "1" })
o1.description = descrStr
-o1.template = appname .. "/cbi/nodes_listvalue"
+o1.template = m:template_path("/cbi/nodes_listvalue")
o1.group = {}
o2 = s:option(ListValue, "to_node", translate("Landing Node"))
o2:depends({ ["chain_proxy"] = "2" })
o2.description = descrStr
-o2.template = appname .. "/cbi/nodes_listvalue"
+o2.template = m:template_path("/cbi/nodes_listvalue")
o2.group = {}
o3 = s:option(Value, "outbound_iface", translate("Outbound Interface"))
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/other.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/other.lua
index 1a91208c..f076e3c7 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/other.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/other.lua
@@ -1,5 +1,6 @@
local api = require "luci.passwall2.api"
-local appname = api.appname
+api.set_default_cbi()
+
local fs = api.fs
local has_singbox = api.finded_com("sing-box")
local has_xray = api.finded_com("xray")
@@ -8,15 +9,10 @@ local port_validate = function(self, value, t)
return value:gsub("-", ":")
end
-api.set_default_cbi()
-
-m = Map(appname)
-api.set_apply_on_parse(m)
+m = Map()
-- [[ Delay Settings ]]--
-s = m:section(TypedSection, "global_delay", translate("Delay Settings"))
-s.anonymous = true
-s.addremove = false
+s = m:section(NamedSection, "@global_delay[0]", "global_delay", translate("Delay Settings"))
---- Open and close Daemon
o = s:option(Flag, "start_daemon", translate("Open and close Daemon"))
@@ -72,9 +68,7 @@ for index, value in ipairs({"stop", "start", "restart"}) do
end
-- [[ Forwarding Settings ]]--
-s = m:section(TypedSection, "global_forwarding", translate("Forwarding Settings"))
-s.anonymous = true
-s.addremove = false
+s = m:section(NamedSection, "@global_forwarding[0]", "global_forwarding", translate("Forwarding Settings"))
---- TCP No Redir Ports
o = s:option(Value, "tcp_no_redir_ports", translate("TCP No Redir Ports"))
@@ -205,9 +199,7 @@ o.validate = function(self, value)
end
if has_xray then
- s_xray = m:section(TypedSection, "global_xray", "Xray " .. translate("Settings"))
- s_xray.anonymous = true
- s_xray.addremove = false
+ s_xray = m:section(NamedSection, "@global_xray[0]", "global_xray", "Xray " .. translate("Settings"))
o = s_xray:option(Flag, "fragment", translate("Fragment"), translate("TCP fragments, which can deceive the censorship system in some cases, such as bypassing SNI blacklists."))
o.default = 0
@@ -245,7 +237,7 @@ if has_xray then
o.default = 0
o:depends("sniffing", true)
- local domains_excluded = string.format("/usr/share/%s/domains_excluded", appname)
+ local domains_excluded = string.format("/usr/share/%s/domains_excluded", m.config)
o = s_xray:option(TextValue, "excluded_domains", translate("Excluded Domains"), translate("If the traffic sniffing result is in this list, the destination address will not be overridden."))
o.rows = 15
o.wrap = "off"
@@ -268,11 +260,14 @@ if has_xray then
end
s_xray_noise.remove = function(self, section)
- for k, v in pairs(self.children) do
- v.rmempty = true
- v.validate = nil
+ local o = m:get(section) or {}
+ if o[".type"] == self.sectiontype then
+ for k, v in pairs(self.children) do
+ v.rmempty = true
+ v.validate = nil
+ end
+ TypedSection.remove(self, section)
end
- TypedSection.remove(self, section)
end
o = s_xray_noise:option(Flag, "enabled", translate("Enable"))
@@ -296,9 +291,7 @@ if has_xray then
end
if has_singbox then
- s = m:section(TypedSection, "global_singbox", "Sing-Box " .. translate("Settings"))
- s.anonymous = true
- s.addremove = false
+ s = m:section(NamedSection, "@global_singbox[0]", "global_singbox", "Sing-Box " .. translate("Settings"))
o = s:option(Flag, "record_fragment", "TLS Record " .. translate("Fragment"),
translate("Split handshake data into multiple TLS records for better censorship evasion. Low overhead. Recommended to enable first."))
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/rule.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/rule.lua
index 6db355fb..cc4ec8d7 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/rule.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/rule.lua
@@ -1,14 +1,10 @@
local api = require "luci.passwall2.api"
-local appname = api.appname
-
api.set_default_cbi()
-m = Map(appname)
-api.set_apply_on_parse(m)
+m = Map()
-- [[ Rule Settings ]]--
-s = m:section(TypedSection, "global_rules", translate("Rule status"))
-s.anonymous = true
+s = m:section(NamedSection, "@global_rules[0]", "global_rules", translate("Rule status"))
o = s:option(Value, "geoip_url", translate("GeoIP Update URL"))
o:value("https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat", translate("Loyalsoldier/geoip"))
@@ -86,12 +82,10 @@ for _, f in ipairs(flags) do
o.rmempty = false
end
-s:append(Template(appname .. "/rule/rule_version"))
+s:appendTemplate("/rule/rule_version")
if true then
- local o = Template(appname .. "/rule/shunt_rule_list")
- o.api = api
- m:append(o)
+ m:appendTemplate("/rule/shunt_rule_list")
if luci.http.formvalue("cbi.submit") == "1" then
local group_order = luci.http.formvaluetable("group.order")
@@ -103,7 +97,7 @@ if true then
new_order[#new_order + 1] = w
end)
for idx, name in ipairs(new_order) do
- m.uci:reorder(appname, name, idx - 1)
+ m.uci:reorder(m.config, name, idx - 1)
end
end
end
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/shunt_rules.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/shunt_rules.lua
index 2e59c050..7194da87 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/shunt_rules.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/shunt_rules.lua
@@ -1,19 +1,17 @@
local api = require "luci.passwall2.api"
-local appname = api.appname
-local datatypes = api.datatypes
-
api.set_default_cbi()
-m = Map(appname, "Sing-Box/Xray " .. translate("Shunt Rule"))
+local datatypes = api.datatypes
+
+m = Map()
m.redirect = api.url("rule")
-api.set_apply_on_parse(m)
if not arg[1] or not m:get(arg[1]) then
luci.http.redirect(m.redirect)
end
function m.on_before_save(self)
- m:set("@global[0]", "flush_set", "1")
+ self:set("@global[0]", "flush_set", "1")
end
-- Add inline CSS to map description
@@ -47,7 +45,7 @@ end
local remarks_lookup = {}
local groups = {}
-m.uci:foreach(appname, "shunt_rules", function(s)
+m:foreach("shunt_rules", function(s)
if s[".name"] ~= arg[1] then
if s.remarks then
remarks_lookup[s.remarks] = s[".name"]
@@ -58,7 +56,7 @@ m.uci:foreach(appname, "shunt_rules", function(s)
end
end)
-s = m:section(NamedSection, arg[1], "shunt_rules", "")
+s = m:section(NamedSection, arg[1], "shunt_rules", "Sing-Box/Xray " .. translate("Shunt Rule"))
s.addremove = false
s.dynamic = false
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/socks_config.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/socks_config.lua
index 5b48df4e..5237e4e6 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/socks_config.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/socks_config.lua
@@ -1,17 +1,14 @@
local api = require "luci.passwall2.api"
-local appname = api.appname
-
api.set_default_cbi()
-m = Map(appname)
-api.set_apply_on_parse(m)
+m = Map()
if not arg[1] or not m:get(arg[1]) then
luci.http.redirect(api.url())
end
-m:append(Template(appname .. "/cbi/nodes_dynamiclist_com"))
-m:append(Template(appname .. "/cbi/nodes_listvalue_com"))
+m:appendTemplate("/cbi/nodes_dynamiclist_com")
+m:appendTemplate("/cbi/nodes_listvalue_com")
local has_singbox = api.finded_com("sing-box")
local has_xray = api.finded_com("xray")
@@ -49,14 +46,14 @@ socks_node = s:option(ListValue, "node", translate("Node"))
if auto_switch_tip then
socks_node.description = auto_switch_tip
end
-socks_node.template = appname .. "/cbi/nodes_listvalue"
+socks_node.template = m:template_path("/cbi/nodes_listvalue")
socks_node.group = {}
o = s:option(Flag, "bind_local", translate("Bind Local"), translate("When selected, it can only be accessed localhost."))
o.default = "0"
local n = 1
-m.uci:foreach(appname, "socks", function(s)
+m:foreach("socks", function(s)
if s[".name"] == section then
return false
end
@@ -90,7 +87,7 @@ o:value("batch", translate("Batch"))
o = s:option(DynamicList, "autoswitch_backup_node", translate("List of backup nodes"))
o:depends("backup_node_add_mode", "manual")
-o.template = appname .. "/cbi/nodes_dynamiclist"
+o.template = m:template_path("/cbi/nodes_dynamiclist")
o.group = {}
o.write = function(self, section, value)
local n = s.fields["node"]:formvalue(section)
@@ -116,7 +113,7 @@ o:depends("backup_node_add_mode", "batch")
o.widget = "checkbox"
o:value("default", translate("default"))
local groups = {}
-m.uci:foreach(appname, "nodes", function(s)
+m:foreach("nodes", function(s)
if s.group and s.group ~= "" then
groups[s.group] = true
end
@@ -164,7 +161,7 @@ o.default = o.keylist[3]
o:depends("enable_autoswitch", true)
o = s:option(DummyValue, "btn")
-o.template = appname .. "/socks_auto_switch/btn"
+o.template = m:template_path("/socks_auto_switch/btn")
o:depends("backup_node_add_mode", "manual")
return api.return_map(m)
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/ray.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/ray.lua
index 69c74cb9..113209b3 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/ray.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/ray.lua
@@ -105,7 +105,7 @@ if load_balancing_options then -- [[ Load balancing Start ]]
o = s:option(MultiValue, _n("balancing_node"), translate("Load balancing node list"), translate("Load balancing node list, document"))
o:depends({ [_n("node_add_mode")] = "manual" })
o.widget = "checkbox"
- o.template = appname .. "/cbi/nodes_multivalue"
+ o.template = m:template_path("/cbi/nodes_multivalue")
o.group = {}
for k1, v1 in pairs(node_list) do
if k1 == "socks_list" or k1 == "normal_list" then
@@ -171,7 +171,7 @@ if load_balancing_options then -- [[ Load balancing Start ]]
o:value("", translate("Close(Not use)"))
o:value("_direct", translate("Direct Connection"))
o:depends({ [_n("protocol")] = "_balancing" })
- o.template = appname .. "/cbi/nodes_listvalue"
+ o.template = m:template_path("/cbi/nodes_listvalue")
-- Maximum number of fallback nesting layers
local MAX_FALLBACK_DEPTH = 3
-- Check if a loop will form.
@@ -863,7 +863,7 @@ if not load_shunt_options then
o1 = s:option(ListValue, _n("preproxy_node"), translate("Preproxy Node"), translate("Only support a layer of proxy."))
o1:depends({ [_n("chain_proxy")] = "1", [_n("hysteria2_realms")] = false })
- o1.template = appname .. "/cbi/nodes_listvalue"
+ o1.template = m:template_path("/cbi/nodes_listvalue")
o1.group = {}
o3 = s:option(Value, _n("outbound_iface"), translate("Outbound Interface"))
@@ -875,7 +875,7 @@ if not load_shunt_options then
o2 = s:option(ListValue, _n("to_node"), translate("Landing Node"), translate("Only support a layer of proxy."))
o2:depends({ [_n("chain_proxy")] = "2", [_n("hysteria2_realms")] = false })
- o2.template = appname .. "/cbi/nodes_listvalue"
+ o2.template = m:template_path("/cbi/nodes_listvalue")
o2.group = {}
for k1, v1 in pairs(node_list) do
@@ -898,7 +898,7 @@ end
api.luci_types(arg[1], m, s, type_name, option_prefix)
if load_shunt_options then
- local current_node = m.uci:get_all(appname, arg[1]) or {}
+ local current_node = m:get(arg[1]) or {}
local shunt_lua = loadfile("/usr/lib/lua/luci/model/cbi/passwall2/client/include/shunt_options.lua")
setfenv(shunt_lua, getfenv(1))(m, s, {
node_id = arg[1],
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/sing-box.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/sing-box.lua
index d5828592..70b3144a 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/sing-box.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/sing-box.lua
@@ -107,7 +107,7 @@ if load_urltest_options then -- [[ URLTest Start ]]
o = s:option(MultiValue, _n("urltest_node"), translate("URLTest node list"), translate("List of nodes to test, document"))
o:depends({ [_n("node_add_mode")] = "manual" })
o.widget = "checkbox"
- o.template = appname .. "/cbi/nodes_multivalue"
+ o.template = m:template_path("/cbi/nodes_multivalue")
o.group = {}
for k1, v1 in pairs(node_list) do
if k1 == "socks_list" or k1 == "normal_list" then
@@ -937,7 +937,7 @@ if not load_shunt_options then
o1 = s:option(ListValue, _n("preproxy_node"), translate("Preproxy Node"), translate("Only support a layer of proxy."))
o1:depends({ [_n("chain_proxy")] = "1", [_n("hysteria2_realms")] = false })
- o1.template = appname .. "/cbi/nodes_listvalue"
+ o1.template = m:template_path("/cbi/nodes_listvalue")
o1.group = {}
o3 = s:option(Value, _n("outbound_iface"), translate("Outbound Interface"))
@@ -949,7 +949,7 @@ if not load_shunt_options then
o2 = s:option(ListValue, _n("to_node"), translate("Landing Node"), translate("Only support a layer of proxy."))
o2:depends({ [_n("chain_proxy")] = "2", [_n("hysteria2_realms")] = false })
- o2.template = appname .. "/cbi/nodes_listvalue"
+ o2.template = m:template_path("/cbi/nodes_listvalue")
o2.group = {}
for k1, v1 in pairs(node_list) do
@@ -972,7 +972,7 @@ end
api.luci_types(arg[1], m, s, type_name, option_prefix)
if load_shunt_options then
- local current_node = m.uci:get_all(appname, arg[1]) or {}
+ local current_node = m:get(arg[1]) or {}
local shunt_lua = loadfile("/usr/lib/lua/luci/model/cbi/passwall2/client/include/shunt_options.lua")
setfenv(shunt_lua, getfenv(1))(m, s, {
node_id = arg[1],
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/index.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/index.lua
index cdb4cc9c..92f29eeb 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/index.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/index.lua
@@ -1,12 +1,9 @@
local api = require "luci.passwall2.api"
-local appname = api.appname
-
api.set_default_cbi()
-m = Map("passwall2_server", translate("Server-Side"))
-api.set_apply_on_parse(m)
+m = Map(api.s_config)
-t = m:section(NamedSection, "global", "global")
+t = m:section(NamedSection, "global", "global", translate("Server-Side"))
t.anonymous = true
t.addremove = false
@@ -88,17 +85,9 @@ e = s_server:option(Flag, "log", translate("Log"))
e.default = "1"
e.rmempty = false
-local sortable = Template(appname .. "/cbi/sortable")
-sortable.api = api
-sortable.appname = m.config
-sortable.target_cfgname = s_server.sectiontype
-m:append(sortable)
+m:appendTemplate("/cbi/sortable", {sectiontype = s_server.sectiontype})
-local server_list_status = Template(appname .. "/server/server_list_status")
-server_list_status.api = api
-server_list_status.appname = m.config
-server_list_status.sectiontype = s_server.sectiontype
-m:append(server_list_status)
+m:appendTemplate("/server/server_list_status", {sectiontype = s_server.sectiontype})
s_user = m:section(TypedSection, "user", translate("Users Manager"))
s_user.anonymous = true
@@ -114,7 +103,7 @@ end
s_user.remove = function(self, section)
local o = m:get(section) or {}
if o[".type"] == self.sectiontype then
- m.uci:foreach(m.config, "server", function(o)
+ m:foreach("server", function(o)
if o.user and section == o.user then
m:set(o[".name"], "user", "")
end
@@ -144,12 +133,8 @@ e.width = "25%"
e = s_user:option(DummyValue, "uuid", "UUID")
e.width = "25%"
-local sortable = Template(appname .. "/cbi/sortable")
-sortable.api = api
-sortable.appname = m.config
-sortable.target_cfgname = s_user.sectiontype
-m:append(sortable)
+m:appendTemplate("/cbi/sortable", {sectiontype = s_user.sectiontype})
-m:append(Template(appname .. "/server/log"))
+m:appendTemplate("/server/log")
return api.return_map(m)
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/server_config.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/server_config.lua
index 8e5824a7..79f6b54f 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/server_config.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/server_config.lua
@@ -1,35 +1,27 @@
api = require "luci.passwall2.api"
-appname = api.appname
-fs = api.fs
-
api.set_default_cbi()
-m = Map("passwall2_server", translate("Server Config"))
+m = Map(api.s_config)
m.redirect = api.url("server")
-api.set_apply_on_parse(m)
if not arg[1] or not m:get(arg[1]) then
luci.http.redirect(m.redirect)
end
-local header = Template(appname .. "/server/config_header")
-header.api = api
-header.config = m.config
-header.section = arg[1]
-m:append(header)
+m:appendTemplate("/server/config_header", {section = arg[1]})
-m:append(Template(appname .. "/cbi/nodes_listvalue_com"))
+m:appendTemplate("/cbi/nodes_listvalue_com")
user_list = {}
-m.uci:foreach(m.config, "user", function(s)
+m:foreach("user", function(s)
user_list[#user_list + 1] = s
end)
-s = m:section(NamedSection, arg[1], "server", "")
+s = m:section(NamedSection, arg[1], "server", translate("Server Config"))
s.addremove = false
s.dynamic = false
-local types_dir = "/usr/lib/lua/luci/model/cbi/" .. appname .. "/server/type/"
+local types_dir = "/usr/lib/lua/luci/model/cbi/" .. api.appname .. "/server/type/"
s.val = m:get(arg[1]) or {}
o = s:option(Flag, "enable", translate("Enable"))
@@ -43,7 +35,7 @@ o.rmempty = false
o = s:option(ListValue, "type", translate("Type"))
local type_table = {}
-for filename in fs.dir(types_dir) do
+for filename in api.fs.dir(types_dir) do
table.insert(type_table, filename)
end
table.sort(type_table, function(a, b)
@@ -55,10 +47,6 @@ for index, value in ipairs(type_table) do
setfenv(p_func, getfenv(1))(m, s)
end
-local footer = Template(appname .. "/server/config_footer")
-footer.api = api
-footer.config = m.config
-footer.section = arg[1]
-m:append(footer)
+m:appendTemplate("/server/config_footer", {section = arg[1]})
return api.return_map(m)
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/ray.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/ray.lua
index 435bb26e..20ac33e8 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/ray.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/ray.lua
@@ -446,7 +446,7 @@ o:value("", translate("Close"))
o:value("_socks", translate("Custom Socks"))
o:value("_http", translate("Custom HTTP"))
o:value("_iface", translate("Custom Interface"))
-o.template = api.appname .. "/cbi/nodes_listvalue"
+o.template = m:template_path("/cbi/nodes_listvalue")
o.group = {"","","",""}
for k, v in pairs(nodes_table) do
o:value(v.id, v.remarks)
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/sing-box.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/sing-box.lua
index d3066bbc..103315a7 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/sing-box.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/sing-box.lua
@@ -424,7 +424,7 @@ o:value("", translate("Close"))
o:value("_socks", translate("Custom Socks"))
o:value("_http", translate("Custom HTTP"))
o:value("_iface", translate("Custom Interface"))
-o.template = api.appname .. "/cbi/nodes_listvalue"
+o.template = m:template_path("/cbi/nodes_listvalue")
o.group = {"","","",""}
for k, v in pairs(nodes_table) do
o:value(v.id, v.remarks)
diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/user_config.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/user_config.lua
index 1cbb1ad7..9c0b67d9 100644
--- a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/user_config.lua
+++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/user_config.lua
@@ -1,24 +1,33 @@
api = require "luci.passwall2.api"
-appname = api.appname
-fs = api.fs
-
api.set_default_cbi()
-m = Map("passwall2_server", translate("User Config"))
+m = Map(api.s_config)
m.redirect = api.url("server")
-api.set_apply_on_parse(m)
if not arg[1] or not m:get(arg[1]) then
luci.http.redirect(m.redirect)
end
-s = m:section(NamedSection, arg[1], "user", "")
+s = m:section(NamedSection, arg[1], "user", translate("User Config"))
s.addremove = false
s.dynamic = false
o = s:option(Value, "username", translate("Username"))
o.datatype = "and(uciname,maxlength(24))"
o.rmempty = false
+function o.validate(self, value, section)
+ local exists = false
+ m:foreach("user", function(s)
+ if s[".name"] ~= section and s.username == value then
+ exists = true
+ return false
+ end
+ end)
+ if exists then
+ return nil, translate("This username already exists.")
+ end
+ return value
+end
o = s:option(Value, "password", translate("Password"))
o.rmempty = false
diff --git a/luci-app-passwall2/luasrc/passwall2/api.lua b/luci-app-passwall2/luasrc/passwall2/api.lua
index 9d1853fa..3e67ce19 100644
--- a/luci-app-passwall2/luasrc/passwall2/api.lua
+++ b/luci-app-passwall2/luasrc/passwall2/api.lua
@@ -1,5 +1,7 @@
module("luci.passwall2.api", package.seeall)
appname = "passwall2"
+c_config = "passwall2"
+s_config = "passwall2_server"
local com = require "luci.passwall2.com"
nixio = require "nixio"
fs = require "nixio.fs"
@@ -22,7 +24,7 @@ TMP_IFACE_PATH = TMP_PATH .. "/iface"
local lang = uci:get("luci", "main", "lang") or "auto"
if lang == "auto" then
- local auto_lang = uci:get(appname, "@global[0]", "auto_lang")
+ local auto_lang = uci:get(c_config, "@global[0]", "auto_lang")
if auto_lang then lang = auto_lang end
end
if lang == "auto" then
@@ -234,7 +236,7 @@ function curl_direct(url, file, args)
end
function curl_auto(url, file, args)
- local localhost_proxy = uci:get(appname, "@global[0]", "localhost_proxy") or "1"
+ local localhost_proxy = uci:get(c_config, "@global[0]", "localhost_proxy") or "1"
if localhost_proxy == "1" then
return curl_base(url, file, args)
else
@@ -493,7 +495,7 @@ function get_node_name(node_id)
if type(node_id) == "table" then
e = node_id
else
- e = uci:get_all(appname, node_id)
+ e = uci:get_all(c_config, node_id)
end
if e then
if e.type and e.remarks then
@@ -509,11 +511,11 @@ function get_node_name(node_id)
end
function get_valid_nodes()
- local show_node_info = uci_get_type("global_other", "show_node_info") or "0"
+ local show_node_info = uci:get(c_config, "@global_other[0]", "show_node_info") or "0"
local nodes = {}
local default_nodes = {}
local other_nodes = {}
- uci:foreach(appname, "nodes", function(e)
+ uci:foreach(c_config, "nodes", function(e)
e.id = e[".name"]
if e.type and e.remarks then
local type_name = e.type
@@ -586,7 +588,7 @@ function get_node_list()
socks_list = {},
normal_list = {},
}
- uci:foreach(appname, "socks", function(s)
+ uci:foreach(c_config, "socks", function(s)
if s.enabled == "1" and s.node then
node_list.socks_list[#node_list.socks_list + 1] = {
id = s[".name"],
@@ -685,22 +687,6 @@ function gen_random_char(length)
return sys.exec("echo -n $(head /dev/urandom | tr -dc A-Za-z0-9 | head -c %s)" % length)
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
- value = default
- end
- return value
-end
-
-function uci_get_type_id(id, config, default)
- local value = uci:get(appname, id, config, default) or sys.exec("echo -n $(uci -q get " .. appname .. "." .. id .. "." .. config .. ")")
- if (value == nil or value == "") and (default and default ~= "") then
- value = default
- end
- return value
-end
-
function chmod_755(file)
if file and file ~= "" then
if not fs.access(file, "rwx", "rx", "rx") then
@@ -710,7 +696,7 @@ function chmod_755(file)
end
function get_customed_path(e)
- return uci_get_type("global_app", e .. "_file")
+ return uci:get(c_config, "@global_app[0]", e .. "_file")
end
function finded_com(e)
@@ -769,7 +755,7 @@ end
function get_app_path(app_name)
if com[app_name] then
local def_path = com[app_name].default_path
- local path = uci_get_type("global_app", app_name:gsub("%-","_") .. "_file")
+ local path = uci:get(c_config, "@global_app[0]", app_name:gsub("%-","_") .. "_file")
path = path and (#path>0 and path or def_path) or def_path
return path
end
@@ -1345,53 +1331,91 @@ function is_js_luci()
return sys.call('[ -f "/www/luci-static/resources/uci.js" ]') == 0
end
-function set_apply_on_parse(map)
- if not map then
- return
- end
- local lang = uci:get("luci", "main", "lang") or "auto"
- if lang == "auto" then
- local http = require "luci.http"
- local aclang = http.getenv("HTTP_ACCEPT_LANGUAGE") or ""
- for lpat in aclang:gmatch("[%w-]+") do
- lpat = lpat and lpat:gsub("-", "_")
- if uci:get("luci", "languages", lpat) then
- lang = lpat
- break
- end
- lpat = lpat and lpat:lower()
- if uci:get("luci", "languages", lpat) then
- lang = lpat
- break
- end
- end
- if lang ~= "auto" then
- sh_uci_set(appname, "@global[0]", "auto_lang", lang, true)
- end
- end
- if is_js_luci() == true then
- local hide_popup_box = nil
- if hide_popup_box == true then
- map.apply_on_parse = false
- map.on_after_apply = function(self)
- if self.redirect then
- os.execute("sleep 1")
- luci.http.redirect(self.redirect)
- end
- end
- else
- apply_redirect(map)
- local old = map.on_after_save
- map.on_after_save = function(self)
- if old then old(self) end
- map:set("@global[0]", "timestamp", os.time())
- end
- end
- end
-end
-
function set_default_cbi()
local cbi = require "luci.cbi"
+ if true then
+ --Map
+ local Map = cbi.Map
+ local original_init = Map.__init__
+ function Map.__init__(self, config, ...)
+ if not config then config = c_config end
+ original_init(self, config, ...)
+ self.api = require "luci.passwall2.api"
+ end
+ function Map.foreach(self, stype, func)
+ self.uci:foreach(self.config, stype, func)
+ end
+ function Map.template_path(self, template)
+ return appname .. template
+ end
+ function Map.appendTemplate(self, template, data)
+ local obj = cbi.Template(self:template_path(template))
+ obj.map = self
+ if data and next(data) then
+ for k, v in pairs(data) do
+ obj[k] = v
+ end
+ end
+ self:append(obj)
+ return obj
+ end
+
+ local lang = uci:get("luci", "main", "lang") or "auto"
+ if lang == "auto" then
+ local http = require "luci.http"
+ local aclang = http.getenv("HTTP_ACCEPT_LANGUAGE") or ""
+ for lpat in aclang:gmatch("[%w-]+") do
+ lpat = lpat and lpat:gsub("-", "_")
+ if uci:get("luci", "languages", lpat) then
+ lang = lpat
+ break
+ end
+ lpat = lpat and lpat:lower()
+ if uci:get("luci", "languages", lpat) then
+ lang = lpat
+ break
+ end
+ end
+ if lang ~= "auto" then
+ sh_uci_set(c_config, "@global[0]", "auto_lang", lang, true)
+ end
+ end
+ if is_js_luci() == true then
+ local hide_popup_box = nil
+ if hide_popup_box == true then
+ Map.apply_on_parse = false
+ Map.on_after_apply = function(self)
+ if self.redirect then
+ os.execute("sleep 1")
+ luci.http.redirect(self.redirect)
+ end
+ end
+ else
+ apply_redirect(Map)
+ local old = Map.on_after_save
+ Map.on_after_save = function(self)
+ if old then old(self) end
+ self:set("@global[0]", "timestamp", os.time())
+ end
+ end
+ end
+ end
+ if true then
+ --AbstractSection
+ local AbstractSection = cbi.AbstractSection
+ function AbstractSection.appendTemplate(self, template, data)
+ local obj = cbi.Template(self.map:template_path(template))
+ obj.map = self.map
+ obj.section = self
+ if data and next(data) then
+ for k, v in pairs(data) do
+ obj[k] = v
+ end
+ end
+ self:append(obj)
+ return obj
+ end
+ end
if true then
--TextValue
local TextValue = cbi.TextValue
@@ -1428,18 +1452,15 @@ function return_map(map)
if true then
-- header
local header = cbi.Template(appname .. "/cbi/header")
- header.api = api
- header.config = map.config
+ header.map = map
table.insert(map.children, 1, header)
end
if true then
-- footer
local footer = cbi.Template(appname .. "/cbi/footer")
- footer.api = api
- footer.config = map.config
+ footer.map = map
map:append(footer)
end
-
return map
end
@@ -1570,7 +1591,7 @@ function format_go_time(input, default)
end
function apply_redirect(m)
- local tmp_uci_file = "/etc/config/" .. appname .. "_redirect"
+ local tmp_uci_file = "/etc/config/" .. c_config .. "_redirect"
if m.redirect and m.redirect ~= "" then
if fs.access(tmp_uci_file) then
local redirect
@@ -1588,7 +1609,7 @@ function apply_redirect(m)
m.on_after_save = function(self)
local redirect = self.redirect
if redirect and redirect ~= "" then
- uci:set(appname .. "_redirect", "@redirect[0]", "url", redirect)
+ uci:set(c_config .. "_redirect", "@redirect[0]", "url", redirect)
end
end
else
@@ -1693,7 +1714,7 @@ end
function get_socks_backup_nodes(id)
id = trim(id)
if id == "" then return "" end
- local socks = uci:get_all(appname, id)
+ local socks = uci:get_all(c_config, id)
local nodes
if socks.backup_node_add_mode and socks.backup_node_add_mode == "batch" then
local node = {}
@@ -1714,7 +1735,7 @@ function get_socks_backup_nodes(id)
end
function get_core(field, candidates)
- local v = uci:get(appname, "@global_subscribe[0]", field)
+ local v = uci:get(c_config, "@global_subscribe[0]", field)
if v and v ~= "" then
for _, c in ipairs(candidates) do
if c[2] == v and c[1] then
diff --git a/luci-app-passwall2/luasrc/passwall2/server_app.lua b/luci-app-passwall2/luasrc/passwall2/server_app.lua
index 7b28da0a..dee45ac7 100644
--- a/luci-app-passwall2/luasrc/passwall2/server_app.lua
+++ b/luci-app-passwall2/luasrc/passwall2/server_app.lua
@@ -6,7 +6,7 @@ local sys = api.sys
local uci = api.uci
local jsonc = api.jsonc
-local CONFIG = "passwall2_server"
+local CONFIG = api.s_config
local CONFIG_PATH = "/tmp/etc/" .. CONFIG
local NFT_INCLUDE_FILE = CONFIG_PATH .. "/" .. CONFIG .. ".nft"
local LOG_APP_FILE = "/tmp/log/" .. CONFIG .. ".log"
diff --git a/luci-app-passwall2/luasrc/passwall2/util_hysteria2.lua b/luci-app-passwall2/luasrc/passwall2/util_hysteria2.lua
index b145fbb3..24dcb776 100644
--- a/luci-app-passwall2/luasrc/passwall2/util_hysteria2.lua
+++ b/luci-app-passwall2/luasrc/passwall2/util_hysteria2.lua
@@ -9,7 +9,7 @@ function gen_config_server(node)
if node.users and #node.users > 0 then
users = {}
for i, v in ipairs(node.users) do
- local user = uci:get_all("passwall2_server", v) or {}
+ local user = uci:get_all(api.s_config, v) or {}
if user[".type"] == "user" then
users[user.username] = user.password
end
@@ -74,7 +74,7 @@ function gen_config(var)
print("node Cannot be empty!")
return
end
- local node = uci:get_all("passwall2", node_id)
+ local node = uci:get_all(api.c_config, node_id)
local local_socks_address = var["local_socks_address"] or "0.0.0.0"
local local_socks_port = var["local_socks_port"]
local local_socks_username = var["local_socks_username"]
diff --git a/luci-app-passwall2/luasrc/passwall2/util_naiveproxy.lua b/luci-app-passwall2/luasrc/passwall2/util_naiveproxy.lua
index b515c75f..4839f53c 100644
--- a/luci-app-passwall2/luasrc/passwall2/util_naiveproxy.lua
+++ b/luci-app-passwall2/luasrc/passwall2/util_naiveproxy.lua
@@ -9,7 +9,7 @@ function gen_config(var)
print("node Cannot be empty!")
return
end
- local node = uci:get_all("passwall2", node_id)
+ local node = uci:get_all(api.c_config, node_id)
local run_type = var["run_type"]
local local_addr = var["local_addr"]
local local_port = var["local_port"]
diff --git a/luci-app-passwall2/luasrc/passwall2/util_shadowsocks.lua b/luci-app-passwall2/luasrc/passwall2/util_shadowsocks.lua
index 77b51795..a0ac3022 100644
--- a/luci-app-passwall2/luasrc/passwall2/util_shadowsocks.lua
+++ b/luci-app-passwall2/luasrc/passwall2/util_shadowsocks.lua
@@ -6,7 +6,7 @@ local jsonc = api.jsonc
function gen_config_server(node)
local user = nil
if node.user then
- user = uci:get_all("passwall2_server", node.user)
+ user = uci:get_all(api.s_config, node.user)
end
local config = {}
@@ -41,7 +41,7 @@ function gen_config(var)
print("node Cannot be empty!")
return
end
- local node = uci:get_all("passwall2", node_id)
+ local node = uci:get_all(api.c_config, node_id)
local server_host = var["server_host"] or (node.address or ""):lower()
local server_port = var["server_port"] or node.port
local local_addr = var["local_addr"]
diff --git a/luci-app-passwall2/luasrc/passwall2/util_sing-box.lua b/luci-app-passwall2/luasrc/passwall2/util_sing-box.lua
index cabd7696..5d9c015a 100644
--- a/luci-app-passwall2/luasrc/passwall2/util_sing-box.lua
+++ b/luci-app-passwall2/luasrc/passwall2/util_sing-box.lua
@@ -34,7 +34,7 @@ function check_geoview()
if GEO_VAR.OK == 0 then
api.log(0, "!!! Note: Geo rules cannot be used if the Geoview component is missing or the version is too low.")
else
- GEO_VAR.DIR = GEO_VAR.DIR or (uci:get(appname, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/")
+ GEO_VAR.DIR = GEO_VAR.DIR or (uci:get(api.c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/")
GEO_VAR.SITE_PATH = GEO_VAR.SITE_PATH or (GEO_VAR.DIR .. "/geosite.dat")
GEO_VAR.IP_PATH = GEO_VAR.IP_PATH or (GEO_VAR.DIR .. "/geoip.dat")
if not fs.access(GEO_VAR.TO_SRS_PATH) then
@@ -794,7 +794,7 @@ function gen_config_server(node)
if node.users and #node.users > 0 then
users = {}
for i, v in ipairs(node.users) do
- local user = uci:get_all("passwall2_server", v) or {}
+ local user = uci:get_all(api.s_config, v) or {}
if user[".type"] == "user" then
local u = {}
if node.protocol == "mixed" or node.protocol == "socks" or node.protocol == "http" or node.protocol == "naive" then
@@ -1030,7 +1030,7 @@ function gen_config_server(node)
}
sys.call(string.format("mkdir -p %s && touch %s/%s", api.TMP_IFACE_PATH, api.TMP_IFACE_PATH, node.outbound_node_iface))
else
- local outbound_node_t = uci:get_all("passwall2", node.outbound_node)
+ local outbound_node_t = uci:get_all(api.c_config, node.outbound_node)
if node.outbound_node == "_socks" or node.outbound_node == "_http" then
outbound_node_t = {
type = node.type,
@@ -1132,7 +1132,7 @@ function gen_config(var)
local CACHE_TEXT_FILE = CACHE_PATH .. "/cache_" .. flag .. ".txt"
- local singbox_settings = uci:get_all(appname, "@global_singbox[0]") or {}
+ local singbox_settings = uci:get_all(api.c_config, "@global_singbox[0]") or {}
local route = {
rules = {}
@@ -1195,7 +1195,7 @@ function gen_config(var)
local node = nil
if node_id then
- node = uci:get_all(appname, node_id)
+ node = uci:get_all(api.c_config, node_id)
end
if local_socks_port then
@@ -1290,7 +1290,7 @@ function gen_config(var)
function get_node_by_id(node_id)
if not node_id or node_id == "" or node_id == "nil" then return nil end
- local section = uci:get_all(appname, node_id) or {}
+ local section = uci:get_all(api.c_config, node_id) or {}
if section[".type"] == "socks" then
local result = {
[".name"] = node_id,
@@ -1569,7 +1569,7 @@ function gen_config(var)
end
--shunt rule
- uci:foreach(appname, "shunt_rules", function(e)
+ uci:foreach(api.c_config, "shunt_rules", function(e)
if node["shunt_group"] ~= e.group then
return
end
@@ -1835,16 +1835,16 @@ function gen_config(var)
if dns_listen_port then
local dns_host = ""
if flag == "global" then
- dns_host = uci:get(appname, "@global[0]", "dns_hosts") or ""
+ dns_host = uci:get(api.c_config, "@global[0]", "dns_hosts") or ""
else
flag = flag:gsub("acl_", "")
- local dns_hosts_mode = uci:get(appname, flag, "dns_hosts_mode") or "default"
+ local dns_hosts_mode = uci:get(api.c_config, flag, "dns_hosts_mode") or "default"
if dns_hosts_mode == "default" then
- dns_host = uci:get(appname, "@global[0]", "dns_hosts") or ""
+ dns_host = uci:get(api.c_config, "@global[0]", "dns_hosts") or ""
elseif dns_hosts_mode == "disable" then
dns_host = ""
elseif dns_hosts_mode == "custom" then
- dns_host = uci:get(appname, flag, "dns_hosts") or ""
+ dns_host = uci:get(api.c_config, flag, "dns_hosts") or ""
end
end
if #dns_host > 0 then
diff --git a/luci-app-passwall2/luasrc/passwall2/util_xray.lua b/luci-app-passwall2/luasrc/passwall2/util_xray.lua
index 47ac9e12..896fa1fe 100644
--- a/luci-app-passwall2/luasrc/passwall2/util_xray.lua
+++ b/luci-app-passwall2/luasrc/passwall2/util_xray.lua
@@ -501,7 +501,7 @@ function gen_config_server(node)
if node.users and #node.users > 0 then
users = {}
for i, v in ipairs(node.users) do
- local user = uci:get_all("passwall2_server", v) or {}
+ local user = uci:get_all(api.s_config, v) or {}
if user[".type"] == "user" then
local u = {}
if node.protocol == "socks" or node.protocol == "http" then
@@ -633,7 +633,7 @@ function gen_config_server(node)
}
sys.call(string.format("mkdir -p %s && touch %s/%s", api.TMP_IFACE_PATH, api.TMP_IFACE_PATH, node.outbound_node_iface))
else
- local outbound_node_t = uci:get_all("passwall2", node.outbound_node)
+ local outbound_node_t = uci:get_all(api.c_config, node.outbound_node)
if node.outbound_node == "_socks" or node.outbound_node == "_http" then
outbound_node_t = {
type = node.type,
@@ -906,7 +906,7 @@ function gen_config(var)
local CACHE_TEXT_FILE = CACHE_PATH .. "/cache_" .. flag .. ".txt"
- local xray_settings = uci:get_all(appname, "@global_xray[0]") or {}
+ local xray_settings = uci:get_all(api.c_config, "@global_xray[0]") or {}
if xray_settings.fragment == "1" then
local lengths, delays = {}, {}
@@ -931,7 +931,7 @@ function gen_config(var)
if xray_settings.noise == "1" then
local noises = {}
- uci:foreach(appname, "xray_noise_packets", function(n)
+ uci:foreach(api.c_config, "xray_noise_packets", function(n)
if n.enabled == "1" then
local noise = {
rand = (n.type == "rand" and n.packet) and (n.packet:find("-", 1, true) and n.packet or tonumber(n.packet)) or nil,
@@ -948,7 +948,7 @@ function gen_config(var)
} or nil
end
- local node = node_id and uci:get_all(appname, node_id) or nil
+ local node = node_id and uci:get_all(api.c_config, node_id) or nil
local balancers = {}
local rules = {}
@@ -1000,7 +1000,7 @@ function gen_config(var)
function get_node_by_id(node_id)
if not node_id or node_id == "" or node_id == "nil" then return nil end
- local section = uci:get_all(appname, node_id) or {}
+ local section = uci:get_all(api.c_config, node_id) or {}
if section[".type"] == "socks" then
local result = {
[".name"] = node_id,
@@ -1394,7 +1394,7 @@ function gen_config(var)
end
--shunt rule
- uci:foreach(appname, "shunt_rules", function(e)
+ uci:foreach(api.c_config, "shunt_rules", function(e)
if node["shunt_group"] ~= e.group then
return
end
@@ -1590,16 +1590,16 @@ function gen_config(var)
local dns_host = ""
if flag == "global" then
- dns_host = uci:get(appname, "@global[0]", "dns_hosts") or ""
+ dns_host = uci:get(api.c_config, "@global[0]", "dns_hosts") or ""
else
flag = flag:gsub("acl_", "")
- local dns_hosts_mode = uci:get(appname, flag, "dns_hosts_mode") or "default"
+ local dns_hosts_mode = uci:get(api.c_config, flag, "dns_hosts_mode") or "default"
if dns_hosts_mode == "default" then
- dns_host = uci:get(appname, "@global[0]", "dns_hosts") or ""
+ dns_host = uci:get(api.c_config, "@global[0]", "dns_hosts") or ""
elseif dns_hosts_mode == "disable" then
dns_host = ""
elseif dns_hosts_mode == "custom" then
- dns_host = uci:get(appname, flag, "dns_hosts") or ""
+ dns_host = uci:get(api.c_config, flag, "dns_hosts") or ""
end
end
if #dns_host > 0 then
@@ -1977,7 +1977,7 @@ function gen_config(var)
if inbounds or outbounds then
local config = {
env = (function()
- local asset_location = uci:get(appname, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"
+ local asset_location = uci:get(api.c_config, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"
return { XRAY_LOCATION_ASSET = asset_location }
end)(),
log = {
diff --git a/luci-app-passwall2/luasrc/view/passwall2/app_update/app_version.htm b/luci-app-passwall2/luasrc/view/passwall2/app_update/app_version.htm
index 7b31c08e..2742c923 100644
--- a/luci-app-passwall2/luasrc/view/passwall2/app_update/app_version.htm
+++ b/luci-app-passwall2/luasrc/view/passwall2/app_update/app_version.htm
@@ -1,6 +1,7 @@