Added initial last seen handler function
Noah Zalev committed
Jul 24, 2021 at 23:19 UTC
18c367040de0b1a05b6d4ec7c339c6fbca49fff7
1 file changed
+27
meshuser.js
+27
@@ -5404,6 +5404,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5404
'getnetworkinfo': serverCommandGetNetworkInfo,
5405
'getsysinfo': serverCommandGetSysInfo,
5406
'lastconnect': serverCommandLastConnect,
5407
+ 'lastseen': serverCommandLastSeen,
5408
'meshes': serverCommandMeshes,
5409
'serverconsole': serverCommandServerConsole,
5410
'servererrors': serverCommandServerErrors,
@@ -5537,6 +5538,32 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5538
});
5539
}
5540
5541
+ function serverCommandLastSeen(command) {
5542
+ var links = parent.GetAllMeshIdWithRights(user);
5543
+ var extraids = getUserExtraIds();
5544
+ db.GetAllTypeNoTypeFieldMeshFiltered(links, extraids, domain.id, 'node', null, (err, docs) => {
5545
+ if (docs == null) { docs = []; }
5546
+
5547
+ // use associative array to join lastconnects on to users's nodes (left join)
5548
+ var LCs = {}
5549
+ for (var i in docs) {
5550
+ LCs[docs[i]._id] = '';
5551
+ }
5552
+
5553
+ db.GetAllType('lastconnect', (err, docs) => {
5554
+ for (var j in docs) {
5555
+ var nodeid = docs[j]._id.substring(2);
5556
+ if (LCs[nodeid] != null) {
5557
+ delete docs[j]._id;
5558
+ LCs[nodeid] = docs[j];
5559
+ }
5560
+ }
5561
+
5562
+ console.log(LCs);
5563
+ });
5564
+ });
5565
+ }
5566
+
5567
function serverCommandMeshes(command) {
5568
// Request a list of all meshes this user as rights to
5569
try { ws.send(JSON.stringify({ action: 'meshes', meshes: parent.GetAllMeshWithRights(user).map(parent.CloneSafeMesh), tag: command.tag })); } catch (ex) { }