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:value("dnscrypt-proxy","dnscrypt-proxy (/tmp)")
32 o2.default = "dnsmasq (/tmp)"
35 o3 = s:option(ListValue, "adb_fetchutil", translate("Download Utility"),
36 translate("List of supported and fully pre-configured download utilities."))
37 o3:value("uclient-fetch")
41 o3:value("wget-nossl", "wget-nossl (noSSL)")
42 o3:value("busybox", "wget-busybox (noSSL)")
43 o3.default = "uclient-fetch"
46 o4 = s:option(ListValue, "adb_trigger", translate("Startup Trigger"),
47 translate("List of available network interfaces. Usually the startup will be triggered by the 'wan' interface. ")
48 ..translate("Choose 'none' to disable automatic startups, 'timed' to use a classic timeout (default 30 sec.) or select another trigger interface."))
53 for i, v in ipairs(dump.interface) do
54 if v.interface ~= "loopback" then
55 local device = v.l3_device or v.device or "-"
56 o4:value(v.interface, v.interface.. " (" ..device.. ")")
62 -- Runtime information
64 ds = s:option(DummyValue, "_dummy")
65 ds.template = "adblock/runtime"
69 bl = m:section(TypedSection, "source", translate("Blocklist Sources"),
70 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!"))
71 bl.template = "adblock/blocklist"
73 name = bl:option(Flag, "enabled", translate("Enabled"))
76 ssl = bl:option(DummyValue, "adb_src", translate("SSL req."))
77 function ssl.cfgvalue(self, section)
78 local source = self.map:get(section, "adb_src")
79 if source and source:match("https://") then
80 return translate("Yes")
82 return translate("No")
86 des = bl:option(DummyValue, "adb_src_desc", translate("Description"))
88 cat = bl:option(DynamicList, "adb_src_cat", translate("Archive Categories"))
89 cat.datatype = "uciname"
94 e = m:section(NamedSection, "extra", "adblock", translate("Extra Options"),
95 translate("Options for further tweaking in case the defaults are not suitable for you."))
97 e1 = e:option(Flag, "adb_debug", translate("Verbose Debug Logging"),
98 translate("Enable verbose debug logging in case of any processing error."))
101 e2 = e:option(Flag, "adb_nice", translate("Low Priority Service"),
102 translate("Set the nice level to 'low priority' and the adblock background processing will take less resources from the system. ")
103 ..translate("This change requires a manual service stop/re-start to take effect."))
108 e3 = e:option(Flag, "adb_forcedns", translate("Force Local DNS"),
109 translate("Redirect all DNS queries from 'lan' zone to the local resolver, apply to udp and tcp protocol on ports 53, 853 and 5353."))
112 e4 = e:option(Flag, "adb_backup", translate("Enable Blocklist Backup"),
113 translate("Create compressed blocklist backups, they will be used in case of download errors or during startup in backup mode."))
116 e5 = e:option(Value, "adb_backupdir", translate("Backup Directory"),
117 translate("Target directory for adblock backups. Please use only a non-volatile disk, e.g. an external usb stick."))
118 e5:depends("adb_backup", 1)
119 e5.datatype = "directory"
123 e6 = e:option(Flag, "adb_backup_mode", translate("Backup Mode"),
124 translate("Do not automatically update blocklists during startup, use blocklist backups instead."))
125 e6:depends("adb_backup", 1)
128 e7 = e:option(Value, "adb_maxqueue", translate("Max. Download Queue"),
129 translate("Size of the download queue to handle downloads & list processing in parallel (default '8'). ")
130 ..translate("For further performance improvements you can raise this value, e.g. '8' or '16' should be safe."))
132 e7.datatype = "range(1,32)"
135 e8 = e:option(Flag, "adb_report", translate("Enable DNS Query Report"),
136 translate("Gather dns related network traffic via tcpdump to provide a DNS Query Report on demand. ")
137 ..translate("Please note: this needs manual 'tcpdump-mini' package installation."))
140 e9 = e:option(Value, "adb_repdir", translate("Report Directory"),
141 translate("Target directory for dns related report files. Please use preferably a non-volatile disk, e.g. an external usb stick."))
142 e9:depends("adb_report", 1)
143 e9.datatype = "directory"
147 e10 = e:option(Flag, "adb_notify", translate("Email Notification"),
148 translate("Send notification emails in case of a processing error or if domain count is ≤ 0. ")
149 .. translate("Please note: this needs manual 'msmtp' package installation and setup."))
152 -- Optional Extra Options
154 e20 = e:option(Flag, "adb_jail", translate("'Jail' Blocklist Creation"),
155 translate("Builds an additional 'Jail' list (/tmp/adb_list.jail) to block access to all domains except those listed in the whitelist file. ")
156 .. translate("You can use this restrictive blocklist e.g. for guest wifi or kidsafe configurations."))
160 e21 = e:option(Value, "adb_notifycnt", translate("Email Notification Count"),
161 translate("Raise the minimum email notification count, to get emails if the overall count is less or equal to the given limit (default 0), ")
162 .. translate("e.g. to receive an email notification with every adblock update set this value to 150000."))
164 e21.datatype = "min(0)"
167 e22 = e:option(Value, "adb_dnsdir", translate("DNS Directory"),
168 translate("Target directory for the generated blocklist 'adb_list.overall'."))
169 e22.datatype = "directory"
172 e23 = e:option(Value, "adb_whitelist", translate("Whitelist File"),
173 translate("Full path to the whitelist file."))
174 e23.datatype = "file"
175 e23.default = "/etc/adblock/adblock.whitelist"
178 e24 = e:option(Value, "adb_triggerdelay", translate("Trigger Delay"),
179 translate("Additional trigger delay in seconds before adblock processing begins."))
180 e24.datatype = "range(1,60)"
183 e25 = e:option(Flag, "adb_dnsflush", translate("Flush DNS Cache"),
184 translate("Flush DNS Cache after adblock processing."))
188 e26 = e:option(ListValue, "adb_repiface", translate("Report Interface"),
189 translate("Reporting interface used by tcpdump, set to 'any' for multiple interfaces (default 'br-lan'). ")
190 ..translate("This change requires a manual service stop/re-start to take effect."))
193 for i, v in ipairs(dump.interface) do
194 if v.interface ~= "loopback" then
195 local device = v.device
205 e27 = e:option(Value, "adb_replisten", translate("Report Listen Port(s)"),
206 translate("Space separated list of reporting port(s) used by tcpdump (default: '53'). ")
207 ..translate("This change requires a manual service stop/re-start to take effect."))
211 e28 = e:option(Value, "adb_repchunkcnt", translate("Report Chunk Count"),
212 translate("Report chunk count used by tcpdump (default '5'). ")
213 ..translate("This change requires a manual service stop/re-start to take effect."))
214 e28.datatype = "range(1,10)"
218 e29 = e:option(Value, "adb_repchunksize", translate("Report Chunk Size"),
219 translate("Report chunk size used by tcpdump in MB (default '1'). ")
220 ..translate("This change requires a manual service stop/re-start to take effect."))
221 e29.datatype = "range(1,10)"