Merge pull request #2983 from dibdot/adblock
[oweals/luci.git] / applications / luci-app-adblock / luasrc / model / cbi / adblock / overview_tab.lua
1 -- Copyright 2017-2019 Dirk Brenken (dev@brenken.org)
2 -- This is free software, licensed under the Apache License, Version 2.0
3
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", {})
9
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"))
15
16 -- Main adblock options
17
18 s = m:section(NamedSection, "global", "adblock")
19
20 o1 = s:option(Flag, "adb_enabled", translate("Enable Adblock"))
21 o1.default = o1.disabled
22 o1.rmempty = false
23
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)"
32 o2.rmempty = false
33
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"
41 o3.rmempty = false
42
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")
46 o4:value("wget")
47 o4:value("curl")
48 o4:value("aria2c")
49 o4:value("wget-nossl", "wget-nossl (noSSL)")
50 o4:value("busybox", "wget-busybox (noSSL)")
51 o4.default = "uclient-fetch"
52 o4.rmempty = false
53
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."))
57 o5:value("none")
58 o5:value("timed")
59 if dump then
60         local i, v
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.. ")")
65                 end
66         end
67 end
68 o5.rmempty = false
69
70 -- Runtime information
71
72 ds = s:option(DummyValue, "_dummy")
73 ds.template = "adblock/runtime"
74
75 -- Blocklist table
76
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"
80
81 name = bl:option(Flag, "enabled", translate("Enabled"))
82 name.rmempty = false
83
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")
89         else
90                 return translate("No")
91         end
92 end
93
94 des = bl:option(DummyValue, "adb_src_desc", translate("Description"))
95
96 cat = bl:option(DynamicList, "adb_src_cat", translate("Archive Categories"))
97 cat.datatype = "uciname"
98 cat.optional = true
99
100 -- Extra options
101
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."))
104
105 e1 = e:option(Flag, "adb_debug", translate("Verbose Debug Logging"),
106         translate("Enable verbose debug logging in case of any processing error."))
107 e1.rmempty = false
108
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."))
112 e2.disabled = "0"
113 e2.enabled = "10"
114 e2.rmempty = false
115
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."))
118 e3.rmempty = false
119
120 e4 = e:option(Value, "adb_maxqueue", translate("Max. Download Queue"),
121         translate("Size of the download queue to handle downloads &amp; 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."))
123 e4.default = 4
124 e4.datatype = "range(1,32)"
125 e4.rmempty = false
126
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"
131 e5.enabled = "true"
132 e5.rmempty = false
133
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."))
137 e6.rmempty = false
138
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"
143 e7.default = "/tmp"
144 e7.rmempty = true
145
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"
149 e8.default = "/tmp"
150 e8.rmempty = true
151
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 &le; 0. ")
154         .. translate("Please note: this needs manual 'msmtp' package installation and setup."))
155 e9.rmempty = true
156
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)
160 e10.rmempty = true
161
162 -- Optional Extra Options
163
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"
167 e20.optional = true
168
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"
173 e21.optional = true
174
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"
179 e22.optional = true
180
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)"
184 e23.optional = true
185
186 e24 = e:option(Flag, "adb_dnsflush", translate("Flush DNS Cache"),
187         translate("Flush DNS Cache after adblock processing."))
188 e24.optional = true
189 e24.default = nil
190
191 e25 = e:option(ListValue, "adb_repiface", translate("Report Interface"),
192         translate("Reporting interface used by tcpdump, set to 'any' for multiple interfaces (default 'br-lan'). ")
193         ..translate("This change requires a manual service stop/re-start to take effect."))
194 if dump then
195         local i, v
196         for i, v in ipairs(dump.interface) do
197                 if v.interface ~= "loopback" then
198                         local device = v.device
199                         if device then
200                                 e25:value(device)
201                         end
202                 end
203         end
204 end
205 e25:value("any")
206 e25.optional = true
207
208 e26 = e:option(Value, "adb_replisten", translate("Report Listen Port(s)"),
209         translate("Space separated list of reporting port(s) used by tcpdump (default: '53'). ")
210         ..translate("This change requires a manual service stop/re-start to take effect."))
211 e26.default = 53
212 e26.optional = true
213
214 e27 = e:option(Value, "adb_repchunkcnt", translate("Report Chunk Count"),
215         translate("Report chunk count used by tcpdump (default '5'). ")
216         ..translate("This change requires a manual service stop/re-start to take effect."))
217 e27.datatype = "range(1,10)"
218 e27.default = 5
219 e27.optional = true
220
221 e28 = e:option(Value, "adb_repchunksize", translate("Report Chunk Size"),
222         translate("Report chunk size used by tcpdump in MB (default '1'). ")
223         ..translate("This change requires a manual service stop/re-start to take effect."))
224 e28.datatype = "range(1,10)"
225 e28.default = 1
226 e28.optional = true
227
228 e29 = e:option(Value, "adb_msender", translate("E-Mail Sender Address"),
229         translate("Sender address for adblock notification E-Mails."))
230 e29.default = "no-reply@adblock"
231 e29.optional = true
232
233 e30 = e:option(Value, "adb_mtopic", translate("E-Mail Topic"),
234         translate("Topic for adblock notification E-Mails."))
235 e30.default = "adblock notification"
236 e30.optional = true
237
238 e31 = e:option(Value, "adb_mprofile", translate("E-Mail Profile"),
239         translate("Mail profile used in 'msmtp' for adblock notification E-Mails."))
240 e31.default = "adb_notify"
241 e31.optional = true
242
243 e32 = e:option(Value, "adb_mcnt", translate("E-Mail Notification Count"),
244         translate("Raise the minimum notification count, to get E-Mails if the overall count is less or equal to the given limit (default 0), ")
245         .. translate("e.g. to receive an E-Mail notification with every adblock run set this value to 200000."))
246 e32.default = 0
247 e32.datatype = "min(0)"
248 e32.optional = true
249
250 return m