MeshCMD inner auth improvements.

Ylian Saint-Hilaire committed Apr 2, 2021 at 17:37 UTC 4519f377bf00521872f95fa8b13c4e79dacfabe3
1 file changed +6 -3
agents/meshcmd.js
+6 -3
@@ -486,8 +486,11 @@ function run(argv) {
486 if ((settings.remotenodeid == null) || (typeof settings.remotenodeid != 'string')) { console.log('No or invalid \"remoteNodeId\" specified.'); exit(1); return; }
487 if (((settings.username == null) || (typeof settings.username != 'string') || (settings.username == '')) && (settings.authcookie == null || typeof settings.authcookie != 'string' || settings.authcookie == '')) { console.log('No or invalid \"username\" specified, use --username [username].'); exit(1); return; }
488 if (((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) && (settings.authcookie == null || typeof settings.authcookie != 'string' || settings.authcookie == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
489 - if ((settings.serverid == null) || (typeof settings.serverid != 'string') || (settings.serverid.length != 96)) { console.log('No or invalid \"serverId\" specified.'); exit(1); return; }
490 - if ((settings.serverhttpshash == null) || (typeof settings.serverhttpshash != 'string') || (settings.serverhttpshash.length != 96)) { console.log('No or invalid \"serverHttpsHash\" specified.'); exit(1); return; }
489 + if (settings.serverid != null) {
490 + if ((typeof settings.serverid != 'string') || (settings.serverid.length != 96)) { console.log('No or invalid \"serverId\" specified.'); exit(1); return; }
491 + } else {
492 + if ((settings.serverhttpshash == null) || (typeof settings.serverhttpshash != 'string') || (settings.serverhttpshash.length != 96)) { console.log('No or invalid \"serverHttpsHash\" or \"serverId\" specified.'); exit(1); return; }
493 + }
494 if ((settings.remoteport == null) || (typeof settings.remoteport != 'number') || (settings.remoteport < 0) || (settings.remoteport > 65535)) { console.log('No or invalid \"remotePort\" specified, use --remoteport [remoteport].'); exit(1); return; }
495 if (settings.serverurl != null) { startRouter(); } else { discoverMeshServer(); } // Start MeshCentral Router
496 } else if ((settings.action == 'amtloadwebapp') || (settings.action == 'amtloadsmallwebapp') || (settings.action == 'amtloadlargewebapp') || (settings.action == 'amtclearwebapp') || (settings.action == 'amtstoragestate')) { // Intel AMT Web Application Actions
@@ -1997,7 +2000,7 @@ function startRouter() {
2000 options.headers = { 'x-meshauth': Buffer.from(settings.username, 'binary').toString('base64') + ',' + Buffer.from(settings.password, 'binary').toString('base64') };
2001 }
2002 }
2000 - }
2003 + } else { options.headers = { 'x-meshauth': '*' }; } // Request inner authentication
2004 if (settings.loginkey) { xurlargs.push('key=' + settings.loginkey); }
2005 if (xurlargs.length > 0) { options.path += '?' + xurlargs.join('&'); }
2006 } catch (e) { console.log("Unable to parse \"serverUrl\"."); process.exit(1); return; }