add password promt to loginpass meshctrl
Signed-off-by: si458 <simonsmith5521@gmail.com>
si458 committed
Nov 12, 2023 at 21:49 UTC
a3717095e72f7fb1f7ff2699986781bada9bfaae
1 file changed
+41
-2
meshctrl.js
+41
-2
@@ -74,7 +74,7 @@ if (args['_'].length == 0) {
74
console.log(" --url [wss://server] - Server url, wss://localhost:443 is default.");
75
console.log(" - Use wss://localhost:443?key=xxx if login key is required.");
76
console.log(" --loginuser [username] - Login username, admin is default.");
77
- console.log(" --loginpass [password] - Login password.");
77
+ console.log(" --loginpass [password] - Login password OR Leave blank to enter password at prompt");
78
console.log(" --token [number] - 2nd factor authentication token.");
79
console.log(" --loginkey [hex] - Server login key in hex.");
80
console.log(" --loginkeyfile [file] - File containing server login key in hex.");
@@ -990,7 +990,46 @@ if (args['_'].length == 0) {
990
}
991
}
992
993
- if (ok) { serverConnect(); }
993
+ if (ok) {
994
+ if(args.loginpass===true){
995
+ const readline = require('readline');
996
+ const rl = readline.createInterface({
997
+ input: process.stdin,
998
+ output: process.stdout,
999
+ terminal: false
1000
+ });
1001
+ process.stdout.write('Enter your password: ');
1002
+ const stdin = process.openStdin();
1003
+ stdin.setRawMode(true); // Set raw mode to prevent echoing of characters
1004
+ stdin.resume();
1005
+ args.loginpass = '';
1006
+ process.stdin.on('data', (char) => {
1007
+ char = char + '';
1008
+ switch (char) {
1009
+ case '\n':
1010
+ case '\r':
1011
+ case '\u0004': // They've finished entering their password
1012
+ stdin.setRawMode(false);
1013
+ stdin.pause();
1014
+ process.stdout.clearLine(); process.stdout.cursorTo(0);
1015
+ rl.close();
1016
+ serverConnect();
1017
+ break;
1018
+ case '\u0003': // Ctrl+C
1019
+ process.stdout.write('\n');
1020
+ process.exit();
1021
+ break;
1022
+ default: // Mask the password with "*"
1023
+ args.loginpass += char;
1024
+ process.stdout.clearLine(); process.stdout.cursorTo(0);
1025
+ process.stdout.write('Enter your password: ' + '*'.repeat(args.loginpass.length));
1026
+ break;
1027
+ }
1028
+ });
1029
+ }else{
1030
+ serverConnect();
1031
+ }
1032
+ }
1033
}
1034
1035
function displayConfigHelp() {