edf5df7ec99b5eba802860b4acf15460021b1a3a
[project/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 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:value("dnscrypt-proxy","dnscrypt-proxy (/tmp)")
32 o2.default = "dnsmasq (/tmp)"
33 o2.rmempty = false
34
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")
38 o3:value("wget")
39 o3:value("curl")
40 o3:value("aria2c")
41 o3:value("wget-nossl", "wget-nossl (noSSL)")
42 o3:value("busybox", "wget-busybox (noSSL)")
43 o3.default = "uclient-fetch"
44 o3.rmempty = false
45
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."))
49 o4:value("none")
50 o4:value("timed")
51 if dump then
52 local i, v
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.. ")")
57 end
58 end
59 end
60 o4.rmempty = false
61
62 -- Runtime information
63
64 ds = s:option(DummyValue, "_dummy")
65 ds.template = "adblock/runtime"
66
67 -- Blocklist table
68
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"
72
73 name = bl:option(Flag, "enabled", translate("Enabled"))
74 name.rmempty = false
75
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")
81 else
82 return translate("No")
83 end
84 end
85
86 des = bl:option(DummyValue, "adb_src_desc", translate("Description"))
87
88 cat = bl:option(DynamicList, "adb_src_cat", translate("Archive Categories"))
89 cat.datatype = "uciname"
90 cat.optional = true
91
92 -- Extra options
93
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."))
96
97 e1 = e:option(Flag, "adb_debug", translate("Verbose Debug Logging"),
98 translate("Enable verbose debug logging in case of any processing error."))
99 e1.rmempty = false
100
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."))
104 e2.disabled = "0"
105 e2.enabled = "10"
106 e2.rmempty = false
107
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."))
110 e3.rmempty = false
111
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."))
114 e4.rmempty = false
115
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"
120 e5.default = "/mnt"
121 e5.rmempty = true
122
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)
126 e6.rmempty = true
127
128 e7 = e:option(Value, "adb_maxqueue", translate("Max. Download Queue"),
129 translate("Size of the download queue to handle downloads &amp; 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."))
131 e7.default = 8
132 e7.datatype = "range(1,32)"
133 e7.rmempty = false
134
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."))
138 e8.rmempty = false
139
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"
144 e9.default = "/tmp"
145 e9.rmempty = true
146
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 &le; 0. ")
149 .. translate("Please note: this needs manual 'msmtp' package installation and setup."))
150 e10.rmempty = true
151
152 -- Optional Extra Options
153
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."))
157 e20.optional = true
158 e20.default = nil
159
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."))
163 e21.default = 0
164 e21.datatype = "min(0)"
165 e21.optional = true
166
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"
170 e22.optional = true
171
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"
176 e23.optional = true
177
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)"
181 e24.optional = true
182
183 e25 = e:option(Flag, "adb_dnsflush", translate("Flush DNS Cache"),
184 translate("Flush DNS Cache after adblock processing."))
185 e25.optional = true
186 e25.default = nil
187
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."))
191 if dump then
192 local i, v
193 for i, v in ipairs(dump.interface) do
194 if v.interface ~= "loopback" then
195 local device = v.device
196 if device then
197 e26:value(device)
198 end
199 end
200 end
201 end
202 e26:value("any")
203 e26.optional = true
204
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."))
208 e27.default = 53
209 e27.optional = true
210
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)"
215 e28.default = 5
216 e28.optional = true
217
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)"
222 e29.default = 1
223 e29.optional = true
224
225 e30 = e:option(Flag, "adb_forcesrt", translate("Force Overall Sort"),
226 translate("Enable memory intense overall sort / duplicate removal on low memory devices (&lt; 64 MB free RAM)"))
227 e30.optional = true
228 e30.default = nil
229
230 return m