Removed meshcore.js debug statement.
Ylian Saint-Hilaire committed
Aug 4, 2022 at 01:52 UTC
8b81ee564cbea8bed76148db81c091f35049a1c5
1 file changed
+75
-154
agents/meshcore.js
+75
-154
@@ -47,43 +47,34 @@ var MESHRIGHT_UNINSTALL = 32768;
47
var MESHRIGHT_NODESKTOP = 65536;
48
49
50
-function bcdOK()
51
-{
50
+function bcdOK() {
51
if (process.platform != 'win32') { return (false); }
53
- if(require('os').arch() == 'x64')
54
- {
52
+ if (require('os').arch() == 'x64') {
53
return (require('_GenericMarshal').PointerSize == 8);
54
}
55
return (true);
56
}
59
-function getDomainInfo()
60
-{
57
+function getDomainInfo() {
58
var hostname = require('os').hostname();
59
var ret = { Name: hostname, Domain: "" };
60
64
- switch (process.platform)
65
- {
61
+ switch (process.platform) {
62
case 'win32':
67
- try
68
- {
69
- ret = require('win-wmi').query('ROOT\\CIMV2', 'SELECT * FROM Win32_ComputerSystem', ['Name', 'Domain'])[0];
63
+ try {
64
+ ret = require('win-wmi').query('ROOT\\CIMV2', 'SELECT * FROM Win32_ComputerSystem', ['Name', 'Domain'])[0];
65
}
71
- catch (x)
72
- {
66
+ catch (x) {
67
}
68
break;
69
case 'linux':
70
var hasrealm = false;
71
78
- try
79
- {
72
+ try {
73
hasrealm = require('lib-finder').hasBinary('realm');
74
}
82
- catch(x)
83
- {
75
+ catch (x) {
76
}
85
- if (hasrealm)
86
- {
77
+ if (hasrealm) {
78
var child = require('child_process').execFile('/bin/sh', ['sh']);
79
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
80
child.stdin.write("realm list | grep domain-name: | tr '\\n' '`' | ");
@@ -101,17 +92,13 @@ function getDomainInfo()
92
child.stdin.write('\nexit\n');
93
child.waitExit();
94
var names = [];
104
- try
105
- {
95
+ try {
96
names = JSON.parse(child.stdout.str);
97
}
108
- catch(e)
109
- {
98
+ catch (e) {
99
}
111
- while(names.length>0)
112
- {
113
- if(hostname.endsWith('.' + names.peek()))
114
- {
100
+ while (names.length > 0) {
101
+ if (hostname.endsWith('.' + names.peek())) {
102
ret = { Name: hostname.substring(0, hostname.length - names.peek().length - 1), Domain: names.peek() };
103
break;
104
}
@@ -188,22 +175,17 @@ function getCoreTranslation() {
175
}
176
var currentTranslation = getCoreTranslation();
177
191
-try
192
-{
178
+try {
179
require('kvm-helper');
180
}
195
-catch (e)
196
-{
181
+catch (e) {
182
var j =
183
{
199
- users: function ()
200
- {
184
+ users: function () {
185
var r = {};
186
require('user-sessions').Current(function (c) { r = c; });
203
- if (process.platform != 'win32')
204
- {
205
- for (var i in r)
206
- {
187
+ if (process.platform != 'win32') {
188
+ for (var i in r) {
189
r[i].SessionId = r[i].uid;
190
}
191
}
@@ -1180,42 +1162,34 @@ function handleServerCommand(data) {
1162
}
1163
case 'messagebox': {
1164
// Display a message box
1183
- if (data.title && data.msg)
1184
- {
1165
+ if (data.title && data.msg) {
1166
MeshServerLogEx(18, [data.title, data.msg], "Displaying message box, title=" + data.title + ", message=" + data.msg, data);
1186
- if (process.platform == 'win32')
1187
- {
1188
- if(global._clientmessage)
1189
- {
1167
+ if (process.platform == 'win32') {
1168
+ if (global._clientmessage) {
1169
global._clientmessage.addMessage(data.msg);
1170
}
1192
- else
1193
- {
1194
- try
1195
- {
1171
+ else {
1172
+ try {
1173
require('win-dialog');
1174
var ipr = server_getUserImage(data.userid);
1175
ipr.title = data.title;
1176
ipr.message = data.msg;
1177
ipr.username = data.username;
1178
if (data.realname && (data.realname != '')) { ipr.username = data.realname; }
1202
- global._clientmessage = ipr.then(function (img)
1203
- {
1204
- this.messagebox = require('win-dialog').create(this.title, this.message, this.username, { timeout: 120000, b64Image: img.split(',').pop(), background: color_options.background, foreground: color_options.foreground });
1179
+ global._clientmessage = ipr.then(function (img) {
1180
+ this.messagebox = require('win-dialog').create(this.title, this.message, this.username, { timeout: 120000, b64Image: img.split(',').pop(), background: color_options.background, foreground: color_options.foreground });
1181
this.__childPromise.addMessage = this.messagebox.addMessage.bind(this.messagebox);
1182
return (this.messagebox);
1183
});
1184
1185
global._clientmessage.then(function () { global._clientmessage = null; });
1186
}
1211
- catch(z)
1212
- {
1187
+ catch (z) {
1188
try { require('message-box').create(data.title, data.msg, 120).then(function () { }).catch(function () { }); } catch (ex) { }
1189
}
1190
}
1191
}
1217
- else
1218
- {
1192
+ else {
1193
try { require('message-box').create(data.title, data.msg, 120).then(function () { }).catch(function () { }); } catch (ex) { }
1194
}
1195
}
@@ -1365,18 +1339,14 @@ function handleServerCommand(data) {
1339
}
1340
case 'setclip': {
1341
// Set the load clipboard to a user value
1368
- if (typeof data.data == 'string')
1369
- {
1342
+ if (typeof data.data == 'string') {
1343
MeshServerLogEx(22, [data.data.length], "Setting clipboard content, " + data.data.length + " byte(s)", data);
1371
- if (require('MeshAgent').isService)
1372
- {
1373
- if (process.platform != 'win32')
1374
- {
1344
+ if (require('MeshAgent').isService) {
1345
+ if (process.platform != 'win32') {
1346
require('clipboard').dispatchWrite(data.data);
1347
mesh.SendCommand({ action: 'msg', type: 'setclip', sessionid: data.sessionid, success: true });
1348
}
1378
- else
1379
- {
1349
+ else {
1350
var clipargs = data.data;
1351
var uid = require('user-sessions').consoleUid();
1352
var user = require('user-sessions').getUsername(uid);
@@ -1386,12 +1356,10 @@ function handleServerCommand(data) {
1356
this._dispatcher = require('win-dispatcher').dispatch({ user: user, modules: [{ name: 'clip-dispatch', script: "module.exports = { dispatch: function dispatch(val) { require('clipboard')(val); process.exit(); } };" }], launch: { module: 'clip-dispatch', method: 'dispatch', args: [clipargs] } });
1357
this._dispatcher.parent = this;
1358
//require('events').setFinalizerMetadata.call(this._dispatcher, 'clip-dispatch');
1389
- this._dispatcher.on('connection', function (c)
1390
- {
1359
+ this._dispatcher.on('connection', function (c) {
1360
this._c = c;
1361
this._c.root = this.parent;
1393
- this._c.on('end', function ()
1394
- {
1362
+ this._c.on('end', function () {
1363
this.root._dispatcher = null;
1364
this.root = null;
1365
mesh.SendCommand({ action: 'msg', type: 'setclip', sessionid: data.sessionid, success: true });
@@ -1399,8 +1367,7 @@ function handleServerCommand(data) {
1367
});
1368
}
1369
}
1402
- else
1403
- {
1370
+ else {
1371
require("clipboard")(data.data);
1372
mesh.SendCommand({ action: 'msg', type: 'setclip', sessionid: data.sessionid, success: true });
1373
} // Set the clipboard
@@ -1886,11 +1853,9 @@ function onTunnelUpgrade(response, s, head) {
1853
s.descriptorMetadata = "MeshAgent_relayTunnel";
1854
1855
//if (this.tcpport != null || this.udpport != null)
1889
- if (require('MeshAgent').idleTimeout != null)
1890
- {
1856
+ if (require('MeshAgent').idleTimeout != null) {
1857
s.setTimeout(require('MeshAgent').idleTimeout * 1000);
1892
- s.on('timeout', function ()
1893
- {
1858
+ s.on('timeout', function () {
1859
this.ping();
1860
this.setTimeout(require('MeshAgent').idleTimeout * 1000);
1861
});
@@ -1898,8 +1863,7 @@ function onTunnelUpgrade(response, s, head) {
1863
1864
//sendConsoleText('onTunnelUpgrade - ' + this.tcpport + ' - ' + this.udpport);
1865
1901
- if (this.tcpport != null)
1902
- {
1866
+ if (this.tcpport != null) {
1867
// This is a TCP relay connection, pause now and try to connect to the target.
1868
s.pause();
1869
s.data = onTcpRelayServerTunnelData;
@@ -1916,8 +1880,7 @@ function onTunnelUpgrade(response, s, head) {
1880
broadcastSessionsToRegisteredApps();
1881
}
1882
}
1919
- if (this.udpport != null)
1920
- {
1883
+ if (this.udpport != null) {
1884
// This is a UDP relay connection, get the UDP socket setup. // TODO: ***************
1885
s.data = onUdpRelayServerTunnelData;
1886
s.udprelay = require('dgram').createSocket({ type: 'udp4' });
@@ -1936,8 +1899,7 @@ function onTunnelUpgrade(response, s, head) {
1899
broadcastSessionsToRegisteredApps();
1900
}
1901
}
1939
- else
1940
- {
1902
+ else {
1903
// This is a normal connect for KVM/Terminal/Files
1904
s.data = onTunnelData;
1905
}
@@ -2080,11 +2042,9 @@ function onTunnelData(data) {
2042
return;
2043
}
2044
2083
- if (this.httprequest.state == 0)
2084
- {
2045
+ if (this.httprequest.state == 0) {
2046
// Check if this is a relay connection
2086
- if ((data == 'c') || (data == 'cr'))
2087
- {
2047
+ if ((data == 'c') || (data == 'cr')) {
2048
this.httprequest.state = 1; /*sendConsoleText("Tunnel #" + this.httprequest.index + " now active", this.httprequest.sessionid);*/
2049
/*
2050
this.setTimeout(global._tunnelTimeout == null ? 5000 : global._tunnelTimeout); // Once we receive 'c', we will only wait the tunnel timeout (5 seconds) before we close the tunnel
@@ -2095,8 +2055,7 @@ function onTunnelData(data) {
2055
*/
2056
}
2057
}
2098
- else
2099
- {
2058
+ else {
2059
/*
2060
// We received some data, so we will reset the idle timeout of the websocket
2061
this.removeAllListeners('timeout');
@@ -2217,7 +2176,7 @@ function onTunnelData(data) {
2176
ipr.consentTitle = consentTitle;
2177
ipr.consentMessage = consentMessage;
2178
ipr.consentTimeout = this.httprequest.consentTimeout;
2220
- ipr.consentAutoAccept = this.httprequest.consentAutoAccept;
2179
+ ipr.consentAutoAccept = this.httprequest.consentAutoAccept;
2180
ipr.username = this.httprequest.realname;
2181
ipr.translations = { Allow: currentTranslation['allow'], Deny: currentTranslation['deny'], Auto: currentTranslation['autoAllowForFive'], Caption: consentMessage };
2182
this.httprequest.tpromise._consent = ipr.then(function (img) {
@@ -2574,7 +2533,7 @@ function onTunnelData(data) {
2533
ipr.consentTitle = consentTitle;
2534
ipr.consentMessage = consentMessage;
2535
ipr.consentTimeout = this.httprequest.consentTimeout;
2577
- ipr.consentAutoAccept = this.httprequest.consentAutoAccept;
2536
+ ipr.consentAutoAccept = this.httprequest.consentAutoAccept;
2537
ipr.tsid = tsid;
2538
ipr.username = this.httprequest.realname;
2539
ipr.translation = { Allow: currentTranslation['allow'], Deny: currentTranslation['deny'], Auto: currentTranslation['autoAllowForFive'], Caption: consentMessage };
@@ -2757,7 +2716,7 @@ function onTunnelData(data) {
2716
ipr.consentTitle = consentTitle;
2717
ipr.consentMessage = consentMessage;
2718
ipr.consentTimeout = this.httprequest.consentTimeout;
2760
- ipr.consentAutoAccept = this.httprequest.consentAutoAccept;
2719
+ ipr.consentAutoAccept = this.httprequest.consentAutoAccept;
2720
ipr.username = this.httprequest.realname;
2721
ipr.translations = { Allow: currentTranslation['allow'], Deny: currentTranslation['deny'], Auto: currentTranslation['autoAllowForFive'], Caption: consentMessage };
2722
pr = ipr.then(function (img) {
@@ -3324,18 +3283,15 @@ function openUserDesktopUrl(url) {
3283
var domain = require('user-sessions').getDomain(uid);
3284
var task = { name: 'MeshChatTask', user: user, domain: domain, execPath: process.env['windir'] + '\\system32\\cmd.exe', arguments: ['/C START ' + url.split('&').join('^&')] };
3285
3327
- try
3328
- {
3286
+ try {
3287
require('win-tasks').addTask(task);
3288
require('win-tasks').getTask({ name: 'MeshChatTask' }).run();
3289
require('win-tasks').deleteTask('MeshChatTask');
3290
return (true);
3291
}
3334
- catch(zz)
3335
- {
3292
+ catch (ex) {
3293
var taskoptions = { env: { _target: process.env['windir'] + '\\system32\\cmd.exe', _args: '/C START ' + url.split('&').join('^&'), _user: '"' + domain + '\\' + user + '"' } };
3337
- for (var c1e in process.env)
3338
- {
3294
+ for (var c1e in process.env) {
3295
taskoptions.env[c1e] = process.env[c1e];
3296
}
3297
var child = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-'], taskoptions);
@@ -3383,18 +3339,11 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3339
var fin = '', f = '', availcommands = 'domain,translations,agentupdate,errorlog,msh,timerinfo,coreinfo,coredump,service,fdsnapshot,fdcount,startupoptions,alert,agentsize,versions,help,info,osinfo,args,print,type,dbkeys,dbget,dbset,dbcompact,eval,parseuri,httpget,wslist,plugin,wsconnect,wssend,wsclose,notify,ls,ps,kill,netinfo,location,power,wakeonlan,setdebug,smbios,rawsmbios,toast,lock,users,openurl,getscript,getclip,setclip,log,av,cpuinfo,sysinfo,apf,scanwifi,wallpaper,agentmsg,task';
3340
if (require('os').dns != null) { availcommands += ',dnsinfo'; }
3341
try { require('linux-dhcp'); availcommands += ',dhcp'; } catch (ex) { }
3386
- if (process.platform == 'win32')
3387
- {
3342
+ if (process.platform == 'win32') {
3343
availcommands += ',cs,wpfhwacceleration,uac,volumes';
3344
if (bcdOK()) { availcommands += ',safemode'; }
3345
if (require('notifybar-desktop').DefaultPinned != null) { availcommands += ',privacybar'; }
3391
- try
3392
- {
3393
- require('win-utils');
3394
- availcommands += ',taskbar';
3395
- }
3396
- catch(zz)
3397
- {}
3346
+ try { require('win-utils'); availcommands += ',taskbar'; } catch (ex) { }
3347
}
3348
if (amt != null) { availcommands += ',amt,amtconfig,amtevents'; }
3349
if (process.platform != 'freebsd') { availcommands += ',vm'; }
@@ -3411,57 +3360,40 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3360
break;
3361
}
3362
case 'taskbar':
3414
- try
3415
- {
3416
- require('win-utils');
3417
- }
3418
- catch(zz)
3419
- {
3420
- response = 'Unknown command "taskbar", type "help" for list of avaialble commands.';
3421
- break;
3422
- }
3423
- switch (args['_'].length)
3424
- {
3425
- default:
3426
- response = 'Proper usage: taskbar HIDE|SHOW [TSID]';
3427
- break;
3363
+ try { require('win-utils'); } catch (ex) { response = 'Unknown command "taskbar", type "help" for list of avaialble commands.'; break; }
3364
+ switch (args['_'].length) {
3365
case 1:
3366
case 2:
3367
{
3368
var tsid = parseInt(args['_'][1]);
3369
if (isNaN(tsid)) { tsid = require('user-sessions').consoleUid(); }
3370
sendConsoleText('Changing TaskBar AutoHide status. Please wait...', sessionid);
3434
- try
3435
- {
3371
+ try {
3372
var result = require('win-utils').taskBar.autoHide(tsid, args['_'][0].toLowerCase() == 'hide');
3373
response = 'Current Status of TaskBar AutoHide: ' + result;
3438
- }
3439
- catch(x)
3440
- {
3441
- response = 'Unable to change TaskBar settings';
3442
- }
3374
+ } catch (ex) { response = 'Unable to change TaskBar settings'; }
3375
}
3376
break;
3377
+ default:
3378
+ {
3379
+ response = 'Proper usage: taskbar HIDE|SHOW [TSID]';
3380
+ break;
3381
+ }
3382
}
3446
- console.log(args['_'].length);
3383
break;
3384
case 'privacybar':
3449
- if (process.platform != 'win32' || require('notifybar-desktop').DefaultPinned == null)
3450
- {
3385
+ if (process.platform != 'win32' || require('notifybar-desktop').DefaultPinned == null) {
3386
response = 'Unknown command "privacybar", type "help" for list of avaialble commands.';
3387
}
3453
- else
3454
- {
3455
- switch(args['_'].length)
3456
- {
3388
+ else {
3389
+ switch (args['_'].length) {
3390
default:
3391
// Show Help
3392
response = "Current Default Pinned State: " + (require('notifybar-desktop').DefaultPinned ? "PINNED" : "UNPINNED") + '\r\n';
3393
response += "To set default pinned state:\r\n privacybar [PINNED|UNPINNED]\r\n";
3394
break;
3395
case 1:
3463
- switch(args['_'][0].toUpperCase())
3464
- {
3396
+ switch (args['_'][0].toUpperCase()) {
3397
case 'PINNED':
3398
require('notifybar-desktop').DefaultPinned = true;
3399
response = "privacybar default pinned state is: PINNED";
@@ -3483,13 +3415,11 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3415
break;
3416
case 'domaininfo':
3417
{
3486
- if(process.platform != 'win32')
3487
- {
3418
+ if (process.platform != 'win32') {
3419
response = 'Unknown command "cs", type "help" for list of avaialble commands.';
3420
break;
3421
}
3491
- if(global._domainQuery != null)
3492
- {
3422
+ if (global._domainQuery != null) {
3423
response = "There is already an outstanding Domain Controller Query... Please try again later...";
3424
break;
3425
}
@@ -3497,34 +3427,28 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3427
sendConsoleText('Querying Domain Controller... This can take up to 60 seconds. Please wait...', sessionid);
3428
global._domainQuery = require('win-wmi').queryAsync('ROOT\\CIMV2', 'SELECT * FROM Win32_NTDomain');
3429
global._domainQuery.session = sessionid;
3500
- global._domainQuery.then(function (v)
3501
- {
3430
+ global._domainQuery.then(function (v) {
3431
var results = [];
3503
- if (Array.isArray(v))
3504
- {
3432
+ if (Array.isArray(v)) {
3433
var i;
3434
var r;
3507
- for (i = 0; i < v.length; ++i)
3508
- {
3435
+ for (i = 0; i < v.length; ++i) {
3436
r = {};
3437
if (v[i].DomainControllerAddress != null) { r.DomainControllerAddress = v[i].DomainControllerAddress.split('\\').pop(); }
3438
if (r.DomainControllerName != null) { r.DomainControllerName = v[i].DomainControllerName.split('\\').pop(); }
3439
r.DomainGuid = v[i].DomainGuid;
3440
r.DomainName = v[i].DomainName;
3514
- if (r.DomainGuid != null)
3515
- {
3441
+ if (r.DomainGuid != null) {
3442
results.push(r);
3443
}
3444
}
3445
}
3520
- if (results.length > 0)
3521
- {
3446
+ if (results.length > 0) {
3447
sendConsoleText('Domain Controller Results:', this.session);
3448
sendConsoleText(JSON.stringify(results, null, 1), this.session);
3449
sendConsoleText('End of results...', this.session);
3450
}
3526
- else
3527
- {
3451
+ else {
3452
sendConsoleText('Domain Controller: No results returned. Is the domain controller reachable?', this.session);
3453
}
3454
global._domainQuery = null;
@@ -4037,14 +3961,11 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3961
}
3962
break;
3963
case 'safemode':
4040
- if (process.platform != 'win32')
4041
- {
3964
+ if (process.platform != 'win32') {
3965
response = 'safemode only supported on Windows Platforms'
3966
}
4044
- else
4045
- {
4046
- if (!bcdOK())
4047
- {
3967
+ else {
3968
+ if (!bcdOK()) {
3969
response = 'safemode not supported on 64 bit Windows from a 32 bit process'
3970
break;
3971
}