[+] add qrcode mode for pass ssh osx

This commit is contained in:
Siarhei Siniak 2024-12-05 09:03:22 +03:00
parent a6cdf03523
commit 0a50c26d1d

@ -1392,6 +1392,12 @@ server {
],
)
class pass_ssh_osx_t:
class kwargs_t:
class Mode(enum.StrEnum):
clipboard = 'clipboard'
qrcode = 'qrcode'
def pass_ssh_osx(argv):
assert isinstance(argv, list) and all([isinstance(o, str) for o in argv])
parser = optparse.OptionParser()
@ -1415,6 +1421,17 @@ def pass_ssh_osx(argv):
default=None,
type=str,
)
parser.add_option(
'--mode',
dest='_mode',
choices=[
o.value
for o in pass_ssh_osx_t.kwargs_t.Mode
],
default=None,
help='a mode to retrieve the password',
)
parser.add_option(
'--debug',
dest='debug',
@ -1424,6 +1441,11 @@ def pass_ssh_osx(argv):
assert sys.platform in ['darwin', 'linux']
options, args = parser.parse_args(argv)
if options._mode is None:
options._mode = pass_ssh_osx_t.kwargs_t.Mode.clipboard.value
options.mode = pass_ssh_osx_t.kwargs_t.Mode(options._mode)
if options.clipboard_copy is None:
if sys.platform == 'linux':
options.clipboard_copy = 'wl-copy'
@ -1596,23 +1618,30 @@ def pass_ssh_osx(argv):
assert not password is None
try:
clipboard_set(password)
get_time = lambda : datetime.datetime.now().timestamp()
start = get_time()
while True:
cur = get_time()
remains = 10 - (cur - start)
if remains <= 1e-8:
break
else:
print('\r%5.2fs remains' % remains, end='')
time.sleep(0.1)
except KeyboardInterrupt:
pass
if options.mode is pass_ssh_osx_t.kwargs_t.Mode.clipboard:
try:
clipboard_set(password)
get_time = lambda : datetime.datetime.now().timestamp()
start = get_time()
while True:
cur = get_time()
remains = 10 - (cur - start)
if remains <= 1e-8:
break
else:
print('\r%5.2fs remains' % remains, end='')
time.sleep(0.1)
except KeyboardInterrupt:
pass
clipboard_set('')
print('\rcleared cliboard\n', end='')
clipboard_set('')
print('\rcleared cliboard\n', end='')
elif options.mode is pass_ssh_osx_t.kwargs_t.Mode.qrcode:
assert subprocess.check_call(r'''
qrencode -t PNG -o - | feh -
''', stdin=password, shell=True) == 0
else:
raise NotImplementedError
def vpn(argv: list[str]) -> None:
python_path : list[str]