From 939b371bc72f4c020c499c815f636dafc296829a Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sat, 21 Dec 2019 20:28:25 +0100 Subject: [PATCH] luci-mod-status: reimplement log pages as client side views Signed-off-by: Jo-Philipp Wich --- .../root/usr/share/rpcd/acl.d/luci-base.json | 2 ++ .../resources/view/status/dmesg.js | 35 +++++++++++++++++++ .../resources/view/status/syslog.js | 33 +++++++++++++++++ .../luasrc/controller/admin/status.lua | 15 -------- .../luasrc/view/admin_status/dmesg.htm | 12 ------- .../luasrc/view/admin_status/syslog.htm | 12 ------- .../share/luci/menu.d/luci-mod-status.json | 10 +++--- 7 files changed, 74 insertions(+), 45 deletions(-) create mode 100644 modules/luci-mod-status/htdocs/luci-static/resources/view/status/dmesg.js create mode 100644 modules/luci-mod-status/htdocs/luci-static/resources/view/status/syslog.js delete mode 100644 modules/luci-mod-status/luasrc/controller/admin/status.lua delete mode 100644 modules/luci-mod-status/luasrc/view/admin_status/dmesg.htm delete mode 100644 modules/luci-mod-status/luasrc/view/admin_status/syslog.htm diff --git a/modules/luci-base/root/usr/share/rpcd/acl.d/luci-base.json b/modules/luci-base/root/usr/share/rpcd/acl.d/luci-base.json index 3c1495de2..ba0c213c9 100644 --- a/modules/luci-base/root/usr/share/rpcd/acl.d/luci-base.json +++ b/modules/luci-base/root/usr/share/rpcd/acl.d/luci-base.json @@ -39,10 +39,12 @@ "/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 index 000000000..3b9428eaf --- /dev/null +++ b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/dmesg.js @@ -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 index 000000000..69694bcfb --- /dev/null +++ b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/syslog.js @@ -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 +}); diff --git a/modules/luci-mod-status/luasrc/controller/admin/status.lua b/modules/luci-mod-status/luasrc/controller/admin/status.lua deleted file mode 100644 index 65a8db1ba..000000000 --- a/modules/luci-mod-status/luasrc/controller/admin/status.lua +++ /dev/null @@ -1,15 +0,0 @@ --- Copyright 2008 Steven Barth --- Copyright 2011 Jo-Philipp Wich --- Licensed to the public under the Apache License 2.0. - -module("luci.controller.admin.status", package.seeall) - -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 index 1a8770ef8..000000000 --- a/modules/luci-mod-status/luasrc/view/admin_status/dmesg.htm +++ /dev/null @@ -1,12 +0,0 @@ -<%# - Copyright 2008 Steven Barth - Copyright 2008 Jo-Philipp Wich - Licensed to the public under the Apache License 2.0. --%> - -<%+header%> -

<%:Kernel Log%>

-
- -
-<%+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 index fb734a76d..000000000 --- a/modules/luci-mod-status/luasrc/view/admin_status/syslog.htm +++ /dev/null @@ -1,12 +0,0 @@ -<%# - Copyright 2008 Steven Barth - Copyright 2008 Jo-Philipp Wich - Licensed to the public under the Apache License 2.0. --%> - -<%+header%> -

<%:System Log%>

-
- -
-<%+footer%> diff --git a/modules/luci-mod-status/root/usr/share/luci/menu.d/luci-mod-status.json b/modules/luci-mod-status/root/usr/share/luci/menu.d/luci-mod-status.json index 7dd7dae73..6fa3f0408 100644 --- a/modules/luci-mod-status/root/usr/share/luci/menu.d/luci-mod-status.json +++ b/modules/luci-mod-status/root/usr/share/luci/menu.d/luci-mod-status.json @@ -30,9 +30,8 @@ "title": "System Log", "order": 4, "action": { - "type": "call", - "module": "luci.controller.admin.status", - "function": "action_syslog" + "type": "view", + "path": "status/syslog" } }, @@ -40,9 +39,8 @@ "title": "Kernel Log", "order": 5, "action": { - "type": "call", - "module": "luci.controller.admin.status", - "function": "action_dmesg" + "type": "view", + "path": "status/dmesg" } }, -- 2.25.1