1 -- Copyright 2017-2019 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("luci.model.uci").cursor()
6 local util = require("luci.util")
7 local net = require "luci.model.network".init()
8 local dump = util.ubus("network.interface", "dump", {})
10 m = Map("adblock", translate("Adblock"),
11 translate("Configuration of the adblock package to block ad/abuse domains by using DNS. ")
12 ..translatef("For further information "
13 .. "<a href=\"%s\" target=\"_blank\">"
14 .. "check the online documentation</a>", "https://github.com/openwrt/packages/blob/master/net/adblock/files/README.md"))
16 -- Main adblock options
18 s = m:section(NamedSection, "global", "adblock")
20 o1 = s:option(Flag, "adb_enabled", translate("Enable Adblock"))
21 o1.default = o1.disabled
24 o2 = s:option(ListValue, "adb_dns", translate("DNS Backend (DNS Directory)"),
25 translate("List of supported DNS backends with their default list export directory. ")
26 ..translate("To overwrite the default path use the 'DNS Directory' option in the extra section below."))
27 o2:value("dnsmasq", "dnsmasq (/tmp)")
28 o2:value("unbound", "unbound (/var/lib/unbound)")
29 o2:value("named", "named (/var/lib/bind)")
30 o2:value("kresd", "kresd (/etc/kresd)")
31 o2.default = "dnsmasq (/tmp)"
34 o3 = s:option(ListValue, "adb_dnsvariant", translate("DNS Blocking Variant"),
35 translate("List of supported DNS blocking variants. By default 'nxdomain' will be used for all DNS backends. ")
36 ..translate("Dnsmasq also supports 'null' block variants, which may provide better response times."))
37 o3:value("nxdomain", "nxdomain, all DNS backends")
38 o3:value("null (IPv4)", "null (IPv4), dnsmasq only")
39 o3:value("null (IPv4/IPv6)", "null (IPv4/IPv6), dnsmasq only")
40 o3.default = "nxdomain, all DNS backends"
43 o4 = s:option(ListValue, "adb_fetchutil", translate("Download Utility"),
44 translate("List of supported and fully pre-configured download utilities."))
45 o4:value("uclient-fetch")
49 o4:value("wget-nossl", "wget-nossl (noSSL)")
50 o4:value("busybox", "wget-busybox (noSSL)")
51 o4.default = "uclient-fetch"
54 o5 = s:option(ListValue, "adb_trigger", translate("Startup Trigger"),
55 translate("List of available network interfaces. Usually the startup will be triggered by the 'wan' interface. ")
56 ..translate("Choose 'none' to disable automatic startups, 'timed' to use a classic timeout (default 30 sec.) or select another trigger interface."))
61 for i, v in ipairs(dump.interface) do
62 if v.interface ~= "loopback" then
63 local device = v.l3_device or v.device or "-"
64 o5:value(v.interface, v.interface.. " (" ..device.. ")")
70 -- Runtime information
72 ds = s:option(DummyValue, "_dummy")
73 ds.template = "adblock/runtime"
77 bl = m:section(TypedSection, "source", translate("Blocklist Sources"),
78 translate("<b>Caution:</b> To prevent OOM exceptions on low memory devices with less than 64 MB free RAM, please only select a few of them!"))
79 bl.template = "adblock/blocklist"
81 name = bl:option(Flag, "enabled", translate("Enabled"))
84 ssl = bl:option(DummyValue, "adb_src", translate("SSL req."))
85 function ssl.cfgvalue(self, section)
86 local source = self.map:get(section, "adb_src")
87 if source and source:match("https://") then
88 return translate("Yes")
90 return translate("No")
94 des = bl:option(DummyValue, "adb_src_desc", translate("Description"))
96 cat = bl:option(DynamicList, "adb_src_cat", translate("Archive Categories"))
97 cat.datatype = "uciname"
102 e = m:section(NamedSection, "extra", "adblock", translate("Extra Options"),
103 translate("Options for further tweaking in case the defaults are not suitable for you."))
105 e1 = e:option(Flag, "adb_debug", translate("Verbose Debug Logging"),
106 translate("Enable verbose debug logging in case of any processing error."))
109 e2 = e:option(Flag, "adb_nice", translate("Low Priority Service"),
110 translate("Set the nice level to 'low priority' and the adblock background processing will take fewer resources from the system. ")
111 ..translate("This change requires a manual service stop/re-start to take effect."))
116 e3 = e:option(Flag, "adb_forcedns", translate("Force Local DNS"),
117 translate("Redirect all DNS queries from 'lan' zone to the local resolver, applies to udp and tcp protocol on ports 53, 853 and 5353."))
120 e4 = e:option(Value, "adb_maxqueue", translate("Max. Download Queue"),
121 translate("Size of the download queue to handle downloads & list processing in parallel (default '4'). ")
122 ..translate("For further performance improvements you can raise this value, e.g. '8' or '16' should be safe."))
124 e4.datatype = "range(1,32)"
127 e5 = e:option(Flag, "adb_dnsfilereset", translate("DNS File Reset"),
128 translate("Resets the final DNS blockfile 'adb_list.overall' after loading through the DNS backend. ")
129 ..translate("This option saves an enormous amount of storage space, but starts a small ubus/adblock monitor in the background."))
130 e5.disabled = "false"
134 e6 = e:option(Flag, "adb_report", translate("DNS Query Report"),
135 translate("Gather dns related network traffic via tcpdump to provide a DNS Query Report on demand. ")
136 ..translate("Please note: this needs manual 'tcpdump-mini' package installation."))
139 e7 = e:option(Value, "adb_repdir", translate("Report Directory"),
140 translate("Target directory for dns related report files. Default is '/tmp', please use preferably a non-volatile disk if available."))
141 e7:depends("adb_report", 1)
142 e7.datatype = "directory"
146 e8 = e:option(Value, "adb_backupdir", translate("Backup Directory"),
147 translate("Target directory for adblock source backups. Default is '/tmp', please use preferably a non-volatile disk if available."))
148 e8.datatype = "directory"
152 e9 = e:option(Flag, "adb_mail", translate("E-Mail Notification"),
153 translate("Send notification E-Mails in case of a processing error or if domain count is ≤ 0. ")
154 .. translate("Please note: this needs manual 'msmtp' package installation and setup."))
157 e10 = e:option(Value, "adb_mreceiver", translate("E-Mail Receiver Address"),
158 translate("Receiver address for adblock notification E-Mails."))
159 e10:depends("adb_mail", 1)
162 -- Optional Extra Options
164 e20 = e:option(Value, "adb_dnsdir", translate("DNS Directory"),
165 translate("Target directory for the generated blocklist 'adb_list.overall'."))
166 e20.datatype = "directory"
169 e21 = e:option(Value, "adb_blacklist", translate("Blacklist File"),
170 translate("Full path to the blacklist file."))
171 e21.datatype = "file"
172 e21.default = "/etc/adblock/adblock.blacklist"
175 e22 = e:option(Value, "adb_whitelist", translate("Whitelist File"),
176 translate("Full path to the whitelist file."))
177 e22.datatype = "file"
178 e22.default = "/etc/adblock/adblock.whitelist"
181 e23 = e:option(Value, "adb_triggerdelay", translate("Trigger Delay"),
182 translate("Additional trigger delay in seconds before adblock processing begins."))
183 e23.datatype = "range(1,60)"
186 e24 = e:option(Value, "adb_maxtld", translate("TLD Compression Threshold"),
187 translate("Disable the toplevel domain compression, if the number of blocked domains is greater than this threshold."))
188 e24.datatype = "min(0)"
192 e25 = e:option(Value, "adb_portlist", translate("Local FW/DNS Ports"),
193 translate("Space separated list of firewall ports which should be redirected locally."))
194 e25.default = "53 853 5353"
197 e26 = e:option(Flag, "adb_dnsinotify", translate("DNS Inotify"),
198 translate("Disable adblock triggered restarts and the 'DNS File Reset' for dns backends with autoload features."))
203 e27 = e:option(Flag, "adb_dnsflush", translate("Flush DNS Cache"),
204 translate("Flush DNS Cache after adblock processing."))
208 e28 = e:option(ListValue, "adb_repiface", translate("Report Interface"),
209 translate("Reporting interface used by tcpdump, set to 'any' for multiple interfaces (default 'br-lan'). ")
210 ..translate("This change requires a manual service stop/re-start to take effect."))
213 for i, v in ipairs(dump.interface) do
214 if v.interface ~= "loopback" then
215 local device = v.device
225 e29 = e:option(Value, "adb_replisten", translate("Report Listen Port(s)"),
226 translate("Space separated list of reporting port(s) used by tcpdump (default: '53'). ")
227 ..translate("This change requires a manual service stop/re-start to take effect."))
231 e30 = e:option(Value, "adb_repchunkcnt", translate("Report Chunk Count"),
232 translate("Report chunk count used by tcpdump (default '5'). ")
233 ..translate("This change requires a manual service stop/re-start to take effect."))
234 e30.datatype = "range(1,10)"
238 e31 = e:option(Value, "adb_repchunksize", translate("Report Chunk Size"),
239 translate("Report chunk size used by tcpdump in MB (default '1'). ")
240 ..translate("This change requires a manual service stop/re-start to take effect."))
241 e31.datatype = "range(1,10)"
245 e32 = e:option(Value, "adb_msender", translate("E-Mail Sender Address"),
246 translate("Sender address for adblock notification E-Mails."))
247 e32.default = "no-reply@adblock"
250 e33 = e:option(Value, "adb_mtopic", translate("E-Mail Topic"),
251 translate("Topic for adblock notification E-Mails."))
252 e33.default = "adblock notification"
255 e34 = e:option(Value, "adb_mprofile", translate("E-Mail Profile"),
256 translate("Mail profile used in 'msmtp' for adblock notification E-Mails."))
257 e34.default = "adb_notify"
260 e35 = e:option(Value, "adb_mcnt", translate("E-Mail Notification Count"),
261 translate("Raise the minimum notification count, to get E-Mails if the overall count is less or equal to the given limit (default 0), ")
262 .. translate("e.g. to receive an E-Mail notification with every adblock run set this value to 200000."))
264 e35.datatype = "min(0)"