mirror of
https://github.com/rwinkhart/sshyp-labs.git
synced 2026-09-06 00:57:19 -04:00
sshyp-mfa - Optimized argument handling
This commit is contained in:
@@ -23,14 +23,14 @@ def totp(_secret, _algo, _digits, _period): # uses provided information to gene
|
|||||||
|
|
||||||
def mfa_read_shortcut(): # reads and extracts MFA info from the user-specified sshyp entry
|
def mfa_read_shortcut(): # reads and extracts MFA info from the user-specified sshyp entry
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
if not Path(f"{directory}{argument}.gpg").exists():
|
if not Path(f"{directory}{arguments[0]}.gpg").exists():
|
||||||
print(f"\n\u001b[38;5;9merror: entry ({argument}) does not exist\u001b[0m\n")
|
print(f"\n\u001b[38;5;9merror: entry ({arguments[0]}) does not exist\u001b[0m\n")
|
||||||
s_exit(1)
|
s_exit(1)
|
||||||
_shm_folder, _shm_entry = shm_gen()
|
_shm_folder, _shm_entry = shm_gen()
|
||||||
if quick_unlock_enabled == 'y':
|
if quick_unlock_enabled == 'y':
|
||||||
decrypt(directory + argument, _shm_folder, _shm_entry, whitelist_verify(port, username_ssh, ip, device_id))
|
decrypt(directory + arguments[0], _shm_folder, _shm_entry, whitelist_verify(port, username_ssh, ip, device_id))
|
||||||
else:
|
else:
|
||||||
decrypt(directory + argument, _shm_folder, _shm_entry, False)
|
decrypt(directory + arguments[0], _shm_folder, _shm_entry, False)
|
||||||
try:
|
try:
|
||||||
_mfa_data = open(f"{path.expanduser('~/.config/sshyp/tmp/')}{_shm_folder}/{_shm_entry}", 'r').readlines()
|
_mfa_data = open(f"{path.expanduser('~/.config/sshyp/tmp/')}{_shm_folder}/{_shm_entry}", 'r').readlines()
|
||||||
_type = _mfa_data[4].split('otpauth://')[1].split('/')[0]
|
_type = _mfa_data[4].split('otpauth://')[1].split('/')[0]
|
||||||
@@ -41,15 +41,15 @@ def mfa_read_shortcut(): # reads and extracts MFA info from the user-specified
|
|||||||
rmtree(f"{path.expanduser('~/.config/sshyp/tmp/')}{_shm_folder}")
|
rmtree(f"{path.expanduser('~/.config/sshyp/tmp/')}{_shm_folder}")
|
||||||
return _type, _secret, _algo, _digits, _period
|
return _type, _secret, _algo, _digits, _period
|
||||||
except IndexError:
|
except IndexError:
|
||||||
print(f"\n\u001b[38;5;9merror: entry ({argument}) does not contain valid mfa data\u001b[0m\n")
|
print(f"\n\u001b[38;5;9merror: entry ({arguments[0]}) does not contain valid mfa data\u001b[0m\n")
|
||||||
rmtree(f"{path.expanduser('~/.config/sshyp/tmp/')}{_shm_folder}")
|
rmtree(f"{path.expanduser('~/.config/sshyp/tmp/')}{_shm_folder}")
|
||||||
s_exit(1)
|
s_exit(1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# argument fetcher
|
# argument fetcher
|
||||||
argument_list = argv
|
arguments = argv[1:]
|
||||||
if not len(argv) == 1 and not argv[1].strip().startswith('/'):
|
if len(arguments) > 0 and not arguments[0].startswith('/'):
|
||||||
print(f"\n\u001b[38;5;9merror: invalid argument - run 'man sshyp-mfa' for usage information\u001b[0m\n")
|
print(f"\n\u001b[38;5;9merror: invalid argument - run 'man sshyp-mfa' for usage information\u001b[0m\n")
|
||||||
s_exit(1)
|
s_exit(1)
|
||||||
|
|
||||||
@@ -64,10 +64,9 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# main process: runs functions to generate MFA key, then continuously copies up-to-date MFA key to clipboard
|
# main process: runs functions to generate MFA key, then continuously copies up-to-date MFA key to clipboard
|
||||||
try:
|
try:
|
||||||
if len(argument_list) == 1:
|
if len(arguments) < 1:
|
||||||
entry_list_gen()
|
entry_list_gen()
|
||||||
argument_list.append(input('entry to read: '))
|
arguments.append(input('entry to read: '))
|
||||||
argument = ' '.join(argument_list[1:]).replace('/', '', 1)
|
|
||||||
mfa_data, copied = mfa_read_shortcut(), None
|
mfa_data, copied = mfa_read_shortcut(), None
|
||||||
print('\nmfa key copied to clipboard\n\nuntil this process is closed, your clipboard will be automatically '
|
print('\nmfa key copied to clipboard\n\nuntil this process is closed, your clipboard will be automatically '
|
||||||
'updated with the newest mfa key')
|
'updated with the newest mfa key')
|
||||||
|
|||||||
Reference in New Issue
Block a user