Remove password masking from admin password prompt
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,6 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import termios
|
import termios
|
||||||
import time
|
import time
|
||||||
import tty
|
|
||||||
import urllib.error
|
import urllib.error
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
@@ -93,40 +92,12 @@ def draw_box(lines: list, colour: str = C.CYN):
|
|||||||
|
|
||||||
|
|
||||||
# ── Input helpers ─────────────────────────────────────────────────────────────
|
# ── Input helpers ─────────────────────────────────────────────────────────────
|
||||||
def prompt(label: str, default: str = "", password: bool = False) -> str:
|
def prompt(label: str, default: str = "") -> str:
|
||||||
display = f" {_c(C.CYN, label)}"
|
display = f" {_c(C.CYN, label)}"
|
||||||
if default:
|
if default:
|
||||||
display += f" {_c(C.DIM, f'[{default}]')}"
|
display += f" {_c(C.DIM, f'[{default}]')}"
|
||||||
display += ": "
|
display += ": "
|
||||||
|
|
||||||
if password:
|
|
||||||
fd = sys.stdin.fileno()
|
|
||||||
old = termios.tcgetattr(fd)
|
|
||||||
try:
|
|
||||||
tty.setraw(fd)
|
|
||||||
sys.stdout.write(display)
|
|
||||||
sys.stdout.flush()
|
|
||||||
chars = []
|
|
||||||
while True:
|
|
||||||
ch = sys.stdin.read(1)
|
|
||||||
if ch in ("\r", "\n"):
|
|
||||||
break
|
|
||||||
elif ch in ("\x7f", "\x08"):
|
|
||||||
if chars:
|
|
||||||
chars.pop()
|
|
||||||
sys.stdout.write("\b \b")
|
|
||||||
sys.stdout.flush()
|
|
||||||
elif ch == "\x03":
|
|
||||||
raise KeyboardInterrupt
|
|
||||||
else:
|
|
||||||
chars.append(ch)
|
|
||||||
sys.stdout.write("*")
|
|
||||||
sys.stdout.flush()
|
|
||||||
print()
|
|
||||||
return "".join(chars)
|
|
||||||
finally:
|
|
||||||
termios.tcsetattr(fd, termios.TCSADRAIN, old)
|
|
||||||
else:
|
|
||||||
sys.stdout.write(display)
|
sys.stdout.write(display)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
val = sys.stdin.readline().strip()
|
val = sys.stdin.readline().strip()
|
||||||
@@ -155,7 +126,6 @@ def prompt_password() -> str:
|
|||||||
while True:
|
while True:
|
||||||
val = prompt(
|
val = prompt(
|
||||||
"Admin password (BMC/chassis serial, e.g. MXE3000043CHA007)",
|
"Admin password (BMC/chassis serial, e.g. MXE3000043CHA007)",
|
||||||
password=True,
|
|
||||||
)
|
)
|
||||||
if val:
|
if val:
|
||||||
return val
|
return val
|
||||||
|
|||||||
Reference in New Issue
Block a user