widgets: add a re-useable filtered logread view
authorKarl Palsson <karlp@etactica.com>
Mon, 18 Oct 2021 13:04:00 +0000 (13:04 +0000)
committerPaul Donald <newtwen@gmail.com>
Sun, 17 Mar 2024 00:02:19 +0000 (01:02 +0100)
Multiple apps introduced their own implementation of a syslog view,
filtered for just their own application logs.  Pull that out as a shared
view.  Some of these had _minor_ style differences, which has been
"standardized" now.  A full "widget" conversion would allow more end app
tuning of that, but is not implemented.

Signed-off-by: Karl Palsson <karlp@etactica.com>
app-nextdns: fix Logs title

Minor typo, introduced in 625abbf (convert simple controllers to
menu.json)

Signed-off-by: Karl Palsson <karlp@etactica.com>
luci-base: implement shared log reader view

Closes #5452

Signed-off-by: Paul Donald <newtwen@gmail.com>
applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/logread.js
applications/luci-app-banip/htdocs/luci-static/resources/view/banip/processing_log.js
applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/logread.js
applications/luci-app-nextdns/root/usr/share/luci/menu.d/luci-app-nextdns.json
applications/luci-app-travelmate/htdocs/luci-static/resources/view/travelmate/logread.js
modules/luci-base/htdocs/luci-static/resources/tools/views.js [new file with mode: 0644]

index 4dc2a2e53313b624ac5a57ddaf40c9b70f5d98be..89b8b393f7d05bdf1e4657e3d0f86bb76837d468 100644 (file)
@@ -1,41 +1,4 @@
 'use strict';
-'require view';
-'require poll';
-'require fs';
+'require tools.views as views';
 
-return 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) {
-               var logger = stat[0] ? stat[0].path : stat[1] ? stat[1].path : null;
-               poll.add(function() {
-                       return L.resolveDefault(fs.exec_direct(logger, ['-e', 'adblock-'])).then(function(res) {
-                               var log = document.getElementById("logfile");
-                               if (res) {
-                                       log.value = res.trim();
-                               } else {
-                                       log.value = _('No adblock related logs yet!');
-                               }
-                               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 adblock related messages only.')),
-                       E('textarea', {
-                               'id': 'logfile',
-                               'style': 'width: 100% !important; padding: 5px; font-family: monospace',
-                               'readonly': 'readonly',
-                               'wrap': 'off',
-                               'rows': 25
-                       })
-               ]));
-       },
-       handleSaveApply: null,
-       handleSave: null,
-       handleReset: null
-});
+return views.LogreadBox("adblock-", "adblock");
\ No newline at end of file
index b6aaabe9f937d02c873e9bc0fabf9287d27350fe..9d2e1654d79030d5331a81f8c330b15cd4b3e6f6 100644 (file)
@@ -1,41 +1,4 @@
 'use strict';
-'require view';
-'require poll';
-'require fs';
+'require tools.views as views';
 
-return 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) {
-               var logger = stat[0] ? stat[0].path : stat[1] ? stat[1].path : null;
-               poll.add(function () {
-                       return L.resolveDefault(fs.exec_direct(logger, ['-e', 'banIP-'])).then(function (res) {
-                               var log = document.getElementById("logfile");
-                               if (res) {
-                                       log.value = res.trim();
-                               } else {
-                                       log.value = _('No banIP related processing logs yet!');
-                               }
-                               log.scrollTop = log.scrollHeight;
-                       });
-               });
-               return E('div', { class: 'cbi-map' },
-                       E('div', { class: 'cbi-section' }, [
-                               E('div', { class: 'cbi-section-descr' }, _('The syslog output, prefiltered for banIP-related processing log entries only.')),
-                               E('textarea', {
-                                       'id': 'logfile',
-                                       'style': 'width: 100% !important; padding: 5px; font-family: monospace',
-                                       'readonly': 'readonly',
-                                       'wrap': 'off',
-                                       'rows': 25
-                               })
-                       ]));
-       },
-       handleSaveApply: null,
-       handleSave: null,
-       handleReset: null
-});
+return views.LogreadBox("banIP-", "banIP");
index 0ad4a79825a2383fe222b3db63283b26769eb6e5..13b22476f74c7f428f39dd779d3bcdf30f13ee0c 100644 (file)
@@ -1,45 +1,4 @@
 'use strict';
