Skip to content

Commit

Permalink
add password promt to loginpass meshctrl
Browse files Browse the repository at this point in the history
Signed-off-by: si458 <simonsmith5521@gmail.com>
  • Loading branch information
si458 committed Nov 12, 2023
1 parent ed56213 commit a371709
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions meshctrl.js
Expand Up @@ -74,7 +74,7 @@ if (args['_'].length == 0) {
console.log(" --url [wss://server] - Server url, wss://localhost:443 is default.");
console.log(" - Use wss://localhost:443?key=xxx if login key is required.");
console.log(" --loginuser [username] - Login username, admin is default.");
console.log(" --loginpass [password] - Login password.");
console.log(" --loginpass [password] - Login password OR Leave blank to enter password at prompt");
console.log(" --token [number] - 2nd factor authentication token.");
console.log(" --loginkey [hex] - Server login key in hex.");
console.log(" --loginkeyfile [file] - File containing server login key in hex.");
Expand Down Expand Up @@ -990,7 +990,46 @@ if (args['_'].length == 0) {
}
}

if (ok) { serverConnect(); }
if (ok) {
if(args.loginpass===true){
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
process.stdout.write('Enter your password: ');
const stdin = process.openStdin();
stdin.setRawMode(true); // Set raw mode to prevent echoing of characters
stdin.resume();
args.loginpass = '';
process.stdin.on('data', (char) => {
char = char + '';
switch (char) {
case '\n':
case '\r':
case '\u0004': // They've finished entering their password
stdin.setRawMode(false);
stdin.pause();
process.stdout.clearLine(); process.stdout.cursorTo(0);
rl.close();
serverConnect();
break;
case '\u0003': // Ctrl+C
process.stdout.write('\n');
process.exit();
break;
default: // Mask the password with "*"
args.loginpass += char;
process.stdout.clearLine(); process.stdout.cursorTo(0);
process.stdout.write('Enter your password: ' + '*'.repeat(args.loginpass.length));
break;
}
});
}else{
serverConnect();
}
}
}

function displayConfigHelp() {
Expand Down

0 comments on commit a371709

Please sign in to comment.