1 -- Copyright 2017 Dirk Brenken (dev@brenken.org)
2 -- This is free software, licensed under the Apache License, Version 2.0
4 local fs = require("nixio.fs")
5 local uci = require("uci")
6 local sys = require("luci.sys")
7 local json = require("luci.jsonc")
8 local adbinput = uci.get("adblock", "global", "adb_rtfile") or "/tmp/adb_runtime.json"
9 local parse = json.parse(fs.readfile(adbinput) or "")
10 local dnsFile1 = sys.exec("find '/tmp/dnsmasq.d/.adb_hidden' -maxdepth 1 -type f -name 'adb_list*' -print 2>/dev/null")
11 local dnsFile2 = sys.exec("find '/var/lib/unbound/.adb_hidden' -maxdepth 1 -type f -name 'adb_list*' -print 2>/dev/null")
13 m = Map("adblock", translate("Adblock"),
14 translate("Configuration of the adblock package to block ad/abuse domains by using DNS. ")
15 .. translatef("For further information "
16 .. "<a href=\"%s\" target=\"_blank\">"
17 .. "see online documentation</a>", "https://github.com/openwrt/packages/blob/master/net/adblock/files/README.md"))
19 function m.on_after_commit(self)
20 function e3.validate(self, value)
22 luci.sys.call("/etc/init.d/adblock reload >/dev/null 2>&1")
24 luci.sys.call("/etc/init.d/adblock start >/dev/null 2>&1")
27 luci.http.redirect(luci.dispatcher.build_url("admin", "services", "adblock"))
30 -- Main adblock options
32 s = m:section(NamedSection, "global", "adblock")
34 o1 = s:option(Flag, "adb_enabled", translate("Enable adblock"))
35 o1.default = o1.enabled
38 btn = s:option(Button, "", translate("Suspend / Resume adblock"))
39 if dnsFile1 ~= "" or dnsFile2 ~= "" then
40 btn.inputtitle = translate("Resume adblock")
41 btn.inputstyle = "apply"
44 luci.sys.call("/etc/init.d/adblock resume >/dev/null 2>&1")
45 luci.http.redirect(luci.dispatcher.build_url("admin", "services", "adblock"))
48 btn.inputtitle = translate("Suspend adblock")
49 btn.inputstyle = "reset"
52 luci.sys.call("/etc/init.d/adblock suspend >/dev/null 2>&1")
53 luci.http.redirect(luci.dispatcher.build_url("admin", "services", "adblock"))
57 o2 = s:option(Value, "adb_iface", translate("Restrict interface trigger to certain interface(s)"),
58 translate("Space separated list of interfaces that trigger adblock processing. "..
59 "To disable event driven (re-)starts remove all entries."))
62 o3 = s:option(Value, "adb_triggerdelay", translate("Trigger delay"),
63 translate("Additional trigger delay in seconds before adblock processing begins."))
65 o3.datatype = "range(1,90)"
68 o4 = s:option(Flag, "adb_debug", translate("Enable verbose debug logging"))
69 o4.default = o4.disabled
72 -- Runtime information
74 ds = s:option(DummyValue, "_dummy", translate("Runtime information"))
75 ds.template = "cbi/nullsection"
77 dv1 = s:option(DummyValue, "status", translate("Status"))
78 dv1.template = "adblock/runtime"
80 dv1.value = translate("n/a")
81 elseif parse.data.blocked_domains == "0" then
82 dv1.value = translate("no domains blocked")
83 elseif dnsFile1 ~= "" or dnsFile2 ~= "" then
84 dv1.value = translate("suspended")
86 dv1.value = translate("active")
88 dv2 = s:option(DummyValue, "adblock_version", translate("Adblock version"))
89 dv2.template = "adblock/runtime"
91 dv2.value = parse.data.adblock_version or translate("n/a")
93 dv2.value = translate("n/a")
96 dv3 = s:option(DummyValue, "fetch_info", translate("Download Utility (SSL Library)"),
97 translate("For SSL protected blocklist sources you need a suitable SSL library, e.g. 'libustream-ssl' or the wget 'built-in'."))
98 dv3.template = "adblock/runtime"
100 dv3.value = parse.data.fetch_info or translate("n/a")
102 dv3.value = translate("n/a")
105 dv4 = s:option(DummyValue, "dns_backend", translate("DNS backend"))
106 dv4.template = "adblock/runtime"
108 dv4.value = parse.data.dns_backend or translate("n/a")
110 dv4.value = translate("n/a")
113 dv5 = s:option(DummyValue, "blocked_domains", translate("Blocked domains (overall)"))
114 dv5.template = "adblock/runtime"
116 dv5.value = parse.data.blocked_domains or translate("n/a")
118 dv5.value = translate("n/a")
121 dv6 = s:option(DummyValue, "last_rundate", translate("Last rundate"))
122 dv6.template = "adblock/runtime"
124 dv6.value = parse.data.last_rundate or translate("n/a")
126 dv6.value = translate("n/a")
131 bl = m:section(TypedSection, "source", translate("Blocklist sources"),
132 translate("Available blocklist sources. ")
133 .. translate("Note that list URLs and Shallalist category selections are configurable in the 'Advanced' section."))
134 bl.template = "cbi/tblsection"
136 name = bl:option(Flag, "enabled", translate("Enabled"))
139 ssl = bl:option(DummyValue, "adb_src", translate("SSL req."))
140 function ssl.cfgvalue(self, section)
141 local source = self.map:get(section, "adb_src")
142 if source and source:match("https://") then
143 return translate("Yes")
145 return translate("No")
149 des = bl:option(DummyValue, "adb_src_desc", translate("Description"))
153 e = m:section(NamedSection, "global", "adblock", translate("Extra options"),
154 translate("Options for further tweaking in case the defaults are not suitable for you."))
156 e1 = e:option(Flag, "adb_forcedns", translate("Force local DNS"),
157 translate("Redirect all DNS queries to the local resolver."))
158 e1.default = e1.disabled
161 e2 = e:option(Flag, "adb_forcesrt", translate("Force Overall Sort"),
162 translate("Enable memory intense overall sort / duplicate removal on low memory devices (< 64 MB RAM)"))
163 e2.default = e2.disabled
166 e3 = e:option(Flag, "adb_manmode", translate("Manual mode"),
167 translate("Do not automatically update blocklists during startup, use blocklist backups instead."))
168 e3.default = e3.disabled
171 e4 = e:option(Flag, "adb_backup", translate("Enable blocklist backup"),
172 translate("Create compressed blocklist backups, they will be used in case of download errors or during startup in manual mode."))
173 e4.default = e4.disabled
176 e5 = e:option(Value, "adb_backupdir", translate("Backup directory"))
177 e5.datatype = "directory"