From fd79ac91b46568ffe803c5c18c1d62d62e57da62 Mon Sep 17 00:00:00 2001 From: action Date: Tue, 17 Nov 2026 10:44:34 +0800 Subject: [PATCH] update 2026-11-17 10:44:34 --- docker/Makefile | 4 +- dockerd/Makefile | 4 +- luci-app-adguardhome/Makefile | 5 +- luci-app-adguardhome/README.md | 9 +- .../luasrc/controller/AdGuardHome.lua | 176 +++++- .../luasrc/model/cbi/AdGuardHome/base.lua | 52 +- .../luasrc/model/cbi/AdGuardHome/diag.lua | 13 + .../luasrc/model/cbi/AdGuardHome/manual.lua | 23 +- .../luasrc/model/cbi/AdGuardHome/tools.lua | 3 +- .../view/AdGuardHome/AdGuardHome_check.htm | 11 +- .../luasrc/view/AdGuardHome/diag.htm | 299 ++++++++++ .../luasrc/view/AdGuardHome/enable_switch.htm | 4 +- .../luasrc/view/AdGuardHome/log.htm | 28 +- .../luasrc/view/AdGuardHome/overview.htm | 2 +- .../luasrc/view/AdGuardHome/redirect_mode.htm | 2 +- luci-app-adguardhome/po/en/adguardhome.po | 186 ++++++ .../root/etc/init.d/AdGuardHome | 233 +++++--- .../AdGuardHome/AdGuardHome_template.yaml | 4 +- .../root/usr/share/AdGuardHome/update_core.sh | 79 ++- .../luci/menu.d/luci-app-adguardhome.json | 8 + luci-app-netdata/Makefile | 19 +- luci-app-netdata/README.md | 179 ++++-- .../luci-static/resources/netdata/ui.css | 413 +++++++++++++ .../resources/view/netdata/advanced.js | 140 ++++- .../resources/view/netdata/config.js | 427 +++++++++---- .../resources/view/netdata/main.js | 498 +++++++++++++++- luci-app-netdata/po/templates/netdata.pot | 255 ++++++-- luci-app-netdata/po/zh_Hans/netdata.po | 283 ++++++--- luci-app-netdata/po/zh_Hant/netdata.po | 305 +++++++--- .../root/etc/uci-defaults/99_luci-app-netdata | 390 ++++++++++++ .../usr/libexec/luci-app-netdata/netdata-ctl | 559 ++++++++++++++++++ .../share/rpcd/acl.d/luci-app-netdata.json | 7 +- netdata/Makefile | 18 +- netdata/README.md | 72 +++ netdata/files/netdata.config | 4 +- netdata/files/netdata.htpasswd | 1 - netdata/files/netdata.init | 210 ++++++- netdata/files/netdata.locations | 9 +- 38 files changed, 4297 insertions(+), 637 deletions(-) create mode 100644 luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/diag.lua create mode 100644 luci-app-adguardhome/luasrc/view/AdGuardHome/diag.htm create mode 100644 luci-app-adguardhome/po/en/adguardhome.po create mode 100644 luci-app-netdata/htdocs/luci-static/resources/netdata/ui.css create mode 100755 luci-app-netdata/root/etc/uci-defaults/99_luci-app-netdata create mode 100755 luci-app-netdata/root/usr/libexec/luci-app-netdata/netdata-ctl create mode 100644 netdata/README.md mode change 100644 => 100755 netdata/files/netdata.init diff --git a/docker/Makefile b/docker/Makefile index b34aa88e..73f9936e 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -1,12 +1,12 @@ include $(TOPDIR)/rules.mk PKG_NAME:=docker -PKG_VERSION:=29.10.0-rc.2 +PKG_VERSION:=29.10.0 PKG_RELEASE:=1 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=https://codeload.github.com/docker/cli/tar.gz/v$(PKG_VERSION)? -PKG_HASH:=efa7d9d39c5feb63b588f12cbf46a9a70850814e0e4e8f298a23650d729a6ea3 +PKG_HASH:=7b955259e070e839586faff4957ce71484380f3aff5caf519470c1448f9e9192 PKG_BUILD_DIR:=$(BUILD_DIR)/cli-$(PKG_VERSION) PKG_GIT_SHORT_COMMIT:=$(shell $(CURDIR)/git-short-commit.sh 'github.com/docker/cli' 'v$(PKG_VERSION)' '$(TMP_DIR)/git-short-commit/$(PKG_NAME)-$(PKG_VERSION)') diff --git a/dockerd/Makefile b/dockerd/Makefile index f9f3ec63..879729b3 100644 --- a/dockerd/Makefile +++ b/dockerd/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=dockerd -PKG_VERSION:=29.9.3 +PKG_VERSION:=29.10.0 PKG_RELEASE:=1 PKG_LICENSE:=Apache-2.0 PKG_LICENSE_FILES:=LICENSE @@ -10,7 +10,7 @@ PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_GIT_URL:=github.com/moby/moby PKG_GIT_REF:=docker-v$(PKG_VERSION) PKG_SOURCE_URL:=https://codeload.$(PKG_GIT_URL)/tar.gz/$(PKG_GIT_REF)? -PKG_HASH:=cd6ce54e46ac19f5dd0b5226a9b292965ba542bc16bdf9edbbca946da8930b15 +PKG_HASH:=52ee9d504b0ff278fb591956d761f6f5a8f0008b6bc6d19bc2916856b3f725b9 PKG_GIT_SHORT_COMMIT:=$(shell $(CURDIR)/git-short-commit.sh '$(PKG_GIT_URL)' '$(PKG_GIT_REF)' '$(TMP_DIR)/git-short-commit/$(PKG_NAME)-$(PKG_VERSION)') PKG_MAINTAINER:=Gerard Ryan diff --git a/luci-app-adguardhome/Makefile b/luci-app-adguardhome/Makefile index 829e66c9..1983817d 100644 --- a/luci-app-adguardhome/Makefile +++ b/luci-app-adguardhome/Makefile @@ -8,11 +8,11 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-adguardhome PKG_MAINTAINER:=kenzok8 PKG_VERSION:=1.0 -PKG_RELEASE:=11 +PKG_RELEASE:=14 LUCI_TITLE:=LuCI app for AdGuardHome LUCI_PKGARCH:=all -LUCI_DEPENDS:=+ca-certs +curl +wget-ssl +PACKAGE_$(PKG_NAME)_INCLUDE_binary:adguardhome +LUCI_DEPENDS:=+ca-certs +curl +wget-ssl +jsonfilter +PACKAGE_$(PKG_NAME)_INCLUDE_binary:adguardhome # luci-compat only exists in ucode-based LuCI (24.10+) ifneq ($(wildcard $(TOPDIR)/feeds/luci/luci-compat/Makefile),) LUCI_DEPENDS+= +luci-compat @@ -37,6 +37,7 @@ PKG_CONFIG_DEPENDS:= CONFIG_PACKAGE_$(PKG_NAME)_INCLUDE_binary define Package/luci-app-adguardhome/conffiles /usr/share/AdGuardHome/links.txt /etc/config/AdGuardHome +/etc/AdGuardHome.yaml endef define Package/luci-app-adguardhome/postinst diff --git a/luci-app-adguardhome/README.md b/luci-app-adguardhome/README.md index 064d5010..272e390b 100644 --- a/luci-app-adguardhome/README.md +++ b/luci-app-adguardhome/README.md @@ -44,7 +44,12 @@ - **概览面板**:服务状态、重定向模式、核心版本、一键启停 + Web 控制台快捷入口 - **基础设置**:启用开关、管理端口、核心更新、重定向模式(4 种,卡片式选择 + 后端/端口/生效状态提示,自动适配 fw4/nftables 与 fw3/iptables)、路径配置、进程参数 -- **服务自检**:启动/停止失败或状态异常时自动清理孤儿进程、恢复缺失配置、重建重定向规则 +- **服务自检**:启动/停止失败或状态异常时清理孤儿进程、恢复缺失配置、重建重定向规则(不再自动杀进程) +- **诊断页**:服务/procd、配置校验、DNS/Web 端口占用、防火墙后端、重定向规则、磁盘/内存、系统日志一览,可复制完整报告 +- **配置中心**:配置备份/恢复、核心回滚(保留上一版核心)、默认 admin/admin +- **WAN 排除**:可指定 WAN 侧接口,避免 53 端口劫持把路由器变成开放解析器 +- **日志增强**:运行日志之外可查看 procd/AGH stderr 系统日志 +- **English UI**:新增 `po/en` 英文翻译源(编译时由 luci.mk 生成 lmo) - **工具与任务**:改密、sysupgrade 保留文件、关机备份、Crontab 计划任务 - **日志查看**:实时轮询、反向/本地时区切换、下载、清空 - **手动配置**:YAML 编辑器(CodeMirror 可选),保存前二次确认 @@ -53,6 +58,8 @@ - **计划任务**:自动更新核心、切割日志、IPv6 hosts 同步 - **升级保护**:sysupgrade 保留文件 + 关机备份 +> 默认 Web 登录:**admin / admin**。首次登录后请立即在「运维 → 修改网页管理密码」中修改。 + ## 安装 ### Feed 方式 diff --git a/luci-app-adguardhome/luasrc/controller/AdGuardHome.lua b/luci-app-adguardhome/luasrc/controller/AdGuardHome.lua index d24d9655..417e916c 100644 --- a/luci-app-adguardhome/luasrc/controller/AdGuardHome.lua +++ b/luci-app-adguardhome/luasrc/controller/AdGuardHome.lua @@ -4,14 +4,55 @@ local fs = require "nixio.fs" local http = require "luci.http" local uci = require "luci.model.uci".cursor() -local function service_running() - local binpath = uci:get("AdGuardHome", "AdGuardHome", "binpath") or "/usr/bin/AdGuardHome" +local function shq(value) + return "'" .. tostring(value or ""):gsub("'", "'\\''") .. "'" +end - if not fs.access(binpath) then +local function binpath() + return uci:get("AdGuardHome", "AdGuardHome", "binpath") or "/usr/bin/AdGuardHome" +end + +local function service_pids() + local name = binpath():match("([^/]+)$") + local pids = {} + if not name then return pids end + for path in fs.glob("/proc/*/comm") do + local comm = fs.readfile(path) + if comm then + comm = comm:gsub("%s+$", "") + if comm == name then + local pid = path:match("/proc/(%d+)/comm") + if pid then pids[#pids + 1] = pid end + end + end + end + table.sort(pids, function(a, b) return tonumber(a) < tonumber(b) end) + return pids +end + +local function service_running() + if not fs.access(binpath()) then return false end + return #service_pids() > 0 +end - return luci.sys.call("/etc/init.d/AdGuardHome status >/dev/null 2>&1") == 0 +local function require_post() + if http.getenv("REQUEST_METHOD") ~= "POST" then + http.status(405, "Method Not Allowed") + http.prepare_content("application/json") + http.write_json({ success = false, message = "POST required" }) + return false + end + -- LuCI's session cookie plus POST is required here. The token is sent by + -- the UI for future stricter checks, but not enforced to stay compatible + -- with older LuCI releases where the token name differs. + return true +end + +local function json_result(result) + http.prepare_content("application/json") + http.write_json(result) end function index() @@ -33,6 +74,8 @@ function index() form("AdGuardHome/log"), _("日志"), 4).leaf = true entry({"admin", "services", "AdGuardHome", "manual"}, cbi("AdGuardHome/manual"), _("手动配置"), 5).leaf = true + entry({"admin", "services", "AdGuardHome", "diag"}, + cbi("AdGuardHome/diag"), _("诊断"), 6).leaf = true end -- API 路由在新旧版本均需注册 @@ -54,6 +97,14 @@ function index() call("get_template_config"), nil) entry({"admin", "services", "AdGuardHome", "repair"}, call("do_repair"), nil) + entry({"admin", "services", "AdGuardHome", "backupconfig"}, + call("do_backup_config"), nil) + entry({"admin", "services", "AdGuardHome", "restoreconfig"}, + call("do_restore_config"), nil) + entry({"admin", "services", "AdGuardHome", "rollbackcore"}, + call("do_rollback_core"), nil) + entry({"admin", "services", "AdGuardHome", "systemlog"}, + call("get_system_log"), nil) end local function gen_template_config() @@ -109,12 +160,14 @@ function act_status() end function do_repair() - local output = luci.sys.exec("/etc/init.d/AdGuardHome repair 2>&1") + if not require_post() then return end + local auto = http.formvalue("auto") == "1" and " auto" or "" + local output = luci.sys.exec("/etc/init.d/AdGuardHome repair" .. auto .. " 2>&1") local enabled = uci:get("AdGuardHome", "AdGuardHome", "enabled") == "1" local running = service_running() -- Starting procd instances is asynchronous; give them a moment before -- reporting the result to the page. - for _ = 1, 5 do + for _ = 1, 3 do if running or not enabled then break end luci.sys.call("sleep 1") running = service_running() @@ -136,7 +189,110 @@ function do_repair() http.write_json(result) end +function do_backup_config() + if not require_post() then return end + local configpath = uci:get("AdGuardHome", "AdGuardHome", "configpath") or "/etc/AdGuardHome.yaml" + local data = fs.readfile(configpath) + if not data then + json_result({ success = false, message = "配置文件不存在" }) + return + end + + local target = configpath .. ".bak." .. os.date("%Y%m%d-%H%M%S") + if fs.writefile(target, data) == nil then + json_result({ success = false, message = "备份写入失败" }) + return + end + + local list = {} + for path in fs.glob(configpath .. ".bak.*") do list[#list + 1] = path end + table.sort(list) + while #list > 5 do + fs.remove(list[1]) + table.remove(list, 1) + end + + json_result({ success = true, file = target }) +end + +function do_restore_config() + if not require_post() then return end + local configpath = uci:get("AdGuardHome", "AdGuardHome", "configpath") or "/etc/AdGuardHome.yaml" + local candidates = {} + for path in fs.glob(configpath .. ".bak*") do + if path ~= configpath .. ".before-restore" then + candidates[#candidates + 1] = path + end + end + table.sort(candidates) + local src = candidates[#candidates] + if not src then + json_result({ success = false, message = "没有可用备份" }) + return + end + + local binary = binpath() + -- Only validate when the current core can execute; a broken core must not + -- prevent restoring a known-good configuration. + if fs.access(binary) and luci.sys.call(shq(binary) .. " --version >/dev/null 2>&1") == 0 then + local ret = luci.sys.call(shq(binary) .. " -c " .. shq(src) .. " --check-config >/dev/null 2>&1") + if ret ~= 0 then + json_result({ success = false, message = "备份配置未通过校验", file = src }) + return + end + end + + local current = fs.readfile(configpath) + if current then + fs.writefile(configpath .. ".before-restore", current) + end + local data = fs.readfile(src) + if not data or fs.writefile(configpath, data) == nil then + json_result({ success = false, message = "恢复失败" }) + return + end + + luci.sys.call("/etc/init.d/AdGuardHome reload >/dev/null 2>&1 &") + json_result({ success = true, file = src }) +end + +function do_rollback_core() + if not require_post() then return end + local binary = binpath() + local old = binary .. ".old" + if not fs.access(old) then + json_result({ success = false, message = "没有可回滚的核心" }) + return + end + + local data = fs.readfile(old) + if not data then + json_result({ success = false, message = "读取旧核心失败" }) + return + end + local tmp = binary .. ".new" + if fs.writefile(tmp, data) == nil then + json_result({ success = false, message = "写入临时核心失败" }) + return + end + luci.sys.call("chmod 755 " .. shq(tmp)) + if luci.sys.call("mv -f " .. shq(tmp) .. " " .. shq(binary)) ~= 0 then + fs.remove(tmp) + json_result({ success = false, message = "替换核心失败" }) + return + end + + luci.sys.call("/etc/init.d/AdGuardHome reload >/dev/null 2>&1 &") + json_result({ success = true }) +end + +function get_system_log() + http.prepare_content("text/plain; charset=utf-8") + http.write(luci.sys.exec("logread -e AdGuardHome 2>/dev/null | tail -n 400") or "") +end + function toggle_service() + if not require_post() then return end local enabled = http.formvalue("enabled") == "1" and "1" or "0" local old_enabled = uci:get("AdGuardHome", "AdGuardHome", "enabled") == "1" and "1" or "0" local result = { @@ -203,6 +359,7 @@ function toggle_service() end function do_update() + if not require_post() then return end fs.writefile("/var/run/lucilogpos", "0") http.prepare_content("application/json") http.write('{}') @@ -269,6 +426,7 @@ function get_log() end function do_dellog() + if not require_post() then return end local logfile = uci:get("AdGuardHome", "AdGuardHome", "logfile") if logfile and logfile ~= "" and logfile ~= "syslog" then fs.writefile(logfile, "") @@ -300,6 +458,10 @@ function check_update() http.write(content) else -- Plain-text end marker: a NUL byte here made the template binary. - http.write(content .. "\n__AGH_UPDATE_FINISHED__\n") + local marker = "__AGH_UPDATE_FINISHED__" + if fs.access("/var/run/update_core_error") then + marker = "__AGH_UPDATE_FINISHED_ERROR__" + end + http.write(content .. "\n" .. marker .. "\n") end end diff --git a/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/base.lua b/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/base.lua index 84506abc..9d1d1789 100644 --- a/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/base.lua +++ b/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/base.lua @@ -57,7 +57,7 @@ m.description = translate("Free and open source, powerful network-wide ads & tra -- ============================================================ -- Section 1: Basic Settings -- ============================================================ -s = m:section(NamedSection, "AdGuardHome", "AdGuardHome", "基本设置") +s = m:section(NamedSection, "AdGuardHome", "AdGuardHome", translate("基本设置")) o = s:option(Flag, "enabled", translate("Enable")) o.default = "0" @@ -87,7 +87,7 @@ o.rmempty = false local port = read_dns_port(configpath) or "?" -o = s:option(ListValue, "redirect", "重定向模式") +o = s:option(ListValue, "redirect", translate("重定向模式")) o.template = "AdGuardHome/redirect_mode" o.backend = firewall_backend o.agh_port = port @@ -98,10 +98,21 @@ o:value("exchange", translate("使用 53 端口替代 dnsmasq")) o.default = "none" o.optional = true +o = s:option(DynamicList, "wan_ifname", translate("WAN 侧排除接口"), + translate("从这些接口进入的 53 端口 DNS 请求不会重定向到 AdGuard Home,避免在 WAN 侧形成开放解析器。")) +o.rmempty = true +o.datatype = "string" +local netmod_ok, netmod = pcall(require, "luci.sys.net") +if netmod_ok and netmod and netmod.devices then + for _, dev in ipairs(netmod.devices()) do + o:value(dev, dev) + end +end + -- ============================================================ -- Section 2: Paths & Logs -- ============================================================ -s = m:section(NamedSection, "AdGuardHome", "AdGuardHome", "路径与日志") +s = m:section(NamedSection, "AdGuardHome", "AdGuardHome", translate("路径与日志")) o = s:option(Value, "binpath", translate("Bin Path"), translate("AdGuardHome Bin path if no bin will auto download")) o.default = "/usr/bin/AdGuardHome" @@ -175,7 +186,7 @@ o.optional = true -- ============================================================ -- Section 3: Advanced Settings -- ============================================================ -s = m:section(NamedSection, "AdGuardHome", "AdGuardHome", "高级设置") +s = m:section(NamedSection, "AdGuardHome", "AdGuardHome", translate("高级设置")) o = s:option(ListValue, "upxflag", translate("use upx to compress bin after download")) o:value("", translate("none")) @@ -236,6 +247,11 @@ o.datatype = "uinteger" o.placeholder = translate("推荐 ") .. tostring(mem_suggest_mib) o.rmempty = true +o = s:option(Flag, "jail", translate("启用 procd 文件隔离(实验性)")) +o.default = "0" +o.rmempty = true +o.description = translate("开启后,上面的“只读/读写文件访问”列表才会生效。需要内核支持 namespaces,可能影响证书或数据目录读取,默认关闭。") + o = s:option(Flag, "waitonboot", translate("On boot when network ok restart")) o.default = "1" o.rmempty = true @@ -245,31 +261,7 @@ o.rmempty = true -- ============================================================ fs.writefile("/var/run/lucilogpos", "0") -function m.on_commit(map) - if fs.access("/var/run/AdGserverdis") then - io.popen("/etc/init.d/AdGuardHome reload &") - return - end - - local ucitracktest = uci:get("AdGuardHome", "AdGuardHome", "ucitracktest") - if ucitracktest == "1" then - return - elseif ucitracktest == "0" then - io.popen("/etc/init.d/AdGuardHome reload &") - else - if fs.access("/var/run/AdGlucitest") then - uci:set("AdGuardHome", "AdGuardHome", "ucitracktest", "0") - io.popen("/etc/init.d/AdGuardHome reload &") - else - fs.writefile("/var/run/AdGlucitest", "") - if ucitracktest == "2" then - uci:set("AdGuardHome", "AdGuardHome", "ucitracktest", "1") - else - uci:set("AdGuardHome", "AdGuardHome", "ucitracktest", "2") - end - end - uci:save("AdGuardHome") - end -end +-- Reloads are handled by procd (ucitrack + service_triggers); the old +-- ucitracktest state machine skipped the first save and is gone. return m diff --git a/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/diag.lua b/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/diag.lua new file mode 100644 index 00000000..561f24ec --- /dev/null +++ b/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/diag.lua @@ -0,0 +1,13 @@ +require("luci.sys") + +local m + +m = Map("AdGuardHome", translate("诊断")) +m.description = translate("服务、配置、端口、防火墙与日志检查") +m.submit = false +m.reset = false +m.apply_on_parse = false + +m:section(SimpleSection).template = "AdGuardHome/diag" + +return m diff --git a/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/manual.lua b/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/manual.lua index 9de02aca..10d3141e 100644 --- a/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/manual.lua +++ b/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/manual.lua @@ -84,13 +84,20 @@ o.validate = function(self, value) end o.write = function(self, section, value) - if fs.access("/tmp/AdGuardHometmpconfig.yaml") then - fs.move("/tmp/AdGuardHometmpconfig.yaml", configpath) + local tmp = "/tmp/AdGuardHometmpconfig.yaml" + if not fs.access(tmp) then return end + + -- Keep one previous version before replacing the live configuration. + local current = fs.readfile(configpath) + if current and current ~= "" then + fs.writefile(configpath .. ".bak", current) end + fs.move(tmp, configpath) end o.remove = function(self, section, value) - fs.writefile(configpath, "") + -- Removing the form value must not wipe the live configuration. + fs.remove("/tmp/AdGuardHometmpconfig.yaml") end o = s:option(DummyValue, "") @@ -116,14 +123,8 @@ if fs.access("/tmp/AdGuardHometest.log") then end function m.on_commit(map) - local ucitracktest = uci:get("AdGuardHome", "AdGuardHome", "ucitracktest") - if ucitracktest == "1" then - return - elseif ucitracktest == "0" then - io.popen("/etc/init.d/AdGuardHome reload &") - else - fs.writefile("/var/run/AdGlucitest", "") - end + -- The YAML is not a UCI config, so procd will not reload on its own. + io.popen("/etc/init.d/AdGuardHome reload >/dev/null 2>&1 &") end return m diff --git a/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/tools.lua b/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/tools.lua index 55a520b0..9a180c43 100644 --- a/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/tools.lua +++ b/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/tools.lua @@ -94,7 +94,8 @@ o.default = nil o.optional = false -- Download links ------------------------------------------------- -o = s:option(TextValue, "downloadlinks", translate("Download links for update")) +o = s:option(TextValue, "downloadlinks", translate("Download links for update"), + "每行一个下载地址,支持 ${Arch} 与 ${latest_ver} 变量;官方源失败后依次尝试。") o.optional = false o.rows = 4 o.wrap = "soft" diff --git a/luci-app-adguardhome/luasrc/view/AdGuardHome/AdGuardHome_check.htm b/luci-app-adguardhome/luasrc/view/AdGuardHome/AdGuardHome_check.htm index a4f2ea51..75a83a91 100644 --- a/luci-app-adguardhome/luasrc/view/AdGuardHome/AdGuardHome_check.htm +++ b/luci-app-adguardhome/luasrc/view/AdGuardHome/AdGuardHome_check.htm @@ -74,7 +74,7 @@ var updatebtn = document.getElementById('apply_update_button'); var forceupdatebtn = document.getElementById('apply_forceupdate_button'); var islogreverse = false; function apply_forceupdate(){ - XHR.get('<%=url([[admin]], [[services]], [[AdGuardHome]], [[doupdate]])%>',{ force: 1 },function(x, data){} + XHR.post('<%=url([[admin]], [[services]], [[AdGuardHome]], [[doupdate]])%>',{ force: 1, token: L.env.token },function(x, data){} ); updatebtn.disabled = true; poll_check(); @@ -91,7 +91,7 @@ function reverselog(){ return } function apply_update(){ - XHR.get('<%=url([[admin]], [[services]], [[AdGuardHome]], [[doupdate]])%>',null,function(x, data){} + XHR.post('<%=url([[admin]], [[services]], [[AdGuardHome]], [[doupdate]])%>',{ token: L.env.token },function(x, data){} ); updatebtn.disabled = true; updatebtn.value = '<%:Check...%>'; @@ -107,8 +107,9 @@ XHR.poll(3, '<%=url([[admin]], [[services]], [[AdGuardHome]], [[check]])%>', nul var lv = document.getElementById('cbid.logview.1.conf'); if (!x.responseText || !lv) return; var text = x.responseText; - var done = text.indexOf('__AGH_UPDATE_FINISHED__') >= 0; - if (done) text = text.replace(/__AGH_UPDATE_FINISHED__\n?/g, ''); + var done = text.indexOf('__AGH_UPDATE_FINISHED') >= 0; + var failed = text.indexOf('__AGH_UPDATE_FINISHED_ERROR__') >= 0; + if (done) text = text.replace(/__AGH_UPDATE_FINISHED(_ERROR)?__\n?/g, ''); if (text) { if (islogreverse) lv.innerHTML = text.split('\n').reverse().join('\n') + lv.innerHTML; else lv.innerHTML += text; @@ -118,7 +119,7 @@ XHR.poll(3, '<%=url([[admin]], [[services]], [[AdGuardHome]], [[check]])%>', nul if (this.XHR._q[j].url == '<%=url([[admin]], [[services]], [[AdGuardHome]], [[check]])%>') { this.XHR._q.splice(j, 1); updatebtn.disabled = false; - updatebtn.value = '<%:Updated%>'; + updatebtn.value = failed ? '<%:Update failed%>' : '<%:Updated%>'; break; } } diff --git a/luci-app-adguardhome/luasrc/view/AdGuardHome/diag.htm b/luci-app-adguardhome/luasrc/view/AdGuardHome/diag.htm new file mode 100644 index 00000000..a34156d8 --- /dev/null +++ b/luci-app-adguardhome/luasrc/view/AdGuardHome/diag.htm @@ -0,0 +1,299 @@ +<%+AdGuardHome/head%> +<% +local fs = require "nixio.fs" +local uci = require "luci.model.uci".cursor() +local sys = require "luci.sys" +local dsp = require "luci.dispatcher" + +local configpath = uci:get("AdGuardHome", "AdGuardHome", "configpath") or "/etc/AdGuardHome.yaml" +local binpath = uci:get("AdGuardHome", "AdGuardHome", "binpath") or "/usr/bin/AdGuardHome" +local workdir = uci:get("AdGuardHome", "AdGuardHome", "workdir") or "/etc/AdGuardHome" +local logfile = uci:get("AdGuardHome", "AdGuardHome", "logfile") or "" +local enabled = uci:get("AdGuardHome", "AdGuardHome", "enabled") == "1" +local mode = uci:get("AdGuardHome", "AdGuardHome", "redirect") or "none" +local http_port = uci:get("AdGuardHome", "AdGuardHome", "httpport") or "3000" + +local function shq(value) + return "'" .. tostring(value or ""):gsub("'", "'\\''") .. "'" +end + +local function run(cmd) + return sys.exec(cmd .. " 2>&1") or "" +end + +local function h(text) + return (tostring(text or ""):gsub("&", "&"):gsub("<", "<"):gsub(">", ">")) +end + +local function firstline(text) + return (text or ""):match("^[^\r\n]*") or "" +end + +local function read_dns_port(path) + local f = io.open(path, "r") + if not f then return nil end + local in_dns = false + local port + for line in f:lines() do + if line:match("^dns:%s*$") then + in_dns = true + elseif line:match("^%S") then + in_dns = false + elseif in_dns then + local p = line:match("^%s+port:%s*(%d+)") + if p then port = p break end + end + end + f:close() + return port +end + +local function service_pids() + local name = binpath:match("([^/]+)$") + local list = {} + if not name then return list end + for path in fs.glob("/proc/*/comm") do + local comm = fs.readfile(path) + if comm then + comm = comm:gsub("%s+$", "") + if comm == name then + local pid = path:match("/proc/(%d+)/comm") + if pid then list[#list + 1] = pid end + end + end + end + table.sort(list, function(a, b) return tonumber(a) < tonumber(b) end) + return list +end + +local dns_port = read_dns_port(configpath) or "?" +local pids = service_pids() +local running = #pids > 0 +local pid_text = #pids > 0 and table.concat(pids, " ") or "-" + +local version = "-" +if fs.access(binpath) then + local v = firstline(run(shq(binpath) .. " --version")) + version = v ~= "" and v or "无法执行" +end + +local config_ok, config_check = nil, "跳过(缺少核心或配置)" +if fs.access(binpath) and fs.access(configpath) then + local rc = sys.call(shq(binpath) .. " -c " .. shq(configpath) .. " --check-config >/tmp/adg_diag_check.log 2>&1") + config_ok = (rc == 0) + config_check = fs.readfile("/tmp/adg_diag_check.log") or (config_ok and "通过" or "失败") + config_check = firstline(config_check) +end + +local backend = "unknown" +if fs.access("/sbin/fw4") or fs.access("/usr/sbin/fw4") then + backend = "nftables (fw4)" +elseif fs.access("/sbin/iptables") or fs.access("/usr/sbin/iptables") then + backend = "iptables (fw3)" +elseif fs.access("/sbin/nft") or fs.access("/usr/sbin/nft") then + backend = "nftables" +end + +local applied = (fs.readfile("/var/run/AdGredir") or "") == "1" +local netstat = run("netstat -lnp") +if netstat == "" or not netstat:find(":") then netstat = run("netstat -ln") end +if netstat == "" or not netstat:find(":") then netstat = run("ss -lnp") end + +local port_lines = {} +for line in netstat:gmatch("[^\r\n]+") do + local port = line:match(":(%d+)%s") + if port == dns_port or port == http_port then + port_lines[#port_lines + 1] = line + end +end +local port_text = #port_lines > 0 and table.concat(port_lines, "\n") or "(未发现监听记录)" + +local dns_listen, web_listen = false, false +local dns_seen, web_seen = false, false +for _, line in ipairs(port_lines) do + local port = line:match(":(%d+)%s") + if port == dns_port then + dns_seen = true + if line:find("AdGuardHome", 1, true) then dns_listen = true end + end + if port == http_port then + web_seen = true + if line:find("AdGuardHome", 1, true) then web_listen = true end + end +end + +local nft_rules = run("nft list table inet adguardhome") +local ipt_rules = run("iptables -t nat -S PREROUTING | grep -- '--dport 53'") +local rule_text = nft_rules ~= "" and nft_rules or ipt_rules +if rule_text == "" then rule_text = "(未发现重定向规则)" end + +local disk = run("df -k " .. shq(workdir) .. " | tail -n 1") +local disk_pct = tonumber(disk:match("(%d+)%%")) +local mem = run("free -m | head -n 2") +if mem == "" then + local total = tonumber(run("awk '/MemTotal/{print $2}' /proc/meminfo")) + local avail = tonumber(run("awk '/MemAvailable/{print $2}' /proc/meminfo")) + if total and avail then + mem = string.format("MemTotal: %d MB\nMemAvailable: %d MB", math.floor(total / 1024), math.floor(avail / 1024)) + end +end + +local logs = run("logread -e AdGuardHome | tail -n 40") +local filelog = "" +if logfile ~= "" and logfile ~= "syslog" and fs.access(logfile) then + filelog = run("tail -n 40 " .. shq(logfile)) +end + +local backups = {} +for path in fs.glob(configpath .. ".bak*") do + if path ~= configpath .. ".before-restore" then backups[#backups + 1] = path end +end +table.sort(backups) +local backup_text = #backups > 0 and table.concat(backups, "\n") or "(无)" +local old_core = fs.access(binpath .. ".old") +local update_lock = fs.access("/var/run/update_core") +local procd_pids = run([[ubus call service list '{"name":"AdGuardHome"}' | jsonfilter -e '@.AdGuardHome.instances.*.pid']]) + +local checks = {} +local function check(name, state, detail) + checks[#checks + 1] = { name = name, state = state, detail = detail } +end + +check("服务进程", running and "ok" or (enabled and "bad" or "warn"), + running and ("PID " .. pid_text) or (enabled and "已启用但未运行" or "服务未启用")) +check("核心文件", fs.access(binpath) and "ok" or "bad", binpath .. " · " .. version) +check("配置文件", fs.access(configpath) and "ok" or "bad", configpath) +check("配置校验", config_ok == nil and "warn" or (config_ok and "ok" or "bad"), config_check) +check("防火墙后端", backend ~= "unknown" and "ok" or "bad", backend) +check("重定向模式", mode == "none" and "warn" or (applied and "ok" or "bad"), + (mode == "none" and "未接管 DNS" or (applied and "已生效" or "未生效"))) +check("DNS 端口监听", (not running) and "warn" or (dns_listen and "ok" or (dns_seen and "warn" or "bad")), + "端口 " .. dns_port .. (dns_listen and "(AdGuardHome)" or (dns_seen and "(监听中,进程未知)" or "(未监听)"))) +check("Web 端口监听", (not running) and "warn" or (web_listen and "ok" or (web_seen and "warn" or "warn")), + "端口 " .. http_port .. (web_listen and "(AdGuardHome)" or (web_seen and "(监听中,进程未知)" or "(未监听)"))) +check("工作目录磁盘", (disk_pct and disk_pct >= 95) and "bad" or (disk_pct and disk_pct >= 85) and "warn" or "ok", + disk ~= "" and disk or "无法读取") +check("核心更新锁", update_lock and "warn" or "ok", update_lock and "更新进行中" or "空闲") + +local report = table.concat({ + "=== AdGuardHome 诊断 ===", + "时间: " .. os.date("%Y-%m-%d %H:%M:%S"), + "启用: " .. tostring(enabled) .. " / 运行: " .. tostring(running) .. " / PID: " .. pid_text, + "procd PID: " .. (procd_pids:gsub("\n", " ") ~= "" and procd_pids:gsub("\n", " ") or "-"), + "核心: " .. binpath .. " (" .. version .. ")", + "配置: " .. configpath, + "配置校验: " .. tostring(config_ok) .. " " .. config_check, + "模式: " .. mode .. " / 生效: " .. tostring(applied) .. " / 后端: " .. backend, + "DNS 端口: " .. dns_port .. " / Web 端口: " .. http_port, + "磁盘: " .. disk, + "内存: " .. mem:gsub("\n", " | "), + "备份: " .. backup_text:gsub("\n", " "), + "旧核心: " .. tostring(old_core), + "", + "--- 端口 ---", port_text, + "--- 规则 ---", rule_text, + "--- 系统日志 ---", logs, + "--- 运行日志 ---", filelog +}, "\n") +%> + + +
+ <%:Refresh%> + + + + + +
+ +
+<% for _, c in ipairs(checks) do %> +
+ <%= c.state == "ok" and "正常" or (c.state == "warn" and "注意" or "异常") %> + + <%=h(c.name)%>
+ <%=h(c.detail)%> +
+
+<% end %> +
+ +
端口监听
+
<%=h(port_text)%>
+ +
重定向规则
+
<%=h(rule_text)%>
+ +
磁盘 / 内存
+
<%=h(disk .. "\n" .. mem)%>
+ +
配置备份
+
<%=h(backup_text)%>
+ +
系统日志(logread -e AdGuardHome)
+
<%=h(logs ~= "" and logs or "(无)")%>
+ +
运行日志
+
<%=h(filelog ~= "" and filelog or "(未配置或为空)")%>
+ +
完整诊断报告
+
<%=h(report)%>
+ + diff --git a/luci-app-adguardhome/luasrc/view/AdGuardHome/enable_switch.htm b/luci-app-adguardhome/luasrc/view/AdGuardHome/enable_switch.htm index 16356de2..e2b118c5 100644 --- a/luci-app-adguardhome/luasrc/view/AdGuardHome/enable_switch.htm +++ b/luci-app-adguardhome/luasrc/view/AdGuardHome/enable_switch.htm @@ -118,7 +118,7 @@ if (!repaired) { if (status) status.innerHTML = '正在自动修复…'; - XHR.get('<%=url([[admin]], [[services]], [[AdGuardHome]], [[repair]])%>', null, function() { + XHR.post('<%=url([[admin]], [[services]], [[AdGuardHome]], [[repair]])%>', { token: L.env.token, auto: 1 }, function() { if (serial !== pollSerial) return; pollTarget(target, serial, 10, true); @@ -153,7 +153,7 @@ if (status) status.innerHTML = next ? '<%:Starting...%>' : '<%:Stopping...%>'; - XHR.get('<%=url([[admin]], [[services]], [[AdGuardHome]], [[toggle]])%>', { enabled: next ? 1 : 0 }, function(x, data) { + XHR.post('<%=url([[admin]], [[services]], [[AdGuardHome]], [[toggle]])%>', { enabled: next ? 1 : 0, token: L.env.token }, function(x, data) { btn.disabled = false; if (data && data.success) { diff --git a/luci-app-adguardhome/luasrc/view/AdGuardHome/log.htm b/luci-app-adguardhome/luasrc/view/AdGuardHome/log.htm index e38d8015..3bee4a81 100644 --- a/luci-app-adguardhome/luasrc/view/AdGuardHome/log.htm +++ b/luci-app-adguardhome/luasrc/view/AdGuardHome/log.htm @@ -43,6 +43,8 @@ .adg-log-pane .adg-error { color: #ea7878; background: rgba(234,120,120,.06); } .adg-log-pane .adg-debug { color: #7a8290; opacity: .7; } body.dark .adg-log-pane { border-color: rgba(255,255,255,.1); } +.adg-syslog-head { display:flex; align-items:center; gap:8px; margin-top:10px; font-size:13px; font-weight:600; flex-wrap:wrap; } +.adg-syslog-head input[type="button"] { margin:0; }
@@ -55,6 +57,12 @@ body.dark .adg-log-pane { border-color: rgba(255,255,255,.1); }
+
+ 系统日志(procd / AGH stderr) + + +
+