diff options
Diffstat (limited to 'applications/luci-app-adblock/luasrc/controller')
-rw-r--r-- | applications/luci-app-adblock/luasrc/controller/adblock.lua | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/applications/luci-app-adblock/luasrc/controller/adblock.lua b/applications/luci-app-adblock/luasrc/controller/adblock.lua index 10110666c3..664822140f 100644 --- a/applications/luci-app-adblock/luasrc/controller/adblock.lua +++ b/applications/luci-app-adblock/luasrc/controller/adblock.lua @@ -3,9 +3,14 @@ module("luci.controller.adblock", package.seeall) +local sys = require("luci.sys") local util = require("luci.util") +local http = require("luci.http") local templ = require("luci.template") local i18n = require("luci.i18n") +local json = require("luci.jsonc") +local uci = require("luci.model.uci").cursor() +local fs = require("nixio.fs") function index() if not nixio.fs.access("/etc/config/adblock") then @@ -13,24 +18,58 @@ function index() end entry({"admin", "services", "adblock"}, firstchild(), _("Adblock"), 30).dependent = false entry({"admin", "services", "adblock", "tab_from_cbi"}, cbi("adblock/overview_tab", {hideresetbtn=true, hidesavebtn=true}), _("Overview"), 10).leaf = true - entry({"admin", "services", "adblock", "logfile"}, call("logread"), _("View Logfile"), 20).leaf = true + entry({"admin", "services", "adblock", "log"}, template("adblock/logread"), _("View Logfile"), 20).leaf = true entry({"admin", "services", "adblock", "advanced"}, firstchild(), _("Advanced"), 100) entry({"admin", "services", "adblock", "advanced", "blacklist"}, form("adblock/blacklist_tab"), _("Edit Blacklist"), 110).leaf = true entry({"admin", "services", "adblock", "advanced", "whitelist"}, form("adblock/whitelist_tab"), _("Edit Whitelist"), 120).leaf = true entry({"admin", "services", "adblock", "advanced", "configuration"}, form("adblock/configuration_tab"), _("Edit Configuration"), 130).leaf = true entry({"admin", "services", "adblock", "advanced", "query"}, template("adblock/query"), _("Query domains"), 140).leaf = true entry({"admin", "services", "adblock", "advanced", "result"}, call("queryData"), nil, 150).leaf = true + entry({"admin", "services", "adblock", "logread"}, call("logread"), nil).leaf = true + entry({"admin", "services", "adblock", "status"}, call("status_update"), nil).leaf = true + entry({"admin", "services", "adblock", "action"}, call("adb_action"), nil).leaf = true +end + +function adb_action(value) + if value == "Suspend" then + luci.sys.call("/etc/init.d/adblock suspend >/dev/null 2>&1") + elseif value == "Resume" then + luci.sys.call("/etc/init.d/adblock resume >/dev/null 2>&1") + elseif value == "Refresh" then + luci.sys.call("/etc/init.d/adblock reload >/dev/null 2>&1") + end + luci.http.prepare_content("text/plain") + luci.http.write("0") +end + +function status_update() + local rt_file + local content + + rt_file = uci:get("adblock", "global", "adb_rtfile") or "/tmp/adb_runtime.json" + + if fs.access(rt_file) then + content = json.parse(fs.readfile(rt_file)) + if content then + http.prepare_content("application/json") + http.write_json(content) + end + end end function logread() - local logfile + local content if nixio.fs.access("/var/log/messages") then - logfile = util.trim(util.exec("grep -F 'adblock-' /var/log/messages")) + content = util.trim(util.exec("grep -F 'adblock-' /var/log/messages")) else - logfile = util.trim(util.exec("logread -e 'adblock-'")) + content = util.trim(util.exec("logread -e 'adblock-'")) + end + + if content == "" then + content = "No adblock related logs yet!" end - templ.render("adblock/logread", {title = i18n.translate("Adblock Logfile"), content = logfile}) + http.write(content) end function queryData(domain) |