Added soft/hard agent disconnect

This commit is contained in:
Ylian Saint-Hilaire 2017-08-31 11:03:02 -07:00
parent 06ee41c3ad
commit 1473b091b0
4 changed files with 13 additions and 10 deletions

View File

@ -32,8 +32,8 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
// Disconnect this agent
obj.close = function (arg) {
//console.log('MeshAgent.close(' + arg + ')');
if (arg !== 1) { try { obj.ws.close(); } catch (e) { } }
if ((arg == 1) || (arg == null)) { try { obj.ws.close(); obj.parent.parent.debug(1, 'Soft disconnect ' + obj.nodeid); } catch (e) { console.log(e); } } // Soft close, close the websocket
if (arg == 2) { try { obj.ws._socket._parent.end(); obj.parent.parent.debug(1, 'Hard disconnect ' + obj.nodeid); } catch (e) { console.log(e); } } // Hard close, close the TCP socket
if (obj.parent.wsagents[obj.dbNodeKey] == obj) {
delete obj.parent.wsagents[obj.dbNodeKey];
obj.parent.parent.ClearConnectivityState(obj.dbMeshKey, obj.dbNodeKey, 1);
@ -211,7 +211,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
ws.on('error', function (err) { console.log(err); });
// If the mesh agent web socket is closed, clean up.
ws.on('close', function (req) { obj.close(1); });
ws.on('close', function (req) { obj.close(0); });
// Start authenticate the mesh agent by sending a auth nonce & server TLS cert hash.
// Send 256 bits SHA256 hash of TLS cert public key + 256 bits nonce

View File

@ -1,6 +1,6 @@
{
"name": "meshcentral",
"version": "0.0.6-u",
"version": "0.0.6-v",
"keywords": [
"Remote Management",
"Intel AMT",

View File

@ -3515,7 +3515,7 @@
if (e.shiftKey == true) { meshserver.Send({ action: 'uploadagentcore', nodeid: consoleNode._id, path:'*' }); } // Upload default core
else if (e.altKey == true) { meshserver.Send({ action: 'uploadagentcore', nodeid: consoleNode._id }); } // Clear the core
else if (e.ctrlKey == true) { p15uploadCore2(); } // Upload the core from a file
else { setDialogMode(2, "Change Mesh Agent Core", 3, p15uploadCoreEx, '<select id=d3coreMode style=float:right;width:260px><option value=1>Upload default server core</option><option value=2>Clear the core</option><option value=3>Upload a core file</option><option value=4>Force disconnect agent</option></select><div>Change Core</div>'); }
else { setDialogMode(2, "Change Mesh Agent Core", 3, p15uploadCoreEx, '<select id=d3coreMode style=float:right;width:260px><option value=1>Upload default server core</option><option value=2>Clear the core</option><option value=3>Upload a core file</option><option value=4>Soft disconnect agent</option><option value=5>Hard disconnect agent</option></select><div>Change Core</div>'); }
}
function p15uploadCoreEx() {
@ -3529,8 +3529,11 @@
// Upload file as core
p15uploadCore2();
} else if (Q('d3coreMode').value == 4) {
// Force disconnect the mesh agent
meshserver.Send({ action: 'agentdisconnect', nodeid: consoleNode._id });
// Soft disconnect the mesh agent
meshserver.Send({ action: 'agentdisconnect', nodeid: consoleNode._id, disconnectMode: 1 });
} else if (Q('d3coreMode').value == 5) {
// Hard disconnect the mesh agent
meshserver.Send({ action: 'agentdisconnect', nodeid: consoleNode._id, disconnectMode: 2 });
}
}

View File

@ -1545,7 +1545,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
case 'agentdisconnect':
{
// Force mesh agent disconnection
forceMeshAgentDisconnect(user, domain, command.nodeid);
forceMeshAgentDisconnect(user, domain, command.nodeid, command.disconnectMode);
break;
}
case 'close':
@ -1913,7 +1913,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
}
// Force mesh agent disconnection
function forceMeshAgentDisconnect(user, domain, nodeid) {
function forceMeshAgentDisconnect(user, domain, nodeid, disconnectMode) {
if ((nodeid == undefined) || (nodeid == null)) return;
var splitnode = nodeid.split('/');
if ((splitnode.length != 3) || (splitnode[1] != domain.id)) return; // Check that nodeid is valid and part of our domain
@ -1922,7 +1922,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
// Check we have agent rights
var rights = user.links[agent.dbMeshKey].rights;
if ((rights != undefined) && ((rights & 16) != 0) && (user.siteadmin == 0xFFFFFFFF)) { agent.close(); }
if ((rights != undefined) && ((rights & 16) != 0) && (user.siteadmin == 0xFFFFFFFF)) { agent.close(disconnectMode); }
}
// Send the core module to the mesh agent