Meshcore.js internalization.
Ylian Saint-Hilaire committed
Jan 7, 2020 at 13:04 UTC
9453ee9ba338e1456f8f9b47d5957737f7b32b06
2 files changed
+230
-376
agents/meshcore.js
+230
-376
@@ -15,7 +15,7 @@ limitations under the License.
15
*/
16
17
process.on('uncaughtException', function (ex) {
18
- require('MeshAgent').SendCommand({ "action": "msg", "type": "console", "value": "uncaughtException1: " + ex });
18
+ require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: "uncaughtException1: " + ex });
19
});
20
21
// NOTE: This seems to cause big problems, don't enable the debugger in the server's meshcore.
@@ -39,24 +39,11 @@ var MESHRIGHT_LIMITEDINPUT = 4096;
39
40
function createMeshCore(agent) {
41
var obj = {};
42
- if (process.platform == 'win32' && require('user-sessions').isRoot())
43
- {
42
+ if (process.platform == 'win32' && require('user-sessions').isRoot()) {
43
// Check the Agent Uninstall MetaData for correctness, as the installer may have written an incorrect value
45
- var actualSize = Math.floor(require('fs').statSync(process.execPath).size / 1024);
46
- var writtenSize = 0;
47
- try
48
- {
49
- writtenSize = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize');
50
- }
51
- catch(x) { }
52
- if (writtenSize != actualSize)
53
- {
54
- try
55
- {
56
- require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize', actualSize);
57
- }
58
- catch (x2) { }
59
- }
44
+ var writtenSize = 0, actualSize = Math.floor(require('fs').statSync(process.execPath).size / 1024);
45
+ try { writtenSize = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize'); } catch (x) { }
46
+ if (writtenSize != actualSize) { try { require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize', actualSize); } catch (x2) { } }
47
}
48
49
if (process.platform == 'darwin' && !process.versions) {
@@ -149,7 +136,7 @@ function createMeshCore(agent) {
136
};
137
this._daipc = c;
138
c.parent = this;
152
- c.on('end', function () { console.log('Connection Closed'); this.parent._daipc = null; });
139
+ c.on('end', function () { console.log("Connection Closed"); this.parent._daipc = null; });
140
c.on('data', function (chunk) {
141
if (chunk.length < 4) { this.unshift(chunk); return; }
142
var len = chunk.readUInt32LE(0);
@@ -205,8 +192,8 @@ function createMeshCore(agent) {
192
require('service-manager').manager.installService(
193
{
194
name: 'meshagentDiagnostic',
208
- displayName: 'Mesh Agent Diagnostic Service',
209
- description: 'Mesh Agent Diagnostic Service',
195
+ displayName: "Mesh Agent Diagnostic Service",
196
+ description: "Mesh Agent Diagnostic Service",
197
servicePath: process.execPath,
198
parameters: ['-recovery']
199
//files: [{ newName: 'diagnostic.js', _buffer: Buffer.from('LyoNCkNvcHlyaWdodCAyMDE5IEludGVsIENvcnBvcmF0aW9uDQoNCkxpY2Vuc2VkIHVuZGVyIHRoZSBBcGFjaGUgTGljZW5zZSwgVmVyc2lvbiAyLjAgKHRoZSAiTGljZW5zZSIpOw0KeW91IG1heSBub3QgdXNlIHRoaXMgZmlsZSBleGNlcHQgaW4gY29tcGxpYW5jZSB3aXRoIHRoZSBMaWNlbnNlLg0KWW91IG1heSBvYnRhaW4gYSBjb3B5IG9mIHRoZSBMaWNlbnNlIGF0DQoNCiAgICBodHRwOi8vd3d3LmFwYWNoZS5vcmcvbGljZW5zZXMvTElDRU5TRS0yLjANCg0KVW5sZXNzIHJlcXVpcmVkIGJ5IGFwcGxpY2FibGUgbGF3IG9yIGFncmVlZCB0byBpbiB3cml0aW5nLCBzb2Z0d2FyZQ0KZGlzdHJpYnV0ZWQgdW5kZXIgdGhlIExpY2Vuc2UgaXMgZGlzdHJpYnV0ZWQgb24gYW4gIkFTIElTIiBCQVNJUywNCldJVEhPVVQgV0FSUkFOVElFUyBPUiBDT05ESVRJT05TIE9GIEFOWSBLSU5ELCBlaXRoZXIgZXhwcmVzcyBvciBpbXBsaWVkLg0KU2VlIHRoZSBMaWNlbnNlIGZvciB0aGUgc3BlY2lmaWMgbGFuZ3VhZ2UgZ292ZXJuaW5nIHBlcm1pc3Npb25zIGFuZA0KbGltaXRhdGlvbnMgdW5kZXIgdGhlIExpY2Vuc2UuDQoqLw0KDQp2YXIgaG9zdCA9IHJlcXVpcmUoJ3NlcnZpY2UtaG9zdCcpLmNyZWF0ZSgnbWVzaGFnZW50RGlhZ25vc3RpYycpOw0KdmFyIFJlY292ZXJ5QWdlbnQgPSByZXF1aXJlKCdNZXNoQWdlbnQnKTsNCg0KaG9zdC5vbignc2VydmljZVN0YXJ0JywgZnVuY3Rpb24gKCkNCnsNCiAgICBjb25zb2xlLnNldERlc3RpbmF0aW9uKGNvbnNvbGUuRGVzdGluYXRpb25zLkxPR0ZJTEUpOw0KICAgIGhvc3Quc3RvcCA9IGZ1bmN0aW9uKCkNCiAgICB7DQogICAgICAgIHJlcXVpcmUoJ3NlcnZpY2UtbWFuYWdlcicpLm1hbmFnZXIuZ2V0U2VydmljZSgnbWVzaGFnZW50RGlhZ25vc3RpYycpLnN0b3AoKTsNCiAgICB9DQogICAgUmVjb3ZlcnlBZ2VudC5vbignQ29ubmVjdGVkJywgZnVuY3Rpb24gKHN0YXR1cykNCiAgICB7DQogICAgICAgIGlmIChzdGF0dXMgPT0gMCkNCiAgICAgICAgew0KICAgICAgICAgICAgY29uc29sZS5sb2coJ0RpYWdub3N0aWMgQWdlbnQ6IFNlcnZlciBjb25uZWN0aW9uIGxvc3QuLi4nKTsNCiAgICAgICAgICAgIHJldHVybjsNCiAgICAgICAgfQ0KICAgICAgICBjb25zb2xlLmxvZygnRGlhZ25vc3RpYyBBZ2VudDogQ29ubmVjdGlvbiBFc3RhYmxpc2hlZCB3aXRoIFNlcnZlcicpOw0KICAgICAgICBzdGFydCgpOw0KICAgIH0pOw0KfSk7DQpob3N0Lm9uKCdub3JtYWxTdGFydCcsIGZ1bmN0aW9uICgpDQp7DQogICAgaG9zdC5zdG9wID0gZnVuY3Rpb24gKCkNCiAgICB7DQogICAgICAgIHByb2Nlc3MuZXhpdCgpOw0KICAgIH0NCiAgICBjb25zb2xlLmxvZygnTm9uIFNlcnZpY2UgTW9kZScpOw0KICAgIFJlY292ZXJ5QWdlbnQub24oJ0Nvbm5lY3RlZCcsIGZ1bmN0aW9uIChzdGF0dXMpDQogICAgew0KICAgICAgICBpZiAoc3RhdHVzID09IDApDQogICAgICAgIHsNCiAgICAgICAgICAgIGNvbnNvbGUubG9nKCdEaWFnbm9zdGljIEFnZW50OiBTZXJ2ZXIgY29ubmVjdGlvbiBsb3N0Li4uJyk7DQogICAgICAgICAgICByZXR1cm47DQogICAgICAgIH0NCiAgICAgICAgY29uc29sZS5sb2coJ0RpYWdub3N0aWMgQWdlbnQ6IENvbm5lY3Rpb24gRXN0YWJsaXNoZWQgd2l0aCBTZXJ2ZXInKTsNCiAgICAgICAgc3RhcnQoKTsNCiAgICB9KTsNCn0pOw0KaG9zdC5vbignc2VydmljZVN0b3AnLCBmdW5jdGlvbiAoKSB7IHByb2Nlc3MuZXhpdCgpOyB9KTsNCmhvc3QucnVuKCk7DQoNCg0KZnVuY3Rpb24gc3RhcnQoKQ0Kew0KDQp9Ow0K', 'base64') }]
@@ -234,7 +221,7 @@ function createMeshCore(agent) {
221
}
222
223
require('MeshAgent').SendCommand({ action: 'diagnostic', value: { command: 'register', value: nodeid } });
237
- require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: 'Diagnostic Agent Registered [' + nodeid.length + '/' + nodeid + ']' });
224
+ require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: "Diagnostic Agent Registered [" + nodeid.length + "/" + nodeid + "]" });
225
226
delete ddb;
227
@@ -280,7 +267,7 @@ function createMeshCore(agent) {
267
*/
268
269
// MeshAgent JavaScript Core Module. This code is sent to and running on the mesh agent.
283
- var meshCoreObj = { "action": "coreinfo", "value": "MeshCore v6", "caps": 14 }; // Capability bitmask: 1 = Desktop, 2 = Terminal, 4 = Files, 8 = Console, 16 = JavaScript, 32 = Temporary Agent, 64 = Recovery Agent
270
+ var meshCoreObj = { action: 'coreinfo', value: 'MeshCore v6', caps: 14 }; // Capability bitmask: 1 = Desktop, 2 = Terminal, 4 = Files, 8 = Console, 16 = JavaScript, 32 = Temporary Agent, 64 = Recovery Agent
271
272
// Get the operating system description string
273
try { require('os').name().then(function (v) { meshCoreObj.osdesc = v; }); } catch (ex) { }
@@ -307,7 +294,7 @@ function createMeshCore(agent) {
294
295
// Add to the server event log
296
function MeshServerLog(msg, state) {
310
- if (typeof msg == 'string') { msg = { 'action': 'log', 'msg': msg }; } else { msg.action = 'log'; }
297
+ if (typeof msg == 'string') { msg = { action: 'log', msg: msg }; } else { msg.action = 'log'; }
298
if (state) {
299
if (state.userid) { msg.userid = state.userid; }
300
if (state.username) { msg.username = state.username; }
@@ -380,7 +367,7 @@ function createMeshCore(agent) {
367
if (data != null) {
368
SMBiosTablesRaw = data;
369
SMBiosTables = require('smbios').parse(data)
383
- if (mesh.isControlChannelConnected) { mesh.SendCommand({ 'action': 'smbios', 'value': SMBiosTablesRaw }); }
370
+ if (mesh.isControlChannelConnected) { mesh.SendCommand({ action: 'smbios', value: SMBiosTablesRaw }); }
371
372
// If SMBios tables say that Intel AMT is present, try to connect MEI
373
if (SMBiosTables.amtInfo && (SMBiosTables.amtInfo.AMT == true)) {
@@ -603,10 +590,10 @@ function createMeshCore(agent) {
590
for (var i = 0; i < interfaces[adapter].length; ++i) {
591
var addr = interfaces[adapter][i];
592
if ((addr.family == 'IPv4') && (addr.mac != '00:00:00:00:00:00')) {
606
- var socket = require('dgram').createSocket({ type: "udp4" });
593
+ var socket = require('dgram').createSocket({ type: 'udp4' });
594
socket.bind({ address: addr.address });
595
socket.setBroadcast(true);
609
- socket.send(magicbin, 7, "255.255.255.255");
596
+ socket.send(magicbin, 7, '255.255.255.255');
597
count++;
598
}
599
}
@@ -625,7 +612,7 @@ function createMeshCore(agent) {
612
switch (data.type) {
613
case 'console': { // Process a console command
614
if (data.value && data.sessionid) {
628
- MeshServerLog('Processing console command: ' + data.value, data);
615
+ MeshServerLog("Processing console command: " + data.value, data);
616
var args = splitArgs(data.value);
617
processConsoleCommand(args[0].toLowerCase(), parseArgs(args), data.rights, data.sessionid);
618
}
@@ -642,11 +629,11 @@ function createMeshCore(agent) {
629
//sendConsoleText('TUNNEL: ' + JSON.stringify(data));
630
var tunnel = http.request(woptions);
631
tunnel.upgrade = onTunnelUpgrade;
645
- tunnel.on('error', function (e) { sendConsoleText('ERROR: ' + JSON.stringify(e)); });
632
+ tunnel.on('error', function (e) { sendConsoleText("ERROR: " + JSON.stringify(e)); });
633
tunnel.sessionid = data.sessionid;
634
tunnel.rights = data.rights;
635
tunnel.consent = data.consent;
649
- tunnel.privacybartext = data.privacybartext ? data.privacybartext : 'Sharing desktop with: {0}';
636
+ tunnel.privacybartext = data.privacybartext ? data.privacybartext : "Sharing desktop with: {0}";
637
tunnel.username = data.username;
638
tunnel.userid = data.userid;
639
tunnel.remoteaddr = data.remoteaddr;
@@ -672,7 +659,7 @@ function createMeshCore(agent) {
659
// Return the list of running processes
660
if (data.sessionid) {
661
processManager.getProcesses(function (plist) {
675
- mesh.SendCommand({ "action": "msg", "type": "ps", "value": JSON.stringify(plist), "sessionid": data.sessionid });
662
+ mesh.SendCommand({ action: 'msg', type: 'ps', value: JSON.stringify(plist), sessionid: data.sessionid });
663
});
664
}
665
break;
@@ -680,7 +667,7 @@ function createMeshCore(agent) {
667
case 'pskill': {
668
// Kill a process
669
if (data.value) {
683
- MeshServerLog('Killing process ' + data.value, data);
670
+ MeshServerLog("Killing process " + data.value, data);
671
try { process.kill(data.value); } catch (e) { sendConsoleText("pskill: " + JSON.stringify(e)); }
672
}
673
break;
@@ -689,7 +676,7 @@ function createMeshCore(agent) {
676
// Return the list of installed services
677
var services = null;
678
try { services = require('service-manager').manager.enumerateService(); } catch (e) { }
692
- if (services != null) { mesh.SendCommand({ "action": "msg", "type": "services", "value": JSON.stringify(services), "sessionid": data.sessionid }); }
679
+ if (services != null) { mesh.SendCommand({ action: 'msg', type: 'services', value: JSON.stringify(services), sessionid: data.sessionid }); }
680
break;
681
}
682
case 'serviceStop': {
@@ -718,48 +705,44 @@ function createMeshCore(agent) {
705
}
706
case 'deskBackground':
707
{
721
- // Toggle desktop background
722
- try {
723
- if (process.platform == 'win32')
724
- {
725
- var stype = require('user-sessions').getProcessOwnerName(process.pid).tsid == 0 ? 1 : 0;
726
- var sid = undefined;
727
- if (stype == 1)
728
- {
729
- if(require('MeshAgent')._tsid != null)
730
- {
731
- stype = 5;
732
- sid = require('MeshAgent')._tsid;
708
+ // Toggle desktop background
709
+ try {
710
+ if (process.platform == 'win32') {
711
+ var stype = require('user-sessions').getProcessOwnerName(process.pid).tsid == 0 ? 1 : 0;
712
+ var sid = undefined;
713
+ if (stype == 1) {
714
+ if (require('MeshAgent')._tsid != null) {
715
+ stype = 5;
716
+ sid = require('MeshAgent')._tsid;
717
+ }
718
}
719
+ var id = require('user-sessions').getProcessOwnerName(process.pid).tsid == 0 ? 1 : 0;
720
+ var child = require('child_process').execFile(process.execPath, [process.execPath.split('\\').pop(), '-b64exec', 'dmFyIFNQSV9HRVRERVNLV0FMTFBBUEVSID0gMHgwMDczOwp2YXIgU1BJX1NFVERFU0tXQUxMUEFQRVIgPSAweDAwMTQ7CnZhciBHTSA9IHJlcXVpcmUoJ19HZW5lcmljTWFyc2hhbCcpOwp2YXIgdXNlcjMyID0gR00uQ3JlYXRlTmF0aXZlUHJveHkoJ3VzZXIzMi5kbGwnKTsKdXNlcjMyLkNyZWF0ZU1ldGhvZCgnU3lzdGVtUGFyYW1ldGVyc0luZm9BJyk7CgppZiAocHJvY2Vzcy5hcmd2Lmxlbmd0aCA9PSAzKQp7CiAgICB2YXIgdiA9IEdNLkNyZWF0ZVZhcmlhYmxlKDEwMjQpOwogICAgdXNlcjMyLlN5c3RlbVBhcmFtZXRlcnNJbmZvQShTUElfR0VUREVTS1dBTExQQVBFUiwgdi5fc2l6ZSwgdiwgMCk7CiAgICBjb25zb2xlLmxvZyh2LlN0cmluZyk7CiAgICBwcm9jZXNzLmV4aXQoKTsKfQplbHNlCnsKICAgIHZhciBuYiA9IEdNLkNyZWF0ZVZhcmlhYmxlKHByb2Nlc3MuYXJndlszXSk7CiAgICB1c2VyMzIuU3lzdGVtUGFyYW1ldGVyc0luZm9BKFNQSV9TRVRERVNLV0FMTFBBUEVSLCBuYi5fc2l6ZSwgbmIsIDApOwogICAgcHJvY2Vzcy5leGl0KCk7Cn0='], { type: stype, uid: sid });
721
+ child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
722
+ child.stderr.on('data', function () { });
723
+ child.waitExit();
724
+ var current = child.stdout.str.trim();
725
+ if (current != '') { require('MeshAgent')._wallpaper = current; }
726
+ child = require('child_process').execFile(process.execPath, [process.execPath.split('\\').pop(), '-b64exec', 'dmFyIFNQSV9HRVRERVNLV0FMTFBBUEVSID0gMHgwMDczOwp2YXIgU1BJX1NFVERFU0tXQUxMUEFQRVIgPSAweDAwMTQ7CnZhciBHTSA9IHJlcXVpcmUoJ19HZW5lcmljTWFyc2hhbCcpOwp2YXIgdXNlcjMyID0gR00uQ3JlYXRlTmF0aXZlUHJveHkoJ3VzZXIzMi5kbGwnKTsKdXNlcjMyLkNyZWF0ZU1ldGhvZCgnU3lzdGVtUGFyYW1ldGVyc0luZm9BJyk7CgppZiAocHJvY2Vzcy5hcmd2Lmxlbmd0aCA9PSAzKQp7CiAgICB2YXIgdiA9IEdNLkNyZWF0ZVZhcmlhYmxlKDEwMjQpOwogICAgdXNlcjMyLlN5c3RlbVBhcmFtZXRlcnNJbmZvQShTUElfR0VUREVTS1dBTExQQVBFUiwgdi5fc2l6ZSwgdiwgMCk7CiAgICBjb25zb2xlLmxvZyh2LlN0cmluZyk7CiAgICBwcm9jZXNzLmV4aXQoKTsKfQplbHNlCnsKICAgIHZhciBuYiA9IEdNLkNyZWF0ZVZhcmlhYmxlKHByb2Nlc3MuYXJndlszXSk7CiAgICB1c2VyMzIuU3lzdGVtUGFyYW1ldGVyc0luZm9BKFNQSV9TRVRERVNLV0FMTFBBUEVSLCBuYi5fc2l6ZSwgbmIsIDApOwogICAgcHJvY2Vzcy5leGl0KCk7Cn0=', current != '' ? '""' : require('MeshAgent')._wallpaper], { type: stype, uid: sid });
727
+ child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
728
+ child.stderr.on('data', function () { });
729
+ child.waitExit();
730
+ } else {
731
+ var id = require('user-sessions').consoleUid();
732
+ var current = require('linux-gnome-helpers').getDesktopWallpaper(id);
733
+ if (current != '/dev/null') { require('MeshAgent')._wallpaper = current; }
734
+ require('linux-gnome-helpers').setDesktopWallpaper(id, current != '/dev/null' ? undefined : require('MeshAgent')._wallpaper);
735
}
735
- var id = require('user-sessions').getProcessOwnerName(process.pid).tsid == 0 ? 1 : 0;
736
- var child = require('child_process').execFile(process.execPath, [process.execPath.split('\\').pop(), '-b64exec', 'dmFyIFNQSV9HRVRERVNLV0FMTFBBUEVSID0gMHgwMDczOwp2YXIgU1BJX1NFVERFU0tXQUxMUEFQRVIgPSAweDAwMTQ7CnZhciBHTSA9IHJlcXVpcmUoJ19HZW5lcmljTWFyc2hhbCcpOwp2YXIgdXNlcjMyID0gR00uQ3JlYXRlTmF0aXZlUHJveHkoJ3VzZXIzMi5kbGwnKTsKdXNlcjMyLkNyZWF0ZU1ldGhvZCgnU3lzdGVtUGFyYW1ldGVyc0luZm9BJyk7CgppZiAocHJvY2Vzcy5hcmd2Lmxlbmd0aCA9PSAzKQp7CiAgICB2YXIgdiA9IEdNLkNyZWF0ZVZhcmlhYmxlKDEwMjQpOwogICAgdXNlcjMyLlN5c3RlbVBhcmFtZXRlcnNJbmZvQShTUElfR0VUREVTS1dBTExQQVBFUiwgdi5fc2l6ZSwgdiwgMCk7CiAgICBjb25zb2xlLmxvZyh2LlN0cmluZyk7CiAgICBwcm9jZXNzLmV4aXQoKTsKfQplbHNlCnsKICAgIHZhciBuYiA9IEdNLkNyZWF0ZVZhcmlhYmxlKHByb2Nlc3MuYXJndlszXSk7CiAgICB1c2VyMzIuU3lzdGVtUGFyYW1ldGVyc0luZm9BKFNQSV9TRVRERVNLV0FMTFBBUEVSLCBuYi5fc2l6ZSwgbmIsIDApOwogICAgcHJvY2Vzcy5leGl0KCk7Cn0='], { type: stype, uid: sid });
737
- child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
738
- child.stderr.on('data', function () { });
739
- child.waitExit();
740
- var current = child.stdout.str.trim();
741
- if (current != '') { require('MeshAgent')._wallpaper = current; }
742
- child = require('child_process').execFile(process.execPath, [process.execPath.split('\\').pop(), '-b64exec', 'dmFyIFNQSV9HRVRERVNLV0FMTFBBUEVSID0gMHgwMDczOwp2YXIgU1BJX1NFVERFU0tXQUxMUEFQRVIgPSAweDAwMTQ7CnZhciBHTSA9IHJlcXVpcmUoJ19HZW5lcmljTWFyc2hhbCcpOwp2YXIgdXNlcjMyID0gR00uQ3JlYXRlTmF0aXZlUHJveHkoJ3VzZXIzMi5kbGwnKTsKdXNlcjMyLkNyZWF0ZU1ldGhvZCgnU3lzdGVtUGFyYW1ldGVyc0luZm9BJyk7CgppZiAocHJvY2Vzcy5hcmd2Lmxlbmd0aCA9PSAzKQp7CiAgICB2YXIgdiA9IEdNLkNyZWF0ZVZhcmlhYmxlKDEwMjQpOwogICAgdXNlcjMyLlN5c3RlbVBhcmFtZXRlcnNJbmZvQShTUElfR0VUREVTS1dBTExQQVBFUiwgdi5fc2l6ZSwgdiwgMCk7CiAgICBjb25zb2xlLmxvZyh2LlN0cmluZyk7CiAgICBwcm9jZXNzLmV4aXQoKTsKfQplbHNlCnsKICAgIHZhciBuYiA9IEdNLkNyZWF0ZVZhcmlhYmxlKHByb2Nlc3MuYXJndlszXSk7CiAgICB1c2VyMzIuU3lzdGVtUGFyYW1ldGVyc0luZm9BKFNQSV9TRVRERVNLV0FMTFBBUEVSLCBuYi5fc2l6ZSwgbmIsIDApOwogICAgcHJvY2Vzcy5leGl0KCk7Cn0=', current != '' ? '""' : require('MeshAgent')._wallpaper], { type: stype, uid: sid });
743
- child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
744
- child.stderr.on('data', function () { });
745
- child.waitExit();
746
- } else {
747
- var id = require('user-sessions').consoleUid();
748
- var current = require('linux-gnome-helpers').getDesktopWallpaper(id);
749
- if (current != '/dev/null') { require('MeshAgent')._wallpaper = current; }
750
- require('linux-gnome-helpers').setDesktopWallpaper(id, current != '/dev/null' ? undefined : require('MeshAgent')._wallpaper);
736
+ } catch (e) {
737
+ sendConsoleText(e);
738
}
752
- } catch (e)
753
- {
754
- sendConsoleText(e);
739
+ break;
740
}
756
- break;
757
- }
741
case 'openUrl': {
742
// Open a local web browser and return success/fail
760
- MeshServerLog('Opening: ' + data.url, data);
761
- sendConsoleText('OpenURL: ' + data.url);
762
- if (data.url) { mesh.SendCommand({ "action": "msg", "type": "openUrl", "url": data.url, "sessionid": data.sessionid, "success": (openUserDesktopUrl(data.url) != null) }); }
743
+ MeshServerLog("Opening: " + data.url, data);
744
+ sendConsoleText("OpenURL: " + data.url);
745
+ if (data.url) { mesh.SendCommand({ action: 'msg', type: 'openUrl', url: data.url, sessionid: data.sessionid, success: (openUserDesktopUrl(data.url) != null) }); }
746
break;
747
}
748
case 'getclip': {
@@ -768,15 +751,15 @@ function createMeshCore(agent) {
751
if (require('MeshAgent').isService) {
752
require('clipboard').dispatchRead().then(function (str) {
753
if (str) {
771
- MeshServerLog('Getting clipboard content, ' + str.length + ' byte(s)', data);
772
- mesh.SendCommand({ "action": "msg", "type": "getclip", "sessionid": data.sessionid, "data": str });
754
+ MeshServerLog("Getting clipboard content, " + str.length + " byte(s)", data);
755
+ mesh.SendCommand({ action: 'msg', type: 'getclip', sessionid: data.sessionid, data: str });
756
}
757
});
758
} else {
759
require("clipboard").read().then(function (str) {
760
if (str) {
778
- MeshServerLog('Getting clipboard content, ' + str.length + ' byte(s)', data);
779
- mesh.SendCommand({ "action": "msg", "type": "getclip", "sessionid": data.sessionid, "data": str });
761
+ MeshServerLog("Getting clipboard content, " + str.length + " byte(s)", data);
762
+ mesh.SendCommand({ action: 'msg', type: 'getclip', sessionid: data.sessionid, data: str });
763
}
764
});
765
}
@@ -786,9 +769,9 @@ function createMeshCore(agent) {
769
// Set the load clipboard to a user value
770
//sendConsoleText('setClip: ' + JSON.stringify(data));
771
if (typeof data.data == 'string') {
789
- MeshServerLog('Setting clipboard content, ' + data.data.length + ' byte(s)', data);
772
+ MeshServerLog("Setting clipboard content, " + data.data.length + " byte(s)", data);
773
if (require('MeshAgent').isService) { require('clipboard').dispatchWrite(data.data); } else { require("clipboard")(data.data); } // Set the clipboard
791
- mesh.SendCommand({ "action": "msg", "type": "setclip", "sessionid": data.sessionid, "success": true });
774
+ mesh.SendCommand({ action: 'msg', type: 'setclip', sessionid: data.sessionid, success: true });
775
}
776
break;
777
}
@@ -798,7 +781,7 @@ function createMeshCore(agent) {
781
if (process.platform != 'win32') break;
782
var p = require('user-sessions').enumerateUsers();
783
p.sessionid = data.sessionid;
801
- p.then(function (u) { mesh.SendCommand({ 'action': 'msg', 'type': 'userSessions', 'sessionid': u.sessionid, 'data': u }); });
784
+ p.then(function (u) { mesh.SendCommand({ action: 'msg', type: 'userSessions', sessionid: u.sessionid, data: u }); });
785
break;
786
}
787
default:
@@ -809,14 +792,14 @@ function createMeshCore(agent) {
792
}
793
case 'acmactivate': {
794
if (amt != null) {
812
- MeshServerLog('Attempting Intel AMT ACM mode activation', data);
795
+ MeshServerLog("Attempting Intel AMT ACM mode activation", data);
796
amt.setAcmResponse(data);
797
}
798
break;
799
}
800
case 'wakeonlan': {
801
// Send wake-on-lan on all interfaces for all MAC addresses in data.macs array. The array is a list of HEX MAC addresses.
819
- sendConsoleText('Server requesting wake-on-lan for: ' + data.macs.join(', '));
802
+ sendConsoleText("Server requesting wake-on-lan for: " + data.macs.join(', '));
803
for (var i in data.macs) { sendWakeOnLan(data.macs[i]); }
804
break;
805
}
@@ -835,22 +818,22 @@ function createMeshCore(agent) {
818
var forced = 0;
819
if (data.forced == 1) { forced = 1; }
820
data.actiontype = parseInt(data.actiontype);
838
- MeshServerLog('Performing power action=' + data.actiontype + ', forced=' + forced, data);
839
- sendConsoleText('Performing power action=' + data.actiontype + ', forced=' + forced + '.');
821
+ MeshServerLog("Performing power action=" + data.actiontype + ", forced=" + forced, data);
822
+ sendConsoleText("Performing power action=" + data.actiontype + ", forced=" + forced + '.');
823
var r = mesh.ExecPowerState(data.actiontype, forced);
841
- sendConsoleText('ExecPowerState returned code: ' + r);
824
+ sendConsoleText("ExecPowerState returned code: " + r);
825
}
826
break;
827
}
828
case 'iplocation': {
829
// Update the IP location information of this node. Only do this when requested by the server since we have a limited amount of time we can call this per day
847
- getIpLocationData(function (location) { mesh.SendCommand({ "action": "iplocation", "type": "publicip", "value": location }); });
830
+ getIpLocationData(function (location) { mesh.SendCommand({ action: 'iplocation', type: 'publicip', value: location }); });
831
break;
832
}
833
case 'toast': {
834
// Display a toast message
835
if (data.title && data.msg) {
853
- MeshServerLog('Displaying toast message, title=' + data.title + ', message=' + data.msg, data);
836
+ MeshServerLog("Displaying toast message, title=" + data.title + ", message=" + data.msg, data);
837
data.msg = data.msg.split('\r').join('\\r').split('\n').join('\\n');
838
try { require('toaster').Toast(data.title, data.msg); } catch (ex) { }
839
}
@@ -859,8 +842,8 @@ function createMeshCore(agent) {
842
case 'openUrl': {
843
// Open a local web browser and return success/fail
844
//sendConsoleText('OpenURL: ' + data.url);
862
- MeshServerLog('Opening: ' + data.url, data);
863
- if (data.url) { mesh.SendCommand({ "action": "openUrl", "url": data.url, "sessionid": data.sessionid, "success": (openUserDesktopUrl(data.url) != null) }); }
845
+ MeshServerLog("Opening: " + data.url, data);
846
+ if (data.url) { mesh.SendCommand({ action: 'openUrl', url: data.url, sessionid: data.sessionid, success: (openUserDesktopUrl(data.url) != null) }); }
847
break;
848
}
849
case 'amtPolicy': {
@@ -878,7 +861,7 @@ function createMeshCore(agent) {
861
case 'sysinfo': {
862
// Fetch system information
863
getSystemInformation(function (results) {
881
- if ((results != null) && (data.hash != results.hash)) { mesh.SendCommand({ "action": "sysinfo", "sessionid": this.sessionid, "data": results }); }
864
+ if ((results != null) && (data.hash != results.hash)) { mesh.SendCommand({ action: 'sysinfo', sessionid: this.sessionid, data: results }); }
865
});
866
break;
867
}
@@ -1123,12 +1106,12 @@ function createMeshCore(agent) {
1106
// Disengage this tunnel, user does not have the rights to do this!!
1107
this.httprequest.protocol = 999999;
1108
this.httprequest.s.end();
1126
- sendConsoleText('Error: No Terminal Control Rights.');
1109
+ sendConsoleText("Error: No Terminal Control Rights.");
1110
return;
1111
}
1112
1113
this.end = function () {
1131
- if (process.platform == "win32") {
1114
+ if (process.platform == 'win32') {
1115
// Unpipe the web socket
1116
this.unpipe(this.httprequest._term);
1117
if (this.httprequest._term) { this.httprequest._term.unpipe(this); }
@@ -1148,60 +1131,48 @@ function createMeshCore(agent) {
1131
};
1132
1133
// Remote terminal using native pipes
1151
- if (process.platform == "win32")
1152
- {
1153
- try
1154
- {
1134
+ if (process.platform == 'win32') {
1135
+ try {
1136
if (!require('win-terminal').PowerShellCapable() && (this.httprequest.protocol == 6 || this.httprequest.protocol == 9)) { throw ('PowerShell is not supported on this version of windows'); }
1156
- if ((this.httprequest.protocol == 1) || (this.httprequest.protocol == 6))
1157
- {
1137
+ if ((this.httprequest.protocol == 1) || (this.httprequest.protocol == 6)) {
1138
// Admin Terminal
1159
- if (require('win-virtual-terminal').supported)
1160
- {
1139
+ if (require('win-virtual-terminal').supported) {
1140
// ConPTY PseudoTerminal
1162
- this.httprequest._term = require('win-virtual-terminal')[this.httprequest.protocol == 6 ? 'StartPowerShell' : 'Start'](80, 25);
1141
+ this.httprequest._term = require('win-virtual-terminal')[this.httprequest.protocol == 6 ? 'StartPowerShell' : 'Start'](80, 25);
1142
}
1164
- else
1165
- {
1143
+ else {
1144
// Legacy Terminal
1145
this.httprequest._term = require('win-terminal')[this.httprequest.protocol == 6 ? 'StartPowerShell' : 'Start'](80, 25);
1146
}
1147
}
1170
- else
1171
- {
1148
+ else {
1149
// Logged in user
1150
var userPromise = require('user-sessions').enumerateUsers();
1151
userPromise.that = this;
1175
- userPromise.then(function (u)
1176
- {
1152
+ userPromise.then(function (u) {
1153
var that = this.that;
1178
- if (u.Active.length > 0)
1179
- {
1154
+ if (u.Active.length > 0) {
1155
var username = u.Active[0].Username;
1181
- if (require('win-virtual-terminal').supported)
1182
- {
1156
+ if (require('win-virtual-terminal').supported) {
1157
// ConPTY PseudoTerminal
1158
that.httprequest._dispatcher = require('win-dispatcher').dispatch({ user: username, modules: [{ name: 'win-virtual-terminal', script: getJSModule('win-virtual-terminal') }], launch: { module: 'win-virtual-terminal', method: (that.httprequest.protocol == 9 ? 'StartPowerShell' : 'Start'), args: [80, 25] } });
1159
}
1186
- else
1187
- {
1160
+ else {
1161
// Legacy Terminal
1162
that.httprequest._dispatcher = require('win-dispatcher').dispatch({ user: username, modules: [{ name: 'win-terminal', script: getJSModule('win-terminal') }], launch: { module: 'win-terminal', method: (that.httprequest.protocol == 9 ? 'StartPowerShell' : 'Start'), args: [80, 25] } });
1163
}
1164
that.httprequest._dispatcher.ws = that;
1192
- that.httprequest._dispatcher.on('connection', function (c)
1193
- {
1165
+ that.httprequest._dispatcher.on('connection', function (c) {
1166
console.log('client connected');
1167
this.ws._term = c;
1168
c.pipe(this.ws, { dataTypeSkip: 1 });
1169
this.ws.pipe(c, { dataTypeSkip: 1, end: false });
1198
- this.ws.prependListener('end', function ()
1199
- {
1170
+ this.ws.prependListener('end', function () {
1171
if (this.httprequest._term) { this.httprequest._term.end(function () { console.log("Terminal was closed"); }); }
1172
});
1173
});
1174
}
1204
- });
1175
+ });
1176
}
1177
} catch (e) {
1178
MeshServerLog('Failed to start remote terminal session, ' + e.toString() + ' (' + this.httprequest.remoteaddr + ')', this.httprequest);
@@ -1209,30 +1180,27 @@ function createMeshCore(agent) {
1180
this.end();
1181
return;
1182
}
1212
- if (!this.httprequest._dispatcher)
1213
- {
1183
+ if (!this.httprequest._dispatcher) {
1184
this.httprequest._term.pipe(this, { dataTypeSkip: 1 });
1185
this.pipe(this.httprequest._term, { dataTypeSkip: 1, end: false });
1186
this.prependListener('end', function () { this.httprequest._term.end(function () { console.log("Terminal was closed"); }); });
1187
}
1188
}
1219
- else
1220
- {
1221
- try
1222
- {
1189
+ else {
1190
+ try {
1191
var bash = fs.existsSync('/bin/bash') ? '/bin/bash' : false;
1192
var sh = fs.existsSync('/bin/sh') ? '/bin/sh' : false;
1193
var script = fs.existsSync('/usr/bin/script') ? '/usr/bin/script' : false;
1194
var python = fs.existsSync('/usr/bin/python') ? '/usr/bin/python' : false;
1195
var shell = bash || sh;
1196
1229
- var options = { uid: (this.httprequest.protocol == 8) ? require('user-sessions').consoleUid() : null, env: { HISTCONTROL: "ignoreboth", TERM: "xterm" } };
1230
- var setupcommands = " alias ls='ls --color=auto'\n";
1231
- if (shell == sh) setupcommands += "stty erase ^H\n"
1197
+ var options = { uid: (this.httprequest.protocol == 8) ? require('user-sessions').consoleUid() : null, env: { HISTCONTROL: 'ignoreboth', TERM: 'xterm' } };
1198
+ var setupcommands = ' alias ls=\'ls --color=auto\'\n';
1199
+ if (shell == sh) setupcommands += 'stty erase ^H\n'
1200
1201
if (script && shell && process.platform == 'linux') {
1202
this.httprequest.process = childProcess.execFile(script, ['script', '--return', '--quiet', '-c', '"' + shell + '"', '/dev/null'], options); // Start as active user
1235
- this.httprequest.process.stdin.write(setupcommands);
1203
+ this.httprequest.process.stdin.write(setupcommands);
1204
} else if (python && shell) {
1205
this.httprequest.process = childProcess.execFile(python, ['python', '-c', 'import pty; pty.spawn(["' + shell + '"])'], options); // Start as active user
1206
if (process.platform == 'linux') { this.httprequest.process.stdin.write(setupcommands); }
@@ -1266,25 +1234,25 @@ function createMeshCore(agent) {
1234
if (this.httprequest.consent && (this.httprequest.consent & 16)) {
1235
// User Consent Prompt is required
1236
// Send a console message back using the console channel, "\n" is supported.
1269
- this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: 'Waiting for user to grant access...' }));
1270
- var pr = require('message-box').create('MeshCentral', this.httprequest.username + ' requesting Terminal Access. Grant access?', 30);
1237
+ this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: "Waiting for user to grant access..." }));
1238
+ var pr = require('message-box').create('MeshCentral', this.httprequest.username + " requesting Terminal Access. Grant access?", 30);
1239
pr.ws = this;
1240
this.pause();
1241
1242
pr.then(
1243
function () {
1244
// Success
1277
- MeshServerLog('Starting remote terminal after local user accepted (' + this.ws.httprequest.remoteaddr + ')', this.ws.httprequest);
1245
+ MeshServerLog("Starting remote terminal after local user accepted (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest);
1246
this.ws.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: null }));
1247
if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 2)) {
1248
// User Notifications is required
1281
- try { require('toaster').Toast('MeshCentral', this.ws.httprequest.username + ' started a remote terminal session.'); } catch (ex) { }
1249
+ try { require('toaster').Toast('MeshCentral', this.ws.httprequest.username + " started a remote terminal session."); } catch (ex) { }
1250
}
1251
this.ws.resume();
1252
},
1253
function (e) {
1254
// User Consent Denied/Failed
1287
- MeshServerLog('Failed to start remote terminal after local user rejected (' + this.ws.httprequest.remoteaddr + ')', this.ws.httprequest);
1255
+ MeshServerLog("Failed to start remote terminal after local user rejected (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest);
1256
this.ws.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString() }));
1257
this.ws.end();
1258
});
@@ -1309,7 +1277,7 @@ function createMeshCore(agent) {
1277
// Disengage this tunnel, user does not have the rights to do this!!
1278
this.httprequest.protocol = 999999;
1279
this.httprequest.s.end();
1312
- sendConsoleText('Error: No Desktop Control Rights.');
1280
+ sendConsoleText("Error: No Desktop Control Rights.");
1281
return;
1282
}
1283
@@ -1323,8 +1291,7 @@ function createMeshCore(agent) {
1291
this.httprequest.desktop.kvm.parent = this.httprequest.desktop;
1292
this.desktop = this.httprequest.desktop;
1293
1326
- this.end = function ()
1327
- {
1294
+ this.end = function () {
1295
--this.desktop.kvm.connectionCount;
1296
1297
// Unpipe the web socket
@@ -1340,35 +1307,28 @@ function createMeshCore(agent) {
1307
// Place wallpaper back if needed
1308
// TODO
1309
1343
- if (this.desktop.kvm.connectionCount == 0)
1344
- {
1310
+ if (this.desktop.kvm.connectionCount == 0) {
1311
// Display a toast message. This may not be supported on all platforms.
1312
// try { require('toaster').Toast('MeshCentral', 'Remote Desktop Control Ended.'); } catch (ex) { }
1313
1314
this.httprequest.desktop.kvm.end();
1349
- if(this.httprequest.desktop.kvm.connectionBar)
1350
- {
1315
+ if (this.httprequest.desktop.kvm.connectionBar) {
1316
this.httprequest.desktop.kvm.connectionBar.removeAllListeners('close');
1317
this.httprequest.desktop.kvm.connectionBar.close();
1318
this.httprequest.desktop.kvm.connectionBar = null;
1319
}
1320
}
1356
- else
1357
- {
1358
- for(var i in this.httprequest.desktop.kvm.users)
1359
- {
1360
- if (this.httprequest.desktop.kvm.users[i] == this.httprequest.username && this.httprequest.desktop.kvm.connectionBar)
1361
- {
1321
+ else {
1322
+ for (var i in this.httprequest.desktop.kvm.users) {
1323
+ if (this.httprequest.desktop.kvm.users[i] == this.httprequest.username && this.httprequest.desktop.kvm.connectionBar) {
1324
this.httprequest.desktop.kvm.users.splice(i, 1);
1325
this.httprequest.desktop.kvm.connectionBar.removeAllListeners('close');
1326
this.httprequest.desktop.kvm.connectionBar.close();
1327
this.httprequest.desktop.kvm.connectionBar = require('notifybar-desktop')(this.httprequest.privacybartext.replace('{0}', this.httprequest.desktop.kvm.users.sort().join(', ')), require('MeshAgent')._tsid);
1328
this.httprequest.desktop.kvm.connectionBar.httprequest = this.httprequest;
1367
- this.httprequest.desktop.kvm.connectionBar.on('close', function ()
1368
- {
1369
- MeshServerLog('Remote Desktop Connection forcefully closed by local user (' + this.httprequest.remoteaddr + ')', this.httprequest);
1370
- for (var i in this.httprequest.desktop.kvm._pipedStreams)
1371
- {
1329
+ this.httprequest.desktop.kvm.connectionBar.on('close', function () {
1330
+ MeshServerLog("Remote Desktop Connection forcefully closed by local user (" + this.httprequest.remoteaddr + ")", this.httprequest);
1331
+ for (var i in this.httprequest.desktop.kvm._pipedStreams) {
1332
this.httprequest.desktop.kvm._pipedStreams[i].end();
1333
}
1334
this.httprequest.desktop.kvm.end();
@@ -1378,13 +1338,11 @@ function createMeshCore(agent) {
1338
}
1339
}
1340
};
1381
- if (this.httprequest.desktop.kvm.hasOwnProperty("connectionCount"))
1382
- {
1341
+ if (this.httprequest.desktop.kvm.hasOwnProperty('connectionCount')) {
1342
this.httprequest.desktop.kvm.connectionCount++;
1343
this.httprequest.desktop.kvm.users.push(this.httprequest.username);
1344
}
1386
- else
1387
- {
1345
+ else {
1346
this.httprequest.desktop.kvm.connectionCount = 1;
1347
this.httprequest.desktop.kvm.users = [this.httprequest.username];
1348
}
@@ -1402,49 +1360,40 @@ function createMeshCore(agent) {
1360
if (this.httprequest.consent && (this.httprequest.consent & 8)) {
1361
// User Consent Prompt is required
1362
// Send a console message back using the console channel, "\n" is supported.
1405
- this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: 'Waiting for user to grant access...' }));
1406
- var pr = require('message-box').create('MeshCentral', this.httprequest.username + ' requesting KVM Access. Grant access?', 30);
1363
+ this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: "Waiting for user to grant access..." }));
1364
+ var pr = require('message-box').create('MeshCentral', this.httprequest.username + " requesting KVM Access. Grant access?", 30);
1365
pr.ws = this;
1366
this.pause();
1367
1368
pr.then(
1369
function () {
1370
// Success
1413
- MeshServerLog('Starting remote desktop after local user accepted (' + this.ws.httprequest.remoteaddr + ')', this.ws.httprequest);
1371
+ MeshServerLog("Starting remote desktop after local user accepted (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest);
1372
this.ws.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: null }));
1415
- if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 1))
1416
- {
1373
+ if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 1)) {
1374
// User Notifications is required
1418
- try { require('toaster').Toast('MeshCentral', this.ws.httprequest.username + ' started a remote desktop session.'); } catch (ex) { }
1375
+ try { require('toaster').Toast('MeshCentral', this.ws.httprequest.username + " started a remote desktop session."); } catch (ex) { }
1376
}
1420
- if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 0x40))
1421
- {
1377
+ if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 0x40)) {
1378
// Connection Bar is required
1423
- if (this.ws.httprequest.desktop.kvm.connectionBar)
1424
- {
1379
+ if (this.ws.httprequest.desktop.kvm.connectionBar) {
1380
this.ws.httprequest.desktop.kvm.connectionBar.removeAllListeners('close');
1381
this.ws.httprequest.desktop.kvm.connectionBar.close();
1382
}
1428
- try
1429
- {
1383
+ try {
1384
this.ws.httprequest.desktop.kvm.connectionBar = require('notifybar-desktop')(this.ws.httprequest.privacybartext.replace('{0}', this.ws.httprequest.desktop.kvm.users.sort().join(', ')), require('MeshAgent')._tsid);
1431
- MeshServerLog('Remote Desktop Connection Bar Activated/Updated (' + this.ws.httprequest.remoteaddr + ')', this.ws.httprequest);
1385
+ MeshServerLog("Remote Desktop Connection Bar Activated/Updated (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest);
1386
}
1433
- catch(xx)
1434
- {
1435
- if(process.platform != 'darwin')
1436
- {
1437
- MeshServerLog('Remote Desktop Connection Bar Failed or Not Supported (' + this.ws.httprequest.remoteaddr + ')', this.ws.httprequest);
1387
+ catch (xx) {
1388
+ if (process.platform != 'darwin') {
1389
+ MeshServerLog("Remote Desktop Connection Bar Failed or Not Supported (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest);
1390
}
1391
}
1440
- if (this.ws.httprequest.desktop.kvm.connectionBar)
1441
- {
1392
+ if (this.ws.httprequest.desktop.kvm.connectionBar) {
1393
this.ws.httprequest.desktop.kvm.connectionBar.httprequest = this.ws.httprequest;
1443
- this.ws.httprequest.desktop.kvm.connectionBar.on('close', function ()
1444
- {
1445
- MeshServerLog('Remote Desktop Connection forcefully closed by local user (' + this.httprequest.remoteaddr + ')', this.httprequest);
1446
- for (var i in this.httprequest.desktop.kvm._pipedStreams)
1447
- {
1394
+ this.ws.httprequest.desktop.kvm.connectionBar.on('close', function () {
1395
+ MeshServerLog("Remote Desktop Connection forcefully closed by local user (" + this.httprequest.remoteaddr + ")", this.httprequest);
1396
+ for (var i in this.httprequest.desktop.kvm._pipedStreams) {
1397
this.httprequest.desktop.kvm._pipedStreams[i].end();
1398
}
1399
this.httprequest.desktop.kvm.end();
@@ -1456,46 +1405,37 @@ function createMeshCore(agent) {
1405
},
1406
function (e) {
1407
// User Consent Denied/Failed
1459
- MeshServerLog('Failed to start remote desktop after local user rejected (' + this.ws.httprequest.remoteaddr + ')', this.ws.httprequest);
1408
+ MeshServerLog("Failed to start remote desktop after local user rejected (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest);
1409
this.ws.end(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString() }));
1410
});
1411
}
1412
else {
1413
// User Consent Prompt is not required
1465
- if (this.httprequest.consent && (this.httprequest.consent & 1))
1466
- {
1414
+ if (this.httprequest.consent && (this.httprequest.consent & 1)) {
1415
// User Notifications is required
1468
- MeshServerLog('Started remote desktop with toast notification (' + this.httprequest.remoteaddr + ')', this.httprequest);
1469
- try { require('toaster').Toast('MeshCentral', this.httprequest.username + ' started a remote desktop session.'); } catch (ex) { }
1470
- } else
1471
- {
1472
- MeshServerLog('Started remote desktop without notification (' + this.httprequest.remoteaddr + ')', this.httprequest);
1416
+ MeshServerLog("Started remote desktop with toast notification (" + this.httprequest.remoteaddr + ")", this.httprequest);
1417
+ try { require('toaster').Toast('MeshCentral', this.httprequest.username + " started a remote desktop session."); } catch (ex) { }
1418
+ } else {
1419
+ MeshServerLog("Started remote desktop without notification (" + this.httprequest.remoteaddr + ")", this.httprequest);
1420
}
1474
- if (this.httprequest.consent && (this.httprequest.consent & 0x40))
1475
- {
1421
+ if (this.httprequest.consent && (this.httprequest.consent & 0x40)) {
1422
// Connection Bar is required
1477
- if(this.httprequest.desktop.kvm.connectionBar)
1478
- {
1423
+ if (this.httprequest.desktop.kvm.connectionBar) {
1424
this.httprequest.desktop.kvm.connectionBar.removeAllListeners('close');
1425
this.httprequest.desktop.kvm.connectionBar.close();
1426
}
1482
- try
1483
- {
1427
+ try {
1428
this.httprequest.desktop.kvm.connectionBar = require('notifybar-desktop')(this.httprequest.privacybartext.replace('{0}', this.httprequest.desktop.kvm.users.sort().join(', ')), require('MeshAgent')._tsid);
1485
- MeshServerLog('Remote Desktop Connection Bar Activated/Updated (' + this.httprequest.remoteaddr + ')', this.httprequest);
1429
+ MeshServerLog("Remote Desktop Connection Bar Activated/Updated (" + this.httprequest.remoteaddr + ")", this.httprequest);
1430
}
1487
- catch(xx)
1488
- {
1489
- MeshServerLog('Remote Desktop Connection Bar Failed or not Supported (' + this.httprequest.remoteaddr + ')', this.httprequest);
1431
+ catch (xx) {
1432
+ MeshServerLog("Remote Desktop Connection Bar Failed or not Supported (" + this.httprequest.remoteaddr + ")", this.httprequest);
1433
}
1491
- if (this.httprequest.desktop.kvm.connectionBar)
1492
- {
1434
+ if (this.httprequest.desktop.kvm.connectionBar) {
1435
this.httprequest.desktop.kvm.connectionBar.httprequest = this.httprequest;
1494
- this.httprequest.desktop.kvm.connectionBar.on('close', function ()
1495
- {
1496
- MeshServerLog('Remote Desktop Connection forcefully closed by local user (' + this.httprequest.remoteaddr + ')', this.httprequest);
1497
- for (var i in this.httprequest.desktop.kvm._pipedStreams)
1498
- {
1436
+ this.httprequest.desktop.kvm.connectionBar.on('close', function () {
1437
+ MeshServerLog("Remote Desktop Connection forcefully closed by local user (" + this.httprequest.remoteaddr + ")", this.httprequest);
1438
+ for (var i in this.httprequest.desktop.kvm._pipedStreams) {
1439
this.httprequest.desktop.kvm._pipedStreams[i].end();
1440
}
1441
this.httprequest.desktop.kvm.end();
@@ -1516,7 +1456,7 @@ function createMeshCore(agent) {
1456
// Disengage this tunnel, user does not have the rights to do this!!
1457
this.httprequest.protocol = 999999;
1458
this.httprequest.s.end();
1519
- sendConsoleText('Error: No files control rights.');
1459
+ sendConsoleText("Error: No files control rights.");
1460
return;
1461
}
1462
@@ -1524,35 +1464,35 @@ function createMeshCore(agent) {
1464
if (this.httprequest.consent && (this.httprequest.consent & 32)) {
1465
// User Consent Prompt is required
1466
// Send a console message back using the console channel, "\n" is supported.
1527
- this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: 'Waiting for user to grant access...' }));
1528
- var pr = require('message-box').create('MeshCentral', this.httprequest.username + ' requesting remote file access. Grant access?', 30);
1467
+ this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: "Waiting for user to grant access..." }));
1468
+ var pr = require('message-box').create('MeshCentral', this.httprequest.username + " requesting remote file access. Grant access?", 30);
1469
pr.ws = this;
1470
this.pause();
1471
1472
pr.then(
1473
function () {
1474
// Success
1535
- MeshServerLog('Starting remote files after local user accepted (' + this.ws.httprequest.remoteaddr + ')', this.ws.httprequest);
1475
+ MeshServerLog("Starting remote files after local user accepted (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest);
1476
this.ws.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: null }));
1477
if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 4)) {
1478
// User Notifications is required
1539
- try { require('toaster').Toast('MeshCentral', this.ws.httprequest.username + ' started a remote file session.'); } catch (ex) { }
1479
+ try { require('toaster').Toast('MeshCentral', this.ws.httprequest.username + " started a remote file session."); } catch (ex) { }
1480
}
1481
this.ws.resume();
1482
},
1483
function (e) {
1484
// User Consent Denied/Failed
1545
- MeshServerLog('Failed to start remote files after local user rejected (' + this.ws.httprequest.remoteaddr + ')', this.ws.httprequest);
1485
+ MeshServerLog("Failed to start remote files after local user rejected (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest);
1486
this.ws.end(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString() }));
1487
});
1488
} else {
1489
// User Consent Prompt is not required
1490
if (this.httprequest.consent && (this.httprequest.consent & 4)) {
1491
// User Notifications is required
1552
- MeshServerLog('Started remote files with toast notification (' + this.httprequest.remoteaddr + ')', this.httprequest);
1553
- try { require('toaster').Toast('MeshCentral', this.httprequest.username + ' started a remote file session.'); } catch (ex) { }
1492
+ MeshServerLog("Started remote files with toast notification (" + this.httprequest.remoteaddr + ")", this.httprequest);
1493
+ try { require('toaster').Toast('MeshCentral', this.httprequest.username + " started a remote file session."); } catch (ex) { }
1494
} else {
1555
- MeshServerLog('Started remote files without notification (' + this.httprequest.remoteaddr + ')', this.httprequest);
1495
+ MeshServerLog("Started remote files without notification (" + this.httprequest.remoteaddr + ")", this.httprequest);
1496
}
1497
this.resume();
1498
}
@@ -1614,7 +1554,7 @@ function createMeshCore(agent) {
1554
case 'mkdir': {
1555
// Create a new empty folder
1556
fs.mkdirSync(cmd.path);
1617
- MeshServerLog('Create folder: \"' + cmd.path + '\"', this.httprequest);
1557
+ MeshServerLog("Create folder: \"" + cmd.path + "\"", this.httprequest);
1558
break;
1559
}
1560
case 'rm': {
@@ -1623,9 +1563,9 @@ function createMeshCore(agent) {
1563
var p = obj.path.join(cmd.path, cmd.delfiles[i]), delcount = 0;
1564
try { delcount = deleteFolderRecursive(p, cmd.rec); } catch (e) { }
1565
if ((delcount == 1) && !cmd.rec) {
1626
- MeshServerLog('Delete: \"' + p + '\"', this.httprequest);
1566
+ MeshServerLog("Delete: \"" + p + "\"", this.httprequest);
1567
} else {
1628
- MeshServerLog((cmd.rec ? 'Delete recursive: \"' : 'Delete: \"') + p + '\", ' + delcount + ' element(s) removed', this.httprequest);
1568
+ MeshServerLog((cmd.rec ? "Delete recursive: \"" : "Delete: \"") + p + "\", " + delcount + " element(s) removed", this.httprequest);
1569
}
1570
}
1571
break;
@@ -1786,7 +1726,7 @@ function createMeshCore(agent) {
1726
// Lock the current user out of the desktop
1727
try {
1728
if (process.platform == 'win32') {
1789
- MeshServerLog('Locking remote user out of desktop', ws.httprequest);
1729
+ MeshServerLog("Locking remote user out of desktop", ws.httprequest);
1730
var child = require('child_process');
1731
child.execFile(process.env['windir'] + '\\system32\\cmd.exe', ['/c', 'RunDll32.exe user32.dll,LockWorkStation'], { type: 1 });
1732
}
@@ -1847,7 +1787,7 @@ function createMeshCore(agent) {
1787
try { ws.webrtc.rtcchannel.pipe(ws.httprequest.desktop.kvm, { dataTypeSkip: 1, end: false }); } catch (e) { sendConsoleText('EX2'); } // 0 = Binary, 1 = Text.
1788
ws.resume(); // Resume the websocket to keep receiving control data
1789
}
1850
- ws.write("{\"ctrlChannel\":\"102938\",\"type\":\"webrtc2\"}"); // Indicates we will no longer get any data on websocket, switching to WebRTC at this point.
1790
+ ws.write('{\"ctrlChannel\":\"102938\",\"type\":\"webrtc2\"}'); // Indicates we will no longer get any data on websocket, switching to WebRTC at this point.
1791
} else if (obj.type == 'webrtc2') {
1792
// Other side received websocket end of data marker, start sending data on WebRTC channel
1793
if ((ws.httprequest.protocol == 1) || (ws.httprequest.protocol == 6)) { // Terminal
@@ -1883,7 +1823,7 @@ function createMeshCore(agent) {
1823
this.websocket.httprequest.desktop.kvm.unpipe(this);
1824
}
1825
});
1886
- this.websocket.write("{\"ctrlChannel\":\"102938\",\"type\":\"webrtc0\"}"); // Indicate we are ready for WebRTC switch-over.
1826
+ this.websocket.write('{\"ctrlChannel\":\"102938\",\"type\":\"webrtc0\"}'); // Indicate we are ready for WebRTC switch-over.
1827
});
1828
var sdp = null;
1829
try { sdp = ws.webrtc.setOffer(obj.sdp); } catch (ex) { }
@@ -1945,174 +1885,102 @@ function createMeshCore(agent) {
1885
f += (((f != '') ? ', ' : ' ') + availcommands.shift());
1886
}
1887
if (f != '') { fin += f; }
1948
- response = 'Available commands: \r\n' + fin + '.';
1888
+ response = "Available commands: \r\n" + fin + ".";
1889
break;
1890
}
1891
case 'agentsize':
1892
var actualSize = Math.floor(require('fs').statSync(process.execPath).size / 1024);
1953
- if (process.platform == 'win32')
1954
- {
1893
+ if (process.platform == 'win32') {
1894
// Check the Agent Uninstall MetaData for correctness, as the installer may have written an incorrect value
1956
- var writtenSize = 0;
1957
- try
1958
- {
1959
- writtenSize = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize');
1960
- }
1961
- catch (x)
1962
- {
1963
- response = x;
1964
- }
1965
- if (writtenSize != actualSize)
1966
- {
1967
- response = 'Size updated from: ' + writtenSize + ' to: ' + actualSize;
1968
- try
1969
- {
1970
- require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize', actualSize);
1971
- }
1972
- catch (x2)
1973
- {
1974
- response = x2;
1975
- }
1976
- }
1977
- else
1978
- {
1979
- response = 'Agent Size: ' + actualSize + ' kb';
1980
- }
1981
- }
1982
- else
1983
- {
1984
- response = 'Agent Size: ' + actualSize + ' kb';
1985
- }
1895
+ var writtenSize = 0;
1896
+ try { writtenSize = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize'); } catch (x) { response = x; }
1897
+ if (writtenSize != actualSize) {
1898
+ response = "Size updated from: " + writtenSize + " to: " + actualSize;
1899
+ try { require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent', 'EstimatedSize', actualSize); } catch (x2) { response = x2; }
1900
+ } else { response = "Agent Size: " + actualSize + " kb"; }
1901
+ } else { response = "Agent Size: " + actualSize + " kb"; }
1902
break;
1903
case 'version':
1988
- response = 'Mesh Agent Version: ' + process.versions.meshAgent;
1904
+ response = "Mesh Agent Version: " + process.versions.meshAgent;
1905
break;
1906
case 'wpfhwacceleration':
1991
- if (process.platform != 'win32') { throw ('wpfhwacceleration setting is only supported on Windows'); }
1992
- if (args['_'].length != 1)
1993
- {
1994
- response = 'Proper usage: wpfhwacceleration (ON|OFF|STATUS)'; // Display usage
1907
+ if (process.platform != 'win32') { throw ("wpfhwacceleration setting is only supported on Windows"); }
1908
+ if (args['_'].length != 1) {
1909
+ response = "Proper usage: wpfhwacceleration (ON|OFF|STATUS)"; // Display usage
1910
}
1996
- else
1997
- {
1911
+ else {
1912
var reg = require('win-registry');
1913
var uname = require('user-sessions').getUsername(require('user-sessions').consoleUid());
1914
var key = reg.usernameToUserKey(uname);
1915
2002
- switch(args['_'][0].toUpperCase())
2003
- {
1916
+ switch (args['_'][0].toUpperCase()) {
1917
default:
2005
- response = 'Proper usage: wpfhwacceleration (ON|OFF|STATUS|DEFAULT)'; // Display usage
1918
+ response = "Proper usage: wpfhwacceleration (ON|OFF|STATUS|DEFAULT)"; // Display usage
1919
break;
1920
case 'ON':
2008
- try
2009
- {
1921
+ try {
1922
reg.WriteKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration', 0);
2011
- response = 'OK';
2012
- }
2013
- catch (ee)
2014
- {
2015
- response = 'FAILED';
2016
- }
1923
+ response = "OK";
1924
+ } catch (ex) { response = "FAILED"; }
1925
break;
1926
case 'OFF':
2019
- try
2020
- {
1927
+ try {
1928
reg.WriteKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration', 1);
1929
response = 'OK';
2023
- }
2024
- catch (ee)
2025
- {
2026
- response = 'FAILED';
2027
- }
2028
- break;
1930
+ } catch (ex) { response = 'FAILED'; }
1931
break;
1932
case 'STATUS':
1933
var s;
2032
- try
2033
- {
2034
- s = reg.QueryKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration')==1?'DISABLED':'ENABLED';
2035
- }
2036
- catch (ee)
2037
- {
2038
- s = 'DEFAULT';
2039
- }
2040
- response = 'WPF Hardware Acceleration: ' + s;
1934
+ try { s = reg.QueryKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration') == 1 ? 'DISABLED' : 'ENABLED'; } catch (ex) { s = 'DEFAULT'; }
1935
+ response = "WPF Hardware Acceleration: " + s;
1936
break;
1937
case 'DEFAULT':
2043
- try
2044
- {
2045
- reg.DeleteKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration');
2046
- }
2047
- catch (ee)
2048
- {
2049
- }
1938
+ try { reg.DeleteKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration'); } catch (ex) { }
1939
response = 'OK';
1940
break;
1941
}
1942
}
1943
break;
1944
case 'tsid':
2056
- if (process.platform == 'win32')
2057
- {
2058
- if (args['_'].length != 1)
2059
- {
2060
- response = 'TSID: ' + (require('MeshAgent')._tsid == null ? 'console' : require('MeshAgent')._tsid);
2061
- }
2062
- else
2063
- {
1945
+ if (process.platform == 'win32') {
1946
+ if (args['_'].length != 1) {
1947
+ response = "TSID: " + (require('MeshAgent')._tsid == null ? "console" : require('MeshAgent')._tsid);
1948
+ } else {
1949
var i = parseInt(args['_'][0]);
1950
require('MeshAgent')._tsid = (isNaN(i) ? null : i);
2066
- response = 'TSID set to: ' + (require('MeshAgent')._tsid == null ? 'console' : require('MeshAgent')._tsid);
1951
+ response = "TSID set to: " + (require('MeshAgent')._tsid == null ? "console" : require('MeshAgent')._tsid);
1952
}
2068
- }
2069
- else
2070
- {
2071
- response = 'TSID command only supported on Windows';
2072
- }
1953
+ } else { response = "TSID command only supported on Windows"; }
1954
break;
1955
case 'activeusers':
2075
- if (process.platform == 'win32')
2076
- {
1956
+ if (process.platform == 'win32') {
1957
var p = require('user-sessions').enumerateUsers();
1958
p.sessionid = sessionid;
2079
- p.then(function (u)
2080
- {
1959
+ p.then(function (u) {
1960
var v = [];
2082
- for(var i in u)
2083
- {
2084
- if(u[i].State == 'Active') { v.push({ tsid: i, type: u[i].StationName, user: u[i].Username, domain: u[i].Domain }); }
1961
+ for (var i in u) {
1962
+ if (u[i].State == 'Active') { v.push({ tsid: i, type: u[i].StationName, user: u[i].Username, domain: u[i].Domain }); }
1963
}
1964
sendConsoleText(JSON.stringify(v, null, 1), this.sessionid);
1965
});
2088
- }
2089
- else
2090
- {
2091
- response = 'activeusers command only supported on Windows';
2092
- }
1966
+ } else { response = "activeusers command only supported on Windows"; }
1967
break;
1968
case 'wallpaper':
2095
- if (process.platform != 'win32' && !(process.platform == 'linux' && require('linux-gnome-helpers').available))
2096
- {
2097
- response = 'wallpaper command not supported on this platform'
1969
+ if (process.platform != 'win32' && !(process.platform == 'linux' && require('linux-gnome-helpers').available)) {
1970
+ response = "wallpaper command not supported on this platform";
1971
}
2099
- else
2100
- {
2101
- if (args['_'].length != 1)
2102
- {
1972
+ else {
1973
+ if (args['_'].length != 1) {
1974
response = 'Proper usage: wallpaper (GET|TOGGLE)'; // Display usage
1975
}
2105
- else
2106
- {
2107
- switch (args['_'][0].toUpperCase())
2108
- {
1976
+ else {
1977
+ switch (args['_'][0].toUpperCase()) {
1978
default:
1979
response = 'Proper usage: wallpaper (GET|TOGGLE)'; // Display usage
1980
break;
1981
case 'GET':
1982
case 'TOGGLE':
2114
- if (process.platform == 'win32')
2115
- {
1983
+ if (process.platform == 'win32') {
1984
var id = require('user-sessions').getProcessOwnerName(process.pid).tsid == 0 ? 1 : 0;
1985
var child = require('child_process').execFile(process.execPath, [process.execPath.split('\\').pop(), '-b64exec', 'dmFyIFNQSV9HRVRERVNLV0FMTFBBUEVSID0gMHgwMDczOwp2YXIgU1BJX1NFVERFU0tXQUxMUEFQRVIgPSAweDAwMTQ7CnZhciBHTSA9IHJlcXVpcmUoJ19HZW5lcmljTWFyc2hhbCcpOwp2YXIgdXNlcjMyID0gR00uQ3JlYXRlTmF0aXZlUHJveHkoJ3VzZXIzMi5kbGwnKTsKdXNlcjMyLkNyZWF0ZU1ldGhvZCgnU3lzdGVtUGFyYW1ldGVyc0luZm9BJyk7CgppZiAocHJvY2Vzcy5hcmd2Lmxlbmd0aCA9PSAzKQp7CiAgICB2YXIgdiA9IEdNLkNyZWF0ZVZhcmlhYmxlKDEwMjQpOwogICAgdXNlcjMyLlN5c3RlbVBhcmFtZXRlcnNJbmZvQShTUElfR0VUREVTS1dBTExQQVBFUiwgdi5fc2l6ZSwgdiwgMCk7CiAgICBjb25zb2xlLmxvZyh2LlN0cmluZyk7CiAgICBwcm9jZXNzLmV4aXQoKTsKfQplbHNlCnsKICAgIHZhciBuYiA9IEdNLkNyZWF0ZVZhcmlhYmxlKHByb2Nlc3MuYXJndlszXSk7CiAgICB1c2VyMzIuU3lzdGVtUGFyYW1ldGVyc0luZm9BKFNQSV9TRVRERVNLV0FMTFBBUEVSLCBuYi5fc2l6ZSwgbmIsIDApOwogICAgcHJvY2Vzcy5leGl0KCk7Cn0='], { type: id });
1986
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
@@ -2134,8 +2002,7 @@ function createMeshCore(agent) {
2002
child.stderr.on('data', function () { });
2003
child.waitExit();
2004
}
2137
- else
2138
- {
2005
+ else {
2006
var id = require('user-sessions').consoleUid();
2007
var current = require('linux-gnome-helpers').getDesktopWallpaper(id);
2008
if (args['_'][0].toUpperCase() == 'GET') {
@@ -2156,20 +2023,15 @@ function createMeshCore(agent) {
2023
}
2024
break;
2025
case 'safemode':
2159
- if (process.platform != 'win32')
2160
- {
2026
+ if (process.platform != 'win32') {
2027
response = 'safemode only supported on Windows Platforms'
2028
}
2163
- else
2164
- {
2165
- if (args['_'].length != 1)
2166
- {
2029
+ else {
2030
+ if (args['_'].length != 1) {
2031
response = 'Proper usage: safemode (ON|OFF|STATUS)'; // Display usage
2168
- }
2169
- else
2170
- {
2171
- switch(args['_'][0].toUpperCase())
2172
- {
2032
+ }
2033
+ else {
2034
+ switch (args['_'][0].toUpperCase()) {
2035
default:
2036
response = 'Proper usage: safemode (ON|OFF|STATUS)'; // Display usage
2037
break;
@@ -2182,10 +2044,8 @@ function createMeshCore(agent) {
2044
break;
2045
case 'STATUS':
2046
var nextboot = require('win-bcd').getKey('safeboot');
2185
- if (nextboot)
2186
- {
2187
- switch(nextboot)
2188
- {
2047
+ if (nextboot) {
2048
+ switch (nextboot) {
2049
case 'Network':
2050
case 'network':
2051
nextboot = 'SAFE_MODE_NETWORK';
@@ -2297,14 +2157,11 @@ function createMeshCore(agent) {
2157
break;
2158
}
2159
case 'toast': {
2300
- if (args['_'].length < 1) { response = 'Proper usage: toast "message"'; } else
2301
- {
2302
- if (require('MeshAgent')._tsid == null)
2303
- {
2160
+ if (args['_'].length < 1) { response = 'Proper usage: toast "message"'; } else {
2161
+ if (require('MeshAgent')._tsid == null) {
2162
require('toaster').Toast('MeshCentral', args['_'][0]).then(sendConsoleText, sendConsoleText);
2163
}
2306
- else
2307
- {
2164
+ else {
2165
require('toaster').Toast('MeshCentral', args['_'][0], require('MeshAgent')._tsid).then(sendConsoleText, sendConsoleText);
2166
}
2167
}
@@ -2401,10 +2258,10 @@ function createMeshCore(agent) {
2258
if (args['_'].length != 1) {
2259
response = 'Proper usage: notify "message" [--session]'; // Display correct command usage
2260
} else {
2404
- var notification = { "action": "msg", "type": "notify", "value": args['_'][0], "tag": "console" };
2261
+ var notification = { action: 'msg', type: 'notify', value: args['_'][0], tag: 'console' };
2262
if (args.session) { notification.sessionid = sessionid; } // If "--session" is specified, notify only this session, if not, the server will notify the mesh
2263
mesh.SendCommand(notification); // no sessionid or userid specified, notification will go to the entire mesh
2407
- response = 'ok';
2264
+ response = "ok";
2265
}
2266
break;
2267
}
@@ -2442,13 +2299,11 @@ function createMeshCore(agent) {
2299
case 'osinfo': { // Return the operating system information
2300
var i = 1;
2301
if (args['_'].length > 0) { i = parseInt(args['_'][0]); if (i > 8) { i = 8; } response = 'Calling ' + i + ' times.'; }
2445
- for (var j = 0; j < i; j++)
2446
- {
2302
+ for (var j = 0; j < i; j++) {
2303
var pr = require('os').name();
2304
pr.sessionid = sessionid;
2449
- pr.then(function (v)
2450
- {
2451
- sendConsoleText("OS: " + v + (process.platform=='win32'?(require('win-virtual-terminal').supported?' [ConPTY: YES]':' [ConPTY: NO]'):''), this.sessionid);
2305
+ pr.then(function (v) {
2306
+ sendConsoleText("OS: " + v + (process.platform == 'win32' ? (require('win-virtual-terminal').supported ? ' [ConPTY: YES]' : ' [ConPTY: NO]') : ''), this.sessionid);
2307
});
2308
}
2309
break;
@@ -2702,7 +2557,7 @@ function createMeshCore(agent) {
2557
}
2558
case 'location': {
2559
getIpLocationData(function (location) {
2705
- sendConsoleText(objToString({ "action": "iplocation", "type": "publicip", "value": location }, 0, ' '));
2560
+ sendConsoleText(objToString({ action: 'iplocation', type: 'publicip', value: location }, 0, ' '));
2561
});
2562
break;
2563
}
@@ -2754,9 +2609,9 @@ function createMeshCore(agent) {
2609
}
2610
case 'getscript': {
2611
if (args['_'].length != 1) {
2757
- response = 'Proper usage: getscript [scriptNumber].';
2612
+ response = "Proper usage: getscript [scriptNumber].";
2613
} else {
2759
- mesh.SendCommand({ "action": "getScript", "type": args['_'][0] });
2614
+ mesh.SendCommand({ action: 'getScript', type: args['_'][0] });
2615
}
2616
break;
2617
}
@@ -2797,7 +2652,7 @@ function createMeshCore(agent) {
2652
if (meshCoreObj.intelamt !== null) {
2653
if (args['_'].length == 1) {
2654
if (args['_'][0] == 'on') {
2800
- response = 'Starting APF tunnel'
2655
+ response = "Starting APF tunnel";
2656
var apfarg = {
2657
mpsurl: mesh.ServerUrl.replace('agent.ashx', 'apf.ashx'),
2658
mpsuser: Buffer.from(mesh.ServerInfo.MeshID, 'hex').toString('base64').substring(0, 16),
@@ -2816,7 +2671,7 @@ function createMeshCore(agent) {
2671
response += JSON.stringify(e);
2672
}
2673
} else if (args['_'][0] == 'off') {
2819
- response = 'Stopping APF tunnel';
2674
+ response = "Stopping APF tunnel";
2675
try {
2676
apftunnel.disconnect();
2677
response += "..success";
@@ -2825,14 +2680,13 @@ function createMeshCore(agent) {
2680
}
2681
apftunnel = null;
2682
} else {
2828
- response = 'Invalid command.\r\nCmd syntax: apf on|off';
2683
+ response = "Invalid command.\r\nCmd syntax: apf on|off";
2684
}
2685
} else {
2831
- response = 'APF tunnel is ' + (apftunnel == null ? 'off' : 'on');
2686
+ response = "APF tunnel is " + (apftunnel == null ? "off" : "on");
2687
}
2833
-
2688
} else {
2835
- response = 'APF tunnel requires Intel AMT';
2689
+ response = "APF tunnel requires Intel AMT";
2690
}
2691
break;
2692
}
@@ -2844,26 +2698,26 @@ function createMeshCore(agent) {
2698
// to control the output / actions here.
2699
response = require(args['_'][0]).consoleaction(args, rights, sessionid, mesh);
2700
} catch (e) {
2847
- response = 'There was an error in the plugin (' + e + ')';
2701
+ response = "There was an error in the plugin (" + e + ")";
2702
}
2703
} else {
2850
- response = 'Proper usage: plugin [pluginName] [args].';
2704
+ response = "Proper usage: plugin [pluginName] [args].";
2705
}
2706
break;
2707
}
2708
default: { // This is an unknown command, return an error message
2855
- response = 'Unknown command \"' + cmd + '\", type \"help\" for list of avaialble commands.';
2709
+ response = "Unknown command \"" + cmd + "\", type \"help\" for list of avaialble commands.";
2710
break;
2711
}
2712
}
2859
- } catch (e) { response = 'Command returned an exception error: ' + e; console.log(e); }
2713
+ } catch (e) { response = "Command returned an exception error: " + e; console.log(e); }
2714
if (response != null) { sendConsoleText(response, sessionid); }
2715
}
2716
2717
// Send a mesh agent console command
2718
function sendConsoleText(text, sessionid) {
2719
if (typeof text == 'object') { text = JSON.stringify(text); }
2866
- mesh.SendCommand({ "action": "msg", "type": "console", "value": text, "sessionid": sessionid });
2720
+ mesh.SendCommand({ action: 'msg', type: 'console', value: text, sessionid: sessionid });
2721
}
2722
2723
// Called before the process exits
@@ -2885,7 +2739,7 @@ function createMeshCore(agent) {
2739
mesh.SendCommand(meshCoreObj);
2740
2741
// Send SMBios tables if present
2888
- if (SMBiosTablesRaw != null) { mesh.SendCommand({ "action": "smbios", "value": SMBiosTablesRaw }); }
2742
+ if (SMBiosTablesRaw != null) { mesh.SendCommand({ action: 'smbios', value: SMBiosTablesRaw }); }
2743
2744
// Update the server on more advanced stuff, like Intel ME and Network Settings
2745
meInfoStr = null;
@@ -3035,5 +2889,5 @@ try {
2889
mainMeshCore.start(null);
2890
}
2891
} catch (ex) {
3038
- require('MeshAgent').SendCommand({ "action": "msg", "type": "console", "value": "uncaughtException2: " + ex });
2892
+ require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: "uncaughtException2: " + ex });
2893
}
translate/translate-010720-Russian.json
Binary files /dev/null and b/translate/translate-010720-Russian.json differ