-'require view';
-'require poll';
-'require fs';
+'require tools.views as views';
 
-return view.extend({
-       render: function() {
-               poll.add(function() {
-                       return L.resolveDefault(fs.exec('/sbin/logread', ['-e', 'nextdns']), { code: 1 })
-                       .then(function(res) {
-                               var content;
-                               if (res.code === 0)
-                                       content = res.stdout.trim();
-                               if (!content)
-                                       content = _('No nextdns related logs yet!');
-                               var view       = document.getElementById("view_id");
-                               view.value     = content;
-                               view.scrollTop = view.scrollHeight;
-                       });
-               });
-               return E('div', { class: 'cbi-map' },
-                       E('div', { class: 'cbi-section' }, [
-                               E('div', { class: 'cbi-section-descr' },
-                                       _('The syslog output, pre-filtered for nextdns related messages only.')),
-                               E('textarea', {
-                                       id: 'view_id',
-                                       readonly: 'readonly',
-                                       wrap: 'off',
-                                       style: 'width: 100% !important;\
-                                               height: 450px !important;\
-                                               border: 1px solid #cccccc;\
-                                               padding: 5px;\
-                                               font-size: 12px;\
-                                               font-family: monospace;\
-                                               resize: none;\
-                                               pointer-events: auto;\
-                                               cursor: auto;'
-                               })
-                       ])
-               );
-       },
-       handleSaveApply: null,
-       handleSave: null,
-       handleReset: null
-});
+return views.LogreadBox("nextdns", "nextdns");
index fb9cb7e3fbee30a7580119cdcc9edf5233f92b87..a27de0c0758c9e3ccfffd04872c16bfe2ec9ac30 100644 (file)
@@ -21,7 +21,7 @@
        },
 
        "admin/services/nextdns/log": {
-               "title": "Configuration",
+               "title": "Logs",
                "order": 2,
                "action": {
                        "type": "view",
index d004ed4d2fbba708a84a53266e107d0abf7d26d8..fc9323aa148c9939fb4d9d26c81f93b3c0dceee6 100644 (file)
@@ -1,42 +1,4 @@
 'use strict';
-'require view';
-'require poll';
-'require fs';
+'require tools.views as views';
 
-return 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) {
-               var logger = stat[0] ? stat[0].path : stat[1] ? stat[1].path : null;
-               poll.add(function() {
-                       return L.resolveDefault(fs.exec_direct(logger, ['-e', 'trm-'])).then(function(res) {
-                               var log = document.getElementById("logfile");
-                               if (res) {
-                                       log.value = res.trim();
-                               }
-                               else {
-                                       log.value = _('No travelmate related logs yet!');
-                               }
-                               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 travelmate related messages only.')),
-                       E('textarea', {
-                               'id': 'logfile',
-                               'style': 'width: 100% !important; padding: 5px; font-family: monospace',
-                               'readonly': 'readonly',
-                               'wrap': 'off',
-                               'rows': 25
-                       })
-               ]));
-       },
-       handleSaveApply: null,
-       handleSave: null,
-       handleReset: null
-});
+return views.LogreadBox("trm-", "travelmate");
diff --git a/modules/luci-base/htdocs/luci-static/resources/tools/views.js b/modules/luci-base/htdocs/luci-static/resources/tools/views.js
new file mode 100644 (file)
index 0000000..f851f61
--- /dev/null
@@ -0,0 +1,45 @@
+'use strict';
+'require fs';
+
+var CBILogreadBox = function(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) {
+                       var logger = stat[0] ? stat[0].path : stat[1] ? stat[1].path : null;
+                       L.Poll.add(function() {
+                               return L.resolveDefault(fs.exec_direct(logger, ['-e', logtag])).then(function(res) {
+                                       var log = document.getElementById("logfile");
+                                       if (res) {
+                                               log.value = res.trim();
+                                       } else {
+                                               log.value = _('No related logs yet!');
+                                       }
+                                       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: ' + name)),
+                               E('textarea', {
+                                       'id': 'logfile',
+                                       'style': 'width: 100% !important; padding: 5px; font-family: monospace',
+                                       'readonly': 'readonly',
+                                       'wrap': 'off',
+                                       'rows': 25
+                               })
+                       ]));
+               },
+               handleSaveApply: null,
+               handleSave: null,
+               handleReset: null
+       });
+};
+
+return L.Class.extend({
+       LogreadBox: CBILogreadBox,
+});