summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-simple-adblock/htdocs
diff options
context:
space:
mode:
Diffstat (limited to 'applications/luci-app-simple-adblock/htdocs')
-rw-r--r--applications/luci-app-simple-adblock/htdocs/luci-static/resources/simple-adblock/status.js305
-rw-r--r--applications/luci-app-simple-adblock/htdocs/luci-static/resources/view/simple-adblock/overview.js161
2 files changed, 466 insertions, 0 deletions
diff --git a/applications/luci-app-simple-adblock/htdocs/luci-static/resources/simple-adblock/status.js b/applications/luci-app-simple-adblock/htdocs/luci-static/resources/simple-adblock/status.js
new file mode 100644
index 0000000000..bde2e34c5b
--- /dev/null
+++ b/applications/luci-app-simple-adblock/htdocs/luci-static/resources/simple-adblock/status.js
@@ -0,0 +1,305 @@
+// Copyright 2022 Stan Grishin <stangri@melmac.ca>
+// This code wouldn't have been possible without help from [@vsviridov](https://github.com/vsviridov)
+
+"require ui";
+"require rpc";
+"require form";
+"require baseclass";
+
+var pkg = {
+ get Name() { return 'simple-adblock'; },
+ get URL() { return 'https://docs.openwrt.melmac.net/' + pkg.Name + '/'; },
+};
+
+var getInitList = rpc.declare({
+ object: "luci." + pkg.Name,
+ method: "getInitList",
+ params: ["name"],
+});
+
+var getInitStatus = rpc.declare({
+ object: "luci." + pkg.Name,
+ method: "getInitStatus",
+ params: ["name"],
+});
+
+var getPlatformSupport = rpc.declare({
+ object: "luci." + pkg.Name,
+ method: "getPlatformSupport",
+ params: ["name"],
+});
+
+var _setInitAction = rpc.declare({
+ object: "luci." + pkg.Name,
+ method: "setInitAction",
+ params: ["name", "action"],
+ expect: { result: false },
+});
+
+var RPC = {
+ listeners: [],
+ on: function on(event, callback) {
+ var pair = { event: event, callback: callback }
+ this.listeners.push(pair);
+ return function unsubscribe() {
+ this.listeners = this.listeners.filter(function (listener) {
+ return listener !== pair;
+ });
+ }.bind(this);
+ },
+ emit: function emit(event, data) {
+ this.listeners.forEach(function (listener) {
+ if (listener.event === event) {
+ listener.callback(data);
+ }
+ });
+ },
+ getInitList: function getInitList(name) {
+ getInitList(name).then(function (result) {
+ this.emit('getInitList', result);
+ }.bind(this));
+ },
+ getInitStatus: function getInitStatus(name) {
+ getInitStatus(name).then(function (result) {
+ this.emit('getInitStatus', result);
+ }.bind(this));
+ },
+ getPlatformSupport: function getPlatformSupport(name) {
+ getPlatformSupport(name).then(function (result) {
+ this.emit('getPlatformSupport', result);
+ }.bind(this));
+ },
+ setInitAction: function setInitAction(name, action) {
+ _setInitAction(name, action).then(function (result) {
+ this.emit('setInitAction', result);
+ }.bind(this));
+ },
+}
+
+var status = baseclass.extend({
+ render: function () {
+ return Promise.all([
+ L.resolveDefault(getInitStatus(), {}),
+ ]).then(function (data) {
+ var replyStatus = data[0];
+ var text ="";
+ var status = replyStatus[pkg.Name];
+ var outputFile = status.outputFile;
+ var outputCache = status.outputCache;
+ var statusTable = {
+ statusNoInstall: _("%s is not installed or not found").format(pkg.Name),
+ statusStopped: _("Stopped"),
+ statusStarting: _("Starting"),
+ statusRestarting: _("Restarting"),
+ statusForceReloading: _("Force Reloading"),
+ statusDownloading: _("Downloading"),
+ statusError: _("Error"),
+ statusWarning: _("Warning"),
+ statusFail: _("Fail"),
+ statusSuccess: _("Active")
+ };
+
+ var header = E('h2', {}, _("Simple AdBlock - Status"))
+ var statusTitle = E('label', { class: 'cbi-value-title' }, _("Service Status"));
+ if (status.version) {
+ text += _("Version: %s").format(status.version) + " - ";
+ switch (status.status) {
+ case 'statusSuccess':
+ text += statusTable[status.status] + ".";
+ text += "<br />" + _("Blocking %s domains (with %s).").format(status.entries, status.dns);
+ if (status.outputGzipExists) {
+ text += "<br />" + _("Compressed cache file created.");
+ }
+ if (status.force_dns_active) {
+ text += "<br />" + _("Force DNS ports:");
+ status.force_dns_ports.forEach(element => {
+ text += " " + element;
+ });
+ text += ".";
+ }
+ break;
+ case 'statusStopped':
+ if (status.enabled) {
+ text += statusTable[status.status] + ".";
+ }
+ else {
+ text += statusTable[status.status] + _("disabled") + "."
+ }
+ if (status.outputCacheExists) {
+ text += "<br />" + _("Cache file found.");
+ }
+ else if (status.outputGzipExists) {
+ text += "<br />" + _("Compressed cache file found.");
+ }
+ break;
+ case 'statusRestarting':
+ case 'statusForceReloading':
+ case 'statusDownloading':
+ text += statusTable[status.status] + "...";
+ break;
+ default:
+ text += statusTable[status.status] + ".";
+ break;
+ }
+ }
+ else {
+ text = _("Not installed or not found");
+ }
+ var statusText = E('div', {}, text);
+ var statusField = E('div', { class: 'cbi-value-field' }, statusText);
+ var statusDiv = E('div', { class: 'cbi-value' }, [statusTitle, statusField]);
+
+ var warningsDiv = [];
+ if (status.warnings) {
+ var warningsTitle = E('label', { class: 'cbi-value-title' }, _("Service Warnings"));
+ var warningsText = E('div', {}, status.warnings);
+ var warningsField = E('div', { class: 'cbi-value-field' }, warningsText);
+ warningsDiv = E('div', { class: 'cbi-value' }, [warningsTitle, warningsField]);
+ }
+
+ var errorsDiv = [];
+ if ((status.errors).length) {
+ var errorTable = {
+ errorOutputFileCreate: _("failed to create '%s' file").format(outputFile),
+ errorFailDNSReload: _("failed to restart/reload DNS resolver"),
+ errorSharedMemory: _("failed to access shared memory"),
+ errorSorting: _("failed to sort data file"),
+ errorOptimization: _("failed to optimize data file"),
+ errorAllowListProcessing: _("failed to process allow-list"),
+ errorDataFileFormatting: _("failed to format data file"),
+ errorMovingDataFile: _("failed to move temporary data file to '%s'").format(outputFile),
+ errorCreatingCompressedCache: _("failed to create compressed cache"),
+ errorRemovingTempFiles: _("failed to remove temporary files"),
+ errorRestoreCompressedCache: _("failed to unpack compressed cache"),
+ errorRestoreCache: _("failed to move '%s' to '%s'").format(outputCache, outputFile),
+ errorOhSnap: _("failed to create block-list or restart DNS resolver"),
+ errorStopping: _("failed to stop %s").format(pkg.Name),
+ errorDNSReload: _("failed to reload/restart DNS resolver"),
+ errorDownloadingConfigUpdate: _("failed to download Config Update file"),
+ errorDownloadingList: _("failed to download"),
+ errorParsingConfigUpdate: _("failed to parse Config Update file"),
+ errorParsingList: _("failed to parse"),
+ errorNoSSLSupport: _("no HTTPS/SSL support on device"),
+ errorCreatingDirectory: _("failed to create output/cache/gzip file directory")
+ }
+ var errorsTitle = E('label', { class: 'cbi-value-title' }, _("Service Errors"));
+ var text = "";
+ (status.errors).forEach(element => {
+ text += errorTable[element] + ".<br />";
+ });
+ var errorsText = E('div', {}, text);
+ var errorsField = E('div', { class: 'cbi-value-field' }, errorsText);
+ errorsDiv = E('div', { class: 'cbi-value' }, [errorsTitle, errorsField]);
+ }
+
+ var btn_gap = E('span', {}, '&#160;&#160;');
+ var btn_gap_long = E('span', {}, '&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;');
+
+ var btn_start = E('button', {
+ 'class': 'btn cbi-button cbi-button-apply',
+ disabled: true,
+ click: function (ev) {
+ ui.showModal(null, [
+ E('p', { 'class': 'spinning' }, _('Starting %s service').format(pkg.Name))
+ ]);
+ return RPC.setInitAction(pkg.Name, 'start');
+ }
+ }, _('Start'));
+
+ var btn_action = E('button', {
+ 'class': 'btn cbi-button cbi-button-apply',
+ disabled: true,
+ click: function (ev) {
+ ui.showModal(null, [
+ E('p', { 'class': 'spinning' }, _('Force re-downloading %s block lists').format(pkg.Name))
+ ]);
+ return RPC.setInitAction(pkg.Name, 'dl');
+ }
+ }, _('Force Re-Download'));
+
+ var btn_stop = E('button', {
+ 'class': 'btn cbi-button cbi-button-reset',
+ disabled: true,
+ click: function (ev) {
+ ui.showModal(null, [
+ E('p', { 'class': 'spinning' }, _('Stopping %s service').format(pkg.Name))
+ ]);
+ return RPC.setInitAction(pkg.Name, 'stop');
+ }
+ }, _('Stop'));
+
+ var btn_enable = E('button', {
+ 'class': 'btn cbi-button cbi-button-apply',
+ disabled: true,
+ click: function (ev) {
+ ui.showModal(null, [
+ E('p', { 'class': 'spinning' }, _('Enabling %s service').format(pkg.Name))
+ ]);
+ return RPC.setInitAction(pkg.Name, 'enable');
+ }
+ }, _('Enable'));
+
+ var btn_disable = E('button', {
+ 'class': 'btn cbi-button cbi-button-reset',
+ disabled: true,
+ click: function (ev) {
+ ui.showModal(null, [
+ E('p', { 'class': 'spinning' }, _('Disabling %s service').format(pkg.Name))
+ ]);
+ return RPC.setInitAction(pkg.Name, 'disable');
+ }
+ }, _('Disable'));
+
+ if (status.enabled) {
+ btn_enable.disabled = true;
+ btn_disable.disabled = false;
+ switch (status.status) {
+ case 'statusSuccess':
+ btn_start.disabled = true;
+ btn_action.disabled = false;
+ btn_stop.disabled = false;
+ break;
+ case 'statusStopped':
+ btn_start.disabled = false;
+ btn_action.disabled = true;
+ btn_stop.disabled = true;
+ break;
+ default:
+ btn_start.disabled = true;
+ btn_action.disabled = true;
+ btn_stop.disabled = true;
+ btn_enable.disabled = true;
+ btn_disable.disabled = true;
+ break;
+ }
+ }
+ else {
+ btn_start.disabled = true;
+ btn_action.disabled = true;
+ btn_stop.disabled = true;
+ btn_enable.disabled = false;
+ btn_disable.disabled = true;
+ }
+
+ var buttonsDiv = [];
+ var buttonsTitle = E('label', { class: 'cbi-value-title' }, _("Service Control"))
+ var buttonsText = E('div', {}, [btn_start, btn_gap, btn_action, btn_gap, btn_stop, btn_gap_long, btn_enable, btn_gap, btn_disable]);
+ var buttonsField = E('div', { class: 'cbi-value-field' }, buttonsText);
+ if (status.version) {
+ buttonsDiv = E('div', { class: 'cbi-value' }, [buttonsTitle, buttonsField]);
+ }
+
+ return E('div', {}, [header, statusDiv, warningsDiv, errorsDiv, buttonsDiv]);
+ });
+ },
+});
+
+RPC.on('setInitAction', function (reply) {
+ ui.hideModal();
+ location.reload();
+});
+
+return L.Class.extend({
+ status: status,
+ getPlatformSupport: getPlatformSupport
+});
diff --git a/applications/luci-app-simple-adblock/htdocs/luci-static/resources/view/simple-adblock/overview.js b/applications/luci-app-simple-adblock/htdocs/luci-static/resources/view/simple-adblock/overview.js
new file mode 100644
index 0000000000..e9334654a1
--- /dev/null
+++ b/applications/luci-app-simple-adblock/htdocs/luci-static/resources/view/simple-adblock/overview.js
@@ -0,0 +1,161 @@
+// Copyright 2022 Stan Grishin <stangri@melmac.ca>
+// This code wouldn't have been possible without help from [@vsviridov](https://github.com/vsviridov)
+
+'use strict';
+'require form';
+'require uci';
+'require view';
+'require simple-adblock.status as adb';
+
+var pkg = {
+ get Name() { return 'simple-adblock'; },
+ get URL() { return 'https://docs.openwrt.melmac.net/' + pkg.Name + '/'; }
+};
+
+return view.extend({
+ load: function () {
+ return Promise.all([
+ uci.load(pkg.Name)
+ ]);
+ },
+
+ render: function () {
+ return Promise.all([
+ L.resolveDefault(adb.getPlatformSupport(), {}),
+ ]).then(function (data) {
+ var replyPlatform = data[0];
+ var status, m, s, o;
+
+ status = new adb.status();
+ m = new form.Map(pkg.Name, _("Simple AdBlock - Configuration"));
+ s = m.section(form.NamedSection, 'config', pkg.Name);
+ s.tab("tab_basic", _("Basic Configuration"));
+ s.tab("tab_advanced", _("Advanced Configuration"));
+
+ o = s.taboption("tab_basic", form.ListValue, "config_update_enabled", _("Automatic Config Update"),
+ _("Perform config update before downloading the block/allow-lists."));
+ o.value("0", _("Disable"));
+ o.value("1", _("Enable"));
+ o.default = ("0", _("Disable"));
+
+ o = s.taboption("tab_basic", form.ListValue, "verbosity", _("Output Verbosity Setting"),
+ _("Controls system log and console output verbosity."));
+ o.value("0", _("Suppress output"));
+ o.value("1", _("Some output"));
+ o.value("2", _("Verbose output"));
+ o.default = ("2", _("Verbose output"));
+
+ o = s.taboption("tab_basic", form.ListValue, "force_dns", _("Force Router DNS"),
+ _("Forces Router DNS use on local devices, also known as DNS Hijacking."));
+ o.value("0", _("Let local devices use their own DNS servers if set"));
+ o.value("1", _("Force Router DNS server to all local devices"));
+ o.default = ("1", _("Force Router DNS server to all local devices"));
+
+
+ if ((replyPlatform[pkg.Name].leds).length) {
+ o = s.taboption("tab_basic", form.ListValue, "led", _("LED to indicate status"),
+ _("Pick the LED not already used in %sSystem LED Configuration%s.").format("<a href=\"" +
+ L.url("admin", "system", "leds") + "\">", "</a>"));
+ o.value("", _("none"));
+ (replyPlatform[pkg.Name].leds).forEach(element => {
+ o.value(element);
+ });
+ o.rmempty = false;
+ }
+ var text = _("DNS resolution option, see the %sREADME%s for details.")
+ .format("<a href=\"" + pkg.URL + "#dns-resolution-option\" target=\"_blank\">", "</a>");
+ if (!(replyPlatform[pkg.Name].dnsmasq_installed)) {
+ text += "<br />" + _("Please note that %s is not supported on this system.").format("<i>dnsmasq.addnhosts</i>");
+ text += "<br />" + _("Please note that %s is not supported on this system.").format("<i>dnsmasq.conf</i>");
+ text += "<br />" + _("Please note that %s is not supported on this system.").format("<i>dnsmasq.ipset</i>");
+ text += "<br />" + _("Please note that %s is not supported on this system.").format("<i>dnsmasq.servers</i>");
+ }
+ else {
+ if (!(replyPlatform[pkg.Name].dnsmasq_ipset_support)) {
+ text += _("Please note that %s is not supported on this system.").format("<i>dnsmasq.ipset</i>") + "<br />";
+ }
+ if (!(replyPlatform[pkg.Name].dnsmasq_nftset_support)) {
+ text += _("Please note that %s is not supported on this system.").format("<i>dnsmasq.nftset</i>") + "<br />";
+ }
+ }
+ if (!(replyPlatform[pkg.Name].unbound_installed)) {
+ text = text + "<br />" + _("Please note that %s is not supported on this system.")
+ .format("<i>unbound.adb_list</i>");
+ }
+
+ o = s.taboption("tab_advanced", form.ListValue, "dns", _("DNS Service"), text);
+ if (replyPlatform[pkg.Name].dnsmasq_installed) {
+ o.value("dnsmasq.addnhosts", _("dnsmasq additional hosts"));
+ o.value("dnsmasq.conf", _("dnsmasq config"));
+ if (replyPlatform[pkg.Name].dnsmasq_ipset_support) {
+ o.value("dnsmasq.ipset", _("dnsmasq ipset"));
+ }
+ if (replyPlatform[pkg.Name].dnsmasq_nftset_support) {
+ o.value("dnsmasq.nftset", _("dnsmasq nft set"));
+ }
+ o.value("dnsmasq.servers", _("dnsmasq servers file"));
+ }
+ if (replyPlatform[pkg.Name].unbound_installed) {
+ o.value("unbound.adb_list", _("unbound adblock list"));
+ }
+ o.default = ("dnsmasq.servers", _("dnsmasq servers file"));
+
+ o = s.taboption("tab_advanced", form.ListValue, "ipv6_enabled", _("IPv6 Support"),
+ _("Add IPv6 entries to block-list."));
+ o.value("", _("Do not add IPv6 entries"));
+ o.value("1", _("Add IPv6 entries"));
+ o.depends('dns', 'dnsmasq.addnhosts');
+ o.depends('dns', 'dnsmasq.nftset');
+ o.default = ("", _("Do not add IPv6 entries"));
+ o.rmempty = true;
+
+ o = s.taboption("tab_advanced", form.Value, "download_timeout", _("Download time-out (in seconds)"),
+ _("Stop the download if it is stalled for set number of seconds."));
+ o.default = "10";
+ o.datatype = "range(1,60)";
+
+ o = s.taboption("tab_advanced", form.Value, "curl_retry", _("Curl download retry"),
+ _("If curl is installed and detected, it would retry download this many times on timeout/fail."));
+ o.default = "3";
+ o.datatype = "range(0,30)";
+
+ o = s.taboption("tab_advanced", form.ListValue, "parallel_downloads", _("Simultaneous processing"),
+ _("Launch all lists downloads and processing simultaneously, reducing service start time."));
+ o.value("0", _("Do not use simultaneous processing"));
+ o.value("1", _("Use simultaneous processing"));
+ o.default = ("1", _("Use simultaneous processing"));
+
+ o = s.taboption("tab_advanced", form.ListValue, "compressed_cache", _("Store compressed cache file on router"),
+ _("Attempt to create a compressed cache of block-list in the persistent memory."));
+ o.value("0", _("Do not store compressed cache"));
+ o.value("1", _("Store compressed cache"));
+ o.default = ("0", _("Do not store compressed cache"));
+
+ o = s.taboption("tab_advanced", form.ListValue, "debug", _("Enable Debugging"),
+ _("Enables debug output to /tmp/simple-adblock.log."));
+ o.value("0", _("Disable Debugging"));
+ o.value("1", _("Enable Debugging"));
+ o.default = ("0", _("Disable Debugging"));
+
+ s = m.section(form.NamedSection, "config", "simple-adblock",
+ _("Allowed and Blocked Lists Management"));
+ o = s.option(form.DynamicList, "allowed_domain", _("Allowed Domains"),
+ _("Individual domains to be allowed."));
+ o.addremove = false;
+ o = s.option(form.DynamicList, "allowed_domains_url", _("Allowed Domain URLs"),
+ _("URLs to lists of domains to be allowed."));
+ o.addremove = false;
+ o = s.option(form.DynamicList, "blocked_domain", _("Blocked Domains"),
+ _("Individual domains to be blocked."));
+ o.addremove = false;
+ o = s.option(form.DynamicList, "blocked_domains_url", _("Blocked Domain URLs"),
+ _("URLs to lists of domains to be blocked."));
+ o.addremove = false;
+ o = s.option(form.DynamicList, "blocked_hosts_url", _("Blocked Hosts URLs"),
+ _("URLs to lists of hosts to be blocked."));
+ o.addremove = false;
+
+ return Promise.all([status.render(), m.render()]);
+ })
+ }
+});