MeshCore.js can now handle long connection name pipes.
Ylian Saint-Hilaire committed
Sep 30, 2020 at 16:59 UTC
974214b9e98b57d229911af7ed53b66fb72ba18a
3 files changed
+107
-110
agents/meshcore.js
+81
-94
@@ -47,16 +47,16 @@ function createMeshCore(agent) {
47
// Check the Agent Uninstall MetaData for correctness, as the installer may have written an incorrect value
48
try {
49
var writtenSize = 0, actualSize = Math.floor(require('fs').statSync(process.execPath).size / 1024);
50
- try { writtenSize = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize'); } catch (x) { }
51
- if (writtenSize != actualSize) { try { require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize', actualSize); } catch (x2) { } }
52
- } catch (ex) { }
50
+ try { writtenSize = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize'); } catch (e) { }
51
+ if (writtenSize != actualSize) { try { require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize', actualSize); } catch (e) { } }
52
+ } catch (x) { }
53
54
// Check to see if we are the Installed Mesh Agent Service, if we are, make sure we can run in Safe Mode
55
try {
56
var meshCheck = false;
57
- try { meshCheck = require('service-manager').manager.getService('Mesh Agent').isMe(); } catch (mce) { }
57
+ try { meshCheck = require('service-manager').manager.getService('Mesh Agent').isMe(); } catch (e) { }
58
if (meshCheck && require('win-bcd').isSafeModeService && !require('win-bcd').isSafeModeService('Mesh Agent')) { require('win-bcd').enableSafeModeService('Mesh Agent'); }
59
- } catch (ex) { }
59
+ } catch (e) { }
60
}
61
62
if (process.platform == 'darwin' && !process.versions) {
@@ -136,7 +136,7 @@ function createMeshCore(agent) {
136
137
// Create Secure IPC for Diagnostic Agent Communications
138
obj.DAIPC = require('net').createServer();
139
- if (process.platform != 'win32') { try { require('fs').unlinkSync(process.cwd() + '/DAIPC'); } catch (ee) { } }
139
+ if (process.platform != 'win32') { try { require('fs').unlinkSync(process.cwd() + '/DAIPC'); } catch (e) { } }
140
obj.DAIPC.IPCPATH = process.platform == 'win32' ? ('\\\\.\\pipe\\' + require('_agentNodeId')() + '-DAIPC') : (process.cwd() + '/DAIPC');
141
try { obj.DAIPC.listen({ path: obj.DAIPC.IPCPATH }); } catch (e) { }
142
obj.DAIPC.on('connection', function (c) {
@@ -145,11 +145,11 @@ function createMeshCore(agent) {
145
var packet = Buffer.alloc(data.length + 4);
146
packet.writeUInt32LE(data.length + 4, 0);
147
Buffer.from(data).copy(packet, 4);
148
- this.end(packet);
148
+ this.write(packet);
149
};
150
this._daipc = c;
151
c.parent = this;
152
- c.on('end', function () { console.log("Connection Closed"); this.parent._daipc = null; });
152
+ c.on('end', function () { this.end(); this.parent._daipc = null; }); // TODO: Must call end() on self to close the named pipe correctly.
153
c.on('data', function (chunk) {
154
if (chunk.length < 4) { this.unshift(chunk); return; }
155
var len = chunk.readUInt32LE(0);
@@ -157,14 +157,8 @@ function createMeshCore(agent) {
157
if (chunk.length < len) { this.unshift(chunk); return; }
158
159
var data = chunk.slice(4, len);
160
- try {
161
- data = JSON.parse(data.toString());
162
- }
163
- catch (de) {
164
- this.parent._daipc = null; this.end(); return;
165
- }
166
-
167
- if (!data.cmd) { this.parent._daipc = null; this.end(); return; }
160
+ try { data = JSON.parse(data.toString()); } catch (e) { }
161
+ if ((data == null) || (typeof data.cmd != 'string')) return;
162
163
try {
164
switch (data.cmd) {
@@ -183,15 +177,9 @@ function createMeshCore(agent) {
177
break;
178
}
179
break;
186
- default:
187
- this.parent._daipc = null;
188
- this.end();
189
- return;
180
}
181
}
192
- catch (xe) {
193
- this.parent._daipc = null; this.end(); return;
194
- }
182
+ catch (e) { this.parent._daipc = null; this.end(); return; }
183
});
184
});
185
function diagnosticAgent_uninstall() {
@@ -260,7 +248,7 @@ function createMeshCore(agent) {
248
try {
249
require('MeshAgent')._batteryFileTimer = null;
250
var data = null;
263
- try { data = require('fs').readFileSync(process.cwd() + 'batterystate.txt').toString(); } catch (ex) { }
251
+ try { data = require('fs').readFileSync(process.cwd() + 'batterystate.txt').toString(); } catch (e) { }
252
if ((data != null) && (data.length < 10)) {
253
data = data.split(',');
254
if ((data.length == 2) && ((data[0] == 'ac') || (data[0] == 'dc'))) {
@@ -268,7 +256,7 @@ function createMeshCore(agent) {
256
if ((level >= 0) && (level <= 100)) { require('MeshAgent').SendCommand({ action: 'battery', state: data[0], level: level }); }
257
}
258
}
271
- } catch (ex) { }
259
+ } catch (e) { }
260
}, 1000);
261
});
262
} else {
@@ -305,7 +293,7 @@ function createMeshCore(agent) {
293
if (process.platform == 'win32') {
294
try {
295
this.container = require('ScriptContainer').Create({ processIsolation: 1, sessionId: user.SessionId });
308
- } catch (ex) {
296
+ } catch (e) {
297
this.container = require('ScriptContainer').Create({ processIsolation: 1 });
298
}
299
} else {
@@ -336,7 +324,7 @@ function createMeshCore(agent) {
324
325
326
// Get the operating system description string
339
- try { require('os').name().then(function (v) { meshCoreObj.osdesc = v; }); } catch (ex) { }
327
+ try { require('os').name().then(function (v) { meshCoreObj.osdesc = v; }); } catch (e) { }
328
329
var meshServerConnectionState = 0;
330
var tunnels = {};
@@ -406,7 +394,7 @@ function createMeshCore(agent) {
394
mesh.SendCommand(meshCoreObj);
395
});
396
}
409
- } catch (ex) { }
397
+ } catch (e) { }
398
}
399
} else {
400
// Running in nodejs
@@ -448,14 +436,14 @@ function createMeshCore(agent) {
436
var AMTScannerModule = require('amt-scanner');
437
amtscanner = new AMTScannerModule();
438
//amtscanner.on('found', function (data) { if (typeof data != 'string') { data = JSON.stringify(data, null, " "); } sendConsoleText(data); });
451
- } catch (ex) { amtscanner = null; }
439
+ } catch (e) { amtscanner = null; }
440
441
// Fetch the SMBios Tables
442
var SMBiosTables = null;
443
var SMBiosTablesRaw = null;
444
try {
445
var SMBiosModule = null;
458
- try { SMBiosModule = require('smbios'); } catch (ex) { }
446
+ try { SMBiosModule = require('smbios'); } catch (e) { }
447
if (SMBiosModule != null) {
448
SMBiosModule.get(function (data) {
449
if (data != null) {
@@ -499,14 +487,14 @@ function createMeshCore(agent) {
487
}
488
});
489
}
502
- } catch (ex) { sendConsoleText("ex1: " + ex); }
490
+ } catch (e) { sendConsoleText("ex1: " + e); }
491
492
// Try to load up the WIFI scanner
493
try {
494
var wifiScannerLib = require('wifi-scanner');
495
wifiScanner = new wifiScannerLib();
496
wifiScanner.on('accessPoint', function (data) { sendConsoleText("wifiScanner: " + data); });
509
- } catch (ex) { wifiScannerLib = null; wifiScanner = null; }
497
+ } catch (e) { wifiScannerLib = null; wifiScanner = null; }
498
499
// Get our location (lat/long) using our public IP address
500
var getIpLocationDataExInProgress = false;
@@ -720,12 +708,12 @@ function createMeshCore(agent) {
708
socket.descriptorMetadata = 'WoL (' + addr.address + ' => ' + hexMac + ')';
709
count++;
710
}
723
- catch (ex) { }
711
+ catch (e) { }
712
}
713
}
714
}
715
}
728
- } catch (ex) { }
716
+ } catch (e) { }
717
return count;
718
}
719
@@ -791,7 +779,7 @@ function createMeshCore(agent) {
779
if (data.title && data.msg) {
780
MeshServerLogEx(18, [data.title, data.msg], "Displaying message box, title=" + data.title + ", message=" + data.msg, data);
781
data.msg = data.msg.split('\r').join('\\r').split('\n').join('\\n');
794
- try { require('message-box').create(data.title, data.msg, 120); } catch (ex) { }
782
+ try { require('message-box').create(data.title, data.msg, 120); } catch (e) { }
783
}
784
break;
785
}
@@ -951,7 +939,7 @@ function createMeshCore(agent) {
939
// data.runAsUser: 0=Agent,1=UserOrAgent,2=UserOnly
940
var options = {};
941
if (data.runAsUser > 0) {
954
- try { options.uid = require('user-sessions').consoleUid(); } catch (ex) { }
942
+ try { options.uid = require('user-sessions').consoleUid(); } catch (e) { }
943
options.type = require('child_process').SpawnTypes.TERM;
944
}
945
if (data.runAsUser == 2) {
@@ -992,7 +980,7 @@ function createMeshCore(agent) {
980
// Uninstall this agent
981
var agentName = process.platform == 'win32' ? 'Mesh Agent' : 'meshagent';
982
if (require('service-manager').manager.getService(agentName).isMe()) {
995
- try { diagnosticAgent_uninstall(); } catch (x) { }
983
+ try { diagnosticAgent_uninstall(); } catch (e) { }
984
var js = "require('service-manager').manager.getService('" + agentName + "').stop(); require('service-manager').manager.uninstallService('" + agentName + "'); process.exit();";
985
this.child = require('child_process').execFile(process.execPath, [process.platform == 'win32' ? (process.execPath.split('\\').pop()) : (process.execPath.split('/').pop()), '-b64exec', Buffer.from(js).toString('base64')], { type: 4, detached: true });
986
}
@@ -1020,7 +1008,7 @@ function createMeshCore(agent) {
1008
if (data.title && data.msg) {
1009
MeshServerLogEx(26, [data.title, data.msg], "Displaying toast message, title=" + data.title + ", message=" + data.msg, data);
1010
data.msg = data.msg.split('\r').join('\\r').split('\n').join('\\n');
1023
- try { require('toaster').Toast(data.title, data.msg); } catch (ex) { }
1011
+ try { require('toaster').Toast(data.title, data.msg); } catch (e) { }
1012
}
1013
break;
1014
}
@@ -1095,18 +1083,18 @@ function createMeshCore(agent) {
1083
if (results.hardware && results.hardware.windows) {
1084
// Remove extra entries and things that change quickly
1085
var x = results.hardware.windows.osinfo;
1098
- try { delete x.FreePhysicalMemory; } catch (ex) { }
1099
- try { delete x.FreeSpaceInPagingFiles; } catch (ex) { }
1100
- try { delete x.FreeVirtualMemory; } catch (ex) { }
1101
- try { delete x.LocalDateTime; } catch (ex) { }
1102
- try { delete x.MaxProcessMemorySize; } catch (ex) { }
1103
- try { delete x.TotalVirtualMemorySize; } catch (ex) { }
1104
- try { delete x.TotalVisibleMemorySize; } catch (ex) { }
1086
+ try { delete x.FreePhysicalMemory; } catch (e) { }
1087
+ try { delete x.FreeSpaceInPagingFiles; } catch (e) { }
1088
+ try { delete x.FreeVirtualMemory; } catch (e) { }
1089
+ try { delete x.LocalDateTime; } catch (e) { }
1090
+ try { delete x.MaxProcessMemorySize; } catch (e) { }
1091
+ try { delete x.TotalVirtualMemorySize; } catch (e) { }
1092
+ try { delete x.TotalVisibleMemorySize; } catch (e) { }
1093
try {
1094
if (results.hardware.windows.memory) { for (var i in results.hardware.windows.memory) { delete results.hardware.windows.memory[i].Node; } }
1095
if (results.hardware.windows.osinfo) { delete results.hardware.windows.osinfo.Node; }
1096
if (results.hardware.windows.partitions) { for (var i in results.hardware.windows.partitions) { delete results.hardware.windows.partitions[i].Node; } }
1109
- } catch (ex) { }
1097
+ } catch (e) { }
1098
}
1099
if (process.platform == 'win32') { results.pendingReboot = require('win-info').pendingReboot(); } // Pending reboot
1100
/*
@@ -1134,7 +1122,7 @@ function createMeshCore(agent) {
1122
results.hash = require('SHA384Stream').create().syncHash(JSON.stringify(results)).toString('hex');
1123
func(results);
1124
//}
1137
- } catch (ex) { func(null, ex); }
1125
+ } catch (e) { func(null, e); }
1126
}
1127
1128
// Get a formated response for a given directory path
@@ -1209,7 +1197,7 @@ function createMeshCore(agent) {
1197
// Add the TCP session to the count and update the server
1198
if (s.httprequest.userid != null) {
1199
if (tunnelUserCount.tcp[s.httprequest.userid] == null) { tunnelUserCount.tcp[s.httprequest.userid] = 1; } else { tunnelUserCount.tcp[s.httprequest.userid]++; }
1212
- try { mesh.SendCommand({ action: 'sessions', type: 'tcp', value: tunnelUserCount.tcp }); } catch (ex) { }
1200
+ try { mesh.SendCommand({ action: 'sessions', type: 'tcp', value: tunnelUserCount.tcp }); } catch (e) { }
1201
}
1202
} if (this.udpport != null) {
1203
// This is a UDP relay connection, get the UDP socket setup. // TODO: ***************
@@ -1225,7 +1213,7 @@ function createMeshCore(agent) {
1213
// Add the UDP session to the count and update the server
1214
if (s.httprequest.userid != null) {
1215
if (tunnelUserCount.udp[s.httprequest.userid] == null) { tunnelUserCount.udp[s.httprequest.userid] = 1; } else { tunnelUserCount.udp[s.httprequest.userid]++; }
1228
- try { mesh.SendCommand({ action: 'sessions', type: 'udp', value: tunnelUserCount.tcp }); } catch (ex) { }
1216
+ try { mesh.SendCommand({ action: 'sessions', type: 'udp', value: tunnelUserCount.tcp }); } catch (e) { }
1217
}
1218
} else {
1219
// This is a normal connect for KVM/Terminal/Files
@@ -1272,10 +1260,10 @@ function createMeshCore(agent) {
1260
if (this.httprequest.userid != null) {
1261
if (this.httprequest.tcpport != null) {
1262
if (tunnelUserCount.tcp[this.httprequest.userid] != null) { tunnelUserCount.tcp[this.httprequest.userid]--; if (tunnelUserCount.tcp[this.httprequest.userid] <= 0) { delete tunnelUserCount.tcp[this.httprequest.userid]; } }
1275
- try { mesh.SendCommand({ action: 'sessions', type: 'tcp', value: tunnelUserCount.tcp }); } catch (ex) { }
1263
+ try { mesh.SendCommand({ action: 'sessions', type: 'tcp', value: tunnelUserCount.tcp }); } catch (e) { }
1264
} else if (this.httprequest.udpport != null) {
1265
if (tunnelUserCount.udp[this.httprequest.userid] != null) { tunnelUserCount.udp[this.httprequest.userid]--; if (tunnelUserCount.udp[this.httprequest.userid] <= 0) { delete tunnelUserCount.udp[this.httprequest.userid]; } }
1278
- try { mesh.SendCommand({ action: 'sessions', type: 'udp', value: tunnelUserCount.udp }); } catch (ex) { }
1266
+ try { mesh.SendCommand({ action: 'sessions', type: 'udp', value: tunnelUserCount.udp }); } catch (e) { }
1267
}
1268
}
1269
@@ -1416,7 +1404,7 @@ function createMeshCore(agent) {
1404
if (this.httprequest.userid != null)
1405
{
1406
if (tunnelUserCount.terminal[this.httprequest.userid] != null) { tunnelUserCount.terminal[this.httprequest.userid]--; if (tunnelUserCount.terminal[this.httprequest.userid] <= 0) { delete tunnelUserCount.terminal[this.httprequest.userid]; } }
1419
- try { mesh.SendCommand({ action: 'sessions', type: 'terminal', value: tunnelUserCount.terminal }); } catch (ex) { }
1407
+ try { mesh.SendCommand({ action: 'sessions', type: 'terminal', value: tunnelUserCount.terminal }); } catch (e) { }
1408
}
1409
1410
if (process.platform == 'win32')
@@ -1642,7 +1630,7 @@ function createMeshCore(agent) {
1630
if (this.ws.httprequest.userid != null)
1631
{
1632
if (tunnelUserCount.terminal[this.ws.httprequest.userid] == null) { tunnelUserCount.terminal[this.ws.httprequest.userid] = 1; } else { tunnelUserCount.terminal[this.ws.httprequest.userid]++; }
1645
- try { mesh.SendCommand({ action: 'sessions', type: 'terminal', value: tunnelUserCount.terminal }); } catch (ex) { }
1633
+ try { mesh.SendCommand({ action: 'sessions', type: 'terminal', value: tunnelUserCount.terminal }); } catch (e) { }
1634
}
1635
1636
// Toast Notification, if required
@@ -1654,7 +1642,7 @@ function createMeshCore(agent) {
1642
if (this.ws.httprequest.soptions.notifyTitle != null) { notifyTitle = this.ws.httprequest.soptions.notifyTitle; }
1643
if (this.ws.httprequest.soptions.notifyMsgTerminal != null) { notifyMessage = this.ws.httprequest.soptions.notifyMsgTerminal.replace('{0}', this.ws.httprequest.realname).replace('{1}', this.ws.httprequest.username); }
1644
}
1657
- try { require('toaster').Toast(notifyTitle, notifyMessage); } catch (ex) { }
1645
+ try { require('toaster').Toast(notifyTitle, notifyMessage); } catch (e) { }
1646
}
1647
},
1648
function (e)
@@ -1705,9 +1693,9 @@ function createMeshCore(agent) {
1693
// Send a metadata update to all desktop sessions
1694
var users = {};
1695
if (this.httprequest.desktop.kvm.tunnels != null) {
1708
- for (var i in this.httprequest.desktop.kvm.tunnels) { try { var userid = this.httprequest.desktop.kvm.tunnels[i].httprequest.userid; if (users[userid] == null) { users[userid] = 1; } else { users[userid]++; } } catch (ex) { } }
1709
- for (var i in this.httprequest.desktop.kvm.tunnels) { try { this.httprequest.desktop.kvm.tunnels[i].write(JSON.stringify({ ctrlChannel: '102938', type: 'metadata', users: users })); } catch (ex) { } }
1710
- try { mesh.SendCommand({ action: 'sessions', type: 'kvm', value: users }); } catch (ex) { }
1696
+ for (var i in this.httprequest.desktop.kvm.tunnels) { try { var userid = this.httprequest.desktop.kvm.tunnels[i].httprequest.userid; if (users[userid] == null) { users[userid] = 1; } else { users[userid]++; } } catch (e) { } }
1697
+ for (var i in this.httprequest.desktop.kvm.tunnels) { try { this.httprequest.desktop.kvm.tunnels[i].write(JSON.stringify({ ctrlChannel: '102938', type: 'metadata', users: users })); } catch (e) { } }
1698
+ try { mesh.SendCommand({ action: 'sessions', type: 'kvm', value: users }); } catch (e) { }
1699
}
1700
1701
this.end = function () {
@@ -1720,9 +1708,9 @@ function createMeshCore(agent) {
1708
// Send a metadata update to all desktop sessions
1709
var users = {};
1710
if (this.httprequest.desktop.kvm.tunnels != null) {
1723
- for (var i in this.httprequest.desktop.kvm.tunnels) { try { var userid = this.httprequest.desktop.kvm.tunnels[i].httprequest.userid; if (users[userid] == null) { users[userid] = 1; } else { users[userid]++; } } catch (ex) { } }
1724
- for (var i in this.httprequest.desktop.kvm.tunnels) { try { this.httprequest.desktop.kvm.tunnels[i].write(JSON.stringify({ ctrlChannel: '102938', type: 'metadata', users: users })); } catch (ex) { } }
1725
- try { mesh.SendCommand({ action: 'sessions', type: 'kvm', value: users }); } catch (ex) { }
1711
+ for (var i in this.httprequest.desktop.kvm.tunnels) { try { var userid = this.httprequest.desktop.kvm.tunnels[i].httprequest.userid; if (users[userid] == null) { users[userid] = 1; } else { users[userid]++; } } catch (e) { } }
1712
+ for (var i in this.httprequest.desktop.kvm.tunnels) { try { this.httprequest.desktop.kvm.tunnels[i].write(JSON.stringify({ ctrlChannel: '102938', type: 'metadata', users: users })); } catch (e) { } }
1713
+ try { mesh.SendCommand({ action: 'sessions', type: 'kvm', value: users }); } catch (e) { }
1714
}
1715
1716
// Unpipe the web socket
@@ -1731,7 +1719,7 @@ function createMeshCore(agent) {
1719
this.unpipe(this.httprequest.desktop.kvm);
1720
this.httprequest.desktop.kvm.unpipe(this);
1721
}
1734
- catch(ex) { }
1722
+ catch(e) { }
1723
1724
// Unpipe the WebRTC channel if needed (This will also be done when the WebRTC channel ends).
1725
if (this.rtcchannel)
@@ -1741,7 +1729,7 @@ function createMeshCore(agent) {
1729
this.rtcchannel.unpipe(this.httprequest.desktop.kvm);
1730
this.httprequest.desktop.kvm.unpipe(this.rtcchannel);
1731
}
1744
- catch(ex) { }
1732
+ catch(e) { }
1733
}
1734
1735
// Place wallpaper back if needed
@@ -1749,7 +1737,7 @@ function createMeshCore(agent) {
1737
1738
if (this.desktop.kvm.connectionCount == 0) {
1739
// Display a toast message. This may not be supported on all platforms.
1752
- // try { require('toaster').Toast('MeshCentral', 'Remote Desktop Control Ended.'); } catch (ex) { }
1740
+ // try { require('toaster').Toast('MeshCentral', 'Remote Desktop Control Ended.'); } catch (e) { }
1741
1742
this.httprequest.desktop.kvm.end();
1743
if (this.httprequest.desktop.kvm.connectionBar) {
@@ -1829,7 +1817,7 @@ function createMeshCore(agent) {
1817
if (this.ws.httprequest.soptions.notifyTitle != null) { notifyTitle = this.ws.httprequest.soptions.notifyTitle; }
1818
if (this.ws.httprequest.soptions.notifyMsgDesktop != null) { notifyMessage = this.ws.httprequest.soptions.notifyMsgDesktop.replace('{0}', this.ws.httprequest.realname).replace('{1}', this.ws.httprequest.username); }
1819
}
1832
- try { require('toaster').Toast(notifyTitle, notifyMessage, tsid); } catch (ex) { }
1820
+ try { require('toaster').Toast(notifyTitle, notifyMessage, tsid); } catch (e) { }
1821
}
1822
if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 0x40)) {
1823
// Connection Bar is required
@@ -1841,7 +1829,7 @@ function createMeshCore(agent) {
1829
this.ws.httprequest.desktop.kvm.connectionBar = require('notifybar-desktop')(this.ws.httprequest.privacybartext.replace('{0}', this.ws.httprequest.desktop.kvm.users.join(', ')).replace('{1}', this.ws.httprequest.desktop.kvm.rusers.join(', ')), require('MeshAgent')._tsid);
1830
MeshServerLogEx(31, null, "Remote Desktop Connection Bar Activated/Updated (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest);
1831
}
1844
- catch (xx) {
1832
+ catch (e) {
1833
if (process.platform != 'darwin') {
1834
MeshServerLogEx(32, null, "Remote Desktop Connection Bar Failed or Not Supported (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest);
1835
}
@@ -1877,7 +1865,7 @@ function createMeshCore(agent) {
1865
if (this.httprequest.soptions.notifyTitle != null) { notifyTitle = this.httprequest.soptions.notifyTitle; }
1866
if (this.httprequest.soptions.notifyMsgDesktop != null) { notifyMessage = this.httprequest.soptions.notifyMsgDesktop.replace('{0}', this.httprequest.realname).replace('{1}', this.httprequest.username); }
1867
}
1880
- try { require('toaster').Toast(notifyTitle, notifyMessage, tsid); } catch (ex) { }
1868
+ try { require('toaster').Toast(notifyTitle, notifyMessage, tsid); } catch (e) { }
1869
} else {
1870
MeshServerLogEx(36, null, "Started remote desktop without notification (" + this.httprequest.remoteaddr + ")", this.httprequest);
1871
}
@@ -1891,7 +1879,7 @@ function createMeshCore(agent) {
1879
this.httprequest.desktop.kvm.connectionBar = require('notifybar-desktop')(this.httprequest.privacybartext.replace('{0}', this.httprequest.desktop.kvm.rusers.join(', ')).replace('{1}', this.httprequest.desktop.kvm.users.join(', ')), require('MeshAgent')._tsid);
1880
MeshServerLogEx(37, null, "Remote Desktop Connection Bar Activated/Updated (" + this.httprequest.remoteaddr + ")", this.httprequest);
1881
}
1894
- catch (xx) {
1882
+ catch (e) {
1883
MeshServerLogEx(38, null, "Remote Desktop Connection Bar Failed or not Supported (" + this.httprequest.remoteaddr + ")", this.httprequest);
1884
}
1885
if (this.httprequest.desktop.kvm.connectionBar) {
@@ -1931,14 +1919,14 @@ function createMeshCore(agent) {
1919
// Add the files session to the count to update the server
1920
if (this.httprequest.userid != null) {
1921
if (tunnelUserCount.files[this.httprequest.userid] == null) { tunnelUserCount.files[this.httprequest.userid] = 1; } else { tunnelUserCount.files[this.httprequest.userid]++; }
1934
- try { mesh.SendCommand({ action: 'sessions', type: 'files', value: tunnelUserCount.files }); } catch (ex) { }
1922
+ try { mesh.SendCommand({ action: 'sessions', type: 'files', value: tunnelUserCount.files }); } catch (e) { }
1923
}
1924
1925
this.end = function () {
1926
// Remove the files session from the count to update the server
1927
if (this.httprequest.userid != null) {
1928
if (tunnelUserCount.files[this.httprequest.userid] != null) { tunnelUserCount.files[this.httprequest.userid]--; if (tunnelUserCount.files[this.httprequest.userid] <= 0) { delete tunnelUserCount.files[this.httprequest.userid]; } }
1941
- try { mesh.SendCommand({ action: 'sessions', type: 'files', value: tunnelUserCount.files }); } catch (ex) { }
1929
+ try { mesh.SendCommand({ action: 'sessions', type: 'files', value: tunnelUserCount.files }); } catch (e) { }
1930
}
1931
};
1932
@@ -1971,7 +1959,7 @@ function createMeshCore(agent) {
1959
if (this.ws.httprequest.soptions.notifyTitle != null) { notifyTitle = this.ws.httprequest.soptions.notifyTitle; }
1960
if (this.ws.httprequest.soptions.notifyMsgFiles != null) { notifyMessage = this.ws.httprequest.soptions.notifyMsgFiles.replace('{0}', this.ws.httprequest.realname).replace('{1}', this.ws.httprequest.username); }
1961
}
1974
- try { require('toaster').Toast(notifyTitle, notifyMessage); } catch (ex) { }
1962
+ try { require('toaster').Toast(notifyTitle, notifyMessage); } catch (e) { }
1963
}
1964
this.ws.resume();
1965
},
@@ -1992,7 +1980,7 @@ function createMeshCore(agent) {
1980
if (this.httprequest.soptions.notifyTitle != null) { notifyTitle = this.httprequest.soptions.notifyTitle; }
1981
if (this.httprequest.soptions.notifyMsgFiles != null) { notifyMessage = this.httprequest.soptions.notifyMsgFiles.replace('{0}', this.httprequest.realname).replace('{1}', this.httprequest.username); }
1982
}
1995
- try { require('toaster').Toast(notifyTitle, notifyMessage); } catch (ex) { }
1983
+ try { require('toaster').Toast(notifyTitle, notifyMessage); } catch (e) { }
1984
} else {
1985
MeshServerLogEx(43, null, "Started remote files without notification (" + this.httprequest.remoteaddr + ")", this.httprequest);
1986
}
@@ -2231,7 +2219,7 @@ function createMeshCore(agent) {
2219
break;
2220
case 'cancel':
2221
// Cancel zip operation if present
2234
- try { this.zipcancel = true; this.zip.cancel(function () { }); } catch (ex) { }
2222
+ try { this.zipcancel = true; this.zip.cancel(function () { }); } catch (e) { }
2223
this.zip = null;
2224
break;
2225
default:
@@ -2436,14 +2424,13 @@ function createMeshCore(agent) {
2424
this.unpipe(this.websocket.desktop.kvm);
2425
this.websocket.httprequest.desktop.kvm.unpipe(this);
2426
}
2439
- catch (xx)
2440
- { }
2427
+ catch (e) { }
2428
}
2429
});
2430
this.websocket.write('{\"ctrlChannel\":\"102938\",\"type\":\"webrtc0\"}'); // Indicate we are ready for WebRTC switch-over.
2431
});
2432
var sdp = null;
2446
- try { sdp = ws.webrtc.setOffer(obj.sdp); } catch (ex) { }
2433
+ try { sdp = ws.webrtc.setOffer(obj.sdp); } catch (e) { }
2434
if (sdp != null) { ws.write({ type: 'answer', ctrlChannel: '102938', sdp: sdp }); }
2435
break;
2436
}
@@ -2497,7 +2484,7 @@ function createMeshCore(agent) {
2484
// Unknown platform, ignore this command.
2485
break;
2486
}
2500
- } catch (ex) { }
2487
+ } catch (e) { }
2488
return child;
2489
}
2490
@@ -2511,7 +2498,7 @@ function createMeshCore(agent) {
2498
if (process.platform == 'win32') { availcommands += ',safemode,wpfhwacceleration,uac'; }
2499
if (process.platform != 'freebsd') { availcommands += ',vm';}
2500
if (require('MeshAgent').maxKvmTileSize != null) { availcommands += ',kvmmode'; }
2514
- try { require('zip-reader'); availcommands += ',zip,unzip'; } catch (xx) { }
2501
+ try { require('zip-reader'); availcommands += ',zip,unzip'; } catch (e) { }
2502
2503
availcommands = availcommands.split(',').sort();
2504
while (availcommands.length > 0) {
@@ -2529,24 +2516,24 @@ function createMeshCore(agent) {
2516
if ((args['_'][0] == 'add') && (args['_'].length > 1)) {
2517
var msgIndex = 1, iconIndex = 0;
2518
while (tunnelUserCount.msg[msgIndex] != null) { msgIndex++; }
2532
- if (args['_'].length >= 3) { try { iconIndex = parseInt(args['_'][2]); } catch (ex) { } }
2519
+ if (args['_'].length >= 3) { try { iconIndex = parseInt(args['_'][2]); } catch (e) { } }
2520
if (typeof iconIndex != 'number') { iconIndex = 0; }
2521
tunnelUserCount.msg[msgIndex] = { msg: args['_'][1], icon: iconIndex };
2522
response = 'Agent message ' + msgIndex + ' added.';
2523
} else if ((args['_'][0] == 'remove') && (args['_'].length > 1)) {
2524
var msgIndex = 0;
2538
- try { msgIndex = parseInt(args['_'][1]); } catch (ex) { }
2525
+ try { msgIndex = parseInt(args['_'][1]); } catch (x) { }
2526
if (tunnelUserCount.msg[msgIndex] == null) { response = "Message not found."; } else { delete tunnelUserCount.msg[msgIndex]; response = "Message removed."; }
2527
} else if (args['_'][0] == 'list') {
2528
response = JSON.stringify(tunnelUserCount.msg, null, 2);
2529
}
2543
- try { mesh.SendCommand({ action: 'sessions', type: 'msg', value: tunnelUserCount.msg }); } catch (ex) { }
2530
+ try { mesh.SendCommand({ action: 'sessions', type: 'msg', value: tunnelUserCount.msg }); } catch (x) { }
2531
}
2532
break;
2533
}
2534
case 'clearagentmsg': {
2535
tunnelUserCount.msg = {};
2549
- try { mesh.SendCommand({ action: 'sessions', type: 'msg', value: tunnelUserCount.msg }); } catch (ex) { }
2536
+ try { mesh.SendCommand({ action: 'sessions', type: 'msg', value: tunnelUserCount.msg }); } catch (x) { }
2537
break;
2538
}
2539
case 'coredump':
@@ -2760,10 +2747,10 @@ function createMeshCore(agent) {
2747
if (process.platform == 'win32') {
2748
// Check the Agent Uninstall MetaData for correctness, as the installer may have written an incorrect value
2749
var writtenSize = 0;
2763
- try { writtenSize = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize'); } catch (x) { response = x; }
2750
+ try { writtenSize = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize'); } catch (e) { response = e; }
2751
if (writtenSize != actualSize) {
2752
response = "Size updated from: " + writtenSize + " to: " + actualSize;
2766
- try { require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize', actualSize); } catch (x2) { response = x2; }
2753
+ try { require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize', actualSize); } catch (e) { response = e; }
2754
} else { response = "Agent Size: " + actualSize + " kb"; }
2755
} else { response = "Agent Size: " + actualSize + " kb"; }
2756
break;
@@ -2788,21 +2775,21 @@ function createMeshCore(agent) {
2775
try {
2776
reg.WriteKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration', 0);
2777
response = "OK";
2791
- } catch (ex) { response = "FAILED"; }
2778
+ } catch (e) { response = "FAILED"; }
2779
break;
2780
case 'OFF':
2781
try {
2782
reg.WriteKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration', 1);
2783
response = 'OK';
2797
- } catch (ex) { response = 'FAILED'; }
2784
+ } catch (e) { response = 'FAILED'; }
2785
break;
2786
case 'STATUS':
2787
var s;
2801
- try { s = reg.QueryKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration') == 1 ? 'DISABLED' : 'ENABLED'; } catch (ex) { s = 'DEFAULT'; }
2788
+ try { s = reg.QueryKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration') == 1 ? 'DISABLED' : 'ENABLED'; } catch (e) { s = 'DEFAULT'; }
2789
response = "WPF Hardware Acceleration: " + s;
2790
break;
2791
case 'DEFAULT':
2805
- try { reg.DeleteKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration'); } catch (ex) { }
2792
+ try { reg.DeleteKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration'); } catch (e) { }
2793
response = 'OK';
2794
break;
2795
}
@@ -3088,7 +3075,7 @@ function createMeshCore(agent) {
3075
if (!require('service-manager').manager.getService(agentName).isMe()) {
3076
response = 'Uininstall failed, this instance is not the service instance';
3077
} else {
3091
- try { diagnosticAgent_uninstall(); } catch (x) { }
3078
+ try { diagnosticAgent_uninstall(); } catch (e) { }
3079
var js = "require('service-manager').manager.getService('" + agentName + "').stop(); require('service-manager').manager.uninstallService('" + agentName + "'); process.exit();";
3080
this.child = require('child_process').execFile(process.execPath, [process.platform == 'win32' ? (process.execPath.split('\\').pop()) : (process.execPath.split('/').pop()), '-b64exec', Buffer.from(js).toString('base64')], { type: 4, detached: true });
3081
}
@@ -3582,7 +3569,7 @@ function createMeshCore(agent) {
3569
3570
// Send any state messages
3571
if (Object.keys(tunnelUserCount.msg).length > 0) {
3585
- try { mesh.SendCommand({ action: 'sessions', type: 'msg', value: tunnelUserCount.msg }); } catch (ex) { }
3572
+ try { mesh.SendCommand({ action: 'sessions', type: 'msg', value: tunnelUserCount.msg }); } catch (e) { }
3573
}
3574
}
3575
}
@@ -3659,7 +3646,7 @@ function createMeshCore(agent) {
3646
lastMeInfo = meInfoStr;
3647
}
3648
}
3662
- } catch (ex) { }
3649
+ } catch (e) { }
3650
});
3651
}
3652
@@ -3672,8 +3659,8 @@ function createMeshCore(agent) {
3659
// Update anti-virus information
3660
// Windows Command: "wmic /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct get /FORMAT:CSV"
3661
var av, pr;
3675
- try { av = require('win-info').av(); } catch (ex) { av = null; } // Antivirus
3676
- //if (process.platform == 'win32') { try { pr = require('win-info').pendingReboot(); } catch (ex) { pr = null; } } // Pending reboot
3662
+ try { av = require('win-info').av(); } catch (e) { av = null; } // Antivirus
3663
+ //if (process.platform == 'win32') { try { pr = require('win-info').pendingReboot(); } catch (e) { pr = null; } } // Pending reboot
3664
if ((meshCoreObj.av == null) || (JSON.stringify(meshCoreObj.av) != JSON.stringify(av))) { meshCoreObj.av = av; mesh.SendCommand(meshCoreObj); }
3665
}
3666
}
@@ -3707,7 +3694,7 @@ function createMeshCore(agent) {
3694
userSession.emit('changed');
3695
//userSession.on('locked', function (user) { sendConsoleText('[' + (user.Domain ? user.Domain + '\\' : '') + user.Username + '] has LOCKED the desktop'); });
3696
//userSession.on('unlocked', function (user) { sendConsoleText('[' + (user.Domain ? user.Domain + '\\' : '') + user.Username + '] has UNLOCKED the desktop'); });
3710
- } catch (ex) { }
3697
+ } catch (e) { }
3698
}
3699
3700
obj.stop = function () {
@@ -3746,6 +3733,6 @@ try {
3733
mainMeshCore = createMeshCore();
3734
mainMeshCore.start(null);
3735
}
3749
-} catch (ex) {
3736
+} catch (e) {
3737
require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: "uncaughtException2: " + ex });
3738
}
sample-config-advanced.json
+1
@@ -161,6 +161,7 @@
161
"oldPasswordBan": 5,
162
"banCommonPasswords": false
163
},
164
+ "_twoFactorCookieDurationDays": 30,
165
"_agentInviteCodes": true,
166
"_agentNoProxy": true,
167
"_geoLocation": true,
webserver.js
+25
-16
@@ -3344,23 +3344,32 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
3344
3345
// Setup session recording if needed
3346
if (domain.sessionrecording == true || ((typeof domain.sessionrecording == 'object') && ((domain.sessionrecording.protocols == null) || (domain.sessionrecording.protocols.indexOf((req.query.p == 2) ? 101 : 100) >= 0)))) { // TODO 100
3347
- var now = new Date(Date.now());
3348
- var recFilename = 'relaysession' + ((domain.id == '') ? '' : '-') + domain.id + '-' + now.getUTCFullYear() + '-' + obj.common.zeroPad(now.getUTCMonth(), 2) + '-' + obj.common.zeroPad(now.getUTCDate(), 2) + '-' + obj.common.zeroPad(now.getUTCHours(), 2) + '-' + obj.common.zeroPad(now.getUTCMinutes(), 2) + '-' + obj.common.zeroPad(now.getUTCSeconds(), 2) + '-' + getRandomPassword() + '.mcrec'
3349
- var recFullFilename = null;
3350
- if (domain.sessionrecording.filepath) {
3351
- try { obj.fs.mkdirSync(domain.sessionrecording.filepath); } catch (e) { }
3352
- recFullFilename = obj.path.join(domain.sessionrecording.filepath, recFilename);
3353
- } else {
3354
- try { obj.fs.mkdirSync(parent.recordpath); } catch (e) { }
3355
- recFullFilename = obj.path.join(parent.recordpath, recFilename);
3347
+ // Check again if we need to do recording
3348
+ var record = true;
3349
+ if (domain.sessionrecording.onlyselecteddevicegroups === true) {
3350
+ var mesh = obj.meshes[node.meshid];
3351
+ if ((mesh.flags == null) || ((mesh.flags & 4) == 0)) { record = false; } // Do not record the session
3352
}
3357
- var fd = obj.fs.openSync(recFullFilename, 'w');
3358
- if (fd != null) {
3359
- // Write the recording file header
3360
- var firstBlock = JSON.stringify({ magic: 'MeshCentralRelaySession', ver: 1, userid: user._id, username: user.name, ipaddr: req.clientIp, nodeid: node._id, intelamt: true, protocol: (req.query.p == 2) ? 101 : 100, time: new Date().toLocaleString() })
3361
- recordingEntry(fd, 1, 0, firstBlock, function () { });
3362
- ws.logfile = { fd: fd, lock: false };
3363
- if (req.query.p == 2) { ws.send(Buffer.from(String.fromCharCode(0xF0), 'binary')); } // Intel AMT Redirection: Indicate the session is being recorded
3353
+
3354
+ if (record == true) {
3355
+ var now = new Date(Date.now());
3356
+ var recFilename = 'relaysession' + ((domain.id == '') ? '' : '-') + domain.id + '-' + now.getUTCFullYear() + '-' + obj.common.zeroPad(now.getUTCMonth(), 2) + '-' + obj.common.zeroPad(now.getUTCDate(), 2) + '-' + obj.common.zeroPad(now.getUTCHours(), 2) + '-' + obj.common.zeroPad(now.getUTCMinutes(), 2) + '-' + obj.common.zeroPad(now.getUTCSeconds(), 2) + '-' + getRandomPassword() + '.mcrec'
3357
+ var recFullFilename = null;
3358
+ if (domain.sessionrecording.filepath) {
3359
+ try { obj.fs.mkdirSync(domain.sessionrecording.filepath); } catch (e) { }
3360
+ recFullFilename = obj.path.join(domain.sessionrecording.filepath, recFilename);
3361
+ } else {
3362
+ try { obj.fs.mkdirSync(parent.recordpath); } catch (e) { }
3363
+ recFullFilename = obj.path.join(parent.recordpath, recFilename);
3364
+ }
3365
+ var fd = obj.fs.openSync(recFullFilename, 'w');
3366
+ if (fd != null) {
3367
+ // Write the recording file header
3368
+ var firstBlock = JSON.stringify({ magic: 'MeshCentralRelaySession', ver: 1, userid: user._id, username: user.name, ipaddr: req.clientIp, nodeid: node._id, intelamt: true, protocol: (req.query.p == 2) ? 101 : 100, time: new Date().toLocaleString() })
3369
+ recordingEntry(fd, 1, 0, firstBlock, function () { });
3370
+ ws.logfile = { fd: fd, lock: false };
3371
+ if (req.query.p == 2) { ws.send(Buffer.from(String.fromCharCode(0xF0), 'binary')); } // Intel AMT Redirection: Indicate the session is being recorded
3372
+ }
3373
}
3374
}
3375