overview.js 14 KB

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