From a45febe8645ec9af912f6975254552e3af32498b Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Tue, 3 Aug 2021 19:28:48 -0700 Subject: [PATCH] More lastconnect improvements, added meshid. --- meshcentral.js | 8 ++++---- meshuser.js | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/meshcentral.js b/meshcentral.js index 1cd71f24..34e76741 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -2139,7 +2139,7 @@ function CreateMeshCentralServer(config, args) { obj.DispatchEvent(obj.webserver.CreateNodeDispatchTargets(meshid, nodeid), obj, { action: 'nodeconnect', meshid: meshid, nodeid: nodeid, domain: nodeid.split('/')[1], conn: state.connectivity, pwr: state.powerState, ct: connectTime, nolog: 1, nopeers: 1 }); // Save indication of node connection change - const lc = { _id: 'lc' + nodeid, type: 'lastconnect', domain: nodeid.split('/')[1], time: Date.now(), cause: 1, connectType: connectType, serverid: obj.serverId }; + const lc = { _id: 'lc' + nodeid, type: 'lastconnect', domain: nodeid.split('/')[1], meshid: meshid, time: Date.now(), cause: 1, connectType: connectType, serverid: obj.serverId }; if (extraInfo && extraInfo.remoteaddrport) { lc.addr = extraInfo.remoteaddrport; } obj.db.Set(lc); } @@ -2182,7 +2182,7 @@ function CreateMeshCentralServer(config, args) { // Save indication of node connection change if (serverid == obj.serverId) { - const lc = { _id: 'lc' + nodeid, type: 'lastconnect', domain: nodeid.split('/')[1], time: Date.now(), cause: 1, connectType: connectType, serverid: obj.serverId }; + const lc = { _id: 'lc' + nodeid, type: 'lastconnect', domain: nodeid.split('/')[1], meshid: meshid, time: Date.now(), cause: 1, connectType: connectType, serverid: obj.serverId }; if (extraInfo && extraInfo.remoteaddrport) { lc.addr = extraInfo.remoteaddrport; } obj.db.Set(lc); } @@ -2210,7 +2210,7 @@ function CreateMeshCentralServer(config, args) { state.connectivity -= connectType; // Save indication of node connection change - const lc = { _id: 'lc' + nodeid, type: 'lastconnect', domain: nodeid.split('/')[1], time: Date.now(), cause: 0, connectType: connectType, serverid: obj.serverId }; + const lc = { _id: 'lc' + nodeid, type: 'lastconnect', domain: nodeid.split('/')[1], meshid: meshid, time: Date.now(), cause: 0, connectType: connectType, serverid: obj.serverId }; if (extraInfo && extraInfo.remoteaddrport) { lc.addr = extraInfo.remoteaddrport; } obj.db.Set(lc); @@ -2250,7 +2250,7 @@ function CreateMeshCentralServer(config, args) { // Save indication of node connection change if (serverid == obj.serverId) { - const lc = { _id: 'lc' + nodeid, type: 'lastconnect', domain: nodeid.split('/')[1], time: Date.now(), cause: 0, connectType: connectType, serverid: obj.serverId }; + const lc = { _id: 'lc' + nodeid, type: 'lastconnect', domain: nodeid.split('/')[1], meshid: meshid, time: Date.now(), cause: 0, connectType: connectType, serverid: obj.serverId }; if (extraInfo && extraInfo.remoteaddrport) { lc.addr = extraInfo.remoteaddrport; } obj.db.Set(lc); } diff --git a/meshuser.js b/meshuser.js index fd4f81be..21585771 100644 --- a/meshuser.js +++ b/meshuser.js @@ -3211,6 +3211,11 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use } } + // Update lastconnect meshid for this node + db.Get('lc' + node._id, function (err, xnodes) { + if ((xnodes != null) && (xnodes.length == 1) && (xnodes[0].meshid != command.meshid)) { xnodes[0].meshid = command.meshid; db.Set(xnodes[0]); } + }); + // Event the node change var newMesh = parent.meshes[command.meshid]; var event = { etype: 'node', userid: user._id, username: user.name, action: 'nodemeshchange', nodeid: node._id, node: node, oldMeshId: oldMeshId, newMeshId: command.meshid, msgid: 85, msgArgs: [node.name, newMesh.name], msg: 'Moved device ' + node.name + ' to group ' + newMesh.name, domain: domain.id }; @@ -5284,7 +5289,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use // Merge any last connection information const lc = lastConnects['lc' + results[i].node._id]; - if (lc != null) { delete lc._id; delete lc.type; delete lc.domain; results[i].lastConnect = lc; } + if (lc != null) { delete lc._id; delete lc.type;; delete lc.meshid; delete lc.domain; results[i].lastConnect = lc; } } var output = null;