diff options
author | Jo-Philipp Wich <jo@mein.io> | 2018-07-22 17:46:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-22 17:46:04 +0200 |
commit | 83c86d2934c713989fcabc529af1e3726212db0a (patch) | |
tree | 857c3c24e2dd359b6d40412304fed33f62932079 /applications/luci-app-adblock/luasrc/controller/adblock.lua | |
parent | e3f76c255a1a4f989f18264747131e8f5ea37180 (diff) | |
parent | 5db2b7649704b229fb618b627225ccc97519280e (diff) |
Merge pull request #1983 from dibdot/adblock
luci-app-adblock: sync with adblock 3.5.4
Diffstat (limited to 'applications/luci-app-adblock/luasrc/controller/adblock.lua')
-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) |