luci-mod-status: reimplement log pages as client side views
authorJo-Philipp Wich <jo@mein.io>
Sat, 21 Dec 2019 19:28:25 +0000 (20:28 +0100)
committerJo-Philipp Wich <jo@mein.io>
Wed, 4 Mar 2020 07:50:21 +0000 (08:50 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(backported from commit 939b371bc72f4c020c499c815f636dafc296829a)

modules/luci-base/root/usr/share/rpcd/acl.d/luci-base.json
modules/luci-mod-status/htdocs/luci-static/resources/view/status/dmesg.js [new file with mode: 0644]
modules/luci-mod-status/htdocs/luci-static/resources/view/status/syslog.js [new file with mode: 0644]
modules/luci-mod-status/luasrc/controller/admin/status.lua
modules/luci-mod-status/luasrc/view/admin_status/dmesg.htm [deleted file]
modules/luci-mod-status/luasrc/view/admin_status/syslog.htm [deleted file]

index 3c1495de260e7158ca367fdc60a7897e538679c6..ba0c213c9e3c37b2f356916dfb1f22b7942a57db 100644 (file)
                                "/proc/sys/net/netfilter/nf_conntrack_*": [ "read" ],
                                "/proc/mounts": [ "read" ],
                                "/usr/lib/lua/luci/version.lua": [ "read" ],
+                               "/bin/dmesg -r": [ "exec" ],
                                "/bin/ping *": [ "exec" ],
                                "/bin/ping6 *": [ "exec" ],
                                "/bin/traceroute *": [ "exec" ],
                                "/bin/traceroute6 *": [ "exec" ],
+                               "/sbin/logread -e ^": [ "exec" ],
                                "/usr/bin/ping *": [ "exec" ],
                                "/usr/bin/ping6 *": [ "exec" ],
                                "/usr/bin/traceroute *": [ "exec" ],
diff --git a/modules/luci-mod-status/htdocs/luci-static/resources/view/status/dmesg.js b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/dmesg.js
new file mode 100644 (file)
index 0000000..3b9428e
--- /dev/null
@@ -0,0 +1,35 @@
+'use strict';
+'require fs';
+'require ui';
+
+return L.view.extend({
+       load: function() {
+               return fs.exec_direct('/bin/dmesg', [ '-r' ]).catch(function(err) {
+                       ui.addNotification(null, E('p', {}, _('Unable to load log data: ' + err.message)));
+                       return '';
+               });
+       },
+
+       render: function(logdata) {
+               var loglines = logdata.trim().split(/\n/).map(function(line) {
+                       return line.replace(/^<\d+>/, '');
+               });
+
+               return E([], [
+                       E('h2', {}, [ _('Kernel Log') ]),
+                       E('div', { 'id': 'content_syslog' }, [
+                               E('textarea', {
+                                       'id': 'syslog',
+                                       'style': 'font-size:12px',
+                                       'readonly': 'readonly',
+                                       'wrap': 'off',
+                                       'rows': loglines.length + 1
+                               }, [ loglines.join('\n') ])
+                       ])
+               ]);
+       },
+
+       handleSaveApply: null,
+       handleSave: null,
+       handleReset: null
+});
diff --git a/modules/luci-mod-status/htdocs/luci-static/resources/view/status/syslog.js b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/syslog.js
new file mode 100644 (file)
index 0000000..69694bc
--- /dev/null
@@ -0,0 +1,33 @@
+'use strict';
+'require fs';
+'require ui';
+
+return L.view.extend({
+       load: function() {
+               return fs.exec_direct('/sbin/logread', [ '-e', '^' ]).catch(function(err) {
+                       ui.addNotification(null, E('p', {}, _('Unable to load log data: ' + err.message)));
+                       return '';
+               });
+       },
+
+       render: function(logdata) {
+               var loglines = logdata.trim().split(/\n/);
+
+               return E([], [
+                       E('h2', {}, [ _('System Log') ]),
+                       E('div', { 'id': 'content_syslog' }, [
+                               E('textarea', {
+                                       'id': 'syslog',
+                                       'style': 'font-size:12px',
+                                       'readonly': 'readonly',
+                                       'wrap': 'off',
+                                       'rows': loglines.length + 1
+                               }, [ loglines.join('\n') ])
+                       ])
+               ]);
+       },
+
+       handleSaveApply: null,
+       handleSave: null,
+       handleReset: null
+});
index 343f89c890e61df86ce0cff451720e7306626e69..d94a6e27fded3fc8fe8247ec9813c0e77212e8c4 100644 (file)
@@ -12,8 +12,8 @@ function index()
        entry({"admin", "status", "iptables"}, view("status/iptables"), _("Firewall"), 2).leaf = true
 
        entry({"admin", "status", "routes"}, template("admin_status/routes"), _("Routes"), 3)
-       entry({"admin", "status", "syslog"}, call("action_syslog"), _("System Log"), 4)
-       entry({"admin", "status", "dmesg"}, call("action_dmesg"), _("Kernel Log"), 5)
+       entry({"admin", "status", "syslog"}, view("status/syslog"), _("System Log"), 4)
+       entry({"admin", "status", "dmesg"}, view("status/dmesg"), _("Kernel Log"), 5)
        entry({"admin", "status", "processes"}, view("status/processes"), _("Processes"), 6)
 
        entry({"admin", "status", "realtime"}, alias("admin", "status", "realtime", "load"), _("Realtime Graphs"), 7)
@@ -25,13 +25,3 @@ function index()
 
        entry({"admin", "status", "nameinfo"}, call("action_nameinfo")).leaf = true
 end
-
-function action_syslog()
-       local syslog = luci.sys.syslog()
-       luci.template.render("admin_status/syslog", {syslog=syslog})
-end
-
-function action_dmesg()
-       local dmesg = luci.sys.dmesg()
-       luci.template.render("admin_status/dmesg", {dmesg=dmesg})
-end
diff --git a/modules/luci-mod-status/luasrc/view/admin_status/dmesg.htm b/modules/luci-mod-status/luasrc/view/admin_status/dmesg.htm
deleted file mode 100644 (file)
index 1a8770e..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<%#
- Copyright 2008 Steven Barth <steven@midlink.org>
- Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
- Licensed to the public under the Apache License 2.0.
--%>
-
-<%+header%>
-<h2 name="content"><%:Kernel Log%></h2>
-<div id="content_syslog">
-<textarea style="font-size: 12px;" readonly="readonly" wrap="off" rows="<%=dmesg:cmatch("\n")+2%>" id="syslog"><%=dmesg:pcdata()%></textarea>
-</div>
-<%+footer%>
diff --git a/modules/luci-mod-status/luasrc/view/admin_status/syslog.htm b/modules/luci-mod-status/luasrc/view/admin_status/syslog.htm
deleted file mode 100644 (file)
index fb734a7..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<%#
- Copyright 2008 Steven Barth <steven@midlink.org>
- Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
- Licensed to the public under the Apache License 2.0.
--%>
-
-<%+header%>
-<h2 name="content"><%:System Log%></h2>
-<div id="content_syslog">
-<textarea style="font-size: 12px;" readonly="readonly" wrap="off" rows="<%=syslog:cmatch("\n")+2%>" id="syslog"><%=syslog:pcdata()%></textarea>
-</div>
-<%+footer%>