diff --git a/luci-app-watchcat-plus/Makefile b/luci-app-watchcat-plus/Makefile new file mode 100644 index 0000000..1f18100 --- /dev/null +++ b/luci-app-watchcat-plus/Makefile @@ -0,0 +1,21 @@ +# +# Copyright (C) 2008-2014 The LuCI gngpp +# +# This is free software, licensed under the Apache License, Version 2.0 . +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=luci-app-watchcat-plus +PKG_VERSION:=1.3 +PKG_RELEASE:=202303012 + +PKG_MAINTAINER:=gngpp + + +LUCI_TITLE:=LuCI Support for Watchcat +LUCI_DEPENDS:=+watchcat + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-watchcat-plus/luasrc/controller/watchcat-plus.lua b/luci-app-watchcat-plus/luasrc/controller/watchcat-plus.lua new file mode 100644 index 0000000..8ed3f6a --- /dev/null +++ b/luci-app-watchcat-plus/luasrc/controller/watchcat-plus.lua @@ -0,0 +1,28 @@ +module("luci.controller.watchcat-plus", package.seeall) + +function index() + if not nixio.fs.access("/etc/config/watchcat") then + return + end + local page + page = entry({"admin", "control", "watchcat-plus"}, alias("admin", "control", "watchcat-plus", "periodic_reboot"), + _("Watchcat Plus"), 10) -- 首页 + page.dependent = true + page.acl_depends = { "luci-app-watchcat-plus" } + + entry({"admin", "control", "watchcat-plus", "periodic_reboot"}, cbi("watchcat-plus/periodic_reboot"), translate("Periodic Reboot"), 10).leaf = true -- "定时重启模式页面" + entry({"admin", "control", "watchcat-plus", "ping_reboot"}, cbi("watchcat-plus/ping_reboot"), translate("Ping Reboot"), 20).leaf = true -- "Ping重启模式页面" + entry({"admin", "control", "watchcat-plus", "restart_iface"}, cbi("watchcat-plus/restart_iface"), translate("Restart Interface"), 30).leaf = true -- "重启接口模式页面" + entry({"admin", "control", "watchcat-plus", "run_script"}, cbi("watchcat-plus/run_script"), translate("Run Script"), 40).leaf = true -- "运行脚本模式界面" + entry({"admin", "control", "watchcat-plus", "log"}, form("watchcat-plus/log"), _("Log"), 50).leaf = true -- 日志页面 + entry({"admin", "control", "watchcat-plus", "logread"}, call("action_logread"), nil).dependent = false -- 日志采集 +end + +function action_logread() + local e = luci.sys.exec("logread | grep watchcat") + if e == nil then + e = "" + end + luci.http.prepare_content("application/json") + luci.http.write_json(e); +end \ No newline at end of file diff --git a/luci-app-watchcat-plus/luasrc/model/cbi/watchcat-plus/log.lua b/luci-app-watchcat-plus/luasrc/model/cbi/watchcat-plus/log.lua new file mode 100644 index 0000000..41ba0ce --- /dev/null +++ b/luci-app-watchcat-plus/luasrc/model/cbi/watchcat-plus/log.lua @@ -0,0 +1,9 @@ +log = SimpleForm("logview") +log.submit = false +log.reset = false + +t = log:field(DummyValue, '', '') +t.rawhtml = true +t.template = 'watchcat-plus/watchcat-plus_log' + +return log \ No newline at end of file diff --git a/luci-app-watchcat-plus/luasrc/model/cbi/watchcat-plus/periodic_reboot.lua b/luci-app-watchcat-plus/luasrc/model/cbi/watchcat-plus/periodic_reboot.lua new file mode 100644 index 0000000..de4ddbe --- /dev/null +++ b/luci-app-watchcat-plus/luasrc/model/cbi/watchcat-plus/periodic_reboot.lua @@ -0,0 +1,46 @@ +m = Map("watchcat", + "", + translate("Here you can set up several checks and actions to take in the event that a host becomes unreachable. \ + Click the Add button at the bottom to set up more than one action." + )) + m.on_after_commit = function(self) + luci.sys.exec("service watchcat reload") + end + +s = m:section(TypedSection, "watchcat") +s.anonymous = true +s.addremove = true +function s.filter(self, section) + return self.map:get(section, "mode") == "periodic_reboot" +end + +-- 定时重启模式 +mode = s:option(ListValue, "mode", + translate("Mode"), + translate("Periodic Reboot: Reboot this device after a specified interval of time.")) +mode:value("periodic_reboot", translate("Periodic Reboot")) +mode.default = "periodic_reboot" + +-- 周期 +period = s:option(Value, "period", + translate("Period"), + translate("In Periodic Reboot mode, it defines how often to reboot.
\ + In Ping Reboot mode, it defines the longest period of \ + time without a reply from the Host To Check before a reboot is engaged.
\ + In Network Restart or Run Script mode, it defines the longest period of \ + time without a reply from the Host to Check before the interface is restarted or the script is run. \ +

The default unit is seconds, without a suffix, but you can use the \ + suffix m for minutes, h for hours or d \ + for days.

Examples: