⛅ Sync 2026-08-15 00:37:20

This commit is contained in:
github-actions[bot] committed 2026-08-15 00:37:20 +08:00
1 parent fefba0b996
commit 619b38b2b7
74 files changed
+807 -850

No files matched your search

+87 -51
View File
@@ -1,4 +1,7 @@
module("luci.passwall.api", package.seeall)
appname = "passwall"
c_config = "passwall"
s_config = "passwall_server"
local com = require "luci.passwall.com"
nixio = require "nixio"
fs = require "nixio.fs"
@@ -30,10 +33,6 @@ function log(...)
end
end
function is_js_luci()
return sys.call('[ -f "/www/luci-static/resources/uci.js" ]') == 0
end
function is_old_uci()
return sys.call("grep -E 'require[ \t]*\"uci\"' /usr/lib/lua/luci/model/uci.lua >/dev/null 2>&1") == 0
end
@@ -214,7 +213,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) -- 当路由器本机开启代理时,采用passwall规则进行访问
else
@@ -482,11 +481,11 @@ function get_domain_from_url(url)
end
function get_valid_nodes()
local show_node_info = 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 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
@@ -559,7 +558,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"],
@@ -658,23 +657,7 @@ 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
local function chmod_755(file)
function chmod_755(file)
if file and file ~= "" then
if not fs.access(file, "rwx", "rx", "rx") then
fs.chmod(file, 755)
@@ -683,7 +666,7 @@ local 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)
@@ -742,7 +725,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
@@ -1020,7 +1003,7 @@ local default_file_tree = {
}
local function get_api_json(url)
local gh_proxy = uci_get_type("global_app", "github_proxy", "0")
local gh_proxy = uci:get(c_config, "@global_app[0]", "github_proxy") or "0"
local return_code, content
if gh_proxy == "1" then
url = "https://gh-proxy.org/" .. url
@@ -1144,7 +1127,7 @@ function to_download(app_name, url, size)
local _curl_args = clone(curl_args)
table.insert(_curl_args, "--speed-limit 51200 --speed-time 15 --max-time 300")
local gh_proxy = uci_get_type("global_app", "github_proxy", "0")
local gh_proxy = uci:get(c_config, "@global_app[0]", "github_proxy") or "0"
local return_code, result
if gh_proxy == "1" then
url = "https://gh-proxy.org/" .. url
@@ -1302,7 +1285,7 @@ end
function to_check_self()
local url = "https://raw.githubusercontent.com/Openwrt-Passwall/openwrt-passwall/main/luci-app-passwall/Makefile"
local tmp_file = "/tmp/passwall_makefile"
local gh_proxy = uci_get_type("global_app", "github_proxy", "0")
local gh_proxy = uci:get(c_config, "@global_app[0]", "github_proxy") or "0"
local return_code, result
if gh_proxy == "1" then
url = "https://gh-proxy.org/" .. url
@@ -1339,8 +1322,72 @@ function to_check_self()
}
end
function is_js_luci()
return sys.call('[ -f "/www/luci-static/resources/uci.js" ]') == 0
end
function set_default_cbi()
local cbi = require "luci.cbi"
if true then
--Map
local Map = cbi.Map
if not Map._passwall_default_cbi then
Map._passwall_default_cbi = true
local original_parse = Map.parse
function Map.parse(self, ...)
if is_js_luci() then
apply_redirect(self)
local old = self.on_after_save
self.on_after_save = function(map)
if old then old(map) end
map:set("@global[0]", "timestamp", os.time())
end
end
return original_parse(self, ...)
end
end
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.passwall.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
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
@@ -1377,18 +1424,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
@@ -1569,20 +1613,8 @@ function format_go_time(input, default)
return result
end
function set_apply_on_parse(map)
if not map then return end
if is_js_luci() then
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
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
@@ -1597,10 +1629,14 @@ function apply_redirect(m)
else
fs.writefile(tmp_uci_file, "config redirect\n")
end
local old = m.on_after_save
m.on_after_save = function(self)
if old then
old(self)
end
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
@@ -1705,7 +1741,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 = {}
@@ -1726,7 +1762,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