2017-03-25 20:58:51 +00:00
|
|
|
-- Copyright 2017 Dirk Brenken (dev@brenken.org)
|
|
|
|
-- This is free software, licensed under the Apache License, Version 2.0
|
|
|
|
|
2017-04-10 05:01:33 +00:00
|
|
|
local fs = require("nixio.fs")
|
|
|
|
local uci = require("uci")
|
2017-03-25 20:58:51 +00:00
|
|
|
local sys = require("luci.sys")
|
2017-04-10 05:01:33 +00:00
|
|
|
local json = require("luci.jsonc")
|
|
|
|
local adbinput = uci.get("adblock", "global", "adb_rtfile") or "/tmp/adb_runtime.json"
|
2017-06-29 10:58:33 +00:00
|
|
|
local dnspath = uci.get("adblock", "global", "adb_dnsdir") or ""
|
2017-07-05 19:31:56 +00:00
|
|
|
local parse = json.parse(fs.readfile(adbinput) or "")
|
2017-06-29 10:58:33 +00:00
|
|
|
if parse ~= nil then
|
|
|
|
version = parse.data.adblock_version
|
|
|
|
domains = parse.data.blocked_domains
|
|
|
|
fetch = parse.data.fetch_info
|
|
|
|
backend = parse.data.dns_backend
|
|
|
|
rundate = parse.data.last_rundate
|
|
|
|
if dnspath == "" then
|
|
|
|
if backend == "dnsmasq" then
|
|
|
|
dnspath = "/tmp/dnsmasq.d"
|
|
|
|
elseif backend == "unbound" then
|
|
|
|
dnspath = "/var/lib/unbound"
|
|
|
|
elseif backend == "named" then
|
|
|
|
dnspath = "/var/lib/bind"
|
2017-08-04 06:34:34 +00:00
|
|
|
elseif backend == "kresd" then
|
|
|
|
dnspath = "/tmp/kresd"
|
2017-06-29 10:58:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local dnsfile = dnspath .. "/.adb_hidden/adb_list.overall"
|
2017-03-25 20:58:51 +00:00
|
|
|
|
|
|
|
m = Map("adblock", translate("Adblock"),
|
|
|
|
translate("Configuration of the adblock package to block ad/abuse domains by using DNS. ")
|
2017-05-08 09:15:19 +00:00
|
|
|
.. translatef("For further information "
|
|
|
|
.. "<a href=\"%s\" target=\"_blank\">"
|
|
|
|
.. "see online documentation</a>", "https://github.com/openwrt/packages/blob/master/net/adblock/files/README.md"))
|
|
|
|
|
|
|
|
function m.on_after_commit(self)
|
2017-06-09 18:18:23 +00:00
|
|
|
function e3.validate(self, value)
|
|
|
|
if value == "0" then
|
|
|
|
luci.sys.call("/etc/init.d/adblock reload >/dev/null 2>&1")
|
|
|
|
else
|
|
|
|
luci.sys.call("/etc/init.d/adblock start >/dev/null 2>&1")
|
|
|
|
end
|
|
|
|
end
|
2017-05-08 09:15:19 +00:00
|
|
|
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "adblock"))
|
|
|
|
end
|
2017-03-25 20:58:51 +00:00
|
|
|
|
|
|
|
-- Main adblock options
|
|
|
|
|
|
|
|
s = m:section(NamedSection, "global", "adblock")
|
|
|
|
|
|
|
|
o1 = s:option(Flag, "adb_enabled", translate("Enable adblock"))
|
2017-04-10 05:01:33 +00:00
|
|
|
o1.default = o1.enabled
|
2017-03-25 20:58:51 +00:00
|
|
|
o1.rmempty = false
|
|
|
|
|
2017-03-27 09:36:41 +00:00
|
|
|
btn = s:option(Button, "", translate("Suspend / Resume adblock"))
|
2017-06-29 10:58:33 +00:00
|
|
|
if parse ~= nil and nixio.fs.access(dnsfile) then
|
2017-04-10 05:01:33 +00:00
|
|
|
btn.inputtitle = translate("Resume adblock")
|
|
|
|
btn.inputstyle = "apply"
|
2017-03-27 09:36:41 +00:00
|
|
|
btn.disabled = false
|
2017-03-25 20:58:51 +00:00
|
|
|
function btn.write()
|
2017-04-10 05:01:33 +00:00
|
|
|
luci.sys.call("/etc/init.d/adblock resume >/dev/null 2>&1")
|
2017-05-08 09:15:19 +00:00
|
|
|
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "adblock"))
|
2017-03-25 20:58:51 +00:00
|
|
|
end
|
|
|
|
else
|
2017-04-10 05:01:33 +00:00
|
|
|
btn.inputtitle = translate("Suspend adblock")
|
|
|
|
btn.inputstyle = "reset"
|
2017-03-27 09:36:41 +00:00
|
|
|
btn.disabled = false
|
2017-03-25 20:58:51 +00:00
|
|
|
function btn.write()
|
2017-04-10 05:01:33 +00:00
|
|
|
luci.sys.call("/etc/init.d/adblock suspend >/dev/null 2>&1")
|
2017-05-08 09:15:19 +00:00
|
|
|
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "adblock"))
|
2017-03-25 20:58:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-10 05:01:33 +00:00
|
|
|
o2 = s:option(Value, "adb_iface", translate("Restrict interface trigger to certain interface(s)"),
|
|
|
|
translate("Space separated list of interfaces that trigger adblock processing. "..
|
|
|
|
"To disable event driven (re-)starts remove all entries."))
|
|
|
|
o2.rmempty = true
|
|
|
|
|
|
|
|
o3 = s:option(Value, "adb_triggerdelay", translate("Trigger delay"),
|
|
|
|
translate("Additional trigger delay in seconds before adblock processing begins."))
|
2017-04-16 06:24:03 +00:00
|
|
|
o3.default = 2
|
2017-04-10 05:01:33 +00:00
|
|
|
o3.datatype = "range(1,90)"
|
|
|
|
o3.rmempty = false
|
2017-03-25 20:58:51 +00:00
|
|
|
|
2017-04-10 05:01:33 +00:00
|
|
|
o4 = s:option(Flag, "adb_debug", translate("Enable verbose debug logging"))
|
|
|
|
o4.default = o4.disabled
|
|
|
|
o4.rmempty = false
|
2017-03-25 20:58:51 +00:00
|
|
|
|
|
|
|
-- Runtime information
|
|
|
|
|
2017-04-10 05:01:33 +00:00
|
|
|
ds = s:option(DummyValue, "_dummy", translate("Runtime information"))
|
|
|
|
ds.template = "cbi/nullsection"
|
2017-03-25 20:58:51 +00:00
|
|
|
|
2017-04-10 05:01:33 +00:00
|
|
|
dv1 = s:option(DummyValue, "status", translate("Status"))
|
|
|
|
dv1.template = "adblock/runtime"
|
|
|
|
if parse == nil then
|
|
|
|
dv1.value = translate("n/a")
|
2017-06-29 10:58:33 +00:00
|
|
|
elseif domains == "0" then
|
2017-04-10 05:01:33 +00:00
|
|
|
dv1.value = translate("no domains blocked")
|
2017-06-29 10:58:33 +00:00
|
|
|
elseif nixio.fs.access(dnsfile) then
|
2017-04-10 05:01:33 +00:00
|
|
|
dv1.value = translate("suspended")
|
|
|
|
else
|
|
|
|
dv1.value = translate("active")
|
|
|
|
end
|
2017-06-29 10:58:33 +00:00
|
|
|
|
2017-04-10 05:01:33 +00:00
|
|
|
dv2 = s:option(DummyValue, "adblock_version", translate("Adblock version"))
|
|
|
|
dv2.template = "adblock/runtime"
|
2017-06-29 10:58:33 +00:00
|
|
|
if parse == nil then
|
2017-04-10 05:01:33 +00:00
|
|
|
dv2.value = translate("n/a")
|
2017-06-29 10:58:33 +00:00
|
|
|
else
|
|
|
|
dv2.value = version
|
2017-04-10 05:01:33 +00:00
|
|
|
end
|
2017-03-25 20:58:51 +00:00
|
|
|
|
2017-04-10 05:01:33 +00:00
|
|
|
dv3 = s:option(DummyValue, "fetch_info", translate("Download Utility (SSL Library)"),
|
|
|
|
translate("For SSL protected blocklist sources you need a suitable SSL library, e.g. 'libustream-ssl' or the wget 'built-in'."))
|
|
|
|
dv3.template = "adblock/runtime"
|
2017-06-29 10:58:33 +00:00
|
|
|
if parse == nil then
|
2017-04-10 05:01:33 +00:00
|
|
|
dv3.value = translate("n/a")
|
2017-06-29 10:58:33 +00:00
|
|
|
else
|
|
|
|
dv3.value = fetch
|
2017-04-10 05:01:33 +00:00
|
|
|
end
|
2017-03-25 20:58:51 +00:00
|
|
|
|
2017-04-10 05:01:33 +00:00
|
|
|
dv4 = s:option(DummyValue, "dns_backend", translate("DNS backend"))
|
|
|
|
dv4.template = "adblock/runtime"
|
2017-06-29 10:58:33 +00:00
|
|
|
if parse == nil then
|
2017-04-10 05:01:33 +00:00
|
|
|
dv4.value = translate("n/a")
|
2017-06-29 10:58:33 +00:00
|
|
|
else
|
|
|
|
dv4.value = backend
|
2017-04-10 05:01:33 +00:00
|
|
|
end
|
2017-03-25 20:58:51 +00:00
|
|
|
|
2017-04-10 05:01:33 +00:00
|
|
|
dv5 = s:option(DummyValue, "blocked_domains", translate("Blocked domains (overall)"))
|
|
|
|
dv5.template = "adblock/runtime"
|
2017-06-29 10:58:33 +00:00
|
|
|
if parse == nil then
|
2017-04-10 05:01:33 +00:00
|
|
|
dv5.value = translate("n/a")
|
2017-06-29 10:58:33 +00:00
|
|
|
else
|
|
|
|
dv5.value = domains
|
2017-04-10 05:01:33 +00:00
|
|
|
end
|
2017-03-25 20:58:51 +00:00
|
|
|
|
2017-04-10 05:01:33 +00:00
|
|
|
dv6 = s:option(DummyValue, "last_rundate", translate("Last rundate"))
|
|
|
|
dv6.template = "adblock/runtime"
|
2017-06-29 10:58:33 +00:00
|
|
|
if parse == nil then
|
2017-04-10 05:01:33 +00:00
|
|
|
dv6.value = translate("n/a")
|
2017-06-29 10:58:33 +00:00
|
|
|
else
|
|
|
|
dv6.value = rundate
|
2017-04-10 05:01:33 +00:00
|
|
|
end
|
2017-03-25 20:58:51 +00:00
|
|
|
|
2017-04-10 05:01:33 +00:00
|
|
|
-- Blocklist table
|
2017-03-25 20:58:51 +00:00
|
|
|
|
|
|
|
bl = m:section(TypedSection, "source", translate("Blocklist sources"),
|
|
|
|
translate("Available blocklist sources. ")
|
|
|
|
.. translate("Note that list URLs and Shallalist category selections are configurable in the 'Advanced' section."))
|
|
|
|
bl.template = "cbi/tblsection"
|
|
|
|
|
|
|
|
name = bl:option(Flag, "enabled", translate("Enabled"))
|
2017-04-10 05:01:33 +00:00
|
|
|
name.rmempty = false
|
|
|
|
|
|
|
|
ssl = bl:option(DummyValue, "adb_src", translate("SSL req."))
|
|
|
|
function ssl.cfgvalue(self, section)
|
|
|
|
local source = self.map:get(section, "adb_src")
|
|
|
|
if source and source:match("https://") then
|
|
|
|
return translate("Yes")
|
|
|
|
else
|
|
|
|
return translate("No")
|
|
|
|
end
|
|
|
|
end
|
2017-03-25 20:58:51 +00:00
|
|
|
|
|
|
|
des = bl:option(DummyValue, "adb_src_desc", translate("Description"))
|
|
|
|
|
2017-04-25 21:17:08 +00:00
|
|
|
-- Extra options
|
2017-03-25 20:58:51 +00:00
|
|
|
|
2017-04-25 21:17:08 +00:00
|
|
|
e = m:section(NamedSection, "global", "adblock", translate("Extra options"),
|
|
|
|
translate("Options for further tweaking in case the defaults are not suitable for you."))
|
2017-03-25 20:58:51 +00:00
|
|
|
|
2017-04-25 21:17:08 +00:00
|
|
|
e1 = e:option(Flag, "adb_forcedns", translate("Force local DNS"),
|
|
|
|
translate("Redirect all DNS queries to the local resolver."))
|
|
|
|
e1.default = e1.disabled
|
|
|
|
e1.rmempty = false
|
2017-04-10 05:01:33 +00:00
|
|
|
|
2017-04-25 21:17:08 +00:00
|
|
|
e2 = e:option(Flag, "adb_forcesrt", translate("Force Overall Sort"),
|
2017-04-26 21:31:11 +00:00
|
|
|
translate("Enable memory intense overall sort / duplicate removal on low memory devices (< 64 MB RAM)"))
|
2017-04-25 21:17:08 +00:00
|
|
|
e2.default = e2.disabled
|
|
|
|
e2.rmempty = false
|
|
|
|
|
2017-08-04 06:34:34 +00:00
|
|
|
e3 = e:option(Flag, "adb_manmode", translate("Manual / Backup mode"),
|
2017-06-07 17:33:31 +00:00
|
|
|
translate("Do not automatically update blocklists during startup, use blocklist backups instead."))
|
2017-04-25 21:17:08 +00:00
|
|
|
e3.default = e3.disabled
|
|
|
|
e3.rmempty = false
|
|
|
|
|
2017-06-07 17:33:31 +00:00
|
|
|
e4 = e:option(Flag, "adb_backup", translate("Enable blocklist backup"),
|
|
|
|
translate("Create compressed blocklist backups, they will be used in case of download errors or during startup in manual mode."))
|
|
|
|
e4.default = e4.disabled
|
2017-04-25 21:17:08 +00:00
|
|
|
e4.rmempty = false
|
2017-03-25 20:58:51 +00:00
|
|
|
|
2017-06-07 17:33:31 +00:00
|
|
|
e5 = e:option(Value, "adb_backupdir", translate("Backup directory"))
|
|
|
|
e5.datatype = "directory"
|
|
|
|
e5.rmempty = false
|
|
|
|
|
2017-03-25 20:58:51 +00:00
|
|
|
return m
|