luci-app-adblock: use separate log viewer template
authorDirk Brenken <[email protected]>
Sun, 26 Oct 2025 18:43:48 +0000 (19:43 +0100)
committerDirk Brenken <[email protected]>
Sun, 26 Oct 2025 18:43:48 +0000 (19:43 +0100)
Signed-off-by: Dirk Brenken <[email protected]>
applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/logread.js
applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/logtemplate.js [new file with mode: 0644]
applications/luci-app-adblock/root/usr/share/rpcd/acl.d/luci-app-adblock.json

index 8a86ea45ed0b4def7ede0a7b90617a5a84ecaaa3..36e9535c1b9b52846c977122629e05f89a93087c 100644 (file)
@@ -1,4 +1,4 @@
 'use strict';
-'require tools.views as views';
+'require view.adblock.logtemplate as LogTemplate';
 
-return views.LogreadBox("adblock-", _('Adblock Log'));
\ No newline at end of file
+return LogTemplate.Logview('adblock-', 'adblock');
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
new file mode 100644 (file)
index 0000000..23a8fbe
--- /dev/null
@@ -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
+});
index b0be56557187c47df3fda39f02d22935128915a5..5fc914d3e76756d77a3d45eeda68011a17113199 100644 (file)
                                "/var/run/adb_runtime.json": [
                                        "read"
                                ],
+                               "/sbin/logread -e adblock-": [
+                                       "exec"
+                               ],
+                               "/usr/sbin/logread -e adblock-": [
+                                       "exec"
+                               ],
                                "/etc/init.d/adblock reload": [
                                        "exec"
                                ],
@@ -55,9 +61,6 @@
                                        "exec"
                                ]
                        },
-                       "ubus": {
-                               "log": [ "read" ]
-                       },
                        "uci": [
                                "adblock"
                        ]