Fixed MeshCtrl.js single quotes.

Ylian Saint-Hilaire committed Jul 17, 2020 at 14:29 UTC 80b2709cea8a62920b7d25f04c3ed62709350823
3 files changed +177 -59
meshagent.js
+27 -8
@@ -250,7 +250,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
250 // The new core will only be sent after the agent updates.
251 obj.sendBinary(common.ShortToStr(10) + common.ShortToStr(0));
252
253 - // We got the agent file open on the server side, tell the agent we are sending an update starting with the SHA384 hash of the result
253 + // We got the agent file open on the server side, tell the agent we are sending an update ending with the SHA384 hash of the result
254 //console.log("Agent update file open.");
255 obj.sendBinary(common.ShortToStr(13) + common.ShortToStr(0)); // Command 13, start mesh agent download
256
@@ -283,7 +283,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
283 // The new core will only be sent after the agent updates.
284 obj.sendBinary(common.ShortToStr(10) + common.ShortToStr(0));
285
286 - // We got the agent file open on the server side, tell the agent we are sending an update starting with the SHA384 hash of the result
286 + // We got the agent file open on the server side, tell the agent we are sending an update ending with the SHA384 hash of the result
287 obj.sendBinary(common.ShortToStr(13) + common.ShortToStr(0)); // Command 13, start mesh agent download
288
289 // Send the first mesh agent update data block
@@ -292,10 +292,29 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
292 obj.agentUpdate.buf[2] = 0;
293 obj.agentUpdate.buf[3] = 1;
294
295 - const len = Math.min(parent.parent.agentUpdateBlockSize, obj.agentExeInfo.data.length - obj.agentUpdate.ptr);
295 + /*
296 + // If agent supports compression, send the compressed agent if possible.
297 + if ((obj.agentInfo.capabilities & 0x80) && (obj.agentExeInfo.zdata != null)) {
298 + // Send compressed data
299 + obj.agentUpdate.agentUpdateData = obj.agentExeInfo.zdata;
300 + obj.agentUpdate.agentUpdateHash = obj.agentExeInfo.zhash;
301 + //console.log('Sending compressed update agent', obj.agentExeInfo.zhashhex);
302 + } else {
303 + // Send uncompressed data
304 + obj.agentUpdate.agentUpdateData = obj.agentExeInfo.data;
305 + obj.agentUpdate.agentUpdateHash = obj.agentExeInfo.hash;
306 + //console.log('Sending uncompressed update agent', obj.agentExeInfo.hashhex);
307 + }
308 + */
309 +
310 + // Send uncompressed data
311 + obj.agentUpdate.agentUpdateData = obj.agentExeInfo.data;
312 + obj.agentUpdate.agentUpdateHash = obj.agentExeInfo.hash;
313 +
314 + const len = Math.min(parent.parent.agentUpdateBlockSize, obj.agentUpdate.agentUpdateData.length - obj.agentUpdate.ptr);
315 if (len > 0) {
316 // Send the first block
298 - obj.agentExeInfo.data.copy(obj.agentUpdate.buf, 4, obj.agentUpdate.ptr, obj.agentUpdate.ptr + len);
317 + obj.agentUpdate.agentUpdateData.copy(obj.agentUpdate.buf, 4, obj.agentUpdate.ptr, obj.agentUpdate.ptr + len);
318 obj.agentUpdate.ptr += len;
319 obj.sendBinary(obj.agentUpdate.buf); // Command 14, mesh agent first data block
320 parent.parent.debug('agentupdate', "Sent first block of " + len + " bytes from RAM.");
@@ -349,17 +368,17 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
368 });
369 } else {
370 // Send the agent from RAM
352 - const len = Math.min(parent.parent.agentUpdateBlockSize, obj.agentExeInfo.data.length - obj.agentUpdate.ptr);
371 + const len = Math.min(parent.parent.agentUpdateBlockSize, obj.agentUpdate.agentUpdateData.length - obj.agentUpdate.ptr);
372 if (len > 0) {
354 - obj.agentExeInfo.data.copy(obj.agentUpdate.buf, 4, obj.agentUpdate.ptr, obj.agentUpdate.ptr + len);
373 + obj.agentUpdate.agentUpdateData.copy(obj.agentUpdate.buf, 4, obj.agentUpdate.ptr, obj.agentUpdate.ptr + len);
374 if (len == parent.parent.agentUpdateBlockSize) { obj.sendBinary(obj.agentUpdate.buf); } else { obj.sendBinary(obj.agentUpdate.buf.slice(0, len + 4)); } // Command 14, mesh agent next data block
375 parent.parent.debug('agentupdate', "Sending RAM agent #" + obj.agentExeInfo.id + " block, ptr=" + obj.agentUpdate.ptr + ", len=" + len + ".");
376 obj.agentUpdate.ptr += len;
377 }
378
360 - if (obj.agentUpdate.ptr == obj.agentExeInfo.data.length) {
379 + if (obj.agentUpdate.ptr == obj.agentUpdate.agentUpdateData.length) {
380 parent.parent.debug('agentupdate', "Completed agent #" + obj.agentExeInfo.id + " update from RAM, ptr=" + obj.agentUpdate.ptr + ".");
362 - obj.sendBinary(common.ShortToStr(13) + common.ShortToStr(0) + obj.agentExeInfo.hash); // Command 13, end mesh agent download, send agent SHA384 hash
381 + obj.sendBinary(common.ShortToStr(13) + common.ShortToStr(0) + obj.agentUpdate.agentUpdateHash); // Command 13, end mesh agent download, send agent SHA384 hash
382 parent.parent.taskLimiter.completed(obj.agentUpdate.taskid); // Indicate this task complete
383 delete obj.agentUpdate.buf;
384 delete obj.agentUpdate;
meshcentral.js
+35 -1
@@ -2160,7 +2160,41 @@ function CreateMeshCentralServer(config, args) {
2160 outStream.bufferList = [];
2161 outStream._write = function (chunk, encoding, callback) { this.bufferList.push(chunk); if (callback) callback(); }; // Append the chuck.
2162 outStream._read = function (size) { }; // Do nothing, this is not going to be called.
2163 - outStream.on('finish', function () { this.meshAgentBinary.data = Buffer.concat(this.bufferList); this.meshAgentBinary.size = this.meshAgentBinary.data.length; delete this.bufferList; }) // Merge all chunks
2163 + outStream.on('finish', function () {
2164 + // Merge all chunks
2165 + this.meshAgentBinary.data = Buffer.concat(this.bufferList);
2166 + this.meshAgentBinary.size = this.meshAgentBinary.data.length;
2167 + delete this.bufferList;
2168 +
2169 + // Compress the agent using ZIP
2170 + var archive = require('archiver')('zip', { level: 9 }); // Sets the compression method.
2171 +
2172 + const onZipData = function onZipData(buffer) { onZipData.x.zacc.push(buffer); }
2173 + const onZipEnd = function onZipEnd() {
2174 + // Concat all the buffer for create compressed zip agent
2175 + var concatData = Buffer.concat(onZipData.x.zacc);
2176 + delete onZipData.x.zacc;
2177 +
2178 + // Hash the compressed binary
2179 + var hash = obj.crypto.createHash('sha384').update(concatData);
2180 + onZipData.x.zhash = hash.digest('binary');
2181 + onZipData.x.zhashhex = Buffer.from(onZipData.x.zhash, 'binary').toString('hex');
2182 +
2183 + // Set the agent
2184 + onZipData.x.zdata = concatData;
2185 + onZipData.x.zsize = concatData.length;
2186 + }
2187 + const onZipError = function onZipError() { delete onZipData.x.zacc; }
2188 + this.meshAgentBinary.zacc = [];
2189 + onZipData.x = this.meshAgentBinary;
2190 + onZipEnd.x = this.meshAgentBinary;
2191 + onZipError.x = this.meshAgentBinary;
2192 + archive.on('data', onZipData);
2193 + archive.on('end', onZipEnd);
2194 + archive.on('error', onZipError);
2195 + archive.append(this.meshAgentBinary.data, { name: 'meshagent' });
2196 + archive.finalize();
2197 + })
2198 obj.exeHandler.streamExeWithMeshPolicy(
2199 {
2200 platform: 'win32',
meshctrl.js
+115 -50
@@ -71,36 +71,36 @@ if (args['_'].length == 0) {
71 case 'listdevicegroups': { ok = true; break; }
72 case 'listdevices': { ok = true; break; }
73 case 'listusersofdevicegroup': {
74 - if (args.id == null) { console.log("Missing group id, use --id '[groupid]'"); }
74 + if (args.id == null) { console.log(winRemoveSingleQuotes("Missing group id, use --id '[groupid]'")); }
75 else { ok = true; }
76 break;
77 }
78 case 'deviceinfo': {
79 - if (args.id == null) { console.log("Missing device id, use --id '[deviceid]'"); }
79 + if (args.id == null) { console.log(winRemoveSingleQuotes("Missing device id, use --id '[deviceid]'")); }
80 else { ok = true; }
81 break;
82 }
83 case 'addusertodevicegroup': {
84 - if ((args.id == null) && (args.group == null)) { console.log("Device group identifier missing, use --id '[groupid]' or --group [groupname]"); }
84 + if ((args.id == null) && (args.group == null)) { console.log(winRemoveSingleQuotes("Device group identifier missing, use --id '[groupid]' or --group [groupname]")); }
85 else if (args.userid == null) { console.log("Add user to group missing useid, use --userid [userid]"); }
86 else { ok = true; }
87 break;
88 }
89 case 'removeuserfromdevicegroup': {
90 - if ((args.id == null) && (args.group == null)) { console.log("Device group identifier missing, use --id '[groupid]' or --group [groupname]"); }
90 + if ((args.id == null) && (args.group == null)) { console.log(winRemoveSingleQuotes("Device group identifier missing, use --id '[groupid]' or --group [groupname]")); }
91 else if (args.userid == null) { console.log("Remove user from group missing useid, use --userid [userid]"); }
92 else { ok = true; }
93 break;
94 }
95 case 'addusertodevice': {
96 if (args.userid == null) { console.log("Add user to device missing userid, use --userid [userid]"); }
97 - else if (args.id == null) { console.log("Add user to device missing device id, use --id '[deviceid]'"); }
97 + else if (args.id == null) { console.log(winRemoveSingleQuotes("Add user to device missing device id, use --id '[deviceid]'")); }
98 else { ok = true; }
99 break;
100 }
101 case 'removeuserfromdevice': {
102 if (args.userid == null) { console.log("Remove user from device missing userid, use --userid [userid]"); }
103 - else if (args.id == null) { console.log("Remove user from device missing device id, use --id '[deviceid]'"); }
103 + else if (args.id == null) { console.log(winRemoveSingleQuotes("Remove user from device missing device id, use --id '[deviceid]'")); }
104 else { ok = true; }
105 break;
106 }
@@ -110,13 +110,13 @@ if (args['_'].length == 0) {
110 break;
111 }
112 case 'removedevicegroup': {
113 - if ((args.id == null) && (args.group == null)) { console.log("Device group identifier missing, use --id '[groupid]' or --group [groupname]"); }
113 + if ((args.id == null) && (args.group == null)) { console.log(winRemoveSingleQuotes("Device group identifier missing, use --id '[groupid]' or --group [groupname]")); }
114 else { ok = true; }
115 break;
116 }
117 case 'movetodevicegroup': {
118 - if ((args.id == null) && (args.group == null)) { console.log("Device group identifier missing, use --id '[groupid]' or --group [groupname]"); }
119 - else if (args.devid == null) { console.log("Device identifier missing, use --devid '[deviceid]'"); }
118 + if ((args.id == null) && (args.group == null)) { console.log(winRemoveSingleQuotes("Device group identifier missing, use --id '[groupid]' or --group [groupname]")); }
119 + else if (args.devid == null) { console.log(winRemoveSingleQuotes("Device identifier missing, use --devid '[deviceid]'")); }
120 else { ok = true; }
121 break;
122 }
@@ -146,7 +146,7 @@ if (args['_'].length == 0) {
146 break;
147 }
148 case 'removeusergroup': {
149 - if (args.groupid == null) { console.log("Remove user group id missing, use --groupid '[id]'"); }
149 + if (args.groupid == null) { console.log(winRemoveSingleQuotes("Remove user group id missing, use --groupid '[id]'")); }
150 else { ok = true; }
151 break;
152 }
@@ -163,18 +163,18 @@ if (args['_'].length == 0) {
163 break;
164 }
165 case 'runcommand': {
166 - if (args.id == null) { console.log("Missing device id, use --id '[deviceid]'"); }
166 + if (args.id == null) { console.log(winRemoveSingleQuotes("Missing device id, use --id '[deviceid]'")); }
167 else if (args.run == null) { console.log("Missing run, use --run \"command\""); }
168 else { ok = true; }
169 break;
170 }
171 case 'shell': {
172 - if (args.id == null) { console.log("Missing device id, use --id '[deviceid]'"); }
172 + if (args.id == null) { console.log(winRemoveSingleQuotes("Missing device id, use --id '[deviceid]'")); }
173 else { ok = true; }
174 break;
175 }
176 case 'upload': {
177 - if (args.id == null) { console.log("Missing device id, use --id '[deviceid]'"); }
177 + if (args.id == null) { console.log(winRemoveSingleQuotes("Missing device id, use --id '[deviceid]'")); }
178 else if (args.file == null) { console.log("Local file missing, use --file [file] specify the file to upload"); }
179 else if (args.target == null) { console.log("Remote target path missing, use --target [path] to specify the remote location"); }
180 else if (require('fs').existsSync(args.file) == false) { console.log("Local file does not exists, check --file"); }
@@ -182,7 +182,7 @@ if (args['_'].length == 0) {
182 break;
183 }
184 case 'download': {
185 - if (args.id == null) { console.log("Missing device id, use --id '[deviceid]'"); }
185 + if (args.id == null) { console.log(winRemoveSingleQuotes("Missing device id, use --id '[deviceid]'")); }
186 else if (args.file == null) { console.log("Remote file missing, use --file [file] specify the remote file to download"); }
187 else if (args.target == null) { console.log("Target path missing, use --target [path] to specify the local download location"); }
188 else { ok = true; }
@@ -199,10 +199,14 @@ if (args['_'].length == 0) {
199 }
200 case 'sendinviteemail': {
201 console.log("Send invitation email with instructions on how to install the mesh agent for a specific device group. Example usage:\r\n");
202 - console.log(" MeshCtrl SendInviteEmail --id 'groupid' --message \"msg\" --email user@sample.com");
203 - console.log(" MeshCtrl SendInviteEmail --group \"My Computers\" --name \"Jack\" --email user@sample.com");
202 + console.log(winRemoveSingleQuotes(" MeshCtrl SendInviteEmail --id 'groupid' --message \"msg\" --email user@sample.com"));
203 + console.log(winRemoveSingleQuotes(" MeshCtrl SendInviteEmail --group \"My Computers\" --name \"Jack\" --email user@sample.com"));
204 console.log("\r\nRequired arguments:\r\n");
205 - console.log(" --id '[groupid]' - Device group identifier (or --group).");
205 + if (process.platform == 'win32') {
206 + console.log(" --id [groupid] - Device group identifier (or --group).");
207 + } else {
208 + console.log(" --id '[groupid]' - Device group identifier (or --group).");
209 + }
210 console.log(" --group [groupname] - Device group name (or --id).");
211 console.log(" --email [email] - Email address.");
212 console.log("\r\nOptional arguments:\r\n");
@@ -212,10 +216,14 @@ if (args['_'].length == 0) {
216 }
217 case 'generateinvitelink': {
218 console.log("Generate a agent invitation URL for a given group. Example usage:\r\n");
215 - console.log(" MeshCtrl GenerateInviteLink --id 'groupid' --hours 24");
219 + console.log(winRemoveSingleQuotes(" MeshCtrl GenerateInviteLink --id 'groupid' --hours 24"));
220 console.log(" MeshCtrl GenerateInviteLink --group \"My Computers\" --hours 0");
221 console.log("\r\nRequired arguments:\r\n");
218 - console.log(" --id '[groupid]' - Device group identifier (or --group).");
222 + if (process.platform == 'win32') {
223 + console.log(" --id [groupid] - Device group identifier (or --group).");
224 + } else {
225 + console.log(" --id '[groupid]' - Device group identifier (or --group).");
226 + }
227 console.log(" --group [groupname] - Device group name (or --id).");
228 console.log(" --hours [hours] - Validity period in hours or 0 for infinit.");
229 break;
@@ -276,9 +284,13 @@ if (args['_'].length == 0) {
284 case 'listdevices': {
285 console.log("List devices, Example usages:\r\n");
286 console.log(" MeshCtrl ListDevices");
279 - console.log(" MeshCtrl ListDevices -id '[groupid]' --json");
287 + console.log(winRemoveSingleQuotes(" MeshCtrl ListDevices -id '[groupid]' --json"));
288 console.log("\r\nOptional arguments:\r\n");
281 - console.log(" --id '[groupid]' - Filter by group identifier (or --group).");
289 + if (process.platform == 'win32') {
290 + console.log(" --id [groupid] - Filter by group identifier (or --group).");
291 + } else {
292 + console.log(" --id '[groupid]' - Filter by group identifier (or --group).");
293 + }
294 console.log(" --group [groupname] - Filter by group name (or --id).");
295 console.log(" --count - Only return the device count.");
296 console.log(" --json - Show result as JSON.");
@@ -288,7 +300,11 @@ if (args['_'].length == 0) {
300 console.log("List users that have permissions for a given device group, Example usage:\r\n");
301 console.log(" MeshCtrl ListUserOfDeviceGroup ");
302 console.log("\r\nRequired arguments:\r\n");
291 - console.log(" --id '[groupid]' - Device group identifier.");
303 + if (process.platform == 'win32') {
304 + console.log(" --id [groupid] - Device group identifier.");
305 + } else {
306 + console.log(" --id '[groupid]' - Device group identifier.");
307 + }
308 console.log("\r\nOptional arguments:\r\n");
309 console.log(" --json - Show result as JSON.");
310 break;
@@ -336,25 +352,41 @@ if (args['_'].length == 0) {
352 console.log("Remove a device group, Example usages:\r\n");
353 console.log(" MeshCtrl RemoveDeviceGroup --id 'groupid'");
354 console.log("\r\nRequired arguments:\r\n");
339 - console.log(" --id '[groupid]' - Device group identifier (or --group).");
355 + if (process.platform == 'win32') {
356 + console.log(" --id [groupid] - Device group identifier (or --group).");
357 + } else {
358 + console.log(" --id '[groupid]' - Device group identifier (or --group).");
359 + }
360 console.log(" --group [groupname] - Device group name (or --id).");
361 break;
362 }
363 case 'movetodevicegroup': {
364 console.log("Move a device to a new device group, Example usages:\r\n");
345 - console.log(" MeshCtrl MoveToDeviceGroup --devid 'deviceid' --id 'groupid'");
365 + console.log(winRemoveSingleQuotes(" MeshCtrl MoveToDeviceGroup --devid 'deviceid' --id 'groupid'"));
366 console.log("\r\nRequired arguments:\r\n");
347 - console.log(" --id '[groupid]' - Device group identifier (or --group).");
367 + if (process.platform == 'win32') {
368 + console.log(" --id [groupid] - Device group identifier (or --group).");
369 + } else {
370 + console.log(" --id '[groupid]' - Device group identifier (or --group).");
371 + }
372 console.log(" --group [groupname] - Device group name (or --id).");
349 - console.log(" --devid '[deviceid]' - Device identifier.");
373 + if (process.platform == 'win32') {
374 + console.log(" --devid [deviceid] - Device identifier.");
375 + } else {
376 + console.log(" --devid '[deviceid]' - Device identifier.");
377 + }
378 break;
379 }
380 case 'addusertodevicegroup': {
381 console.log("Add a user to a device group, Example usages:\r\n");
354 - console.log(" MeshCtrl AddUserToDeviceGroup --id 'groupid' --userid userid --fullrights");
382 + console.log(winRemoveSingleQuotes(" MeshCtrl AddUserToDeviceGroup --id 'groupid' --userid userid --fullrights"));
383 console.log(" MeshCtrl AddUserToDeviceGroup --group groupname --userid userid --editgroup --manageusers");
384 console.log("\r\nRequired arguments:\r\n");
357 - console.log(" --id '[groupid]' - Device group identifier (or --group).");
385 + if (process.platform == 'win32') {
386 + console.log(" --id [groupid] - Device group identifier (or --group).");
387 + } else {
388 + console.log(" --id '[groupid]' - Device group identifier (or --group).");
389 + }
390 console.log(" --group [groupname] - Device group name (or --id).");
391 console.log(" --userid [userid] - The user identifier.");
392 console.log("\r\nOptional arguments:\r\n");
@@ -384,19 +416,27 @@ if (args['_'].length == 0) {
416 }
417 case 'removeuserfromdevicegroup': {
418 console.log("Remove a user from a device group, Example usages:\r\n");
387 - console.log(" MeshCtrl RemoveuserFromDeviceGroup --id 'groupid' --userid userid");
419 + console.log(winRemoveSingleQuotes(" MeshCtrl RemoveuserFromDeviceGroup --id 'groupid' --userid userid"));
420 console.log("\r\nRequired arguments:\r\n");
389 - console.log(" --id '[groupid]' - Device group identifier (or --group).");
421 + if (process.platform == 'win32') {
422 + console.log(" --id [groupid] - Device group identifier (or --group).");
423 + } else {
424 + console.log(" --id '[groupid]' - Device group identifier (or --group).");
425 + }
426 console.log(" --group [groupname] - Device group name (or --id).");
427 console.log(" --userid [userid] - The user identifier.");
428 break;
429 }
430 case 'addusertodevice': {
431 console.log("Add a user to a device, Example usages:\r\n");
396 - console.log(" MeshCtrl AddUserToDevice --id 'deviceid' --userid userid --fullrights");
397 - console.log(" MeshCtrl AddUserToDevice --id 'deviceid' --userid userid --remotecontrol");
432 + console.log(winRemoveSingleQuotes(" MeshCtrl AddUserToDevice --id 'deviceid' --userid userid --fullrights"));
433 + console.log(winRemoveSingleQuotes(" MeshCtrl AddUserToDevice --id 'deviceid' --userid userid --remotecontrol"));
434 console.log("\r\nRequired arguments:\r\n");
399 - console.log(" --id '[deviceid]' - The device identifier.");
435 + if (process.platform == 'win32') {
436 + console.log(" --id [deviceid] - The device identifier.");
437 + } else {
438 + console.log(" --id '[deviceid]' - The device identifier.");
439 + }
440 console.log(" --userid [userid] - The user identifier.");
441 console.log("\r\nOptional arguments:\r\n");
442 console.log(" --fullrights - Allow full rights over this device.");
@@ -417,9 +457,13 @@ if (args['_'].length == 0) {
457 }
458 case 'removeuserfromdevice': {
459 console.log("Remove a user from a device, Example usages:\r\n");
420 - console.log(" MeshCtrl RemoveuserFromDeviceGroup --id 'deviceid' --userid userid");
460 + console.log(winRemoveSingleQuotes(" MeshCtrl RemoveuserFromDeviceGroup --id 'deviceid' --userid userid"));
461 console.log("\r\nRequired arguments:\r\n");
422 - console.log(" --id '[deviceid]' - The device identifier.");
462 + if (process.platform == 'win32') {
463 + console.log(" --id [deviceid] - The device identifier.");
464 + } else {
465 + console.log(" --id '[deviceid]' - The device identifier.");
466 + }
467 console.log(" --userid [userid] - The user identifier.");
468 break;
469 }
@@ -432,10 +476,14 @@ if (args['_'].length == 0) {
476 }
477 case 'deviceinfo': {
478 console.log("Display information about a device, Example usages:\r\n");
435 - console.log(" MeshCtrl DeviceInfo --id 'deviceid'");
436 - console.log(" MeshCtrl DeviceInfo --id 'deviceid' --json");
479 + console.log(winRemoveSingleQuotes(" MeshCtrl DeviceInfo --id 'deviceid'"));
480 + console.log(winRemoveSingleQuotes(" MeshCtrl DeviceInfo --id 'deviceid' --json"));
481 console.log("\r\nRequired arguments:\r\n");
438 - console.log(" --id '[deviceid]' - The device identifier.");
482 + if (process.platform == 'win32') {
483 + console.log(" --id [deviceid] - The device identifier.");
484 + } else {
485 + console.log(" --id '[deviceid]' - The device identifier.");
486 + }
487 console.log("\r\nOptional arguments:\r\n");
488 console.log(" --raw - Output raw data in JSON format.");
489 console.log(" --json - Give results in JSON format.");
@@ -443,10 +491,14 @@ if (args['_'].length == 0) {
491 }
492 case 'runcommand': {
493 console.log("Run a shell command on a remote device, Example usages:\r\n");
446 - console.log(" MeshCtrl RunCommand --id 'deviceid' --run \"command\"");
447 - console.log(" MeshCtrl RunCommand --id 'deviceid' --run \"command\" --powershell");
494 + console.log(winRemoveSingleQuotes(" MeshCtrl RunCommand --id 'deviceid' --run \"command\""));
495 + console.log(winRemoveSingleQuotes(" MeshCtrl RunCommand --id 'deviceid' --run \"command\" --powershell"));
496 console.log("\r\nRequired arguments:\r\n");
449 - console.log(" --id '[deviceid]' - The device identifier.");
497 + if (process.platform == 'win32') {
498 + console.log(" --id [deviceid] - The device identifier.");
499 + } else {
500 + console.log(" --id '[deviceid]' - The device identifier.");
501 + }
502 console.log(" --run \"[command]\" - Shell command to execute on the remote device.");
503 console.log("\r\nOptional arguments:\r\n");
504 console.log(" --powershell - Run in Windows PowerShell.");
@@ -454,30 +506,42 @@ if (args['_'].length == 0) {
506 }
507 case 'shell': {
508 console.log("Access a command shell on a remote device, Example usages:\r\n");
457 - console.log(" MeshCtrl Shell --id 'deviceid'");
458 - console.log(" MeshCtrl Shell --id 'deviceid' --powershell");
509 + console.log(winRemoveSingleQuotes(" MeshCtrl Shell --id 'deviceid'"));
510 + console.log(winRemoveSingleQuotes(" MeshCtrl Shell --id 'deviceid' --powershell"));
511 console.log("\r\nRequired arguments:\r\n");
460 - console.log(" --id '[deviceid]' - The device identifier.");
512 + if (process.platform == 'win32') {
513 + console.log(" --id [deviceid] - The device identifier.");
514 + } else {
515 + console.log(" --id '[deviceid]' - The device identifier.");
516 + }
517 console.log("\r\nOptional arguments:\r\n");
518 console.log(" --powershell - Run a Windows PowerShell.");
519 break;
520 }
521 case 'upload': {
522 console.log("Upload a local file to a remote device, Example usages:\r\n");
467 - console.log(" MeshCtrl Upload --id 'deviceid' --file sample.txt --target c:\\");
468 - console.log(" MeshCtrl Upload --id 'deviceid' --file sample.txt --target /tmp");
523 + console.log(winRemoveSingleQuotes(" MeshCtrl Upload --id 'deviceid' --file sample.txt --target c:\\"));
524 + console.log(winRemoveSingleQuotes(" MeshCtrl Upload --id 'deviceid' --file sample.txt --target /tmp"));
525 console.log("\r\nRequired arguments:\r\n");
470 - console.log(" --id '[deviceid]' - The device identifier.");
526 + if (process.platform == 'win32') {
527 + console.log(" --id [deviceid] - The device identifier.");
528 + } else {
529 + console.log(" --id '[deviceid]' - The device identifier.");
530 + }
531 console.log(" --file [localfile] - The local file to upload.");
532 console.log(" --target [remotepath] - The remote path to upload the file to.");
533 break;
534 }
535 case 'download': {
536 console.log("Download a file from a remote device, Example usages:\r\n");
477 - console.log(" MeshCtrl Download --id 'deviceid' --file C:\\sample.txt --target c:\\temp");
478 - console.log(" MeshCtrl Download --id 'deviceid' --file /tmp/sample.txt --target /tmp");
537 + console.log(winRemoveSingleQuotes(" MeshCtrl Download --id 'deviceid' --file C:\\sample.txt --target c:\\temp"));
538 + console.log(winRemoveSingleQuotes(" MeshCtrl Download --id 'deviceid' --file /tmp/sample.txt --target /tmp"));
539 console.log("\r\nRequired arguments:\r\n");
480 - console.log(" --id '[deviceid]' - The device identifier.");
540 + if (process.platform == 'win32') {
541 + console.log(" --id [deviceid] - The device identifier.");
542 + } else {
543 + console.log(" --id '[deviceid]' - The device identifier.");
544 + }
545 console.log(" --file [remotefile] - The remote file to download.");
546 console.log("\r\nOptional arguments:\r\n");
547 console.log(" --target [localpath] - The local path to download the file to.");
@@ -1274,6 +1338,7 @@ function checkAmtPassword(p) { return (p.length > 7) && (/\d/.test(p)) && (/[a-z
1338 function getRandomAmtPassword() { var p; do { p = Buffer.from(crypto.randomBytes(9), 'binary').toString('base64').split('/').join('@'); } while (checkAmtPassword(p) == false); return p; }
1339 function getRandomHex(count) { return Buffer.from(crypto.randomBytes(count), 'binary').toString('hex'); }
1340 function format(format) { var args = Array.prototype.slice.call(arguments, 1); return format.replace(/{(\d+)}/g, function (match, number) { return typeof args[number] != 'undefined' ? args[number] : match; }); };
1341 +function winRemoveSingleQuotes(str) { if (process.platform != 'win32') return str; else return str.split('\'').join(''); }
1342
1343 function displayDeviceInfo(sysinfo, lastconnect, network) {
1344 var node = sysinfo.node;