diff --git a/meshagent.js b/meshagent.js index 64bca3aa..3e4921c1 100644 --- a/meshagent.js +++ b/meshagent.js @@ -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 diff --git a/package.json b/package.json index 8efd4f32..e621c5c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.0.6-u", + "version": "0.0.6-v", "keywords": [ "Remote Management", "Intel AMT", diff --git a/views/default.handlebars b/views/default.handlebars index 65e230ec..54fa71ed 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -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, '
Change Core
'); } + else { setDialogMode(2, "Change Mesh Agent Core", 3, p15uploadCoreEx, '
Change Core
'); } } 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 }); } } diff --git a/webserver.js b/webserver.js index 339e75d4..3d5285eb 100644 --- a/webserver.js +++ b/webserver.js @@ -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