diff --git a/applications/luci-app-banip/Makefile b/applications/luci-app-banip/Makefile index 783fc06475..f9e50b0b96 100644 --- a/applications/luci-app-banip/Makefile +++ b/applications/luci-app-banip/Makefile @@ -7,7 +7,7 @@ LUCI_TITLE:=LuCI support for banIP LUCI_DEPENDS:=+luci-base +banip PKG_VERSION:=1.8.1 -PKG_RELEASE:=2 +PKG_RELEASE:=3 PKG_LICENSE:=Apache-2.0 PKG_MAINTAINER:=Dirk Brenken diff --git a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/feeds.js b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/feeds.js index 1b8bbf47a5..e1827276b7 100644 --- a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/feeds.js +++ b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/feeds.js @@ -233,7 +233,7 @@ return view.extend({ o = s.option(form.Value, 'rule', _('Rule')); o.value('feed 1', _('')); o.value('feed 1 ,', _('')); - o.value('feed 13', _(' ')); + o.value('feed 13', _('')); o.value('suricata 1', _('')); o.optional = true; o.rmempty = true; diff --git a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/logtemplate.js b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/logtemplate.js index 22160d1d5d..2026fffe8f 100644 --- a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/logtemplate.js +++ b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/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-banip/htdocs/luci-static/resources/view/banip/setreport.js b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/setreport.js index 1f59bd1215..c01268a12f 100644 --- a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/setreport.js +++ b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/setreport.js @@ -45,14 +45,34 @@ function handleAction(report, ev) { 'class': 'btn cbi-button-action', 'click': ui.createHandlerFn(this, function (ev) { let ip = document.getElementById('search').value.trim().toLowerCase(); + if (ip) { document.getElementById('search').value = ip; - document.getElementById('result').textContent = 'The search is running, please wait...'; - return L.resolveDefault(fs.exec_direct('/etc/init.d/banip', ['search', ip])).then(function (res) { - let result = document.getElementById('result'); - result.textContent = res.trim(); - document.getElementById('search').value = ''; - }) + document.getElementById('result').textContent = _('Search is running, please wait...'); + if (window._banipPoller) { + clearInterval(window._banipPoller); + window._banipPoller = null; + } + L.resolveDefault(fs.write('/var/run/banIP.search', ''), '').then(function () { + L.resolveDefault(fs.exec_direct('/etc/init.d/banip', ['search', ip]), '').then(function () { + let attempts = 0; + window._banipPoller = setInterval(function () { + attempts++; + L.resolveDefault(fs.read('/var/run/banIP.search'), '').then(function (res) { + if (res && res.trim()) { + clearInterval(window._banipPoller); + window._banipPoller = null; + document.getElementById('result').textContent = res.trim(); + document.getElementById('search').value = ''; + } else if (attempts >= 40) { + clearInterval(window._banipPoller); + window._banipPoller = null; + document.getElementById('result').textContent = _('Search timed out.'); + } + }); + }, 3000); + }); + }); } document.getElementById('search').focus(); }) @@ -132,9 +152,9 @@ function handleAction(report, ev) { let set = document.getElementById('set').value; if (set) { document.getElementById('result').textContent = 'Collecting Set content, please wait...'; - return L.resolveDefault(fs.exec_direct('/etc/init.d/banip', ['content', set, isChecked])).then(function (res) { + return L.resolveDefault(fs.exec_direct('/etc/init.d/banip', ['content', set, isChecked]), '').then(function (res) { let result = document.getElementById('result'); - result.textContent = res.trim(); + result.textContent = res ? res.trim() : _('Network error'); document.getElementById('set').value = ''; }) } @@ -339,18 +359,26 @@ return view.extend({ }); btn.blur(); btn.classList.add('spinning'); - L.resolveDefault(fs.exec_direct('/etc/init.d/banip', ['report', 'gen'])) - .then(function (res) { - if (res !== null) { - location.reload(); - } else { - btn.classList.remove('spinning'); - document.querySelectorAll('.cbi-page-actions button').forEach(function (b) { - b.disabled = false; - }); - ui.addNotification(null, E('p', _('Failed to generate banIP report!')), 'error'); - } - }); + L.resolveDefault(fs.write('/var/run/banIP.report', ''), '').then(function () { + L.resolveDefault(fs.exec_direct('/etc/init.d/banip', ['report', 'gen']), ''); + let attempts = 0; + let poller = setInterval(function () { + attempts++; + L.resolveDefault(fs.read('/var/run/banIP.report'), '').then(function (res) { + if (res && res.trim()) { + clearInterval(poller); + location.reload(); + } else if (attempts >= 40) { + clearInterval(poller); + btn.classList.remove('spinning'); + document.querySelectorAll('.cbi-page-actions button').forEach(function (b) { + b.disabled = false; + }); + ui.addNotification(null, E('p', _('Failed to generate a banIP report!')), 'error'); + } + }); + }, 3000); + }); } }, [_('Refresh')]) ]) diff --git a/applications/luci-app-banip/root/usr/share/rpcd/acl.d/luci-app-banip.json b/applications/luci-app-banip/root/usr/share/rpcd/acl.d/luci-app-banip.json index e43ac0111f..6faf4eb0d7 100644 --- a/applications/luci-app-banip/root/usr/share/rpcd/acl.d/luci-app-banip.json +++ b/applications/luci-app-banip/root/usr/share/rpcd/acl.d/luci-app-banip.json @@ -2,31 +2,80 @@ "luci-app-banip": { "description": "Grant access to LuCI app banIP", "write": { - "uci": [ "banip" ], + "uci": [ + "banip" + ], "file": { - "/etc/banip/*": [ "read", "write" ], - "/etc/banip/banip.allowlist": [ "write" ], - "/etc/banip/banip.blocklist": [ "write" ], - "/etc/banip/banip.custom.feeds": [ "read", "write" ] + "/etc/banip/*": [ + "read" + ], + "/etc/banip/banip.allowlist": [ + "read", + "write" + ], + "/etc/banip/banip.blocklist": [ + "read", + "write" + ], + "/etc/banip/banip.custom.feeds": [ + "read", + "write" + ], + "/var/run/banIP.search": [ + "read", + "write" + ], + "/var/run/banIP.report": [ + "read", + "write" + ] } }, "read": { - "cgi-io": [ "exec" ], + "cgi-io": [ + "exec" + ], "file": { - "/var/run/banip.lock": [ "read" ], - "/var/run/banip_runtime.json": [ "read" ], - "/usr/sbin/nft -tj list sets": [ "exec" ], - "/etc/init.d/banip stop": [ "exec" ], - "/etc/init.d/banip reload": [ "exec" ], - "/etc/init.d/banip restart": [ "exec" ], - "/etc/init.d/banip report json": [ "exec" ], - "/etc/init.d/banip report gen": [ "exec" ], - "/etc/init.d/banip search [A-Za-z0-9:.]*": [ "exec" ], - "/etc/init.d/banip content [A-Za-z0-9]* *": [ "exec" ], - "/etc/init.d/banip status": [ "exec" ] + "/var/run/banip.lock": [ + "read" + ], + "/var/run/banip_runtime.json": [ + "read" + ], + "/usr/sbin/nft -tj list sets": [ + "exec" + ], + "/etc/init.d/banip stop": [ + "exec" + ], + "/etc/init.d/banip reload": [ + "exec" + ], + "/etc/init.d/banip restart": [ + "exec" + ], + "/etc/init.d/banip report json": [ + "exec" + ], + "/etc/init.d/banip report gen": [ + "exec" + ], + "/etc/init.d/banip search *": [ + "exec" + ], + "/etc/init.d/banip content *": [ + "exec" + ], + "/etc/init.d/banip status": [ + "exec" + ] }, - "uci": [ "banip"], - "log": [ "read" ] + "uci": [ + "banip" + ], + "log": [ + "read" + ] } } } \ No newline at end of file