diff --git a/applications/luci-app-adblock/Makefile b/applications/luci-app-adblock/Makefile index 6d56148f87..6ea51a3075 100644 --- a/applications/luci-app-adblock/Makefile +++ b/applications/luci-app-adblock/Makefile @@ -7,7 +7,7 @@ LUCI_TITLE:=LuCI support for Adblock LUCI_DEPENDS:=+luci-base +luci-lib-uqr +adblock PKG_VERSION:=4.5.3 -PKG_RELEASE:=2 +PKG_RELEASE:=3 PKG_LICENSE:=Apache-2.0 PKG_MAINTAINER:=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 4bd71a8f5e..8615229a3f 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 @@ -88,9 +88,9 @@ function handleAction(ev) { document.getElementById('allowlist').focus(); } - if (ev === 'query') { - ui.showModal(_('Blocklist Query'), [ - E('p', _('Query active blocklists and backups for a specific domain.')), + if (ev === 'search') { + ui.showModal(_('Blocklist Search'), [ + E('p', _('Search active blocklists and backups for a specific domain.')), E('div', { 'class': 'left', 'style': 'display:flex; flex-direction:column' }, [ E('label', { 'style': 'padding-top:.5em', 'id': 'run' }, [ E('input', { @@ -126,21 +126,37 @@ function handleAction(ev) { if (domain) { document.getElementById('run').classList.add("spinning"); document.getElementById('search').value = domain; - document.getElementById('result').textContent = 'The query is running, please wait...'; - L.resolveDefault(fs.exec_direct('/etc/init.d/adblock', ['query', domain])).then(function (res) { - const result = document.getElementById('result'); - if (res) { - result.textContent = res.trim(); - } else { - result.textContent = _('No Query results!'); - } - document.getElementById('run').classList.remove("spinning"); - document.getElementById('search').value = ''; + document.getElementById('result').textContent = _('The search is running, please wait...'); + + if (window._adbSearchPoller) { + clearInterval(window._adbSearchPoller); + window._adbSearchPoller = null; + } + L.resolveDefault(fs.write('/var/run/adblock.search', ''), '').then(function () { + L.resolveDefault(fs.exec_direct('/etc/init.d/adblock', ['search', domain]), ''); + let attempts = 0; + window._adbSearchPoller = setInterval(function () { + attempts++; + L.resolveDefault(fs.read('/var/run/adblock.search'), '').then(function (res) { + if (res && res.trim()) { + clearInterval(window._adbSearchPoller); + window._adbSearchPoller = null; + document.getElementById('result').textContent = res.trim(); + document.getElementById('run').classList.remove("spinning"); + document.getElementById('search').value = ''; + } else if (attempts >= 40) { + clearInterval(window._adbSearchPoller); + window._adbSearchPoller = null; + document.getElementById('result').textContent = _('No Search results!'); + document.getElementById('run').classList.remove("spinning"); + } + }); + }, 3000); }); } document.getElementById('search').focus(); }) - }, _('Query')) + }, _('Search')) ]) ]); document.getElementById('search').focus(); @@ -197,10 +213,27 @@ function handleAction(ev) { const top_count = document.getElementById('top_count').value; const res_count = document.getElementById('res_count').value; const search = document.getElementById('search').value.trim().replace(/[^\w.\-:]/g, '') || '+'; - L.resolveDefault(fs.exec_direct('/etc/init.d/adblock', ['report', 'gen', top_count, res_count, search]), '') - .then(function () { - location.reload(); - }); + L.resolveDefault(fs.write('/var/run/adblock.report', ''), '').then(function () { + L.resolveDefault(fs.exec_direct('/etc/init.d/adblock', ['report', 'gen', top_count, res_count, search]), ''); + let attempts = 0; + let poller = setInterval(function () { + attempts++; + L.resolveDefault(fs.read('/var/run/adblock.report'), '').then(function (res) { + if (res && res.trim()) { + clearInterval(poller); + ui.hideModal(); + location.reload(); + } else if (attempts >= 40) { + clearInterval(poller); + document.querySelectorAll('.cbi-page-actions button').forEach(function (btn) { + btn.disabled = false; + }); + document.getElementById('refresh').classList.remove('spinning'); + ui.addNotification(null, E('p', _('Failed to generate adblock report!')), 'error'); + } + }); + }, 3000); + }); } }, _('Refresh')) ]) @@ -420,11 +453,11 @@ return view.extend({ E('button', { 'class': 'btn cbi-button cbi-button-apply', 'style': 'float:none;margin-right:.4em;', - 'title': 'Blocklist Query', + 'title': 'Blocklist Search', 'click': ui.createHandlerFn(this, function () { - return handleAction('query'); + return handleAction('search'); }) - }, [_('Blocklist Query...')]), + }, [_('Blocklist Search...')]), E('button', { 'class': 'btn cbi-button cbi-button-positive important', 'style': 'float:none;margin-right:.4em;', diff --git a/applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/logtemplate.js b/applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/logtemplate.js index 22160d1d5d..2026fffe8f 100644 --- a/applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/logtemplate.js +++ b/applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/logtemplate.js @@ -17,25 +17,15 @@ function Logview(logtag, name) { return callLogRead(1000, false, true).then(res => { const logEl = document.getElementById('logfile'); if (!logEl) return; - const filtered = (res?.log ?? []) .filter(entry => !logtag || entry.msg.includes(logtag)) .map(entry => { - const d = new Date(entry.time * 1000); - const date = d.toLocaleDateString([], { - year: 'numeric', - month: '2-digit', - day: '2-digit' - }); - const time = d.toLocaleTimeString([], { - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - hour12: false - }); + const d = new Date(entry.time); + const pad = n => String(n).padStart(2, '0'); + const date = `${pad(d.getDate())}/${pad(d.getMonth() + 1)}/${d.getFullYear()}`; + const time = `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`; return `[${date}-${time}] ${entry.msg}`; }); - logEl.value = filtered.length > 0 ? filtered.join('\n') : _('No %s related logs yet!').format(name); diff --git a/applications/luci-app-adblock/root/usr/share/rpcd/acl.d/luci-app-adblock.json b/applications/luci-app-adblock/root/usr/share/rpcd/acl.d/luci-app-adblock.json index 4016b2420b..a1aa6c436d 100644 --- a/applications/luci-app-adblock/root/usr/share/rpcd/acl.d/luci-app-adblock.json +++ b/applications/luci-app-adblock/root/usr/share/rpcd/acl.d/luci-app-adblock.json @@ -2,29 +2,74 @@ "luci-app-adblock": { "description": "Grant access to LuCI app adblock", "write": { - "uci": [ "adblock" ], + "uci": [ + "adblock" + ], "file": { - "/etc/adblock/*": [ "read", "write" ], - "/etc/adblock/adblock.allowlist": [ "write" ], - "/etc/adblock/adblock.blocklist": [ "write" ], - "/etc/adblock/adblock.custom.feeds": [ "read", "write" ] + "/etc/adblock/*": [ + "read" + ], + "/etc/adblock/adblock.allowlist": [ + "read", + "write" + ], + "/etc/adblock/adblock.blocklist": [ + "read", + "write" + ], + "/etc/adblock/adblock.custom.feeds": [ + "read", + "write" + ], + "/var/run/adblock.search": [ + "read", + "write" + ], + "/var/run/adblock.report": [ + "read", + "write" + ] } }, "read": { - "cgi-io": [ "exec" ], + "cgi-io": [ + "exec" + ], "file": { - "/var/run/adblock.pid": [ "read" ], - "/var/run/adb_runtime.json": [ "read" ], - "/etc/init.d/adblock reload": [ "exec" ], - "/etc/init.d/adblock restart": [ "exec" ], - "/etc/init.d/adblock suspend": [ "exec" ], - "/etc/init.d/adblock resume": [ "exec" ], - "/etc/init.d/adblock stop": [ "exec" ], - "/etc/init.d/adblock report [a-z]* [0-9]* [0-9]* *": [ "exec" ], - "/etc/init.d/adblock query *": [ "exec" ] + "/var/run/adblock.pid": [ + "read" + ], + "/var/run/adb_runtime.json": [ + "read" + ], + "/etc/init.d/adblock reload": [ + "exec" + ], + "/etc/init.d/adblock restart": [ + "exec" + ], + "/etc/init.d/adblock suspend": [ + "exec" + ], + "/etc/init.d/adblock resume": [ + "exec" + ], + "/etc/init.d/adblock stop": [ + "exec" + ], + "/etc/init.d/adblock report *": [ + "exec" + ], + "/etc/init.d/adblock search *": [ + "exec" + ] }, - "uci": [ "adblock" ], - "log": [ "read" ] + "uci": [ + "adblock" + ], + "log": [ + "read" + ] } } } \ No newline at end of file