Merge pull request #1786 from musashino205/l10n/pagekite-add-ja
[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 local json = require("luci.jsonc")
10 local adbinput = uci:get("adblock", "global", "adb_rtfile") or "/tmp/adb_runtime.json"
11
12 if not uci:get("adblock", "extra") then
13 m = SimpleForm("", nil, translate("Please update your adblock config file to use this package.<br />")
14 .. translatef("During opkg package installation use the '--force-maintainer' option to overwrite the pre-existing config file or download a fresh default config from "
15 .. "<a href=\"%s\" target=\"_blank\">"
16 .. "here</a>", "https://raw.githubusercontent.com/openwrt/packages/master/net/adblock/files/adblock.conf"))
17 m.submit = false
18 m.reset = false
19 return m
20 end
21
22 m = Map("adblock", translate("Adblock"),
23 translate("Configuration of the adblock package to block ad/abuse domains by using DNS. ")
24 .. translatef("For further information "
25 .. "<a href=\"%s\" target=\"_blank\">"
26 .. "check the online documentation</a>", "https://github.com/openwrt/packages/blob/master/net/adblock/files/README.md"))
27 m.apply_on_parse = true
28
29 function m.on_apply(self)
30 luci.sys.call("/etc/init.d/adblock reload >/dev/null 2>&1")
31 luci.http.redirect(luci.dispatcher.build_url("admin", "services", "adblock"))
32 end
33
34 -- Main adblock options
35
36 s = m:section(NamedSection, "global", "adblock")
37
38 local parse = json.parse(fs.readfile(adbinput) or "")
39 if parse then
40 status = parse.data.adblock_status
41 version = parse.data.adblock_version
42 domains = parse.data.overall_domains
43 fetch = parse.data.fetch_utility
44 backend = parse.data.dns_backend
45 rundate = parse.data.last_rundate
46 end
47
48 o1 = s:option(Flag, "adb_enabled", translate("Enable Adblock"))
49 o1.default = o1.disabled
50 o1.rmempty = false
51
52 btn = s:option(Button, "", translate("Suspend / Resume Adblock"))
53 if parse and status == "enabled" then
54 btn.inputtitle = translate("Suspend")
55 btn.inputstyle = "reset"
56 btn.disabled = false
57 function btn.write()
58 luci.sys.call("/etc/init.d/adblock suspend >/dev/null 2>&1")
59 luci.http.redirect(luci.dispatcher.build_url("admin", "services", "adblock"))
60 end
61 elseif parse and status == "paused" then
62 btn.inputtitle = translate("Resume")
63 btn.inputstyle = "apply"
64 btn.disabled = false
65 function btn.write()
66 luci.sys.call("/etc/init.d/adblock resume >/dev/null 2>&1")
67 luci.http.redirect(luci.dispatcher.build_url("admin", "services", "adblock"))
68 end
69 else
70 btn.inputtitle = translate("-------")
71 btn.inputstyle = "button"
72 btn.disabled = true
73 end
74
75 o2 = s:option(ListValue, "adb_dns", translate("DNS Backend (DNS Directory)"),
76 translate("List of supported DNS backends with their default list export directory.<br />")
77 .. translate("To overwrite the default path use the 'DNS Directory' option in the extra section below."))
78 o2:value("dnsmasq", "dnsmasq (/tmp)")
79 o2:value("unbound", "unbound (/var/lib/unbound)")
80 o2:value("named", "named (/var/lib/bind)")
81 o2:value("kresd", "kresd (/etc/kresd)")
82 o2:value("dnscrypt-proxy","dnscrypt-proxy (/tmp)")
83 o2.default = "dnsmasq (/tmp)"
84 o2.rmempty = false
85
86 o3 = s:option(ListValue, "adb_fetchutil", translate("Download Utility"),
87 translate("List of supported and fully pre-configured download utilities."))
88 o3:value("uclient-fetch")
89 o3:value("wget")
90 o3:value("curl")
91 o3:value("aria2c")
92 o3:value("wget-nossl", "wget-nossl (noSSL)")
93 o3:value("busybox", "wget-busybox (noSSL)")
94 o3.default = "uclient-fetch"
95 o3.rmempty = false
96
97 o4 = s:option(ListValue, "adb_trigger", translate("Startup Trigger"),
98 translate("List of available network interfaces. Usually the startup will be triggered by the 'wan' interface.<br />")
99 .. translate("Choose 'none' to disable automatic startups, 'timed' to use a classic timeout (default 30 sec.) or select another trigger interface."))
100 o4:value("none")
101 o4:value("timed")
102 if dump then
103 local i, v
104 for i, v in ipairs(dump.interface) do
105 if v.interface ~= "loopback" then
106 o4:value(v.interface)
107 end
108 end
109 end
110 o4.rmempty = false
111
112 -- Runtime information
113
114 ds = m:section(NamedSection, "global", "adblock", translate("Runtime Information"))
115
116 dv1 = ds:option(DummyValue, "", translate("Adblock Status"))
117 dv1.template = "adblock/runtime"
118 if parse == nil then
119 dv1.value = translate("n/a")
120 else
121 if status == "error" then
122 dv1.value = translate("error")
123 elseif status == "disabled" then
124 dv1.value = translate("disabled")
125 elseif status == "paused" then
126 dv1.value = translate("paused")
127 elseif status == "running" then
128 dv1.value = translate("running")
129 else
130 dv1.value = translate("enabled")
131 end
132 end
133
134 dv2 = ds:option(DummyValue, "", translate("Adblock Version"))
135 dv2.template = "adblock/runtime"
136 if parse == nil then
137 dv2.value = translate("n/a")
138 else
139 dv2.value = version
140 end
141
142 dv3 = ds:option(DummyValue, "", translate("Download Utility (SSL Library)"),
143 translate("For SSL protected blocklist sources you need a suitable SSL library, e.g. 'libustream-ssl' or 'built-in'."))
144 dv3.template = "adblock/runtime"
145 if parse == nil then
146 dv3.value = translate("n/a")
147 else
148 dv3.value = fetch
149 end
150
151 dv4 = ds:option(DummyValue, "", translate("DNS Backend (DNS Directory)"))
152 dv4.template = "adblock/runtime"
153 if parse == nil then
154 dv4.value = translate("n/a")
155 else
156 dv4.value = backend
157 end
158
159 dv5 = ds:option(DummyValue, "", translate("Overall Domains"))
160 dv5.template = "adblock/runtime"
161 if parse == nil then
162 dv5.value = translate("n/a")
163 else
164 dv5.value = domains
165 end
166
167 dv6 = ds:option(DummyValue, "", translate("Last Run"))
168 dv6.template = "adblock/runtime"
169 if parse == nil then
170 dv6.value = translate("n/a")
171 else
172 dv6.value = rundate
173 end
174
175 -- Blocklist table
176
177 bl = m:section(TypedSection, "source", translate("Blocklist Sources"),
178 translate("Available blocklist sources. ")
179 .. translate("List URLs and Shallalist category selections are configurable in the 'Advanced' section.<br />")
180 .. translate("Caution: To prevent OOM exceptions on low memory devices with less than 64 MB free RAM, please do not select more than five blocklist sources!"))
181 bl.template = "adblock/blocklist"
182
183 name = bl:option(Flag, "enabled", translate("Enabled"))
184 name.rmempty = false
185
186 ssl = bl:option(DummyValue, "adb_src", translate("SSL req."))
187 function ssl.cfgvalue(self, section)
188 local source = self.map:get(section, "adb_src")
189 if source and source:match("https://") then
190 return translate("Yes")
191 else
192 return translate("No")
193 end
194 end
195 des = bl:option(DummyValue, "adb_src_desc", translate("Description"))
196
197 -- Extra options
198
199 e = m:section(NamedSection, "extra", "adblock", translate("Extra Options"),
200 translate("Options for further tweaking in case the defaults are not suitable for you."))
201
202 e1 = e:option(Flag, "adb_debug", translate("Verbose Debug Logging"),
203 translate("Enable verbose debug logging in case of any processing error."))
204 e1.default = e1.disabled
205 e1.rmempty = false
206
207 e2 = e:option(Flag, "adb_forcedns", translate("Force Local DNS"),
208 translate("Redirect all DNS queries from 'lan' zone to the local resolver."))
209 e2.default = e2.disabled
210 e2.rmempty = false
211
212 e3 = e:option(Flag, "adb_forcesrt", translate("Force Overall Sort"),
213 translate("Enable memory intense overall sort / duplicate removal on low memory devices (&lt; 64 MB free RAM)"))
214 e3.default = e3.disabled
215 e3.rmempty = false
216
217 e4 = e:option(Flag, "adb_backup", translate("Enable Blocklist Backup"),
218 translate("Create compressed blocklist backups, they will be used in case of download errors or during startup in backup mode."))
219 e4.default = e4.disabled
220 e4.rmempty = false
221
222 e5 = e:option(Value, "adb_backupdir", translate("Backup Directory"),
223 translate("Target directory for adblock backups. Please use only non-volatile disks, e.g. an external usb stick."))
224 e5:depends("adb_backup", 1)
225 e5.datatype = "directory"
226 e5.default = "/mnt"
227 e5.rmempty = true
228
229 e6 = e:option(Flag, "adb_backup_mode", translate("Backup Mode"),
230 translate("Do not automatically update blocklists during startup, use blocklist backups instead."))
231 e6:depends("adb_backup", 1)
232 e6.default = e6.disabled
233 e6.rmempty = true
234
235 e7 = e:option(Value, "adb_maxqueue", translate("Max. Download Queue"),
236 translate("Size of the download queue to handle downloads &amp; list processing in parallel (default '4').<br />")
237 .. translate("For further performance improvements you can raise this value, e.g. '8' or '16' should be safe."))
238 e7.default = 4
239 e7.datatype = "range(1,32)"
240 e7.rmempty = false
241
242 e8 = e:option(Flag, "adb_jail", translate("'Jail' Blocklist Creation"),
243 translate("Builds an additional 'Jail' list (/tmp/adb_list.jail) to block access to all domains except those listed in the whitelist file.<br />")
244 .. translate("You can use this restrictive blocklist manually e.g. for guest wifi or kidsafe configurations."))
245 e8.default = e8.disabled
246 e8.rmempty = true
247
248 e9 = e:option(Flag, "adb_dnsflush", translate("Flush DNS Cache"),
249 translate("Flush DNS Cache after adblock processing."))
250 e9.default = e9.disabled
251 e9.rmempty = true
252
253 e10 = e:option(Flag, "adb_notify", translate("Email Notification"),
254 translate("Send notification emails in case of a processing error or if domain count is &le; 0.<br />")
255 .. translate("Please note: this needs additional 'msmtp' package installation and setup."))
256 e10.default = e10.disabled
257 e10.rmempty = true
258
259 e11 = e:option(Value, "adb_notifycnt", translate("Email Notification Count"),
260 translate("Raise the minimum email notification count, to get emails if the overall count is less or equal to the given limit (default 0),<br />")
261 .. translate("e.g. to receive an email notification with every adblock update set this value to 150000."))
262 e11.default = 0
263 e11.datatype = "min(0)"
264 e11.optional = true
265
266 e12 = e:option(Value, "adb_dnsdir", translate("DNS Directory"),
267 translate("Target directory for the generated blocklist 'adb_list.overall'."))
268 e12.datatype = "directory"
269 e12.optional = true
270
271 e13 = e:option(Value, "adb_whitelist", translate("Whitelist File"),
272 translate("Full path to the whitelist file."))
273 e13.datatype = "file"
274 e13.default = "/etc/adblock/adblock.whitelist"
275 e13.optional = true
276
277 e14 = e:option(Value, "adb_triggerdelay", translate("Trigger Delay"),
278 translate("Additional trigger delay in seconds before adblock processing begins."))
279 e14.datatype = "range(1,60)"
280 e14.optional = true
281
282 return m