update 2026-08-18 00:20:24

This commit is contained in:
action committed 2026-08-18 00:20:24 +08:00
1 parent 91e6a562e7
commit 6c82a121e9
43 files changed
+4622 -4834

No files matched your search

@@ -143,40 +143,54 @@ end
-- 默认的保存并应用行为
local function apply_redirect(m)
local tmp_uci_file = "/etc/config/" .. "shadowsocksr" .. "_redirect"
local tmp_uci_file = "/etc/config/shadowsocksr_redirect"
if m.redirect and m.redirect ~= "" then
-- 如果存在临时文件,读取 URL 并通过 luci.http.redirect 跳转
if nixio.fs.access(tmp_uci_file) then
local redirect
local redirect_url
for line in io.lines(tmp_uci_file) do
redirect = line:match("option%s+url%s+['\"]([^'\"]+)['\"]")
if redirect and redirect ~= "" then break end
redirect_url = line:match("option%s+url%s+['\"]([^'\"]+)['\"]")
if redirect_url and redirect_url ~= "" then break end
end
if redirect and redirect ~= "" then
luci.sys.call("/bin/rm -f " .. tmp_uci_file)
luci.http.redirect(redirect)
if redirect_url and redirect_url ~= "" then
-- 使用 nixio 安全删除文件,替代外部 Shell 命令
nixio.fs.remove(tmp_uci_file)
-- JS 版 LuCI 依赖 luci.http.redirect 向前端重定向
luci.http.redirect(redirect_url)
return
end
else
-- 创建标记文件
nixio.fs.writefile(tmp_uci_file, "config redirect\n")
end
-- 挂载保存回调
local old_on_after_save = m.on_after_save
m.on_after_save = function(self)
local redirect = self.redirect
if redirect and redirect ~= "" then
m.uci:set("shadowsocksr" .. "_redirect", "@redirect[0]", "url", redirect)
if old_on_after_save then old_on_after_save(self) end
local target = self.redirect
if target and target ~= "" then
-- 使用标准的 nixio.fs 写入文件,保持格式一致
local content = string.format("config redirect\n\toption url '%s'\n", target)
nixio.fs.writefile(tmp_uci_file, content)
end
end
else
luci.sys.call("/bin/rm -f " .. tmp_uci_file)
-- 不满足重定向条件时清理文件
if nixio.fs.access(tmp_uci_file) then
nixio.fs.remove(tmp_uci_file)
end
end
end
local 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())
local function set_apply_on_parse(m)
if not m then return end
-- is_js_luci 保护
if is_js_luci and is_js_luci() then
apply_redirect(m)
local old_on_after_save = m.on_after_save
m.on_after_save = function(self)
if old_on_after_save then old_on_after_save(self) end
-- m:set("@global[0]", "timestamp", os.time())
end
end
end
@@ -345,15 +359,12 @@ if not sid or m.uci:get("shadowsocksr", sid) ~= "servers" then
return
end
-- 保存&应用成功后跳转到节点列表
set_apply_on_parse(m)
local old_after_save = m.on_after_save
m.on_after_save = function(self)
if old_after_save then old_after_save(self) end
set_apply_on_parse(m, function(self)
local node_type = self.uci:get("shadowsocksr", sid, "type")
if node_type == "clash" then
luci.sys.call(string.format("/etc/init.d/shadowsocksr clash_cache %s >/dev/null 2>&1 &", sid))
end
end
end)
local server_header = Template("/shadowsocksr/server_header")
server_header.section = sid
@@ -29,42 +29,56 @@ local function is_js_luci()
return luci.sys.call('[ -f "/www/luci-static/resources/uci.js" ]') == 0
end
-- 保存并应用行为
-- 默认的保存并应用行为
local function apply_redirect(m)
local tmp_uci_file = "/etc/config/" .. "shadowsocksr" .. "_redirect"
local tmp_uci_file = "/etc/config/shadowsocksr_redirect"
if m.redirect and m.redirect ~= "" then
-- 如果存在临时文件,读取 URL 并通过 luci.http.redirect 跳转
if nixio.fs.access(tmp_uci_file) then
local redirect
local redirect_url
for line in io.lines(tmp_uci_file) do
redirect = line:match("option%s+url%s+['\"]([^'\"]+)['\"]")
if redirect and redirect ~= "" then break end
redirect_url = line:match("option%s+url%s+['\"]([^'\"]+)['\"]")
if redirect_url and redirect_url ~= "" then break end
end
if redirect and redirect ~= "" then
luci.sys.call("/bin/rm -f " .. tmp_uci_file)
luci.http.redirect(redirect)
if redirect_url and redirect_url ~= "" then
-- 使用 nixio 安全删除文件,替代外部 Shell 命令
nixio.fs.remove(tmp_uci_file)
-- JS 版 LuCI 依赖 luci.http.redirect 向前端重定向
luci.http.redirect(redirect_url)
return
end
else
-- 创建标记文件
nixio.fs.writefile(tmp_uci_file, "config redirect\n")
end
-- 挂载保存回调
local old_on_after_save = m.on_after_save
m.on_after_save = function(self)
local redirect = self.redirect
if redirect and redirect ~= "" then
m.uci:set("shadowsocksr" .. "_redirect", "@redirect[0]", "url", redirect)
if old_on_after_save then old_on_after_save(self) end
local target = self.redirect
if target and target ~= "" then
-- 使用标准的 nixio.fs 写入文件,保持格式一致
local content = string.format("config redirect\n\toption url '%s'\n", target)
nixio.fs.writefile(tmp_uci_file, content)
end
end
else
luci.sys.call("/bin/rm -f " .. tmp_uci_file)
-- 不满足重定向条件时清理文件
if nixio.fs.access(tmp_uci_file) then
nixio.fs.remove(tmp_uci_file)
end
end
end
local 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())
local function set_apply_on_parse(m)
if not m then return end
-- is_js_luci 保护
if is_js_luci and is_js_luci() then
apply_redirect(m)
local old_on_after_save = m.on_after_save
m.on_after_save = function(self)
if old_on_after_save then old_on_after_save(self) end
-- m:set("@global[0]", "timestamp", os.time())
end
end
end
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff