Fixed MeshCmd.js login method.

This commit is contained in:
Ylian Saint-Hilaire 2021-03-24 13:36:23 -07:00
parent da44d6f4d5
commit 0f39d31ffc
3 changed files with 24 additions and 8 deletions

Binary file not shown.

Binary file not shown.

View File

@ -159,6 +159,7 @@ function run(argv) {
if ((typeof args.uuidoutput) == 'string' || args.uuidoutput) { settings.uuidoutput = args.uuidoutput; } if ((typeof args.uuidoutput) == 'string' || args.uuidoutput) { settings.uuidoutput = args.uuidoutput; }
if ((typeof args.desc) == 'string') { settings.desc = args.desc; } if ((typeof args.desc) == 'string') { settings.desc = args.desc; }
if (args.emailtoken) { settings.emailtoken = true; } if (args.emailtoken) { settings.emailtoken = true; }
if (args.smstoken) { settings.smstoken = true; }
if (args.debug === true) { settings.debuglevel = 1; } if (args.debug === true) { settings.debuglevel = 1; }
if (args.debug) { try { waitForDebugger(); } catch (e) { } } if (args.debug) { try { waitForDebugger(); } catch (e) { } }
if (args.noconsole) { settings.noconsole = true; } if (args.noconsole) { settings.noconsole = true; }
@ -1950,16 +1951,31 @@ function startRouter() {
// Start by requesting a login token, this is needed because of 2FA and check that we have correct credentials from the start // Start by requesting a login token, this is needed because of 2FA and check that we have correct credentials from the start
var options; var options;
try { try {
var url = settings.serverurl.split('meshrelay.ashx').join('control.ashx'); // Parse the URL
options = http.parseUri(settings.serverurl.split('meshrelay.ashx').join('control.ashx'));
// Figure out the 2FA token to use if any
var xtoken = null;
if (settings.emailtoken) { xtoken = '**email**'; }
else if (settings.smstoken) { xtoken = '**sms**'; }
else if (settings.token != null) { xtoken = settings.token; }
// Complete the URL and add a x-meshauth header if needed
var xurlargs = [];
if (settings.authcookie != null) { if (settings.authcookie != null) {
url += '?auth=' + settings.authcookie; xurlargs.push('auth=' + settings.authcookie);
} else if (settings.username != null && settings.password != null) { if (xtoken != null) { xurlargs.push('token=' + xtoken); }
url += '?user=' + settings.username + '&pass=' + settings.password; } else {
if (xtoken != null) {
options.headers = { 'x-meshauth': Buffer.from(settings.username,'binary').toString('base64') + ',' + Buffer.from(settings.password,'binary').toString('base64') + ',' + Buffer.from(xtoken,'binary').toString('base64') };
} else {
options.headers = { 'x-meshauth': Buffer.from(settings.username,'binary').toString('base64') + ',' + Buffer.from(settings.password,'binary').toString('base64') };
}
} }
if (settings.emailtoken) { url += '&token=**email**'; } else if (settings.token != null) { url += '&token=' + settings.token; } if (settings.loginkey) { xurlargs.push('key=' + settings.loginkey); }
if (settings.loginkey) { url += '&key=' + settings.loginkey; } if (xurlargs.length > 0) { options.path += '?' + xurlargs.join('&'); }
options = http.parseUri(url);
} catch (e) { console.log("Unable to parse \"serverUrl\"."); process.exit(1); return; } } catch (e) { console.log("Unable to parse \"serverUrl\"."); process.exit(1); return; }
options.checkServerIdentity = onVerifyServer; options.checkServerIdentity = onVerifyServer;
options.rejectUnauthorized = false; options.rejectUnauthorized = false;
settings.websocket = http.request(options); settings.websocket = http.request(options);
@ -1979,7 +1995,7 @@ function OnServerWebSocket(msg, s, head) {
if (command.email2fasent === true) { if (command.email2fasent === true) {
console.log("Login token email sent."); console.log("Login token email sent.");
} else if (command.email2fa === true) { } else if (command.email2fa === true) {
console.log("Login token required, use --token [token], or --emailtoken get a token."); console.log("Login token required, use --token [token], or --emailtoken, --smstoken get a token.");
} else { } else {
console.log("Login token required, use --token [token]."); console.log("Login token required, use --token [token].");
} }