luci-app-adblock: sync with adblock 3.5.4
[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 sys = require("luci.sys")
7 local util = require("luci.util")
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 function m.on_apply(self)
17 luci.sys.call("/etc/init.d/adblock reload >/dev/null 2>&1")
18 end
19
20 -- Main adblock options
21
22 s = m:section(NamedSection, "global", "adblock")
23
24 o1 = s:option(Flag, "adb_enabled", translate("Enable Adblock"))
25 o1.default = o1.disabled
26 o1.rmempty = false
27
28 o2 = s:option(ListValue, "adb_dns", translate("DNS Backend (DNS Directory)"),
29 translate("List of supported DNS backends with their default list export directory. ")
30 .. translate("To overwrite the default path use the 'DNS Directory' option in the extra section below."))
31 o2:value("dnsmasq", "dnsmasq (/tmp)")
32 o2:value("unbound", "unbound (/var/lib/unbound)")
33 o2:value("named", "named (/var/lib/bind)")
34 o2:value("kresd", "kresd (/etc/kresd)")
35 o2:value("dnscrypt-proxy","dnscrypt-proxy (/tmp)")
36 o2.default = "dnsmasq (/tmp)"
37 o2.rmempty = false
38
39 o3 = s:option(ListValue, "adb_fetchutil", translate("Download Utility"),
40 translate("List of supported and fully pre-configured download utilities."))
41 o3:value("uclient-fetch")
42 o3:value("wget")
43 o3:value("curl")
44 o3:value("aria2c")
45 o3:value("wget-nossl", "wget-nossl (noSSL)")
46 o3:value("busybox", "wget-busybox (noSSL)")
47 o3.default = "uclient-fetch"
48 o3.rmempty = false
49
50 o4 = s:option(ListValue, "adb_trigger", translate("Startup Trigger"),
51 translate("List of available network interfaces. Usually the startup will be triggered by the 'wan' interface. ")
52 .. translate("Choose 'none' to disable automatic startups, 'timed' to use a classic timeout (default 30 sec.) or select another trigger interface."))
53 o4:value("none")
54 o4:value("timed")
55 if dump then
56 local i, v
57 for i, v in ipairs(dump.interface) do
58 if v.interface ~= "loopback" then
59 o4:value(v.interface)
60 end
61 end
62 end
63 o4.rmempty = false
64
65 -- Runtime information
66
67 ds = s:option(DummyValue, "_dummy")
68 ds.template = "adblock/runtime"
69
70 -- Blocklist table
71
72 bl = m:section(TypedSection, "source", translate("Blocklist Sources"),
73 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!"))
74 bl.template = "adblock/blocklist"
75
76 name = bl:option(Flag, "enabled", translate("Enabled"))
77 name.rmempty = false
78
79 ssl = bl:option(DummyValue, "adb_src", translate("SSL req."))
80 function ssl.cfgvalue(self, section)
81 local source = self.map:get(section, "adb_src")
82 if source and source:match("https://") then
83 return translate("Yes")
84 else
85 return translate("No")
86 end
87 end
88
89 des = bl:option(DummyValue, "adb_src_desc", translate("Description"))
90
91 cat = bl:option(DynamicList, "adb_src_cat", translate("Archive Categories"))
92 cat.datatype = "uciname"
93 cat.optional = true
94
95 -- Extra options
96
97 e = m:section(NamedSection, "extra", "adblock", translate("Extra Options"),
98 translate("Options for further tweaking in case the defaults are not suitable for you."))
99
100 e1 = e:option(Flag, "adb_debug", translate("Verbose Debug Logging"),
101 translate("Enable verbose debug logging in case of any processing error."))
102 e1.default = e1.disabled
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.default = e2.disabled
109 e2.disabled = "0"
110 e2.enabled = "10"
111 e2.rmempty = false
112
113 e3 = e:option(Flag, "adb_forcedns", translate("Force Local DNS"),
114 translate("Redirect all DNS queries from 'lan' zone to the local resolver, apply to udp and tcp protocol on ports 53, 853 and 5353."))
115 e3.default = e3.disabled
116 e3.rmempty = false
117
118 e4 = e:option(Flag, "adb_forcesrt", translate("Force Overall Sort"),
119 translate("Enable memory intense overall sort / duplicate removal on low memory devices (&lt; 64 MB free RAM)"))
120 e4.default = e4.disabled
121 e4.rmempty = false
122
123 e5 = e:option(Flag, "adb_backup", translate("Enable Blocklist Backup"),
124 translate("Create compressed blocklist backups, they will be used in case of download errors or during startup in backup mode."))
125 e5.default = e5.disabled
126 e5.rmempty = false
127
128 e6 = e:option(Value, "adb_backupdir", translate("Backup Directory"),
129 translate("Target directory for adblock backups. Please use only non-volatile disks, e.g. an external usb stick."))
130 e6:depends("adb_backup", 1)
131 e6.datatype = "directory"
132 e6.default = "/mnt"
133 e5.rmempty = true
134
135 e7 = e:option(Flag, "adb_backup_mode", translate("Backup Mode"),
136 translate("Do not automatically update blocklists during startup, use blocklist backups instead."))
137 e7:depends("adb_backup", 1)
138 e7.default = e7.disabled
139 e7.rmempty = true
140
141 e8 = e:option(Value, "adb_maxqueue", translate("Max. Download Queue"),
142 translate("Size of the download queue to handle downloads &amp; list processing in parallel (default '4'). ")
143 .. translate("For further performance improvements you can raise this value, e.g. '8' or '16' should be safe."))
144 e8.default = 4
145 e8.datatype = "range(1,32)"
146 e8.rmempty = false
147
148 e9 = e:option(Flag, "adb_jail", translate("'Jail' Blocklist Creation"),
149 translate("Builds an additional 'Jail' list (/tmp/adb_list.jail) to block access to all domains except those listed in the whitelist file. ")
150 .. translate("You can use this restrictive blocklist manually e.g. for guest wifi or kidsafe configurations."))
151 e9.default = e9.disabled
152 e9.rmempty = true
153
154 e9 = e:option(Flag, "adb_dnsflush", translate("Flush DNS Cache"),
155 translate("Flush DNS Cache after adblock processing."))
156 e9.default = e9.disabled
157 e9.rmempty = true
158
159 e10 = e:option(Flag, "adb_notify", translate("Email Notification"),
160 translate("Send notification emails in case of a processing error or if domain count is &le; 0. ")
161 .. translate("Please note: this needs additional 'msmtp' package installation and setup."))
162 e10.default = e10.disabled
163 e10.rmempty = true
164
165 e11 = e:option(Value, "adb_notifycnt", translate("Email Notification Count"),
166 translate("Raise the minimum email notification count, to get emails if the overall count is less or equal to the given limit (default 0), ")
167 .. translate("e.g. to receive an email notification with every adblock update set this value to 150000."))
168 e11.default = 0
169 e11.datatype = "min(0)"
170 e11.optional = true
171
172 e12 = e:option(Value, "adb_dnsdir", translate("DNS Directory"),
173 translate("Target directory for the generated blocklist 'adb_list.overall'."))
174 e12.datatype = "directory"
175 e12.optional = true
176
177 e13 = e:option(Value, "adb_whitelist", translate("Whitelist File"),
178 translate("Full path to the whitelist file."))
179 e13.datatype = "file"
180 e13.default = "/etc/adblock/adblock.whitelist"
181 e13.optional = true
182
183 e14 = e:option(Value, "adb_triggerdelay", translate("Trigger Delay"),
184 translate("Additional trigger delay in seconds before adblock processing begins."))
185 e14.datatype = "range(1,60)"
186 e14.optional = true
187
188 return m