1 -- Copyright 2017-2018 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 sys = require("luci.sys")
9 local devices = sys.net:devices()
11 m = Map("adblock", translate("Adblock"),
12 translate("Configuration of the adblock package to block ad/abuse domains by using DNS. ")
13 ..translatef("For further information "
14 .. "<a href=\"%s\" target=\"_blank\">"
15 .. "check the online documentation</a>", "https://github.com/openwrt/packages/blob/master/net/adblock/files/README.md"))
17 -- Main adblock options
19 s = m:section(NamedSection, "global", "adblock")
21 o1 = s:option(Flag, "adb_enabled", translate("Enable Adblock"))
22 o1.default = o1.disabled
25 o2 = s:option(ListValue, "adb_dns", translate("DNS Backend (DNS Directory)"),
26 translate("List of supported DNS backends with their default list export directory. ")
27 ..translate("To overwrite the default path use the 'DNS Directory' option in the extra section below."))
28 o2:value("dnsmasq", "dnsmasq (/tmp)")
29 o2:value("unbound", "unbound (/var/lib/unbound)")
30 o2:value("named", "named (/var/lib/bind)")
31 o2:value("kresd", "kresd (/etc/kresd)")
32 o2:value("dnscrypt-proxy","dnscrypt-proxy (/tmp)")
33 o2.default = "dnsmasq (/tmp)"
36 o3 = s:option(ListValue, "adb_fetchutil", translate("Download Utility"),
37 translate("List of supported and fully pre-configured download utilities."))
38 o3:value("uclient-fetch")
42 o3:value("wget-nossl", "wget-nossl (noSSL)")
43 o3:value("busybox", "wget-busybox (noSSL)")
44 o3.default = "uclient-fetch"
47 o4 = s:option(ListValue, "adb_trigger", translate("Startup Trigger"),
48 translate("List of available network interfaces. Usually the startup will be triggered by the 'wan' interface. ")
49 ..translate("Choose 'none' to disable automatic startups, 'timed' to use a classic timeout (default 30 sec.) or select another trigger interface."))
52 for _, dev in ipairs(devices) do
54 local iface = net:get_interface(dev)
56 iface = iface:get_networks() or {}
57 for k, v in pairs(iface) do
58 iface[k] = iface[k].sid
59 o4:value(iface[k], iface[k].. " (" ..dev.. ")")
66 -- Runtime information
68 ds = s:option(DummyValue, "_dummy")
69 ds.template = "adblock/runtime"
73 bl = m:section(TypedSection, "source", translate("Blocklist Sources"),
74 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!"))
75 bl.template = "adblock/blocklist"
77 name = bl:option(Flag, "enabled", translate("Enabled"))
80 ssl = bl:option(DummyValue, "adb_src", translate("SSL req."))
81 function ssl.cfgvalue(self, section)
82 local source = self.map:get(section, "adb_src")
83 if source and source:match("https://") then
84 return translate("Yes")
86 return translate("No")
90 des = bl:option(DummyValue, "adb_src_desc", translate("Description"))
92 cat = bl:option(DynamicList, "adb_src_cat", translate("Archive Categories"))
93 cat.datatype = "uciname"
98 e = m:section(NamedSection, "extra", "adblock", translate("Extra Options"),
99 translate("Options for further tweaking in case the defaults are not suitable for you."))
101 e1 = e:option(Flag, "adb_debug", translate("Verbose Debug Logging"),
102 translate("Enable verbose debug logging in case of any processing error."))
105 e2 = e:option(Flag, "adb_nice", translate("Low Priority Service"),
106 translate("Set the nice level to 'low priority' and the adblock background processing will take less resources from the system. ")
107 ..translate("This change requires a manual service stop/re-start to take effect."))
112 e3 = e:option(Flag, "adb_forcedns", translate("Force Local DNS"),
113 translate("Redirect all DNS queries from 'lan' zone to the local resolver, apply to udp and tcp protocol on ports 53, 853 and 5353."))
116 e4 = e:option(Flag, "adb_backup", translate("Enable Blocklist Backup"),
117 translate("Create compressed blocklist backups, they will be used in case of download errors or during startup in backup mode."))
120 e5 = e:option(Value, "adb_backupdir", translate("Backup Directory"),
121 translate("Target directory for adblock backups. Please use only a non-volatile disk, e.g. an external usb stick."))
122 e5:depends("adb_backup", 1)
123 e5.datatype = "directory"
127 e6 = e:option(Flag, "adb_backup_mode", translate("Backup Mode"),
128 translate("Do not automatically update blocklists during startup, use blocklist backups instead."))
129 e6:depends("adb_backup", 1)
132 e7 = e:option(Value, "adb_maxqueue", translate("Max. Download Queue"),
133 translate("Size of the download queue to handle downloads & list processing in parallel (default '8'). ")
134 ..translate("For further performance improvements you can raise this value, e.g. '8' or '16' should be safe."))
136 e7.datatype = "range(1,32)"
139 e8 = e:option(Flag, "adb_report", translate("Enable DNS Query Report"),
140 translate("Gather dns related network traffic via tcpdump to provide a DNS Query Report on demand. ")
141 ..translate("Please note: this needs manual 'tcpdump-mini' package installation."))
144 e9 = e:option(Value, "adb_repdir", translate("Report Directory"),
145 translate("Target directory for dns related report files. Please use preferably a non-volatile disk, e.g. an external usb stick."))
146 e9:depends("adb_report", 1)
147 e9.datatype = "directory"
151 e10 = e:option(Flag, "adb_notify", translate("Email Notification"),
152 translate("Send notification emails in case of a processing error or if domain count is ≤ 0. ")
153 .. translate("Please note: this needs manual 'msmtp' package installation and setup."))
156 -- Optional Extra Options
158 e20 = e:option(Flag, "adb_jail", translate("'Jail' Blocklist Creation"),
159 translate("Builds an additional 'Jail' list (/tmp/adb_list.jail) to block access to all domains except those listed in the whitelist file. ")
160 .. translate("You can use this restrictive blocklist e.g. for guest wifi or kidsafe configurations."))
164 e21 = e:option(Value, "adb_notifycnt", translate("Email Notification Count"),
165 translate("Raise the minimum email notification count, to get emails if the overall count is less or equal to the given limit (default 0), ")
166 .. translate("e.g. to receive an email notification with every adblock update set this value to 150000."))
168 e21.datatype = "min(0)"
171 e22 = e:option(Value, "adb_dnsdir", translate("DNS Directory"),
172 translate("Target directory for the generated blocklist 'adb_list.overall'."))
173 e22.datatype = "directory"
176 e23 = e:option(Value, "adb_whitelist", translate("Whitelist File"),
177 translate("Full path to the whitelist file."))
178 e23.datatype = "file"
179 e23.default = "/etc/adblock/adblock.whitelist"
182 e24 = e:option(Value, "adb_triggerdelay", translate("Trigger Delay"),
183 translate("Additional trigger delay in seconds before adblock processing begins."))
184 e24.datatype = "range(1,60)"
187 e25 = e:option(Flag, "adb_dnsflush", translate("Flush DNS Cache"),
188 translate("Flush DNS Cache after adblock processing."))
192 e26 = e:option(ListValue, "adb_repiface", translate("Report Interface"),
193 translate("Reporting interface used by tcpdump (default 'br-lan')."))
194 for _, dev in ipairs(devices) do
201 e28 = e:option(Value, "adb_repchunkcnt", translate("Report Chunk Count"),
202 translate("Report chunk count used by tcpdump (default '5')."))
203 e28.datatype = "range(1,10)"
206 e29 = e:option(Value, "adb_repchunksize", translate("Report Chunk Size"),
207 translate("Report chunk size used by tcpdump in MB (default '1')."))
208 e29.datatype = "range(1,10)"
211 e30 = e:option(Flag, "adb_forcesrt", translate("Force Overall Sort"),
212 translate("Enable memory intense overall sort / duplicate removal on low memory devices (< 64 MB free RAM)"))