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)
10 "require adblock-fast.status as adb";
14 return "adblock-fast";
17 return "https://docs.openwrt.melmac.net/" + pkg
.Name
+ "/";
19 humanFileSize: function (bytes
, si
= false, dp
= 2) {
20 return `%${si ? 1000 : 1024}.${dp ?? 0}mB`.format(bytes
);
27 L
.resolveDefault(adb
.getFileUrlFilesizes(pkg
.Name
), {}),
28 L
.resolveDefault(adb
.getPlatformSupport(pkg
.Name
), {}),
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 unbound_installed
: false,
42 dnsmasq_ipset_support
: false,
43 dnsmasq_nftset_support
: false,
47 var status
, m
, s1
, s2
, s3
, o
;
49 status
= new adb
.status();
50 m
= new form
.Map(pkg
.Name
, _("AdBlock-Fast - Configuration"));
51 s1
= m
.section(form
.NamedSection
, "config", pkg
.Name
);
52 s1
.tab("tab_basic", _("Basic Configuration"));
53 s1
.tab("tab_advanced", _("Advanced Configuration"));
56 "DNS resolution option, see the %sREADME%s for details."
58 '<a href="' + pkg
.URL
+ '#dns-resolver-option" target="_blank">',
61 if (!reply
.platform
.dnsmasq_installed
) {
64 _("Please note that %s is not supported on this system.").format(
65 "<i>dnsmasq.addnhosts</i>"
69 _("Please note that %s is not supported on this system.").format(
74 _("Please note that %s is not supported on this system.").format(
75 "<i>dnsmasq.ipset</i>"
79 _("Please note that %s is not supported on this system.").format(
80 "<i>dnsmasq.servers</i>"
83 if (!reply
.platform
.dnsmasq_ipset_support
) {
86 _("Please note that %s is not supported on this system.").format(
87 "<i>dnsmasq.ipset</i>"
90 if (!reply
.platform
.dnsmasq_nftset_support
) {
93 _("Please note that %s is not supported on this system.").format(
94 "<i>dnsmasq.nftset</i>"
98 if (!reply
.platform
.unbound_installed
) {
102 _("Please note that %s is not supported on this system.").format(
103 "<i>unbound.adb_list</i>"
114 if (reply
.platform
.dnsmasq_installed
) {
115 o
.value("dnsmasq.addnhosts", _("dnsmasq additional hosts"));
116 o
.value("dnsmasq.conf", _("dnsmasq config"));
117 if (reply
.platform
.dnsmasq_ipset_support
) {
118 o
.value("dnsmasq.ipset", _("dnsmasq ipset"));
120 if (reply
.platform
.dnsmasq_nftset_support
) {
121 o
.value("dnsmasq.nftset", _("dnsmasq nft set"));
123 o
.value("dnsmasq.servers", _("dnsmasq servers file"));
125 if (reply
.platform
.unbound_installed
) {
126 o
.value("unbound.adb_list", _("unbound adblock list"));
128 o
.default = ("dnsmasq.servers", _("dnsmasq servers file"));
133 "dnsmasq_config_file_url",
134 _("Dnsmasq Config File URL"),
136 "URL to the external dnsmasq config file, see the %sREADME%s for details."
138 '<a href="' + pkg
.URL
+ '#dnsmasq_config_file_url" target="_blank">',
142 o
.depends("dns", "dnsmasq.conf");
148 _("Use AdBlocking on the dnsmasq instance(s)"),
150 "You can limit the AdBlocking to a specific dnsmasq instance(s) (%smore information%s)."
152 '<a href="' + pkg
.URL
+ "#dnsmasq_instance" + '" target="_blank">',
156 o
.value("*", _("AdBlock on all instances"));
157 var sections
= uci
.sections("dhcp", "dnsmasq");
158 sections
.forEach((element
) => {
161 if (element
[".name"] === uci
.resolveSID("dhcp", element
[".name"])) {
162 key
= element
[".index"];
163 description
= "dnsmasq[" + element
[".index"] + "]";
165 key
= element
[".name"];
166 description
= element
[".name"];
168 o
.value(key
, _("AdBlock on %s only").format(description
));
170 o
.value("-", _("No AdBlock on dnsmasq"));
172 o
.depends("dns", "dnsmasq.addnhosts");
173 o
.depends("dns", "dnsmasq.servers");
180 _("Force Router DNS"),
181 _("Forces Router DNS use on local devices, also known as DNS Hijacking.")
183 o
.value("0", _("Let local devices use their own DNS servers if set"));
184 o
.value("1", _("Force Router DNS server to all local devices"));
185 o
.default = ("1", _("Force Router DNS server to all local devices"));
191 _("Output Verbosity Setting"),
192 _("Controls system log and console output verbosity.")
194 o
.value("0", _("Suppress output"));
195 o
.value("1", _("Some output"));
196 o
.value("2", _("Verbose output"));
197 o
.default = ("2", _("Verbose output"));
199 if (reply
.platform
.leds
.length
) {
204 _("LED to indicate status"),
206 "Pick the LED not already used in %sSystem LED Configuration%s."
207 ).format('<a href="' + L
.url("admin", "system", "leds") + '">', "</a>")
209 o
.value("", _("none"));
210 reply
.platform
.leds
.forEach((element
) => {
217 "config_update_enabled",
218 _("Automatic Config Update"),
219 _("Perform config update before downloading the block/allow-lists.")
221 o
.value("0", _("Disable"));
222 o
.value("1", _("Enable"));
223 o
.default = ("0", _("Disable"));
230 _("Add IPv6 entries to block-list.")
232 o
.value("", _("Do not add IPv6 entries"));
233 o
.value("1", _("Add IPv6 entries"));
234 o
.depends("dns", "dnsmasq.addnhosts");
235 o
.depends("dns", "dnsmasq.nftset");
236 o
.default = ("", _("Do not add IPv6 entries"));
244 _("Download time-out (in seconds)"),
245 _("Stop the download if it is stalled for set number of seconds.")
248 o
.datatype
= "range(1,60)";
253 "curl_max_file_size",
254 _("Curl maximum file size (in bytes)"),
256 "If curl is installed and detected, it would not download files bigger than this."
260 o
.datatype
= "uinteger";
267 _("Curl download retry"),
269 "If curl is installed and detected, it would retry download this many times on timeout/fail."
273 o
.datatype
= "range(0,30)";
278 "parallel_downloads",
279 _("Simultaneous processing"),
281 "Launch all lists downloads and processing simultaneously, reducing service start time."
284 o
.value("0", _("Do not use simultaneous processing"));
285 o
.value("1", _("Use simultaneous processing"));
286 o
.default = ("1", _("Use simultaneous processing"));
292 _("Store compressed cache file on router"),
294 "Attempt to create a compressed cache of block-list in the persistent memory."
297 o
.value("0", _("Do not store compressed cache"));
298 o
.value("1", _("Store compressed cache"));
299 o
.default = ("0", _("Do not store compressed cache"));
304 "compressed_cache_dir",
305 _("Directory for compressed cache file"),
307 "Directory for compressed cache file of block-list in the persistent memory."
310 o
.datatype
= "string";
313 o
.depends("compressed_cache", "1");
320 _("Enable Debugging"),
321 _("Enables debug output to /tmp/adblock-fast.log.")
323 o
.value("0", _("Disable Debugging"));
324 o
.value("1", _("Enable Debugging"));
325 o
.default = ("0", _("Disable Debugging"));
331 _("AdBlock-Fast - Allowed and Blocked Domains")
338 _("Allowed Domains"),
339 _("Individual domains to be allowed.")
346 _("Blocked Domains"),
347 _("Individual domains to be blocked.")
354 _("AdBlock-Fast - Allowed and Blocked Lists URLs"),
355 _("URLs to file(s) containing lists to be allowed or blocked.")
361 o
= s3
.option(form
.DummyValue
, "_size", "Size");
363 o
.cfgvalue = function (section_id
) {
364 let url
= uci
.get(pkg
.Name
, section_id
, "url");
365 let ret
= _("Unknown");
366 reply
.sizes
.forEach((element
) => {
367 if (element
.url
=== url
) {
368 ret
= element
.size
=== 0 ? ret
: pkg
.humanFileSize(element
.size
);
371 return _("Size: %s").format(ret
);
373 o
= s3
.option(form
.Flag
, "enabled", _("Enable"));
376 o
= s3
.option(form
.ListValue
, "action", _("Action"));
377 o
.value("allow", _("Allow"));
378 o
.value("block", _("Block"));
380 o
= s3
.option(form
.Value
, "url", _("URL"));
383 return Promise
.all([status
.render(), m
.render()]);