Added soft/hard agent disconnect
Ylian Saint-Hilaire committed
Aug 31, 2017 at 11:03 UTC
1473b091b032b694eed137edaa0f1e67e2aab429
4 files changed
+13
-10
meshagent.js
+3
-3
@@ -32,8 +32,8 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
32
33
// Disconnect this agent
34
obj.close = function (arg) {
35
- //console.log('MeshAgent.close(' + arg + ')');
36
- if (arg !== 1) { try { obj.ws.close(); } catch (e) { } }
35
+ 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
36
+ 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
37
if (obj.parent.wsagents[obj.dbNodeKey] == obj) {
38
delete obj.parent.wsagents[obj.dbNodeKey];
39
obj.parent.parent.ClearConnectivityState(obj.dbMeshKey, obj.dbNodeKey, 1);
@@ -211,7 +211,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
211
ws.on('error', function (err) { console.log(err); });
212
213
// If the mesh agent web socket is closed, clean up.
214
- ws.on('close', function (req) { obj.close(1); });
214
+ ws.on('close', function (req) { obj.close(0); });
215
216
// Start authenticate the mesh agent by sending a auth nonce & server TLS cert hash.
217
// Send 256 bits SHA256 hash of TLS cert public key + 256 bits nonce
package.json
+1
-1
@@ -1,6 +1,6 @@
1
{
2
"name": "meshcentral",
3
- "version": "0.0.6-u",
3
+ "version": "0.0.6-v",
4
"keywords": [
5
"Remote Management",
6
"Intel AMT",
views/default.handlebars
+6
-3
@@ -3515,7 +3515,7 @@
3515
if (e.shiftKey == true) { meshserver.Send({ action: 'uploadagentcore', nodeid: consoleNode._id, path:'*' }); } // Upload default core
3516
else if (e.altKey == true) { meshserver.Send({ action: 'uploadagentcore', nodeid: consoleNode._id }); } // Clear the core
3517
else if (e.ctrlKey == true) { p15uploadCore2(); } // Upload the core from a file
3518
- 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>'); }
3518
+ 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>'); }
3519
}
3520
3521
function p15uploadCoreEx() {
@@ -3529,8 +3529,11 @@
3529
// Upload file as core
3530
p15uploadCore2();
3531
} else if (Q('d3coreMode').value == 4) {
3532
- // Force disconnect the mesh agent
3533
- meshserver.Send({ action: 'agentdisconnect', nodeid: consoleNode._id });
3532
+ // Soft disconnect the mesh agent
3533
+ meshserver.Send({ action: 'agentdisconnect', nodeid: consoleNode._id, disconnectMode: 1 });
3534
+ } else if (Q('d3coreMode').value == 5) {
3535
+ // Hard disconnect the mesh agent
3536
+ meshserver.Send({ action: 'agentdisconnect', nodeid: consoleNode._id, disconnectMode: 2 });
3537
}
3538
}
3539
webserver.js
+3
-3
@@ -1545,7 +1545,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1545
case 'agentdisconnect':
1546
{
1547
// Force mesh agent disconnection
1548
- forceMeshAgentDisconnect(user, domain, command.nodeid);
1548
+ forceMeshAgentDisconnect(user, domain, command.nodeid, command.disconnectMode);
1549
break;
1550
}
1551
case 'close':
@@ -1913,7 +1913,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1913
}
1914
1915
// Force mesh agent disconnection
1916
- function forceMeshAgentDisconnect(user, domain, nodeid) {
1916
+ function forceMeshAgentDisconnect(user, domain, nodeid, disconnectMode) {
1917
if ((nodeid == undefined) || (nodeid == null)) return;
1918
var splitnode = nodeid.split('/');
1919
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
1922
1923
// Check we have agent rights
1924
var rights = user.links[agent.dbMeshKey].rights;
1925
- if ((rights != undefined) && ((rights & 16) != 0) && (user.siteadmin == 0xFFFFFFFF)) { agent.close(); }
1925
+ if ((rights != undefined) && ((rights & 16) != 0) && (user.siteadmin == 0xFFFFFFFF)) { agent.close(disconnectMode); }
1926
}
1927
1928
// Send the core module to the mesh agent