From: Dirk Brenken Date: Fri, 30 May 2025 16:42:18 +0000 (+0200) Subject: luci-app-adblock: sync with update 4.4.2-1 X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=d971e88a0f7ab653d1bcf73dd4481e205c841c0b;p=openwrt-luci.git luci-app-adblock: sync with update 4.4.2-1 Various fixes, a new modal reporting GeoIP map of blocked domains. Signed-off-by: Dirk Brenken --- diff --git a/applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/dnsreport.js b/applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/dnsreport.js index e8806db3e9..07f1ec0da4 100644 --- a/applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/dnsreport.js +++ b/applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/dnsreport.js @@ -2,6 +2,7 @@ 'require view'; 'require fs'; 'require ui'; +'require uci'; /* button handling @@ -200,19 +201,65 @@ function handleAction(ev) { ]); document.getElementById('refresh').focus(); } + + if (ev === 'map') { + let md = L.ui.showModal(null, [ + E('div', { id: 'mapModal', + style: 'position: relative;' }, [ + E('iframe', { + id: 'mapFrame', + src: L.resource('view/adblock/map.html'), + style: 'width: 100%; height: 80vh; border: none;' + }), + ]), + E('div', { 'class': 'right' }, [ + E('button', { + 'class': 'btn cbi-button', + 'click': ui.createHandlerFn(this, function (ev) { + ui.hideModal(); + sessionStorage.clear(); + location.reload(); + }) + }, _('Cancel')), + ' ', + E('button', { + 'class': 'btn cbi-button-action', + 'click': ui.createHandlerFn(this, function (ev) { + const iframe = document.getElementById('mapFrame'); + iframe.contentWindow.location.reload(); + }) + }, _('Map Reset')) + ]) + ]); + md.style.maxWidth = '90%'; + document.getElementById('mapModal').focus(); + } } return view.extend({ load: function() { - return L.resolveDefault(fs.exec_direct('/etc/init.d/adblock', ['report', 'json', '10', '50', '+']),''); + return Promise.all([ + L.resolveDefault(fs.exec_direct('/etc/init.d/adblock', ['report', 'json', '10', '50', '+']),''), + uci.load('adblock') + ]); }, render: function(dnsreport) { - if (!dnsreport) { - dnsreport = '{}'; - }; - var content; - content = JSON.parse(dnsreport); + let content, notMsg, errMsg; + + if (dnsreport) { + try { + content = JSON.parse(dnsreport[0]); + } catch (e) { + content = ""; + if (!errMsg) { + errMsg = true; + ui.addNotification(null, E('p', _('Unable to parse the report file!')), 'error'); + } + } + } else { + content = ""; + } var rows_top = []; var tbl_top = E('table', { 'class': 'table', 'id': 'top_10' }, [ @@ -227,28 +274,28 @@ return view.extend({ ]); var max = 0; - if (content.top_clients && content.top_domains && content.top_blocked) { - max = Math.max(content.top_clients.length, content.top_domains.length, content.top_blocked.length); + if (content[0].top_clients && content[0].top_domains && content[0].top_blocked) { + max = Math.max(content[0].top_clients.length, content[0].top_domains.length, content[0].top_blocked.length); } for (var i = 0; i < max; i++) { var a_cnt = '\xa0', a_addr = '\xa0', b_cnt = '\xa0', b_addr = '\xa0', c_cnt = '\xa0', c_addr = '\xa0'; - if (content.top_clients[i]) { - a_cnt = content.top_clients[i].count; + if (content[0].top_clients[i]) { + a_cnt = content[0].top_clients[i].count; } - if (content.top_clients[i]) { - a_addr = content.top_clients[i].address; + if (content[0].top_clients[i]) { + a_addr = content[0].top_clients[i].address; } - if (content.top_domains[i]) { - b_cnt = content.top_domains[i].count; + if (content[0].top_domains[i]) { + b_cnt = content[0].top_domains[i].count; } - if (content.top_domains[i]) { - b_addr = '' + content.top_domains[i].address + ''; + if (content[0].top_domains[i]) { + b_addr = '' + content[0].top_domains[i].address + ''; } - if (content.top_blocked[i]) { - c_cnt = content.top_blocked[i].count; + if (content[0].top_blocked[i]) { + c_cnt = content[0].top_blocked[i].count; } - if (content.top_blocked[i]) { - c_addr = '' + content.top_blocked[i].address + ''; + if (content[0].top_blocked[i]) { + c_addr = '' + content[0].top_blocked[i].address + ''; } rows_top.push([ a_cnt, @@ -274,16 +321,16 @@ return view.extend({ ]); max = 0; - if (content.requests) { + if (content[0].requests) { var button; - max = content.requests.length; + max = content[0].requests.length; for (var i = 0; i < max; i++) { - if (content.requests[i].rc === 'NX') { + if (content[0].requests[i].rc === 'NX') { button = E('button', { 'class': 'btn cbi-button cbi-button-positive', 'style': 'word-break: inherit', 'name': 'allowlist', - 'value': content.requests[i].domain, + 'value': content[0].requests[i].domain, 'click': handleAction }, [ _('Allowlist...') ]); } else { @@ -291,16 +338,16 @@ return view.extend({ 'class': 'btn cbi-button cbi-button-negative', 'style': 'word-break: inherit', 'name': 'blocklist', - 'value': content.requests[i].domain, + 'value': content[0].requests[i].domain, 'click': handleAction }, [ _('Blocklist...') ]); } rows_requests.push([ - content.requests[i].date, - content.requests[i].time, - content.requests[i].client, - '' + content.requests[i].domain + '', - content.requests[i].rc, + content[0].requests[i].date, + content[0].requests[i].time, + content[0].requests[i].client, + '' + content[0].requests[i].domain + '', + content[0].requests[i].rc, button ]); } @@ -313,19 +360,19 @@ return view.extend({ E('p', '\xa0'), E('div', { 'class': 'cbi-value' }, [ E('div', { 'class': 'cbi-value-title', 'style': 'float:left;width:230px' }, _('Start Timestamp')), - E('div', { 'class': 'cbi-value-title', 'id': 'start', 'style': 'float:left;color:#37c' }, (content.start_date || '-') + ', ' + (content.start_time || '-')) + E('div', { 'class': 'cbi-value-title', 'id': 'start', 'style': 'float:left;color:#37c' }, (content[0].start_date || '-') + ', ' + (content[0].start_time || '-')) ]), E('div', { 'class': 'cbi-value' }, [ E('div', { 'class': 'cbi-value-title', 'style': 'float:left;width:230px' }, _('End Timestamp')), - E('div', { 'class': 'cbi-value-title', 'id': 'end', 'style': 'float:left;color:#37c' }, (content.end_date || '-') + ', ' + (content.end_time || '-')) + E('div', { 'class': 'cbi-value-title', 'id': 'end', 'style': 'float:left;color:#37c' }, (content[0].end_date || '-') + ', ' + (content[0].end_time || '-')) ]), E('div', { 'class': 'cbi-value' }, [ E('div', { 'class': 'cbi-value-title', 'style': 'float:left;width:230px' }, _('Total DNS Requests')), - E('div', { 'class': 'cbi-value-title', 'id': 'total', 'style': 'float:left;color:#37c' }, content.total || '-') + E('div', { 'class': 'cbi-value-title', 'id': 'total', 'style': 'float:left;color:#37c' }, content[0].total || '-') ]), E('div', { 'class': 'cbi-value' }, [ E('div', { 'class': 'cbi-value-title', 'style': 'float:left;width:230px' }, _('Blocked DNS Requests')), - E('div', { 'class': 'cbi-value-title', 'id': 'blocked', 'style': 'float:left;color:#37c' }, (content.blocked || '-') + ' (' + (content.percent || '-') + ')') + E('div', { 'class': 'cbi-value-title', 'id': 'blocked', 'style': 'float:left;color:#37c' }, (content[0].blocked || '-') + ' (' + (content[0].percent || '-') + ')') ]) ]), E('div', { 'class': 'cbi-section' }, [ @@ -342,6 +389,28 @@ return view.extend({ ]) ]), E('div', { 'class': 'cbi-page-actions' }, [ + E('button', { + 'class': 'btn cbi-button cbi-button-apply', + 'style': 'float:none;margin-right:.4em;', + 'click': ui.createHandlerFn(this, function () { + if (uci.get('adblock', 'global', 'adb_map') !== '1') { + if (!notMsg) { + notMsg = true; + return ui.addNotification(null, E('p', _('GeoIP Map is not enabled!')), 'info'); + } + } + if (content[1] && content[1].length > 1) { + sessionStorage.setItem('mapData', JSON.stringify(content[1])); + return handleAction('map'); + } + else { + if (!notMsg) { + notMsg = true; + return ui.addNotification(null, E('p', _('No GeoIP Map data!')), 'info'); + } + } + }) + }, [_('Map...')]), E('button', { 'class': 'btn cbi-button cbi-button-apply', 'style': 'float:none;margin-right:.4em;', diff --git a/applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/feeds.js b/applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/feeds.js index acfa8995d2..6a133c3439 100644 --- a/applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/feeds.js +++ b/applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/feeds.js @@ -121,11 +121,18 @@ function handleEdit(ev) { const nodeKeys = document.querySelectorAll('[id^="widget.cbid.json"][id$="name"]'); for (let i = 0; i < nodeKeys.length; i++) { let subElements = {}; - let elements = document.querySelectorAll('[id^="widget.cbid.json.' + nodeKeys[i].id.split('.')[3] + '\."]'); + const elements = document.querySelectorAll('[id^="widget.cbid.json.' + nodeKeys[i].id.split('.')[3] + '\."], \ + [id^="cbid.json.' + nodeKeys[i].id.split('.')[3] + '\.rule"]'); for (const element of elements) { - let key = element.id.split('.')[4]; - let value = element.value || ""; - if (value === "") { + let key; + const value = element.value || ""; + const parts = element.id.split('.'); + if (parts.length === 5) { + key = element.id.split('.')[4]; + } else if (parts.length === 4) { + key = element.id.split('.')[3]; + } + if (!key || value === "") { continue; } switch (key) { @@ -207,7 +214,7 @@ return view.extend({ return true; } - o = s.option(form.ListValue, 'rule', _('Rule')); + o = s.option(form.Value, 'rule', _('Rule')); o.value('/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($1)}', _('')); o.value('/^127\\.0\\.0\\.1[[:space:]]+([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($2)}', _('127.0.0.1')); o.value('/^0\\.0\\.0\\.0[[:space:]]+([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($2)}', _('0.0.0.0')); diff --git a/applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/map.html b/applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/map.html new file mode 100644 index 0000000000..e747a59b85 --- /dev/null +++ b/applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/map.html @@ -0,0 +1,118 @@ + + + + + adblock Map + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/overview.js b/applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/overview.js index 6d612fc452..45d26cd197 100644 --- a/applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/overview.js +++ b/applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/overview.js @@ -110,10 +110,6 @@ return view.extend({ if (backend && info) { backend.textContent = info.dns_backend || '-'; } - var utils = document.getElementById('utils'); - if (utils && info) { - utils.textContent = info.run_utils || '-'; - } var ifaces = document.getElementById('ifaces'); if (ifaces && info) { ifaces.textContent = info.run_ifaces || '-'; @@ -160,10 +156,6 @@ return view.extend({ E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;padding-top:0rem;' }, _('DNS Backend')), E('div', { 'class': 'cbi-value-field', 'id': 'backend', 'style': 'margin-bottom:-5px;color:#37c;' }, '-') ]), - E('div', { 'class': 'cbi-value' }, [ - E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;padding-top:0rem;' }, _('Run Utils')), - E('div', { 'class': 'cbi-value-field', 'id': 'utils', 'style': 'margin-bottom:-5px;color:#37c;' }, '-') - ]), E('div', { 'class': 'cbi-value' }, [ E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;padding-top:0rem;' }, _('Run Interfaces')), E('div', { 'class': 'cbi-value-field', 'id': 'ifaces', 'style': 'margin-bottom:-5px;color:#37c;' }, '-') @@ -282,12 +274,19 @@ return view.extend({ o = s.taboption('additional', form.Flag, 'adb_debug', _('Verbose Debug Logging'), _('Enable verbose debug logging in case of any processing errors.')); o.rmempty = false; - o = s.taboption('additional', form.Flag, 'adb_nice', _('Low Priority Service'), _('Reduce the priority of the adblock background processing to take fewer resources from the system.')); - o.enabled = '10'; + o = s.taboption('additional', form.ListValue, 'adb_nicelimit', _('Nice Level'), _('The selected priority will be used for adblock background processing.')); + o.value('-20', _('Highest Priority')); + o.value('-10', _('High Priority')); + o.value('0', _('Normal Priority')); + o.value('10', _('Less Priority')); + o.value('19', _('Least Priority')); + o.default = '0'; + o.placeholder = _('-- default --'); + o.create = true; + o.optional = true; o.rmempty = true; - o = s.taboption('additional', form.Value, 'adb_tmpbase', _('Base Temp Directory'), _('Base temp directory for all adblock related runtime operations, \ - e.g. downloading, sorting, merging etc.')); + o = s.taboption('additional', form.Value, 'adb_basedir', _('Base Directory'), _('Base working directory during adblock processing.')); o.placeholder = '/tmp'; o.rmempty = true; @@ -410,6 +409,10 @@ return view.extend({ o = s.taboption('adv_report', form.Flag, 'adb_represolve', _('Resolve IPs'), _('Resolve reporting IP addresses by using reverse DNS (PTR) lookups.')); o.rmempty = true; + o = s.taboption('adv_report', form.Flag, 'adb_map', _('GeoIP Map'), _('Enable a GeoIP map that shows the geographical location of the blocked domains. This requires external requests to get the map tiles and geolocation data.')); + o.optional = true; + o.rmempty = true; + /* advanced email settings tab */ diff --git a/applications/luci-app-adblock/root/usr/share/luci/menu.d/luci-app-adblock.json b/applications/luci-app-adblock/root/usr/share/luci/menu.d/luci-app-adblock.json index 807310b957..bc7d2edd86 100644 --- a/applications/luci-app-adblock/root/usr/share/luci/menu.d/luci-app-adblock.json +++ b/applications/luci-app-adblock/root/usr/share/luci/menu.d/luci-app-adblock.json @@ -57,10 +57,10 @@ }, "admin/services/adblock/logread": { "title": "Log View", - "order": 50, + "order": 60, "action": { "type": "view", "path": "adblock/logread" } } -} +} \ No newline at end of file