Merge pull request #2380 from dibdot/adblock
[oweals/luci.git] / applications / luci-app-adblock / luasrc / model / cbi / adblock / overview_tab.lua
1 -- Copyright 2017-2018 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 sys     = require("luci.sys")
9 local devices = sys.net:devices()
10
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"))
16
17 -- Main adblock options
18
19 s = m:section(NamedSection, "global", "adblock")
20
21 o1 = s:option(Flag, "adb_enabled", translate("Enable Adblock"))
22 o1.default = o1.disabled
23 o1.rmempty = false
24
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)"
34 o2.rmempty = false
35
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")
39 o3:value("wget")
40 o3:value("curl")
41 o3:value("aria2c")
42 o3:value("wget-nossl", "wget-nossl (noSSL)")
43 o3:value("busybox", "wget-busybox (noSSL)")
44 o3.default = "uclient-fetch"
45 o3.rmempty = false
46
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."))
50 o4:value("none")
51 o4:value("timed")
52 for _, dev in ipairs(devices) do
53         if dev ~= "lo" then
54                 local iface = net:get_interface(dev)
55                 if iface then
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.. ")")
60                         end
61                 end
62         end
63 end
64 o4.rmempty = false
65
66 -- Runtime information
67
68 ds = s:option(DummyValue, "_dummy")
69 ds.template = "adblock/runtime"
70
71 -- Blocklist table
72
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"
76
77 name = bl:option(Flag, "enabled", translate("Enabled"))
78 name.rmempty = false
79
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")
85         else
86                 return translate("No")
87         end
88 end
89
90 des = bl:option(DummyValue, "adb_src_desc", translate("Description"))
91
92 cat = bl:option(DynamicList, "adb_src_cat", translate("Archive Categories"))
93 cat.datatype = "uciname"
94 cat.optional = true
95
96 -- Extra options
97
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."))
100
101 e1 = e:option(Flag, "adb_debug", translate("Verbose Debug Logging"),
102         translate("Enable verbose debug logging in case of any processing error."))
103 e1.rmempty = false
104
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."))
108 e2.disabled = "0"
109 e2.enabled = "10"
110 e2.rmempty = false
111
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."))
114 e3.rmempty = false
115
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."))
118 e4.rmempty = false
119
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"
124 e5.default = "/mnt"
125 e5.rmempty = true
126
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)
130 e6.rmempty = true
131
132 e7 = e:option(Value, "adb_maxqueue", translate("Max. Download Queue"),
133         translate("Size of the download queue to handle downloads &amp; 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."))
135 e7.default = 8
136 e7.datatype = "range(1,32)"
137 e7.rmempty = false
138
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."))
142 e8.rmempty = false
143
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"
148 e9.default = "/tmp"
149 e9.rmempty = true
150
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 &le; 0. ")
153         .. translate("Please note: this needs manual 'msmtp' package installation and setup."))
154 e10.rmempty = true
155
156 -- Optional Extra Options
157
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."))
161 e20.optional = true
162 e20.default = nil
163
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."))
167 e21.default = 0
168 e21.datatype = "min(0)"
169 e21.optional = true
170
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"
174 e22.optional = true
175
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"
180 e23.optional = true
181
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)"
185 e24.optional = true
186
187 e25 = e:option(Flag, "adb_dnsflush", translate("Flush DNS Cache"),
188         translate("Flush DNS Cache after adblock processing."))
189 e25.optional = true
190 e25.default = nil
191
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
195         if dev ~= "lo" then
196                 e26:value(dev)
197         end
198 end
199 e26.optional = true
200
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)"
204 e28.optional = true
205
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)"
209 e29.optional = true
210
211 e30 = e:option(Flag, "adb_forcesrt", translate("Force Overall Sort"),
212         translate("Enable memory intense overall sort / duplicate removal on low memory devices (&lt; 64 MB free RAM)"))
213 e30.optional = true
214 e30.default = nil
215
216 return m