summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-adblock/luasrc/controller/adblock.lua
diff options
context:
space:
mode:
authorDirk Brenken <dev@brenken.org>2018-07-21 22:32:16 +0200
committerDirk Brenken <dev@brenken.org>2018-07-22 08:58:33 +0200
commit5db2b7649704b229fb618b627225ccc97519280e (patch)
tree5b5f582d6d7aed5cc53b0cfb0556fed41fe9669b /applications/luci-app-adblock/luasrc/controller/adblock.lua
parent39cabc03611369d7cb421b5fcff90ce20d9d51c4 (diff)
luci-app-adblock: sync with adblock 3.5.4
backend: * add low priority mode (nice level 10), disabled by default * enhance 'Force DNS' to redirect ports 53, 853 and 5353 frontend: * switch to dynamic XHR polling for runtime information and logfile viewing * add new 'Refresh' button to reload blocklists * various cleanups & small fixes Signed-off-by: Dirk Brenken <dev@brenken.org>
Diffstat (limited to 'applications/luci-app-adblock/luasrc/controller/adblock.lua')
-rw-r--r--applications/luci-app-adblock/luasrc/controller/adblock.lua49
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)