summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-adblock/luasrc/model
diff options
context:
space:
mode:
authorHannu Nyman <hannu.nyman@iki.fi>2017-04-30 00:02:31 +0300
committerHannu Nyman <hannu.nyman@iki.fi>2017-04-30 00:09:39 +0300
commitae565bc39372a9ef2996c4caebbc714518529a53 (patch)
tree53a7bf06d6a3259938bad9f1f7884c948c96235b /applications/luci-app-adblock/luasrc/model
parent7fee975bb41e590aaeba3436e07aa759b9e3ec27 (diff)
luci-app-adblock: backport updates to match 2.6.2
Backport updates to luci-app-adblock that correspond to the adblock 2.6.2 version. Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
Diffstat (limited to 'applications/luci-app-adblock/luasrc/model')
-rw-r--r--applications/luci-app-adblock/luasrc/model/cbi/adblock.lua63
-rw-r--r--applications/luci-app-adblock/luasrc/model/cbi/adblock/blacklist_tab.lua39
-rw-r--r--applications/luci-app-adblock/luasrc/model/cbi/adblock/configuration_tab.lua36
-rw-r--r--applications/luci-app-adblock/luasrc/model/cbi/adblock/overview_tab.lua164
-rw-r--r--applications/luci-app-adblock/luasrc/model/cbi/adblock/whitelist_tab.lua39
5 files changed, 278 insertions, 63 deletions
diff --git a/applications/luci-app-adblock/luasrc/model/cbi/adblock.lua b/applications/luci-app-adblock/luasrc/model/cbi/adblock.lua
deleted file mode 100644
index 0a4a4cdd2f..0000000000
--- a/applications/luci-app-adblock/luasrc/model/cbi/adblock.lua
+++ /dev/null
@@ -1,63 +0,0 @@
--- Copyright 2016 Hannu Nyman
--- Licensed to the public under the Apache License 2.0.
-
-m = Map("adblock", translate("Adblock"),
- translate("Configuration of the adblock package to block ad/abuse domains by using DNS."))
-
--- General options
-
-s = m:section(NamedSection, "global", "adblock", translate("Global options"))
-
-o1 = s:option(Flag, "adb_enabled", translate("Enable adblock"))
-o1.rmempty = false
-o1.default = 0
-
-o3 = s:option(Value, "adb_whitelist", translate("Whitelist file"),
- translate("File with whitelisted hosts/domains that are allowed despite being on a blocklist."))
-o3.rmempty = false
-o3.datatype = "file"
-
--- Blocklist options
-
-bl = m:section(TypedSection, "source", translate("Blocklist sources"),
- translate("Available blocklist sources (")
- .. [[<a href="https://github.com/openwrt/packages/blob/master/net/adblock/files/README.md" target="_blank">]]
- .. translate("see list details")
- .. [[</a>]]
- .. translate("). Note that list URLs and Shallalist category selections are not configurable via Luci."))
-bl.template = "cbi/tblsection"
-
-name = bl:option(Flag, "enabled", translate("Enabled"))
-name.rmempty = false
-
-des = bl:option(DummyValue, "adb_src_desc", translate("Description"))
-
--- Additional options
-
-s2 = m:section(NamedSection, "global", "adblock", translate("Backup options"))
-
-o4 = s2:option(Flag, "adb_backup", translate("Enable blocklist backup"))
-o4.rmempty = false
-o4.default = 0
-
-o5 = s2:option(Value, "adb_backupdir", translate("Backup directory"))
-o5.rmempty = false
-o5.datatype = "directory"
-
--- Extra options
-
-e = m:section(NamedSection, "global", "adblock", translate("Extra options"),
- translate("Options for further tweaking in case the defaults are not suitable for you."))
-
-a = e:option(Flag, "adb_debug", translate("Enable verbose debug logging"))
-a.default = a.disabled
-a.rmempty = false
-
-a = e:option(Value, "adb_iface", translate("Restrict reload trigger to certain interface(s)"),
- translate("Space separated list of wan interfaces that trigger reload action. " ..
- "To disable reload trigger set it to 'false'. Default: empty"))
-a.datatype = "network"
-a.rmempty = true
-
-return m
-
diff --git a/applications/luci-app-adblock/luasrc/model/cbi/adblock/blacklist_tab.lua b/applications/luci-app-adblock/luasrc/model/cbi/adblock/blacklist_tab.lua
new file mode 100644
index 0000000000..d540c77d10
--- /dev/null
+++ b/applications/luci-app-adblock/luasrc/model/cbi/adblock/blacklist_tab.lua
@@ -0,0 +1,39 @@
+-- Copyright 2017 Dirk Brenken (dev@brenken.org)
+-- This is free software, licensed under the Apache License, Version 2.0
+
+local fs = require("nixio.fs")
+local util = require("luci.util")
+local uci = require("uci")
+local adbinput = uci.get("adblock", "blacklist", "adb_src" or "/etc/adblock/adblock.blacklist")
+
+if not nixio.fs.access(adbinput) then
+ m = SimpleForm("error", nil, translate("Input file not found, please check your configuration."))
+ return m
+end
+
+m = SimpleForm("input", nil)
+m:append(Template("adblock/config_css"))
+m.reset = false
+
+s = m:section(SimpleSection, nil,
+ translatef("This form allows you to modify the content of the adblock blacklist (%s).<br />", adbinput)
+ .. translate("Please add only one domain per line. Comments introduced with '#' are allowed - ip addresses, wildcards and regex are not."))
+
+f = s:option(TextValue, "data")
+f.datatype = "string"
+f.rows = 20
+f.rmempty = true
+
+function f.cfgvalue()
+ return nixio.fs.readfile(adbinput) or ""
+end
+
+function f.write(self, section, data)
+ return nixio.fs.writefile(adbinput, "\n" .. util.trim(data:gsub("\r\n", "\n")) .. "\n")
+end
+
+function s.handle(self, state, data)
+ return true
+end
+
+return m
diff --git a/applications/luci-app-adblock/luasrc/model/cbi/adblock/configuration_tab.lua b/applications/luci-app-adblock/luasrc/model/cbi/adblock/configuration_tab.lua
new file mode 100644
index 0000000000..1b83c949e1
--- /dev/null
+++ b/applications/luci-app-adblock/luasrc/model/cbi/adblock/configuration_tab.lua
@@ -0,0 +1,36 @@
+-- Copyright 2017 Dirk Brenken (dev@brenken.org)
+-- This is free software, licensed under the Apache License, Version 2.0
+
+local fs = require("nixio.fs")
+local util = require("luci.util")
+local adbinput = "/etc/config/adblock"
+
+if not nixio.fs.access(adbinput) then
+ m = SimpleForm("error", nil, translate("Input file not found, please check your configuration."))
+ return m
+end
+
+m = SimpleForm("input", nil)
+m:append(Template("adblock/config_css"))
+m.reset = false
+
+s = m:section(SimpleSection, nil,
+ translate("This form allows you to modify the content of the main adblock configuration file (/etc/config/adblock)."))
+
+f = s:option(TextValue, "data")
+f.rows = 20
+f.rmempty = true
+
+function f.cfgvalue()
+ return nixio.fs.readfile(adbinput) or ""
+end
+
+function f.write(self, section, data)
+ return nixio.fs.writefile(adbinput, "\n" .. util.trim(data:gsub("\r\n", "\n")) .. "\n")
+end
+
+function s.handle(self, state, data)
+ return true
+end
+
+return m
diff --git a/applications/luci-app-adblock/luasrc/model/cbi/adblock/overview_tab.lua b/applications/luci-app-adblock/luasrc/model/cbi/adblock/overview_tab.lua
new file mode 100644
index 0000000000..d2740f4daf
--- /dev/null
+++ b/applications/luci-app-adblock/luasrc/model/cbi/adblock/overview_tab.lua
@@ -0,0 +1,164 @@
+-- Copyright 2017 Dirk Brenken (dev@brenken.org)
+-- This is free software, licensed under the Apache License, Version 2.0
+
+local fs = require("nixio.fs")
+local uci = require("uci")
+local sys = require("luci.sys")
+local json = require("luci.jsonc")
+local adbinput = uci.get("adblock", "global", "adb_rtfile") or "/tmp/adb_runtime.json"
+local parse = json.parse(fs.readfile(adbinput) or "")
+local dnsFile1 = sys.exec("find '/tmp/dnsmasq.d/.adb_hidden' -maxdepth 1 -type f -name 'adb_list*' -print 2>/dev/null")
+local dnsFile2 = sys.exec("find '/var/lib/unbound/.adb_hidden' -maxdepth 1 -type f -name 'adb_list*' -print 2>/dev/null")
+
+m = Map("adblock", translate("Adblock"),
+ translate("Configuration of the adblock package to block ad/abuse domains by using DNS. ")
+ .. translate("For further information ")
+ .. [[<a href="https://github.com/openwrt/packages/blob/master/net/adblock/files/README.md" target="_blank">]]
+ .. translate("see online documentation")
+ .. [[</a>]]
+ .. translate("."))
+m.reset = false
+
+-- Main adblock options
+
+s = m:section(NamedSection, "global", "adblock")
+
+o1 = s:option(Flag, "adb_enabled", translate("Enable adblock"))
+o1.default = o1.enabled
+o1.rmempty = false
+
+btn = s:option(Button, "", translate("Suspend / Resume adblock"))
+if dnsFile1 ~= "" or dnsFile2 ~= "" then
+ btn.inputtitle = translate("Resume adblock")
+ btn.inputstyle = "apply"
+ btn.disabled = false
+ function btn.write()
+ luci.sys.call("/etc/init.d/adblock resume >/dev/null 2>&1")
+ end
+else
+ btn.inputtitle = translate("Suspend adblock")
+ btn.inputstyle = "reset"
+ btn.disabled = false
+ function btn.write()
+ luci.sys.call("/etc/init.d/adblock suspend >/dev/null 2>&1")
+ end
+end
+
+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."))
+o3.default = 2
+o3.datatype = "range(1,90)"
+o3.rmempty = false
+
+o4 = s:option(Flag, "adb_debug", translate("Enable verbose debug logging"))
+o4.default = o4.disabled
+o4.rmempty = false
+
+-- Runtime information
+
+ds = s:option(DummyValue, "_dummy", translate("Runtime information"))
+ds.template = "cbi/nullsection"
+
+dv1 = s:option(DummyValue, "status", translate("Status"))
+dv1.template = "adblock/runtime"
+if parse == nil then
+ dv1.value = translate("n/a")
+elseif parse.data.blocked_domains == "0" then
+ dv1.value = translate("no domains blocked")
+elseif dnsFile1 ~= "" or dnsFile2 ~= "" then
+ dv1.value = translate("suspended")
+else
+ dv1.value = translate("active")
+end
+dv2 = s:option(DummyValue, "adblock_version", translate("Adblock version"))
+dv2.template = "adblock/runtime"
+if parse ~= nil then
+ dv2.value = parse.data.adblock_version or translate("n/a")
+else
+ dv2.value = translate("n/a")
+end
+
+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"
+if parse ~= nil then
+ dv3.value = parse.data.fetch_info or translate("n/a")
+else
+ dv3.value = translate("n/a")
+end
+
+dv4 = s:option(DummyValue, "dns_backend", translate("DNS backend"))
+dv4.template = "adblock/runtime"
+if parse ~= nil then
+ dv4.value = parse.data.dns_backend or translate("n/a")
+else
+ dv4.value = translate("n/a")
+end
+
+dv5 = s:option(DummyValue, "blocked_domains", translate("Blocked domains (overall)"))
+dv5.template = "adblock/runtime"
+if parse ~= nil then
+ dv5.value = parse.data.blocked_domains or translate("n/a")
+else
+ dv5.value = translate("n/a")
+end
+
+dv6 = s:option(DummyValue, "last_rundate", translate("Last rundate"))
+dv6.template = "adblock/runtime"
+if parse ~= nil then
+ dv6.value = parse.data.last_rundate or translate("n/a")
+else
+ dv6.value = translate("n/a")
+end
+
+-- Blocklist table
+
+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"))
+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
+
+des = bl:option(DummyValue, "adb_src_desc", translate("Description"))
+
+-- Extra options
+
+e = m:section(NamedSection, "global", "adblock", translate("Extra options"),
+ translate("Options for further tweaking in case the defaults are not suitable for you."))
+
+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
+
+e2 = e:option(Flag, "adb_forcesrt", translate("Force Overall Sort"),
+ translate("Enable memory intense overall sort / duplicate removal on low memory devices (&lt; 64 MB RAM)"))
+e2.default = e2.disabled
+e2.rmempty = false
+
+e3 = e:option(Flag, "adb_backup", translate("Enable blocklist backup"))
+e3.default = e3.disabled
+e3.rmempty = false
+
+e4 = e:option(Value, "adb_backupdir", translate("Backup directory"))
+e4.datatype = "directory"
+e4.rmempty = false
+
+return m
diff --git a/applications/luci-app-adblock/luasrc/model/cbi/adblock/whitelist_tab.lua b/applications/luci-app-adblock/luasrc/model/cbi/adblock/whitelist_tab.lua
new file mode 100644
index 0000000000..23c99a9778
--- /dev/null
+++ b/applications/luci-app-adblock/luasrc/model/cbi/adblock/whitelist_tab.lua
@@ -0,0 +1,39 @@
+-- Copyright 2017 Dirk Brenken (dev@brenken.org)
+-- This is free software, licensed under the Apache License, Version 2.0
+
+local fs = require("nixio.fs")
+local util = require("luci.util")
+local uci = require("uci")
+local adbinput = uci.get("adblock", "global", "adb_whitelist") or "/etc/adblock/adblock.whitelist"
+
+if not nixio.fs.access(adbinput) then
+ m = SimpleForm("error", nil, translate("Input file not found, please check your configuration."))
+ return m
+end
+
+m = SimpleForm("input", nil)
+m:append(Template("adblock/config_css"))
+m.reset = false
+
+s = m:section(SimpleSection, nil,
+ translatef("This form allows you to modify the content of the adblock whitelist (%s).<br />", adbinput)
+ .. translate("Please add only one domain per line. Comments introduced with '#' are allowed - ip addresses, wildcards and regex are not."))
+
+f = s:option(TextValue, "data")
+f.datatype = "string"
+f.rows = 20
+f.rmempty = true
+
+function f.cfgvalue()
+ return nixio.fs.readfile(adbinput) or ""
+end
+
+function f.write(self, section, data)
+ return nixio.fs.writefile(adbinput, "\n" .. util.trim(data:gsub("\r\n", "\n")) .. "\n")
+end
+
+function s.handle(self, state, data)
+ return true
+end
+
+return m