Fixes for #2973

Ylian Saint-Hilaire committed Jul 30, 2021 at 13:23 UTC 19f596ce8650666eb88699c8ebbfcec715ea7b81
2 files changed +25 -33
agents/meshcore.js
+19 -28
@@ -172,9 +172,10 @@ if (process.platform == 'darwin' && !process.versions) {
172 // Add an Intel AMT event to the log
173 function addAmtEvent(msg) {
174 if (obj.amtevents == null) { obj.amtevents = []; }
175 - var d = new Date();
176 - obj.amtevents.push(zeroPad(d.getHours(), 2) + ':' + zeroPad(d.getMinutes(), 2) + ':' + zeroPad(d.getSeconds(), 2) + ', ' + msg);
175 + var d = new Date(), e = zeroPad(d.getHours(), 2) + ':' + zeroPad(d.getMinutes(), 2) + ':' + zeroPad(d.getSeconds(), 2) + ', ' + msg;
176 + obj.amtevents.push(e);
177 if (obj.amtevents.length > 100) { obj.amtevents.splice(0, obj.amtevents.length - 100); }
178 + if (obj.showamtevent) { require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: e }); }
179 }
180 function zeroPad(num, size) { var s = '000000000' + num; return s.substr(s.length - size); }
181
@@ -3966,14 +3967,17 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3967 break;
3968 }
3969 case 'amtevents': {
3969 - if (obj.amtevents == null) { response = 'No events.'; } else { response = obj.amtevents.join('\r\n'); }
3970 + if ((args['_'].length == 1) && (args['_'][0] == 'on')) { obj.showamtevent = true; response = 'Intel AMT configuration events live view enabled.'; }
3971 + else if ((args['_'].length == 1) && (args['_'][0] == 'off')) { delete obj.showamtevent; response = 'Intel AMT configuration events live view disabled.'; }
3972 + else if (obj.amtevents == null) { response = 'No events.'; } else { response = obj.amtevents.join('\r\n'); }
3973 break;
3974 }
3975 case 'amtconfig': {
3973 - if (amt == null) { response = "Intel AMT not detected."; break; }
3974 - if (apftunnel != null) { response = "Intel AMT server tunnel already active"; break; }
3976 + if (amt == null) { response = 'Intel AMT not detected.'; break; }
3977 + if (apftunnel != null) { response = 'Intel AMT server tunnel already active'; break; }
3978 + if (!obj.showamtevent) { obj.showamtevent = true; require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: 'Enabled live view of Intel AMT configuration events, \"amtevents off\" to disable.' }); }
3979 amt.getMeiState(15, function (state) {
3976 - if ((state == null) || (state.ProvisioningState == null)) { require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: "Intel AMT not ready for configuration." }); } else {
3980 + if ((state == null) || (state.ProvisioningState == null)) { require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: 'Intel AMT not ready for configuration.' }); } else {
3981 getAmtOsDnsSuffix(state, function () {
3982 var rx = '';
3983 var apfarg = {
@@ -3994,12 +3998,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3998 apftunnel = require('amt-apfclient')({ debug: false }, apfarg);
3999 apftunnel.onJsonControl = handleApfJsonControl;
4000 apftunnel.onChannelClosed = function () { addAmtEvent('User LMS tunnel closed.'); apftunnel = null; }
3997 - try {
3998 - apftunnel.connect();
3999 - rx = "Started Intel AMT configuration";
4000 - } catch (ex) {
4001 - rx = JSON.stringify(ex);
4002 - }
4001 + try { apftunnel.connect(); } catch (ex) { rx = JSON.stringify(ex); }
4002 }
4003 if (rx != '') { require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: rx }); }
4004 });
@@ -4132,8 +4131,9 @@ function sendAgentMessage(msg, icon, serverid, first) {
4131 return (arguments.length > 0 ? sendAgentMessage.messages.peek().id : sendAgentMessage.messages);
4132 }
4133 function getOpenDescriptors() {
4134 + var r = [];
4135 switch (process.platform) {
4136 - case "freebsd":
4136 + case "freebsd": {
4137 var child = require('child_process').execFile('/bin/sh', ['sh']);
4138 child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
4139 child.stderr.on('data', function (c) { });
@@ -4157,14 +4157,10 @@ function getOpenDescriptors() {
4157 child.stdin.write('\nexit\n');
4158 child.waitExit();
4159
4160 - try {
4161 - return (JSON.parse(child.stdout.str.trim()));
4162 - }
4163 - catch (e) {
4164 - return ([]);
4165 - }
4160 + try { r = JSON.parse(child.stdout.str.trim()); } catch (ex) { }
4161 break;
4167 - case "linux":
4162 + }
4163 + case "linux": {
4164 var child = require('child_process').execFile('/bin/sh', ['sh']);
4165 child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
4166 child.stderr.on('data', function (c) { });
@@ -4183,16 +4179,11 @@ function getOpenDescriptors() {
4179 child.stdin.write('\nexit\n');
4180 child.waitExit();
4181
4186 - try {
4187 - return (JSON.parse(child.stdout.str.trim()));
4188 - }
4189 - catch (e) {
4190 - return ([]);
4191 - }
4182 + try { r = JSON.parse(child.stdout.str.trim()); } catch (ex) { }
4183 break;
4193 - default:
4194 - return ([]);
4184 + }
4185 }
4186 + return r;
4187 }
4188 function closeDescriptors(libc, descriptors) {
4189 var fd = null;
views/default.handlebars
+6 -5
@@ -3777,9 +3777,11 @@
3777 else if (sort == 1) { nodes.sort(powerSort); }
3778 else if (sort == 2) { if (showRealNames == true) { nodes.sort(deviceHostSort); } else { nodes.sort(deviceSort); } }
3779 else if (sort == 5) {
3780 - // if the last seen column is not turned on, turn it on first (we require this to sort the data)
3780 + // If the last seen column is not turned on, turn it on first (we require this to sort the data)
3781 if (!(deviceViewSettings && deviceViewSettings.devsCols && deviceViewSettings.devsCols.indexOf('lastseen') >= 0)) {
3782 - // force initialize the view settings
3782 + // Request last connection data if not requested yet
3783 + if (requestedLastConnects == false) { requestedLastConnects = true; meshserver.send({ action: 'lastconnects' }); }
3784 + // Force initialize the view settings
3785 if (deviceViewSettings == null) { deviceViewSettings = {}; }
3786 if (!Array.isArray(deviceViewSettings.devsCols)) { deviceViewSettings.devsCols = ['user','ip','conn', 'lastseen']; }
3787 else { deviceViewSettings.devsCols.push('lastseen'); }
@@ -3787,7 +3789,6 @@
3789 nodes.sort(lastConnectSort);
3790 }
3791
3790 -
3792 // Compute the width of the device view.
3793 var totalDeviceViewWidth = Q('column_l').clientWidth - 60;
3794 var deviceBoxWidth = Math.floor(totalDeviceViewWidth / 301);
@@ -4268,7 +4269,7 @@
4269 if (deviceViewSettings.devsCols.indexOf('user') >= 0) { r += '<td style=text-align:center>' + getUserShortStr(node); } // User
4270 if (deviceViewSettings.devsCols.indexOf('ip') >= 0) { r += '<td style=text-align:center>' + (node.ip != null ? node.ip : ''); } // IP address
4271 if (deviceViewSettings.devsCols.indexOf('conn') >= 0) { r += '<td style=text-align:center>' + states.join('&nbsp;+&nbsp;'); } // Connectivity
4271 - if (deviceViewSettings.devsCols.indexOf('lastseen') >= 0) { r += '<td style=text-align:center;font-size:x-small>' + ((node.conn & 23 > 0 || node.lastconnect == null) ? '' : printDateTime(new Date(node.lastconnect))); }
4272 + if (deviceViewSettings.devsCols.indexOf('lastseen') >= 0) { r += '<td style=text-align:center;font-size:x-small>'; if (node.conn & 1) { r += "Connected"; } else if (node.lastconnect != null) { r += printDateTime(new Date(node.lastconnect)); } }
4273
4274 div.innerHTML = r;
4275 } else if ((view == 3) || (view == 5)) {
@@ -5295,7 +5296,7 @@
5296 function powerSort(a, b) { var ap = a.pwr?a.pwr:0; var bp = b.pwr?b.pwr:0; if (ap > bp) return -1; if (ap < bp) return 1; if (ap == bp) { if (showRealNames == true) { if (a.rnamel > b.rnamel) return 1; if (a.rnamel < b.rnamel) return -1; return 0; } else { if (a.namel > b.namel) return 1; if (a.namel < b.namel) return -1; return 0; } } return 0; }
5297 function deviceSort(a, b) { if (a.namel > b.namel) return 1; if (a.namel < b.namel) return -1; return 0; }
5298 function deviceHostSort(a, b) { if (a.rnamel > b.rnamel) return 1; if (a.rnamel < b.rnamel) return -1; return 0; }
5298 - function lastConnectSort(a, b) { return a.lastconnect - b.lastconnect; }
5299 + function lastConnectSort(a, b) { var aa = a.lastconnect, bb = b.lastconnect; if (aa == null) { aa = 99999999999999; } if (bb == null) { bb = 99999999999999; } if (a.conn & 1) { aa = 99999999999998; } if (b.conn & 1) { bb = 99999999999998; } if (aa == bb) { return nameSort(a, b); } return (aa - bb); }
5300 function onSearchFocus(x) { searchFocus = x; }
5301 function clearDeviceSearch() { Q('KvmSearchInput').value = Q('SearchInput').value = ''; Q('DevFilterSelect').value = 0; onOnlineCheckBox(); mainUpdate(1); }
5302 function onMapSearchFocus(x) { mapSearchFocus = x; }