diff options
Diffstat (limited to 'applications/luci-app-adblock/luasrc/controller/adblock.lua')
-rw-r--r-- | applications/luci-app-adblock/luasrc/controller/adblock.lua | 76 |
1 files changed, 73 insertions, 3 deletions
diff --git a/applications/luci-app-adblock/luasrc/controller/adblock.lua b/applications/luci-app-adblock/luasrc/controller/adblock.lua index 4c7724471..0cfb8fc80 100644 --- a/applications/luci-app-adblock/luasrc/controller/adblock.lua +++ b/applications/luci-app-adblock/luasrc/controller/adblock.lua @@ -16,7 +16,8 @@ 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", "log"}, template("adblock/logread"), _("View Logfile"), 20).leaf = true + entry({"admin", "services", "adblock", "report"}, template("adblock/report"), _("DNS Query Report"), 20).leaf = true + entry({"admin", "services", "adblock", "log"}, template("adblock/logread"), _("Logfile"), 30).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 @@ -24,17 +25,49 @@ function index() 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", "status_update"}, call("status_update"), nil).leaf = true + entry({"admin", "services", "adblock", "report_json"}, call("report_json"), nil).leaf = true + entry({"admin", "services", "adblock", "report_text"}, call("report_text"), nil).leaf = true entry({"admin", "services", "adblock", "action"}, call("adb_action"), nil).leaf = true end -function adb_action(name) +function adb_action(name, domain) if name == "do_suspend" then luci.sys.call("/etc/init.d/adblock suspend >/dev/null 2>&1") elseif name == "do_resume" then luci.sys.call("/etc/init.d/adblock resume >/dev/null 2>&1") elseif name == "do_refresh" then luci.sys.call("/etc/init.d/adblock reload >/dev/null 2>&1") + local pid_file = "/var/run/adblock.pid" + if nixio.fs.access(pid_file) then + repeat + nixio.nanosleep(1) + until nixio.fs.readfile(pid_file) == "" + end + elseif name == "do_report" then + luci.sys.call("/etc/init.d/adblock report false >/dev/null 2>&1") + local rep_dir = uci:get("adblock", "extra", "adb_repdir") or "/tmp" + repeat + nixio.nanosleep(1) + until not nixio.fs.access(rep_dir.. "/adb_report.raw") + elseif name == "add_blacklist" then + local file = uci:get("adblock", "blacklist", "adb_src") or "/etc/adblock/adblock.blacklist" + if nixio.fs.access(file) then + local blacklist = nixio.fs.readfile(file) + if not string.find(blacklist, domain, 1, plain) + then + nixio.fs.writefile(file, blacklist.. domain.. "\n") + end + end + elseif name == "add_whitelist" then + local file = uci:get("adblock", "global", "adb_whitelist") or "/etc/adblock/adblock.whitelist" + if nixio.fs.access(file) then + local whitelist = nixio.fs.readfile(file) + if not string.find(whitelist, domain, 1, plain) + then + nixio.fs.writefile(file, whitelist.. domain.. "\n") + end + end end luci.http.prepare_content("text/plain") luci.http.write("0") @@ -53,6 +86,43 @@ function status_update() end end +function report_json() + local rep_dir + local rep_file + local content + + rep_dir = uci:get("adblock", "extra", "adb_repdir") or "/tmp" + rep_file = rep_dir.. "/adb_report.json" + http.prepare_content("application/json") + + if nixio.fs.access(rep_file) then + content = json.parse(nixio.fs.readfile(rep_file) or "") + http.write_json(content) + else + http.write_json("{}") + end +end + +function report_text() + local file + local rep_dir + local rep_file + local content + + rep_dir = uci:get("adblock", "extra", "adb_repdir") or "/tmp" + rep_file = rep_dir.. "/adb_report" + http.prepare_content("text/plain") + + if nixio.fs.access(rep_file) then + file = io.open(rep_file, "r") + content = file:read("*all") + file:close() + http.write(content) + else + http.write("") + end +end + function logread() local content |