086200aa89cab648b5e94741ba0934d0722ac195
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)
9 "require adblock-fast.status as adb";
13 return "adblock-fast";
16 return "https://docs.openwrt.melmac.net/" + pkg
.Name
+ "/";
18 humanFileSize: function (bytes
, si
= false, dp
= 2) {
19 return `%${si ? 1000 : 1024}.${dp ?? 0}mB`.format(bytes
);
26 L
.resolveDefault(adb
.getFileUrlFilesizes(pkg
.Name
), {}),
27 L
.resolveDefault(adb
.getPlatformSupport(pkg
.Name
), {}),
28 L
.resolveDefault(L
.uci
.load(pkg
.Name
), {}),
29 L
.resolveDefault(L
.uci
.load("dhcp"), {}),
30 L
.resolveDefault(L
.uci
.load("smartdns"), {}),
34 render: function (data
) {
36 sizes
: (data
[0] && data
[0][pkg
.Name
] && data
[0][pkg
.Name
]["sizes"]) || [],
37 platform
: (data
[1] && data
[1][pkg
.Name
]) || {
38 ipset_installed
: false,
40 dnsmasq_installed
: false,
41 dnsmasq_ipset_support
: false,
42 dnsmasq_nftset_support
: false,
43 smartdns_installed
: false,
44 smartdns_ipset_support
: false,
45 smartdns_nftset_support
: false,
46 unbound_installed
: false,
50 var status
, m
, s1
, s2
, s3
, o
;
52 status
= new adb
.status();
53 m
= new form
.Map(pkg
.Name
, _("AdBlock-Fast - Configuration"));
54 s1
= m
.section(form
.NamedSection
, "config", pkg
.Name
);
55 s1
.tab("tab_basic", _("Basic Configuration"));
56 s1
.tab("tab_advanced", _("Advanced Configuration"));
59 "DNS resolution option, see the %sREADME%s for details."
61 '<a href="' + pkg
.URL
+ '#dns-resolver-option" target="_blank">',
64 if (!reply
.platform
.dnsmasq_installed
) {
67 _("Please note that %s is not supported on this system.").format(
68 "<i>dnsmasq.addnhosts</i>"
72 _("Please note that %s is not supported on this system.").format(
77 _("Please note that %s is not supported on this system.").format(
78 "<i>dnsmasq.ipset</i>"
82 _("Please note that %s is not supported on this system.").format(
83 "<i>dnsmasq.servers</i>"
86 if (!reply
.platform
.dnsmasq_ipset_support
) {
89 _("Please note that %s is not supported on this system.").format(
90 "<i>dnsmasq.ipset</i>"
93 if (!reply
.platform
.dnsmasq_nftset_support
) {
96 _("Please note that %s is not supported on this system.").format(
97 "<i>dnsmasq.nftset</i>"
101 if (!reply
.platform
.smartdns_installed
) {
105 _("Please note that %s is not supported on this system.").format(
106 "<i>smartdns.domainset</i>"
109 if (!reply
.platform
.smartdns_ipset_support
) {
112 _("Please note that %s is not supported on this system.").format(
113 "<i>smartdns.ipset</i>"
116 if (!reply
.platform
.smartdns_nftset_support
) {
119 _("Please note that %s is not supported on this system.").format(
120 "<i>smartdns.nftset</i>"
124 if (!reply
.platform
.unbound_installed
) {
128 _("Please note that %s is not supported on this system.").format(
129 "<i>unbound.adb_list</i>"
140 if (reply
.platform
.dnsmasq_installed
) {
141 o
.value("dnsmasq.addnhosts", _("dnsmasq additional hosts"));
142 o
.value("dnsmasq.conf", _("dnsmasq config"));
143 if (reply
.platform
.dnsmasq_ipset_support
) {
144 o
.value("dnsmasq.ipset", _("dnsmasq ipset"));
146 if (reply
.platform
.dnsmasq_nftset_support
) {
147 o
.value("dnsmasq.nftset", _("dnsmasq nft set"));
149 o
.value("dnsmasq.servers", _("dnsmasq servers file"));
151 if (reply
.platform
.smartdns_installed
) {
152 o
.value("smartdns.domainset", _("smartdns domain set"));
153 if (reply
.platform
.smartdns_ipset_support
) {
154 o
.value("smartdns.ipset", _("smartdns ipset"));
156 if (reply
.platform
.smartdns_nftset_support
) {
157 o
.value("smartdns.nftset", _("smartdns nft set"));
160 if (reply
.platform
.unbound_installed
) {
161 o
.value("unbound.adb_list", _("unbound adblock list"));
163 o
.default = "dnsmasq.servers";
168 "dnsmasq_config_file_url",
169 _("Dnsmasq Config File URL"),
171 "URL to the external dnsmasq config file, see the %sREADME%s for details."
173 '<a href="' + pkg
.URL
+ '#dnsmasq_config_file_url" target="_blank">',
177 o
.depends("dns", "dnsmasq.conf");
183 _("Use AdBlocking on the dnsmasq instance(s)"),
185 "You can limit the AdBlocking to a specific dnsmasq instance(s) (%smore information%s)."
187 '<a href="' + pkg
.URL
+ "#dnsmasq_instance" + '" target="_blank">',
191 o
.value("*", _("AdBlock on all instances"));
193 Object
.values(L
.uci
.sections("dhcp", "dnsmasq")).forEach(function (
198 if (element
[".name"] === L
.uci
.resolveSID("dhcp", element
[".name"])) {
199 key
= element
[".index"];
200 description
= "dnsmasq[" + element
[".index"] + "]";
202 key
= element
[".name"];
203 description
= element
[".name"];
205 o
.value(key
, _("AdBlock on %s only").format(description
));
207 o
.value("-", _("No AdBlock on dnsmasq"));
209 o
.depends("dns", "dnsmasq.addnhosts");
210 o
.depends("dns", "dnsmasq.servers");
217 _("Use AdBlocking on the SmartDNS instance(s)"),
219 "You can limit the AdBlocking to a specific SmartDNS instance(s) (%smore information%s)."
221 '<a href="' + pkg
.URL
+ "#smartdns_instance" + '" target="_blank">',
225 o
.value("*", _("AdBlock on all instances"));
227 Object
.values(L
.uci
.sections("smartdns", "smartdns")).forEach(function (
232 if (element
[".name"] === L
.uci
.resolveSID("smartdns", element
[".name"])) {
233 key
= element
[".index"];
234 description
= "smartdns[" + element
[".index"] + "]";
236 key
= element
[".name"];
237 description
= element
[".name"];
239 o
.value(key
, _("AdBlock on %s only").format(description
));
241 o
.value("-", _("No AdBlock on SmartDNS"));
243 o
.depends("dns", "smartdns.domainset");
244 o
.depends("dns", "smartdns.ipset");
245 o
.depends("dns", "smartdns.nftset");
252 _("Force Router DNS"),
253 _("Forces Router DNS use on local devices, also known as DNS Hijacking.")
255 o
.value("0", _("Let local devices use their own DNS servers if set"));
256 o
.value("1", _("Force Router DNS server to all local devices"));
263 _("Output Verbosity Setting"),
264 _("Controls system log and console output verbosity.")
266 o
.value("0", _("Suppress output"));
267 o
.value("1", _("Some output"));
268 o
.value("2", _("Verbose output"));
271 if (reply
.platform
.leds
.length
) {
276 _("LED to indicate status"),
278 "Pick the LED not already used in %sSystem LED Configuration%s."
279 ).format('<a href="' + L
.url("admin", "system", "leds") + '">', "</a>")
281 o
.value("", _("none"));
282 reply
.platform
.leds
.forEach((element
) => {
290 "config_update_enabled",
291 _("Automatic Config Update"),
292 _("Perform config update before downloading the block/allow-lists.")
294 o
.value("0", _("Disable"));
295 o
.value("1", _("Enable"));
303 _("Add IPv6 entries to block-list.")
305 o
.value("", _("Do not add IPv6 entries"));
306 o
.value("1", _("Add IPv6 entries"));
307 o
.depends("dns", "dnsmasq.addnhosts");
308 o
.depends("dns", "dnsmasq.nftset");
317 _("Download time-out (in seconds)"),
318 _("Stop the download if it is stalled for set number of seconds.")
321 o
.datatype
= "range(1,60)";
326 "curl_max_file_size",
327 _("Curl maximum file size (in bytes)"),
329 "If curl is installed and detected, it would not download files bigger than this."
333 o
.datatype
= "uinteger";
340 _("Curl download retry"),
342 "If curl is installed and detected, it would retry download this many times on timeout/fail."
346 o
.datatype
= "range(0,30)";
351 "parallel_downloads",
352 _("Simultaneous processing"),
354 "Launch all lists downloads and processing simultaneously, reducing service start time."
357 o
.value("0", _("Do not use simultaneous processing"));
358 o
.value("1", _("Use simultaneous processing"));
365 _("Store compressed cache file on router"),
367 "Attempt to create a compressed cache of block-list in the persistent memory."
370 o
.value("0", _("Do not store compressed cache"));
371 o
.value("1", _("Store compressed cache"));
377 "compressed_cache_dir",
378 _("Directory for compressed cache file"),
380 "Directory for compressed cache file of block-list in the persistent memory."
383 o
.datatype
= "string";
386 o
.depends("compressed_cache", "1");
393 _("Enable Debugging"),
394 _("Enables debug output to /tmp/adblock-fast.log.")
396 o
.value("0", _("Disable Debugging"));
397 o
.value("1", _("Enable Debugging"));
404 _("AdBlock-Fast - Allowed and Blocked Domains")
412 _("Allowed Domains"),
413 _("Individual domains to be allowed.")
420 _("Blocked Domains"),
421 _("Individual domains to be blocked.")
428 _("AdBlock-Fast - Allowed and Blocked Lists URLs"),
429 _("URLs to file(s) containing lists to be allowed or blocked.")
436 o
= s3
.option(form
.DummyValue
, "_size", _("Size"));
438 o
.cfgvalue = function (section_id
) {
439 let url
= L
.uci
.get(pkg
.Name
, section_id
, "url");
440 let ret
= _("Unknown");
441 reply
.sizes
.forEach((element
) => {
442 if (element
.url
=== url
) {
443 ret
= element
.size
=== 0 ? ret
: pkg
.humanFileSize(element
.size
);
446 return _("Size: %s").format(ret
);
449 o
= s3
.option(form
.Flag
, "enabled", _("Enable"));
453 o
= s3
.option(form
.ListValue
, "action", _("Action"));
454 o
.value("allow", _("Allow"));
455 o
.value("block", _("Block"));
457 o
.textvalue = function (section_id
) {
458 var val
= this.cfgvalue(section_id
);
459 return val
== "allow" ? _("Allow") : _("Block");
462 o
= s3
.option(form
.Value
, "url", _("URL"));
465 return Promise
.all([status
.render(), m
.render()]);