luci-app-acme: Remove use_acme_server option since it's ignored by acme
[project/luci.git] / applications / luci-app-adblock-fast / htdocs / luci-static / resources / view / adblock-fast / overview.js
1 // Copyright 2023 MOSSDeF, Stan Grishin <stangri@melmac.ca>
2 // This code wouldn't have been possible without help from:
3 // - [@stokito](https://github.com/stokito)
4 // - [@vsviridov](https://github.com/vsviridov)
5
6 "use strict";
7 "require form";
8 "require view";
9 "require adblock-fast.status as adb";
10
11 var pkg = {
12 get Name() {
13 return "adblock-fast";
14 },
15 get URL() {
16 return "https://docs.openwrt.melmac.net/" + pkg.Name + "/";
17 },
18 humanFileSize: function (bytes, si = false, dp = 2) {
19 return `%${si ? 1000 : 1024}.${dp ?? 0}mB`.format(bytes);
20 },
21 isObjEmpty: function (obj) {
22 return Object.keys(obj).length === 0;
23 },
24 };
25
26 return view.extend({
27 load: function () {
28 return Promise.all([
29 L.resolveDefault(adb.getFileUrlFilesizes(pkg.Name), {}),
30 L.resolveDefault(adb.getPlatformSupport(pkg.Name), {}),
31 L.resolveDefault(L.uci.load(pkg.Name), {}),
32 L.resolveDefault(L.uci.load("dhcp"), {}),
33 L.resolveDefault(L.uci.load("smartdns"), {}),
34 ]);
35 },
36
37 render: function (data) {
38 var reply = {
39 sizes: (data[0] && data[0][pkg.Name] && data[0][pkg.Name]["sizes"]) || [],
40 platform: (data[1] && data[1][pkg.Name]) || {
41 ipset_installed: false,
42 nft_installed: false,
43 dnsmasq_installed: false,
44 dnsmasq_ipset_support: false,
45 dnsmasq_nftset_support: false,
46 smartdns_installed: false,
47 smartdns_ipset_support: false,
48 smartdns_nftset_support: false,
49 unbound_installed: false,
50 leds: [],
51 },
52 pkg: (!pkg.isObjEmpty(data[2]) && data[2]) || null,
53 dhcp: (!pkg.isObjEmpty(data[3]) && data[3]) || null,
54 smartdns: (!pkg.isObjEmpty(data[4]) && data[4]) || null,
55 };
56 var status, m, s1, s2, s3, o;
57
58 status = new adb.status();
59 m = new form.Map(pkg.Name, _("AdBlock-Fast - Configuration"));
60
61 s1 = m.section(form.NamedSection, "config", pkg.Name);
62 s1.tab("tab_basic", _("Basic Configuration"));
63 s1.tab("tab_advanced", _("Advanced Configuration"));
64
65 var text = _(
66 "DNS resolution option, see the %sREADME%s for details."
67 ).format(
68 '<a href="' + pkg.URL + '#dns-resolver-option" target="_blank">',
69 "</a>"
70 );
71 if (!reply.platform.dnsmasq_installed) {
72 text +=
73 "<br />" +
74 _("Please note that %s is not supported on this system.").format(
75 "<i>dnsmasq.addnhosts</i>"
76 );
77 text +=
78 "<br />" +
79 _("Please note that %s is not supported on this system.").format(
80 "<i>dnsmasq.conf</i>"
81 );
82 text +=
83 "<br />" +
84 _("Please note that %s is not supported on this system.").format(
85 "<i>dnsmasq.ipset</i>"
86 );
87 text +=
88 "<br />" +
89 _("Please note that %s is not supported on this system.").format(
90 "<i>dnsmasq.servers</i>"
91 );
92 } else {
93 if (!reply.platform.dnsmasq_ipset_support) {
94 text +=
95 "<br />" +
96 _("Please note that %s is not supported on this system.").format(
97 "<i>dnsmasq.ipset</i>"
98 );
99 }
100 if (!reply.platform.dnsmasq_nftset_support) {
101 text +=
102 "<br />" +
103 _("Please note that %s is not supported on this system.").format(
104 "<i>dnsmasq.nftset</i>"
105 );
106 }
107 }
108 if (!reply.platform.smartdns_installed) {
109 text =
110 text +
111 "<br />" +
112 _("Please note that %s is not supported on this system.").format(
113 "<i>smartdns.domainset</i>"
114 );
115 } else {
116 if (!reply.platform.smartdns_ipset_support) {
117 text +=
118 "<br />" +
119 _("Please note that %s is not supported on this system.").format(
120 "<i>smartdns.ipset</i>"
121 );
122 }
123 if (!reply.platform.smartdns_nftset_support) {
124 text +=
125 "<br />" +
126 _("Please note that %s is not supported on this system.").format(
127 "<i>smartdns.nftset</i>"
128 );
129 }
130 }
131 if (!reply.platform.unbound_installed) {
132 text =
133 text +
134 "<br />" +
135 _("Please note that %s is not supported on this system.").format(
136 "<i>unbound.adb_list</i>"
137 );
138 }
139
140 o = s1.taboption(
141 "tab_basic",
142 form.ListValue,
143 "dns",
144 _("DNS Service"),
145 text
146 );
147 if (reply.platform.dnsmasq_installed) {
148 o.value("dnsmasq.addnhosts", _("dnsmasq additional hosts"));
149 o.value("dnsmasq.conf", _("dnsmasq config"));
150 if (reply.platform.dnsmasq_ipset_support) {
151 o.value("dnsmasq.ipset", _("dnsmasq ipset"));
152 }
153 if (reply.platform.dnsmasq_nftset_support) {
154 o.value("dnsmasq.nftset", _("dnsmasq nft set"));
155 }
156 o.value("dnsmasq.servers", _("dnsmasq servers file"));
157 }
158 if (reply.platform.smartdns_installed) {
159 o.value("smartdns.domainset", _("smartdns domain set"));
160 if (reply.platform.smartdns_ipset_support) {
161 o.value("smartdns.ipset", _("smartdns ipset"));
162 }
163 if (reply.platform.smartdns_nftset_support) {
164 o.value("smartdns.nftset", _("smartdns nft set"));
165 }
166 }
167 if (reply.platform.unbound_installed) {
168 o.value("unbound.adb_list", _("unbound adblock list"));
169 }
170 o.default = "dnsmasq.servers";
171
172 o = s1.taboption(
173 "tab_basic",
174 form.Value,
175 "dnsmasq_config_file_url",
176 _("Dnsmasq Config File URL"),
177 _(
178 "URL to the external dnsmasq config file, see the %sREADME%s for details."
179 ).format(
180 '<a href="' + pkg.URL + '#dnsmasq_config_file_url" target="_blank">',
181 "</a>"
182 )
183 );
184 o.depends("dns", "dnsmasq.conf");
185
186 if (reply.platform.dnsmasq_installed && reply.dhcp) {
187 o = s1.taboption(
188 "tab_basic",
189 form.ListValue,
190 "dnsmasq_instance_option",
191 _("Use AdBlocking on the dnsmasq instance(s)"),
192 _(
193 "You can limit the AdBlocking to the specific dnsmasq instance(s) (%smore information%s)."
194 ).format(
195 '<a href="' + pkg.URL + "#dnsmasq_instance" + '" target="_blank">',
196 "</a>"
197 )
198 );
199 o.value("*", _("AdBlock on all instances"));
200 o.value("+", _("AdBlock on select instances"));
201 o.value("-", _("No AdBlock on dnsmasq"));
202 o.default = "*";
203 o.depends("dns", "dnsmasq.addnhosts");
204 o.depends("dns", "dnsmasq.servers");
205 o.retain = true;
206 o.cfgvalue = function (section_id) {
207 let val = this.map.data.get(
208 this.map.config,
209 section_id,
210 "dnsmasq_instance"
211 );
212 if (val && val[0]) {
213 switch (val[0]) {
214 case "*":
215 case "-":
216 return val[0];
217 default:
218 return "+";
219 }
220 } else return "*";
221 };
222 o.write = function (section_id, formvalue) {
223 L.uci.set(pkg.Name, section_id, "dnsmasq_instance", formvalue);
224 };
225
226 o = s1.taboption(
227 "tab_basic",
228 form.MultiValue,
229 "dnsmasq_instance",
230 _("Pick the dnsmasq instance(s) for AdBlocking")
231 );
232 Object.values(L.uci.sections("dhcp", "dnsmasq")).forEach(function (
233 element
234 ) {
235 var description;
236 var key;
237 if (element[".name"] === L.uci.resolveSID("dhcp", element[".name"])) {
238 key = element[".index"];
239 description = "dnsmasq[" + element[".index"] + "]";
240 } else {
241 key = element[".name"];
242 description = element[".name"];
243 }
244 o.value(key, description);
245 });
246 o.depends("dnsmasq_instance_option", "+");
247 o.retain = true;
248 }
249
250 if (reply.platform.smartdns_installed && reply.smartdns) {
251 o = s1.taboption(
252 "tab_basic",
253 form.ListValue,
254 "smartdns_instance_option",
255 _("Use AdBlocking on the SmartDNS instance(s)"),
256 _(
257 "You can limit the AdBlocking to the specific SmartDNS instance(s) (%smore information%s)."
258 ).format(
259 '<a href="' + pkg.URL + "#smartdns_instance" + '" target="_blank">',
260 "</a>"
261 )
262 );
263 o.value("*", _("AdBlock on all instances"));
264 o.value("+", _("AdBlock on select instances"));
265 o.value("-", _("No AdBlock on SmartDNS"));
266 o.default = "*";
267 o.depends("dns", "smartdns.domainset");
268 o.retain = true;
269 o.cfgvalue = function (section_id) {
270 let val = this.map.data.get(
271 this.map.config,
272 section_id,
273 "smartdns_instance"
274 );
275 if (val && val[0]) {
276 switch (val[0]) {
277 case "*":
278 case "-":
279 return val[0];
280 default:
281 return "+";
282 }
283 } else return "*";
284 };
285 o.write = function (section_id, formvalue) {
286 L.uci.set(pkg.Name, section_id, "smartdns_instance", formvalue);
287 };
288
289 o = s1.taboption(
290 "tab_basic",
291 form.MultiValue,
292 "smartdns_instance",
293 _("Pick the SmartDNS instance(s) for AdBlocking")
294 );
295 Object.values(L.uci.sections("smartdns", "smartdns")).forEach(function (
296 element
297 ) {
298 var description;
299 var key;
300 if (
301 element[".name"] === L.uci.resolveSID("smartdns", element[".name"])
302 ) {
303 key = element[".index"];
304 description = "smartdns[" + element[".index"] + "]";
305 } else {
306 key = element[".name"];
307 description = element[".name"];
308 }
309 o.value(key, description);
310 });
311 o.depends("smartdns_instance_option", "+");
312 o.retain = true;
313 }
314 o = s1.taboption(
315 "tab_basic",
316 form.ListValue,
317 "force_dns",
318 _("Force Router DNS"),
319 _("Forces Router DNS use on local devices, also known as DNS Hijacking.")
320 );
321 o.value("0", _("Let local devices use their own DNS servers if set"));
322 o.value("1", _("Force Router DNS server to all local devices"));
323 o.default = "1";
324
325 o = s1.taboption(
326 "tab_basic",
327 form.ListValue,
328 "verbosity",
329 _("Output Verbosity Setting"),
330 _("Controls system log and console output verbosity.")
331 );
332 o.value("0", _("Suppress output"));
333 o.value("1", _("Some output"));
334 o.value("2", _("Verbose output"));
335 o.default = "2";
336
337 if (reply.platform.leds.length) {
338 o = s1.taboption(
339 "tab_basic",
340 form.ListValue,
341 "led",
342 _("LED to indicate status"),
343 _(
344 "Pick the LED not already used in %sSystem LED Configuration%s."
345 ).format('<a href="' + L.url("admin", "system", "leds") + '">', "</a>")
346 );
347 o.value("", _("none"));
348 reply.platform.leds.forEach((element) => {
349 o.value(element);
350 });
351 }
352
353 o = s1.taboption(
354 "tab_advanced",
355 form.ListValue,
356 "config_update_enabled",
357 _("Automatic Config Update"),
358 _("Perform config update before downloading the block/allow-lists.")
359 );
360 o.value("0", _("Disable"));
361 o.value("1", _("Enable"));
362 o.default = "0";
363
364 o = s1.taboption(
365 "tab_advanced",
366 form.ListValue,
367 "ipv6_enabled",
368 _("IPv6 Support"),
369 _("Add IPv6 entries to block-list.")
370 );
371 o.value("", _("Do not add IPv6 entries"));
372 o.value("1", _("Add IPv6 entries"));
373 o.depends("dns", "dnsmasq.addnhosts");
374 o.depends("dns", "dnsmasq.nftset");
375 o.default = "";
376 o.rmempty = true;
377 o.retain = true;
378
379 o = s1.taboption(
380 "tab_advanced",
381 form.Value,
382 "download_timeout",
383 _("Download time-out (in seconds)"),
384 _("Stop the download if it is stalled for set number of seconds.")
385 );
386 o.default = "20";
387 o.datatype = "range(1,60)";
388
389 o = s1.taboption(
390 "tab_advanced",
391 form.Value,
392 "curl_max_file_size",
393 _("Curl maximum file size (in bytes)"),
394 _(
395 "If curl is installed and detected, it would not download files bigger than this."
396 )
397 );
398 o.default = "";
399 o.datatype = "uinteger";
400 o.rmempty = true;
401
402 o = s1.taboption(
403 "tab_advanced",
404 form.Value,
405 "curl_retry",
406 _("Curl download retry"),
407 _(
408 "If curl is installed and detected, it would retry download this many times on timeout/fail."
409 )
410 );
411 o.default = "3";
412 o.datatype = "range(0,30)";
413
414 o = s1.taboption(
415 "tab_advanced",
416 form.ListValue,
417 "parallel_downloads",
418 _("Simultaneous processing"),
419 _(
420 "Launch all lists downloads and processing simultaneously, reducing service start time."
421 )
422 );
423 o.value("0", _("Do not use simultaneous processing"));
424 o.value("1", _("Use simultaneous processing"));
425 o.default = "1";
426
427 o = s1.taboption(
428 "tab_advanced",
429 form.ListValue,
430 "compressed_cache",
431 _("Store compressed cache file on router"),
432 _(
433 "Attempt to create a compressed cache of block-list in the persistent memory."
434 )
435 );
436 o.value("0", _("Do not store compressed cache"));
437 o.value("1", _("Store compressed cache"));
438 o.default = "0";
439
440 o = s1.taboption(
441 "tab_advanced",
442 form.Value,
443 "compressed_cache_dir",
444 _("Directory for compressed cache file"),
445 _(
446 "Directory for compressed cache file of block-list in the persistent memory."
447 )
448 );
449 o.datatype = "string";
450 o.rmempty = true;
451 o.default = "/etc";
452 o.depends("compressed_cache", "1");
453 o.retain = true;
454
455 o = s1.taboption(
456 "tab_advanced",
457 form.ListValue,
458 "debug",
459 _("Enable Debugging"),
460 _("Enables debug output to /tmp/adblock-fast.log.")
461 );
462 o.value("0", _("Disable Debugging"));
463 o.value("1", _("Enable Debugging"));
464 o.default = "0";
465
466 s2 = m.section(
467 form.NamedSection,
468 "config",
469 "adblock-fast",
470 _("AdBlock-Fast - Allowed and Blocked Domains")
471 );
472 o.addremove = true;
473 o.rmempty = true;
474
475 o = s2.option(
476 form.DynamicList,
477 "allowed_domain",
478 _("Allowed Domains"),
479 _("Individual domains to be allowed.")
480 );
481 o.addremove = true;
482
483 o = s2.option(
484 form.DynamicList,
485 "blocked_domain",
486 _("Blocked Domains"),
487 _("Individual domains to be blocked.")
488 );
489 o.addremove = true;
490
491 s3 = m.section(
492 form.GridSection,
493 "file_url",
494 _("AdBlock-Fast - Allowed and Blocked Lists URLs"),
495 _("URLs to file(s) containing lists to be allowed or blocked.")
496 );
497 s3.rowcolors = true;
498 s3.sortable = true;
499 s3.anonymous = true;
500 s3.addremove = true;
501
502 o = s3.option(form.DummyValue, "_size", _("Size"));
503 o.modalonly = false;
504 o.cfgvalue = function (section_id) {
505 let url = L.uci.get(pkg.Name, section_id, "url");
506 let ret = _("Unknown");
507 reply.sizes.forEach((element) => {
508 if (element.url === url) {
509 ret = element.size === 0 ? ret : pkg.humanFileSize(element.size);
510 }
511 });
512 return _("Size: %s").format(ret);
513 };
514
515 o = s3.option(form.Flag, "enabled", _("Enable"));
516 o.editable = true;
517 o.default = "1";
518
519 o = s3.option(form.ListValue, "action", _("Action"));
520 o.value("allow", _("Allow"));
521 o.value("block", _("Block"));
522 o.default = "block";
523 o.textvalue = function (section_id) {
524 var val = this.cfgvalue(section_id);
525 return val == "allow" ? _("Allow") : _("Block");
526 };
527
528 o = s3.option(form.Value, "url", _("URL"));
529 o.optional = false;
530
531 return Promise.all([status.render(), m.render()]);
532 },
533 });