1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-02-12 11:01:52 +00:00

Server peering improvements.

This commit is contained in:
Ylian Saint-Hilaire 2020-11-15 18:40:32 -08:00
parent ad5777e4b8
commit cd6d5b12ac
2 changed files with 26 additions and 9 deletions

View file

@ -282,8 +282,8 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
// Route a command to all targets in a mesh // Route a command to all targets in a mesh
function routeCommandToMesh(meshid, command) { function routeCommandToMesh(meshid, command) {
// Send the request to all peer servers // If we have peer servers, inform them of this command to send to all agents of this device group
// TODO !!!! if (parent.parent.multiServer != null) { parent.parent.multiServer.DispatchMessage({ action: 'agentMsgByMeshId', meshid: meshid, command: command }); }
// See if the node is connected // See if the node is connected
for (var nodeid in parent.wsagents) { for (var nodeid in parent.wsagents) {
@ -3347,10 +3347,10 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the mesh. Another event will come. if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the mesh. Another event will come.
parent.parent.DispatchEvent(parent.CreateMeshDispatchTargets(mesh, [user._id]), obj, event); parent.parent.DispatchEvent(parent.CreateMeshDispatchTargets(mesh, [user._id]), obj, event);
// Send new policy to all computers on this mesh // If we have peer servers, inform them of the new Intel AMT policy for this device group
//routeCommandToMesh(command.meshid, { action: 'amtPolicy', amtPolicy: amtpolicy }); if (parent.parent.multiServer != null) { parent.parent.multiServer.DispatchMessage({ action: 'newIntelAmtPolicy', meshid: command.meshid, amtpolicy: amtpolicy }); }
// See if the node is connected // See if any agents for the affected device group is connected, if so, update the Intel AMT policy
for (var nodeid in parent.wsagents) { for (var nodeid in parent.wsagents) {
const agent = parent.wsagents[nodeid]; const agent = parent.wsagents[nodeid];
if (agent.dbMeshKey == command.meshid) { agent.sendUpdatedIntelAmtPolicy(amtpolicy); } if (agent.dbMeshKey == command.meshid) { agent.sendUpdatedIntelAmtPolicy(amtpolicy); }

View file

@ -570,6 +570,23 @@ module.exports.CreateMultiServer = function (parent, args) {
} }
break; break;
} }
case 'newIntelAmtPolicy': {
// See if any agents for the affected device group is connected, if so, update the Intel AMT policy
for (var nodeid in obj.parent.webserver.wsagents) {
const agent = obj.parent.webserver.wsagents[nodeid];
if (agent.dbMeshKey == msg.meshid) { agent.sendUpdatedIntelAmtPolicy(msg.amtpolicy); }
}
break;
}
case 'agentMsgByMeshId': {
// See if any agents for the target device group is connected, if so, send the message
const jsonCmd = JSON.stringify(msg.command);
for (var nodeid in obj.parent.webserver.wsagents) {
var agent = obj.parent.webserver.wsagents[nodeid];
if (agent.dbMeshKey == msg.meshid) { try { agent.send(jsonCmd); } catch (ex) { } }
}
break;
}
default: { default: {
// Unknown peer server command // Unknown peer server command
console.log('Unknown action from peer server ' + peerServerId + ': ' + msg.action + '.'); console.log('Unknown action from peer server ' + peerServerId + ': ' + msg.action + '.');
@ -651,12 +668,12 @@ module.exports.CreateMultiServer = function (parent, args) {
peerTunnel.close = function (arg) { peerTunnel.close = function (arg) {
if (arg == 2) { if (arg == 2) {
// Hard close, close the TCP socket // Hard close, close the TCP socket
if (peerTunnel.ws1 != null) { try { peerTunnel.ws1._socket._parent.end(); peerTunnel.parent.parent.debug('peer', 'FTunnel1: Hard disconnect'); } catch (e) { console.log(e); } } if (peerTunnel.ws1 != null) { try { peerTunnel.ws1._socket._parent.end(); peerTunnel.parent.parent.debug('peer', 'FTunnel1: Hard disconnect'); } catch (e) { console.log(e); } delete peerTunnel.ws1; }
if (peerTunnel.ws2 != null) { try { peerTunnel.ws2._socket._parent.end(); peerTunnel.parent.parent.debug('peer', 'FTunnel2: Hard disconnect'); } catch (e) { console.log(e); } } if (peerTunnel.ws2 != null) { try { peerTunnel.ws2._socket._parent.end(); peerTunnel.parent.parent.debug('peer', 'FTunnel2: Hard disconnect'); } catch (e) { console.log(e); } delete peerTunnel.ws2; }
} else { } else {
// Soft close, close the websocket // Soft close, close the websocket
if (peerTunnel.ws1 != null) { try { peerTunnel.ws1.close(); peerTunnel.parent.parent.debug('peer', 'FTunnel1: Soft disconnect '); } catch (e) { console.log(e); } } if (peerTunnel.ws1 != null) { try { peerTunnel.ws1.close(); peerTunnel.parent.parent.debug('peer', 'FTunnel1: Soft disconnect '); } catch (e) { console.log(e); } delete peerTunnel.ws1; }
if (peerTunnel.ws2 != null) { try { peerTunnel.ws2.close(); peerTunnel.parent.parent.debug('peer', 'FTunnel2: Soft disconnect '); } catch (e) { console.log(e); } } if (peerTunnel.ws2 != null) { try { peerTunnel.ws2.close(); peerTunnel.parent.parent.debug('peer', 'FTunnel2: Soft disconnect '); } catch (e) { console.log(e); } delete peerTunnel.ws2; }
} }
}; };