Last Connect improvements, #2939

This commit is contained in:
Ylian Saint-Hilaire 2021-07-27 00:13:41 -07:00
parent a5ab48242a
commit e55d04a2c6
38 changed files with 22 additions and 23 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -5404,7 +5404,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
'getnetworkinfo': serverCommandGetNetworkInfo, 'getnetworkinfo': serverCommandGetNetworkInfo,
'getsysinfo': serverCommandGetSysInfo, 'getsysinfo': serverCommandGetSysInfo,
'lastconnect': serverCommandLastConnect, 'lastconnect': serverCommandLastConnect,
'lastseen': serverCommandLastSeen, 'lastconnects': serverCommandLastConnects,
'meshes': serverCommandMeshes, 'meshes': serverCommandMeshes,
'serverconsole': serverCommandServerConsole, 'serverconsole': serverCommandServerConsole,
'servererrors': serverCommandServerErrors, 'servererrors': serverCommandServerErrors,
@ -5538,27 +5538,22 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
}); });
} }
function serverCommandLastSeen(command) { function serverCommandLastConnects(command) {
var links = parent.GetAllMeshIdWithRights(user); const links = parent.GetAllMeshIdWithRights(user);
var extraids = getUserExtraIds(); const extraids = getUserExtraIds();
db.GetAllTypeNoTypeFieldMeshFiltered(links, extraids, domain.id, 'node', null, (err, docs) => { db.GetAllTypeNoTypeFieldMeshFiltered(links, extraids, domain.id, 'node', null, function (err, docs) {
if (docs == null) { docs = []; } if (docs == null) return;
// use associative array to join lastconnects on to users's nodes (left join) // Create a list of node ids for this user and query them for last device connection time
var LCs = {} const ids = []
for (var i in docs) { for (var i in docs) { ids.push('lc' + docs[i]._id); }
LCs[docs[i]._id] = '';
}
db.GetAllType('lastconnect', (err, docs) => { // Pull list of last connections only for device owned by this user
for (var j in docs) { db.GetAllIdsOfType(ids, domain.id, 'lastconnect', function (err, docs) {
var nodeid = docs[j]._id.substring(2); if (docs == null) return;
if (LCs[nodeid] != null) { const response = {};
LCs[nodeid] = docs[j].time; for (var j in docs) { response[docs[j]._id.substring(2)] = docs[j].time; }
} try { ws.send(JSON.stringify({ action: 'lastconnects', lastconnects: response, tag: command.tag })); } catch (ex) { }
}
try { ws.send(JSON.stringify({ action: 'lastseen', lastconnects: LCs })); } catch (ex) { }
}); });
}); });
} }

View File

@ -1373,6 +1373,7 @@
var checkedNodeids = {}; var checkedNodeids = {};
var deskKeyboardShortcuts = []; var deskKeyboardShortcuts = [];
var deskLastClipboardSent = null; var deskLastClipboardSent = null;
var requestedLastConnects = false;
// Console Message Display Timers // Console Message Display Timers
var p11DeskConsoleMsgTimer = null; var p11DeskConsoleMsgTimer = null;
@ -1929,7 +1930,6 @@
meshserver.send({ action: 'usergroups' }); meshserver.send({ action: 'usergroups' });
meshserver.send({ action: 'meshes' }); meshserver.send({ action: 'meshes' });
meshserver.send({ action: 'nodes', id: '{{currentNode}}' }); meshserver.send({ action: 'nodes', id: '{{currentNode}}' });
meshserver.send({ action: 'lastseen' });
meshserver.send({ action: 'loginTokens' }); meshserver.send({ action: 'loginTokens' });
if (pluginHandler != null) { meshserver.send({ action: 'plugins' }); } if (pluginHandler != null) { meshserver.send({ action: 'plugins' }); }
if ('{{currentNode}}'.toLowerCase() == '') { meshserver.send({ action: 'files' }); } if ('{{currentNode}}'.toLowerCase() == '') { meshserver.send({ action: 'files' }); }
@ -2292,13 +2292,14 @@
} }
break; break;
} }
case 'lastseen': { case 'lastconnects': {
var lcnodes = Object.keys(message.lastconnects); var lcnodes = Object.keys(message.lastconnects);
for (var i in lcnodes) { for (var i in lcnodes) {
var lcnodeid = lcnodes[i]; var lcnodeid = lcnodes[i];
var node = getNodeFromId(lcnodeid); var node = getNodeFromId(lcnodeid);
if (node != null) { node.lastconnect = message.lastconnects[lcnodeid] } if (node != null) { node.lastconnect = message.lastconnects[lcnodeid] }
} }
mainUpdate(4);
} }
case 'msg': { case 'msg': {
// Check if this is a message from a node // Check if this is a message from a node
@ -3984,7 +3985,10 @@
if (deviceViewSettings.devsCols.indexOf('user') >= 0) { colums += '<th style=color:gray;width:120px>' + "User"; } if (deviceViewSettings.devsCols.indexOf('user') >= 0) { colums += '<th style=color:gray;width:120px>' + "User"; }
if (deviceViewSettings.devsCols.indexOf('ip') >= 0) { colums += '<th style=color:gray;width:120px>' + "Address"; } if (deviceViewSettings.devsCols.indexOf('ip') >= 0) { colums += '<th style=color:gray;width:120px>' + "Address"; }
if (deviceViewSettings.devsCols.indexOf('conn') >= 0) { colums += '<th style=color:gray;width:100px>' + "Connectivity"; } if (deviceViewSettings.devsCols.indexOf('conn') >= 0) { colums += '<th style=color:gray;width:100px>' + "Connectivity"; }
if (deviceViewSettings.devsCols.indexOf('lastseen') >= 0) { colums += '<th style=color:gray;width:120px>' + "Last Seen"; } if (deviceViewSettings.devsCols.indexOf('lastseen') >= 0) {
colums += '<th style=color:gray;width:120px>' + "Last Seen";
if (requestedLastConnects == false) { requestedLastConnects = true; meshserver.send({ action: 'lastconnects' }); }
}
// This height of 1 div at the end to fix a problem in Linux firefox browsers // This height of 1 div at the end to fix a problem in Linux firefox browsers
r = '<table style=width:100%;margin-top:4px cellpadding=0 cellspacing=0><th style=color:gray>' + colums + r + '</tr></table><div style=height:1px></div>'; r = '<table style=width:100%;margin-top:4px cellpadding=0 cellspacing=0><th style=color:gray>' + colums + r + '</tr></table><div style=height:1px></div>';