diff options
author | Dirk Brenken <dev@brenken.org> | 2017-03-25 21:58:51 +0100 |
---|---|---|
committer | Dirk Brenken <dev@brenken.org> | 2017-03-26 08:49:02 +0200 |
commit | 1bc3833e6876c9e2796fb7ec1ad2711bc12ef85f (patch) | |
tree | a53dc5e0c88ff78b34f82cfe9cf6682982fda678 /applications/luci-app-adblock/luasrc/controller | |
parent | 0ec9636be4e82c22b37fa379bd350ef661a8b5ab (diff) |
luci-app-adblock: major update
* multi-tab navigation
Overview/View Logfile/Advanced
Advanced: Edit Blacklist/Whitelist/Configuration
Query domains
* all adblock options are now configurable via LuCI
Signed-off-by: Dirk Brenken <dev@brenken.org>
Diffstat (limited to 'applications/luci-app-adblock/luasrc/controller')
-rw-r--r-- | applications/luci-app-adblock/luasrc/controller/adblock.lua | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/applications/luci-app-adblock/luasrc/controller/adblock.lua b/applications/luci-app-adblock/luasrc/controller/adblock.lua index d8b471814..bcb297603 100644 --- a/applications/luci-app-adblock/luasrc/controller/adblock.lua +++ b/applications/luci-app-adblock/luasrc/controller/adblock.lua @@ -1,12 +1,53 @@ --- Copyright 2016 Openwrt.org --- Licensed to the public under the Apache License 2.0. +-- Copyright 2016 Hannu Nyman +-- Copyright 2017 Dirk Brenken (dev@brenken.org) +-- This is free software, licensed under the Apache License, Version 2.0 module("luci.controller.adblock", package.seeall) +local fs = require("nixio.fs") +local util = require("luci.util") +local template = require("luci.template") +local i18n = require("luci.i18n") + function index() if not nixio.fs.access("/etc/config/adblock") then return end + entry({"admin", "services", "adblock"}, firstchild(), _("Adblock"), 30).dependent = false + entry({"admin", "services", "adblock", "tab_from_cbi"}, cbi("adblock/overview_tab"), _("Overview"), 10).leaf = true + entry({"admin", "services", "adblock", "logfile"}, call("logread"), _("View Logfile"), 20).leaf = true + entry({"admin", "services", "adblock", "advanced"}, firstchild(), _("Advanced"), 100) + entry({"admin", "services", "adblock", "advanced", "blacklist"}, cbi("adblock/blacklist_tab"), _("Edit Blacklist"), 110).leaf = true + entry({"admin", "services", "adblock", "advanced", "whitelist"}, cbi("adblock/whitelist_tab"), _("Edit Whitelist"), 120).leaf = true + entry({"admin", "services", "adblock", "advanced", "configuration"}, cbi("adblock/configuration_tab"), _("Edit Configuration"), 130).leaf = true + entry({"admin", "services", "adblock", "advanced", "query"}, call("query"), _("Query domains"), 140).leaf = true + entry({"admin", "services", "adblock", "advanced", "result"}, call("queryData"), nil, 150).leaf = true +end + +function logread() + local logfile = util.trim(util.exec("logread -e 'adblock'")) + template.render("adblock/logread", {title = i18n.translate("Adblock Logfile"), content = logfile}) +end - entry({"admin", "services", "adblock"}, cbi("adblock"), _("Adblock"), 40) +function query() + template.render("adblock/query", {title = i18n.translate("Adblock Domain Query")}) +end + +function queryData(domain) + if domain and domain:match("^[a-zA-Z0-9%-%._]+$") then + luci.http.prepare_content("text/plain") + local cmd = "/etc/init.d/adblock query %q 2>&1" + local util = io.popen(cmd % domain) + if util then + while true do + local line = util:read("*l") + if not line then + break + end + luci.http.write(line) + luci.http.write("\n") + end + util:close() + end + end end |