From be07e61c4cefe2f212cb2d7cd7722b3533d8f3ad Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 21 Dec 2024 17:24:59 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9B=85=20Sync=202024-12-21=2017:24?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../luasrc/controller/passwall.lua | 32 ++++- .../luasrc/model/cbi/passwall/client/log.lua | 66 ++++++++- .../luasrc/view/passwall/global/faq.htm | 8 -- .../view/passwall/log/backup_restore.htm | 130 ++++++++++++++++++ luci-app-passwall/po/zh-cn/passwall.po | 48 +++++-- 5 files changed, 262 insertions(+), 22 deletions(-) create mode 100644 luci-app-passwall/luasrc/view/passwall/log/backup_restore.htm diff --git a/luci-app-passwall/luasrc/controller/passwall.lua b/luci-app-passwall/luasrc/controller/passwall.lua index 68518613..ae0617a6 100644 --- a/luci-app-passwall/luasrc/controller/passwall.lua +++ b/luci-app-passwall/luasrc/controller/passwall.lua @@ -8,6 +8,7 @@ local uci = luci.model.uci.cursor() -- in funtion index() local http = require "luci.http" local util = require "luci.util" local i18n = require "luci.i18n" +local fs = require "nixio.fs" function index() if not nixio.fs.access("/etc/config/passwall") then @@ -46,7 +47,7 @@ function index() entry({"admin", "services", appname, "socks_config"}, cbi(appname .. "/client/socks_config")).leaf = true entry({"admin", "services", appname, "acl"}, cbi(appname .. "/client/acl"), _("Access control"), 98).leaf = true entry({"admin", "services", appname, "acl_config"}, cbi(appname .. "/client/acl_config")).leaf = true - entry({"admin", "services", appname, "log"}, form(appname .. "/client/log"), _("Watch Logs"), 999).leaf = true + entry({"admin", "services", appname, "log"}, form(appname .. "/client/log"), _("Log Maint"), 999).leaf = true --[[ Server ]] entry({"admin", "services", appname, "server"}, cbi(appname .. "/server/index"), _("Server-Side"), 99).leaf = true @@ -90,6 +91,9 @@ function index() entry({"admin", "services", appname, "check_" .. com}, call("com_check", com)).leaf = true entry({"admin", "services", appname, "update_" .. com}, call("com_update", com)).leaf = true end + + --[[Backup]] + entry({"admin", "services", appname, "backup"}, call("create_backup")).leaf = true end local function http_write_json(content) @@ -500,9 +504,29 @@ function read_rulelist(list) else rule_path = "/usr/share/passwall/rules/chnroute" end - if api.fs.access(rule_path) then - luci.http.prepare_content("text/plain") - luci.http.write(api.fs.readfile(rule_path)) + if fs.access(rule_path) then + http.prepare_content("text/plain") + http.write(fs.readfile(rule_path)) end end +function create_backup() + local backup_files = { + "/etc/config/passwall", + "/etc/config/passwall_server", + "/usr/share/passwall/rules/block_host", + "/usr/share/passwall/rules/block_ip", + "/usr/share/passwall/rules/direct_host", + "/usr/share/passwall/rules/direct_ip", + "/usr/share/passwall/rules/proxy_host", + "/usr/share/passwall/rules/proxy_ip" + } + local tar_file = "/tmp/passwall-backup.tar.gz" + fs.remove(tar_file) + local cmd = "tar -czf " .. tar_file .. " " .. table.concat(backup_files, " ") + api.sys.call(cmd) + http.header("Content-Disposition", "attachment; filename=passwall-backup.tar.gz") + http.prepare_content("application/octet-stream") + http.write(fs.readfile(tar_file)) + fs.remove(tar_file) +end diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/log.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/log.lua index ef8c9be0..8abea56c 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/log.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/log.lua @@ -1,8 +1,72 @@ local api = require "luci.passwall.api" +local http = require "luci.http" local appname = "passwall" +local fs = api.fs +local sys = api.sys f = SimpleForm(appname) f.reset = false f.submit = false f:append(Template(appname .. "/log/log")) -return f + +fb = SimpleForm('backup-restore') +fb.reset = false +fb.submit = false +s = fb:section(SimpleSection, translate("Backup and Restore"), translate("Backup or Restore Client and Server Configurations.")) +o = s:option(DummyValue, '', nil) +o.template = appname .. "/log/backup_restore" + + +local backup_files = { + "/etc/config/passwall", + "/etc/config/passwall_server", + "/usr/share/passwall/rules/block_host", + "/usr/share/passwall/rules/block_ip", + "/usr/share/passwall/rules/direct_host", + "/usr/share/passwall/rules/direct_ip", + "/usr/share/passwall/rules/proxy_host", + "/usr/share/passwall/rules/proxy_ip" +} + +local file_path = '/tmp/passwall_upload.tar.gz' +local temp_dir = '/tmp/passwall_bak' +local fd +http.setfilehandler(function(meta, chunk, eof) + if not fd and meta and meta.name == "ulfile" and chunk then + sys.call("rm -rf " .. temp_dir) + fs.remove(file_path) + fd = nixio.open(file_path, "w") + sys.call("echo '' > /tmp/log/passwall.log") + end + if fd and chunk then + fd:write(chunk) + end + if eof and fd then + fd:close() + fd = nil + if fs.access(file_path) then + api.log(" * PassWall 配置文件上传成功…") + sys.call("mkdir -p " .. temp_dir) + if sys.call("tar -xzf " .. file_path .. " -C " .. temp_dir) == 0 then + for _, backup_file in ipairs(backup_files) do + local temp_file = temp_dir .. backup_file + if fs.access(temp_file) then + sys.call("cp -f " .. temp_file .. " " .. backup_file) + end + end + api.log(" * PassWall 配置还原成功…") + api.log(" * 重启 PassWall 服务中…\n") + sys.call('/etc/init.d/passwall restart > /dev/null 2>&1 &') + sys.call('/etc/init.d/passwall_server restart > /dev/null 2>&1 &') + else + api.log(" * PassWall 配置文件解压失败,请重试!") + end + else + api.log(" * PassWall 配置文件上传失败,请重试!") + end + sys.call("rm -rf " .. temp_dir) + fs.remove(file_path) + end +end) + +return f, fb diff --git a/luci-app-passwall/luasrc/view/passwall/global/faq.htm b/luci-app-passwall/luasrc/view/passwall/global/faq.htm index ca92ed61..ccb0f4e4 100644 --- a/luci-app-passwall/luasrc/view/passwall/global/faq.htm +++ b/luci-app-passwall/luasrc/view/passwall/global/faq.htm @@ -47,16 +47,9 @@ local api = require "luci.passwall.api" +<%+cbi/valuefooter%> diff --git a/luci-app-passwall/po/zh-cn/passwall.po b/luci-app-passwall/po/zh-cn/passwall.po index a845a9a0..b02db4bf 100644 --- a/luci-app-passwall/po/zh-cn/passwall.po +++ b/luci-app-passwall/po/zh-cn/passwall.po @@ -52,9 +52,6 @@ msgstr "规则列表" msgid "Access control" msgstr "访问控制" -msgid "Watch Logs" -msgstr "查看日志" - msgid "Node Config" msgstr "节点配置" @@ -238,9 +235,6 @@ msgstr "清空 NFTSET" msgid "Try this feature if the rule modification does not take effect." msgstr "如果修改规则后没有生效,请尝试此功能。" -msgid "Are you sure to reset?" -msgstr "你确定要恢复吗?" - msgid "Are you sure to hide?" msgstr "你确定要隐藏吗?" @@ -265,9 +259,6 @@ msgstr "对于移动设备,可通过重新接入网络的方式清除。比如 msgid "Please make sure your device's network settings point both the DNS server and default gateway to this router, to ensure DNS queries are properly routed." msgstr "请确认您设备的网络设置,客户端 DNS 服务器和默认网关应均指向本路由器,以确保 DNS 查询正确路由。" -msgid "Restore to default configuration:" -msgstr "恢复默认配置:" - msgid "Browser access:" msgstr "浏览器访问:" @@ -1758,3 +1749,42 @@ msgstr "总行数:" msgid "Read List" msgstr "读取列表" + +msgid "Log Maint" +msgstr "日志维护" + +msgid "Backup and Restore" +msgstr "备份还原" + +msgid "Backup or Restore Client and Server Configurations." +msgstr "备份或还原客户端及服务端配置。" + +msgid "Create Backup File" +msgstr "创建备份文件" + +msgid "Restore Backup File" +msgstr "恢复备份文件" + +msgid "DL Backup" +msgstr "下载备份" + +msgid "RST Backup" +msgstr "恢复备份" + +msgid "UL Restore" +msgstr "上传恢复" + +msgid "CLOSE WIN" +msgstr "关闭窗口" + +msgid "Restore to default configuration" +msgstr "恢复默认配置" + +msgid "Do Reset" +msgstr "执行重置" + +msgid "Do you want to restore the client to default settings?" +msgstr "是否要恢复客户端默认配置?" + +msgid "Are you sure you want to restore the client to default settings?" +msgstr "是否真的要恢复客户端默认配置?"