From 0a50c26d1d9e7a3cdaad941fb9e708703a62acfa Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Thu, 5 Dec 2024 09:03:22 +0300 Subject: [PATCH] [+] add qrcode mode for pass ssh osx --- python/online/fxreader/pr34/commands.py | 61 ++++++++++++++++++------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/python/online/fxreader/pr34/commands.py b/python/online/fxreader/pr34/commands.py index 679820c..7364cc7 100644 --- a/python/online/fxreader/pr34/commands.py +++ b/python/online/fxreader/pr34/commands.py @@ -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]