Added initial last seen handler function

This commit is contained in:
Noah Zalev 2021-07-24 23:19:10 -04:00
parent da8947d25e
commit 18c367040d

View File

@ -5404,6 +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,
'meshes': serverCommandMeshes, 'meshes': serverCommandMeshes,
'serverconsole': serverCommandServerConsole, 'serverconsole': serverCommandServerConsole,
'servererrors': serverCommandServerErrors, 'servererrors': serverCommandServerErrors,
@ -5537,6 +5538,32 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
}); });
} }
function serverCommandLastSeen(command) {
var links = parent.GetAllMeshIdWithRights(user);
var extraids = getUserExtraIds();
db.GetAllTypeNoTypeFieldMeshFiltered(links, extraids, domain.id, 'node', null, (err, docs) => {
if (docs == null) { docs = []; }
// use associative array to join lastconnects on to users's nodes (left join)
var LCs = {}
for (var i in docs) {
LCs[docs[i]._id] = '';
}
db.GetAllType('lastconnect', (err, docs) => {
for (var j in docs) {
var nodeid = docs[j]._id.substring(2);
if (LCs[nodeid] != null) {
delete docs[j]._id;
LCs[nodeid] = docs[j];
}
}
console.log(LCs);
});
});
}
function serverCommandMeshes(command) { function serverCommandMeshes(command) {
// Request a list of all meshes this user as rights to // Request a list of all meshes this user as rights to
try { ws.send(JSON.stringify({ action: 'meshes', meshes: parent.GetAllMeshWithRights(user).map(parent.CloneSafeMesh), tag: command.tag })); } catch (ex) { } try { ws.send(JSON.stringify({ action: 'meshes', meshes: parent.GetAllMeshWithRights(user).map(parent.CloneSafeMesh), tag: command.tag })); } catch (ex) { }