From 0f97532791ac8b3dd4cba0559bdf1dcce99cfd26 Mon Sep 17 00:00:00 2001 From: Dirk Brenken Date: Sun, 26 Oct 2025 20:38:01 +0100 Subject: [PATCH] luci-app-banip: use separate log viewer template Signed-off-by: Dirk Brenken --- .../resources/view/banip/firewall_log.js | 4 +- .../resources/view/banip/logtemplate.js | 48 +++++++++++++++++++ .../resources/view/banip/processing_log.js | 4 +- .../usr/share/rpcd/acl.d/luci-app-banip.json | 15 ++++-- 4 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 applications/luci-app-banip/htdocs/luci-static/resources/view/banip/logtemplate.js diff --git a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/firewall_log.js b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/firewall_log.js index 08b7364f3c..7ed6580bc0 100644 --- a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/firewall_log.js +++ b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/firewall_log.js @@ -1,4 +1,4 @@ 'use strict'; -'require tools.views as views'; +'require view.banip.logtemplate as LogTemplate'; -return views.LogreadBox(" banIP/", _('banIP firewall Log')); +return LogTemplate.Logview('banIP/', 'banIP'); 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 new file mode 100644 index 0000000000..23a8fbebe7 --- /dev/null +++ b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/logtemplate.js @@ -0,0 +1,48 @@ +'use strict'; +'require fs'; + +function Logview(logtag, name) { + return L.view.extend({ + load: function() { + return Promise.all([ + L.resolveDefault(fs.stat('/sbin/logread'), null), + L.resolveDefault(fs.stat('/usr/sbin/logread'), null) + ]); + }, + + render: function(stat) { + let logger = stat[0]?.path || stat[1]?.path || null; + + if (!logger) { + return E('div', { class: 'error' }, _('logread not found on system.')); + } + L.Poll.add(function() { + return L.resolveDefault(fs.exec_direct(logger, ['-e', logtag])).then(function(res) { + var log = document.getElementById('logfile'); + if (log) { + log.value = res ? res.trim() : _('No %s related logs yet!').format(name); + log.scrollTop = log.scrollHeight; + } + }); + }); + return E('div', { class: 'cbi-map' }, [ + E('div', { class: 'cbi-section' }, [ + E('div', { class: 'cbi-section-descr' }, _('The syslog output, pre-filtered for messages related to: %s').format(name)), + E('textarea', { + id: 'logfile', + style: 'min-height: 500px; max-height: 90vh; width: 100%; padding: 5px; font-family: monospace; resize: vertical;', + readonly: 'readonly', + wrap: 'off' + }) + ]) + ]); + }, + handleSaveApply: null, + handleSave: null, + handleReset: null + }); +} + +return L.Class.extend({ + Logview: Logview +}); diff --git a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/processing_log.js b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/processing_log.js index c693610378..79a8e6292f 100644 --- a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/processing_log.js +++ b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/processing_log.js @@ -1,4 +1,4 @@ 'use strict'; -'require tools.views as views'; +'require view.banip.logtemplate as LogTemplate'; -return views.LogreadBox("banIP-", _('banIP Log')); +return LogTemplate.Logview('banIP-', 'banIP'); 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 b5884a6fb7..51a1d63222 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 @@ -30,6 +30,18 @@ "/var/run/banip.lock": [ "read" ], + "/sbin/logread -e banIP-": [ + "exec" + ], + "/usr/sbin/logread -e banIP-": [ + "exec" + ], + "/sbin/logread -e banIP/": [ + "exec" + ], + "/usr/sbin/logread -e banIP/": [ + "exec" + ], "/usr/sbin/nft -tj list sets": [ "exec" ], @@ -58,9 +70,6 @@ "exec" ] }, - "ubus": { - "log": [ "read" ] - }, "uci": [ "banip" ] -- 2.30.2