From 39dbc1c83daaa499f0a9018cd1032d878b737032 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Tue, 21 Feb 2023 16:58:29 -0500 Subject: [PATCH] Updated help menu for new argument system, adjusted exit codes Former-commit-id: 4c326eb4668fcdb2cacc7b86d800a4f941c4630c [formerly a068d19aeb8d08c6f58497514791edb013ef06c6] Former-commit-id: ed67ead67fc4a23eb11df52a7627d79a09835589 --- extra/manpage | 40 +++++++++++++++++++--------------------- lib/sshync.py | 4 ++-- lib/sshyp.py | 32 ++++++++++++++++---------------- 3 files changed, 37 insertions(+), 39 deletions(-) diff --git a/extra/manpage b/extra/manpage index cf4e252..b114e5c 100644 --- a/extra/manpage +++ b/extra/manpage @@ -1,8 +1,8 @@ -.TH sshyp 1 "14 December 2022" "v1.3.0" "sshyp man page" +.TH sshyp 1 "21 February 2023" "v1.4.0" "sshyp man page" .SH NAME sshyp \- A very simple self-hosted, synchronized password manager for UNIX(-like) systems. Alternative to (and compatible with) pass/password-store. .SH SYNOPSIS -Client Usage: sshyp [option [flag] []] | [/] +Client Usage: sshyp [/] [option [flag]] Server Usage: sshyp [option [flag] []] .SH DESCRIPTION @@ -18,22 +18,22 @@ Reading an existing entry saved as ~/.local/share/sshyp/development/github.gpg: sshyp /development/github Copying the password of an existing entry saved as ~/.local/share/sshyp/financial/bank.gpg: - sshyp copy -p /financial/bank + sshyp /financial/bank copy -p Editing the username of an existing entry saved as ~/.local/share/sshyp/game.gpg: - sshyp edit -u game + sshyp /game edit -u Making a new entry saved as ~/.local/share/sshyp/school/university.gpg using the built-in password generator: - sshyp gen /school/university + sshyp /school/university gen -Creating a note-only entry saved as ~/.local/share/sshyp/notes/testNote.gpg: - sshyp add -n /notes/testNote +Creating a note-only entry saved as ~/.local/share/sshyp/notes/test note.gpg: + sshyp /notes/test\ note add -n Manually syncing entries with the server: sshyp sync Removing an existing folder saved as ~/.local/share/sshyp/social: - sshyp shear social/ + sshyp /social/ shear .SH EXAMPLES (SERVER) Setting up the quick-unlock whitelist: sshyp whitelist setup @@ -41,21 +41,21 @@ Setting up the quick-unlock whitelist: Checking the quick-unlock whitelist status of all registered client devices: sshyp whitelist list -Adding a device with the id "laptop-im|lAoa;&;r&o:ez((g/Dz;EVb.nO_" to the quick-unlock whitelist: +Adding a device with the id 'laptop-im|lAoa;&;r&o:ez((g/Dz;EVb.nO_' to the quick-unlock whitelist: sshyp whitelist add 'laptop-im|lAoa;&;r&o:ez((g/Dz;EVb.nO_' -Removing a device with the id "laptop-im|lAoa;&;r&o:ez((g/Dz;EVb.nO_" from the quick-unlock whitelist: +Removing a device with the id 'laptop-im|lAoa;&;r&o:ez((g/Dz;EVb.nO_' from the quick-unlock whitelist: sshyp whitelist del 'laptop-im|lAoa;&;r&o:ez((g/Dz;EVb.nO_' .SH OPTIONS (CLIENT) - help/--help/-h bring up the help menu + help/-h bring up the help menu version/-v display sshyp version info tweak configure sshyp add add an entry gen generate a new password edit edit an existing entry copy copy details of an entry to your clipboard - shear/-rm delete an existing entry - sync/-s manually sync the entry directory via sshync + shear delete an existing entry + sync manually sync the entry directory via sshync .SH FLAGS (CLIENT) add: password/-p add a password entry @@ -78,7 +78,7 @@ copy: gen: update/-u generate a password for an existing entry .SH OPTIONS (SERVER) - help/--help/-h bring up this menu + help/-h bring up this menu version/-v display sshyp version info tweak configure sshyp whitelist manage the quick-unlock whitelist @@ -113,16 +113,14 @@ Please note that the server setup intentionally does not allow the reading of en .SH EXIT CODES 0 - no error -1 - argument error +1 - configuration error -2 - configuration error +2 - data not found error -3 - data not found error +3 - data already exists error -4 - data already exists error +4 - decryption/encryption error -5 - decryption/encryption error - -6 - server connection error +5 - server connection error .SH AUTHOR Randall Winkhart (https://github.com/rwinkhart) diff --git a/lib/sshync.py b/lib/sshync.py index 0d96cc3..be6e6a5 100755 --- a/lib/sshync.py +++ b/lib/sshync.py @@ -68,7 +68,7 @@ def remote_list_fetch(_user_data): # captures and returns all necessary data fr except CalledProcessError: print('\n\u001b[38;5;9merror: failed to connect to the remote server\u001b[0m\n') _remote_data = '' - s_exit(6) + s_exit(5) _deletion_database = _remote_data[0].strip().splitlines() _folder_database = _remote_data[1].strip().splitlines() _titles_mods = _remote_data[2].strip().splitlines() @@ -119,7 +119,7 @@ def get_profile(_profile_dir): # returns a list of data read from a sshync job except (FileNotFoundError, IndexError): print('\n\u001b[38;5;9merror: the profile does not exist or is corrupted\u001b[0m\n') _profile_data = None - s_exit(3) + s_exit(2) _user = _profile_data[0].rstrip() _ip = _profile_data[1].rstrip() _port = _profile_data[2].rstrip() diff --git a/lib/sshyp.py b/lib/sshyp.py index 4231425..58e2375 100755 --- a/lib/sshyp.py +++ b/lib/sshyp.py @@ -168,10 +168,10 @@ def decrypt(_entry_dir, _shm_folder, _shm_entry, _quick_pass, run(['gpg', '-qd', '--output'] + _output_target, stderr=DEVNULL, check=True) except CalledProcessError: print('\n\u001b[38;5;9merror: could not decrypt - ensure the correct gpg key is present\u001b[0m\n') - s_exit(5) + s_exit(4) else: print('\n\u001b[38;5;9merror: could not decrypt - ensure the correct gpg key is present\u001b[0m\n') - s_exit(5) + s_exit(4) def determine_decrypt(_entry_dir, _shm_folder, _shm_entry): @@ -414,8 +414,8 @@ def print_info(): # prints help text based on argument print('\n\u001b[1msshyp copyright (c) 2021-2023 randall winkhart\u001b[0m\n') print("this is free software, and you are welcome to redistribute it under certain conditions;\nthis program " "comes with absolutely no warranty;\ntype 'sshyp license' for details") - if device_type == 'client': # TODO update for re-order (also man page) - print('\n\u001b[1musage:\u001b[0m sshyp [option [flag] []] | [/]\n') + if device_type == 'client': + print('\n\u001b[1musage:\u001b[0m sshyp [/] [option [flag]]\n') print('\u001b[1moptions:\u001b[0m') print('help/-h bring up this menu') print('version/-v display sshyp version info') @@ -465,7 +465,7 @@ def no_arg(): # displays a list of entries and gives an option to select one fo _entry_name = entry_name_fetch('entry to read: ') if not Path(f"{directory}{_entry_name}.gpg").exists(): print(f"\n\u001b[38;5;9merror: entry ({_entry_name}) does not exist\u001b[0m\n") # TODO display with starting '/' in ALL errors - s_exit(3) + s_exit(2) _shm_folder, _shm_entry = shm_gen() determine_decrypt(directory + _entry_name, _shm_folder, _shm_entry) entry_reader(f"{tmp_dir}{_shm_folder}/{_shm_entry}") @@ -475,7 +475,7 @@ def no_arg(): # displays a list of entries and gives an option to select one fo def read_shortcut(): # shortcut to quickly read an entry if not Path(f"{directory}{arguments[0].replace('/', '', 1)}.gpg").exists(): print(f"\n\u001b[38;5;9merror: entry ({arguments[0].replace('/', '', 1)}) does not exist\u001b[0m\n") - s_exit(3) + s_exit(2) _shm_folder, _shm_entry = shm_gen() determine_decrypt(directory + arguments[0].replace('/', '', 1), _shm_folder, _shm_entry) entry_reader(f"{tmp_dir}{_shm_folder}/{_shm_entry}") @@ -586,7 +586,7 @@ def whitelist_manage(): # adds or removes quick-unlock whitelisted device ids whitelist_list() else: print(f"\n\u001b[38;5;9merror: device id ({_device_id}) is not registered\u001b[0m\n") - s_exit(2) + s_exit(1) elif Path(expanduser(f"~/.config/sshyp/whitelist/{_device_id}")).is_file(): remove(expanduser(f"~/.config/sshyp/whitelist/{_device_id}")) @@ -601,7 +601,7 @@ def add_entry(): # adds a new entry _entry_name = entry_name_fetch() if Path(f"{directory}{_entry_name}.gpg").is_file(): print(f"\n\u001b[38;5;9merror: entry ({_entry_name}) already exists\u001b[0m\n") - s_exit(4) + s_exit(3) if arguments[arg_start_p] == 'note' or arguments[arg_start_p] == '-n': # note entry _shm_folder, _shm_entry = shm_gen() run([editor, f"{tmp_dir}{_shm_folder}/{_shm_entry}-n"]) @@ -645,11 +645,11 @@ def rename(): # renames an entry or folder _entry_name = entry_name_fetch() if not Path(f"{directory}{_entry_name}.gpg").is_file() and not Path(f"{directory}{_entry_name}").is_dir(): print(f"\n\u001b[38;5;9merror: entry ({_entry_name}) does not exist\u001b[0m\n") - s_exit(3) + s_exit(2) _new_name = entry_name_fetch('new name: ') if Path(f"{directory}{_new_name}.gpg").is_file() or Path(f"{directory}{_new_name}").is_dir(): print(f"\n\u001b[38;5;9merror: ({_new_name}) already exists\u001b[0m\n") - s_exit(4) + s_exit(3) if _entry_name.endswith('/'): if not ssh_error: Path(f"{directory}{_new_name}").mkdir(mode=0o700, parents=True, exist_ok=True) @@ -676,7 +676,7 @@ def edit(): # edits the contents of an entry _entry_name = entry_name_fetch() if not Path(f"{directory}{_entry_name}.gpg").is_file(): print(f"\n\u001b[38;5;9merror: entry ({_entry_name}) does not exist\u001b[0m\n") - s_exit(3) + s_exit(2) _shm_folder, _shm_entry = shm_gen() determine_decrypt(directory + _entry_name, _shm_folder, _shm_entry) if arguments[arg_start_p] == 'username' or arguments[arg_start_p] == '-u': @@ -706,11 +706,11 @@ def gen(): # generates a password for a new or an existing entry _entry_name = entry_name_fetch() if (arg_count > 2) and not Path(f"{directory}{_entry_name}.gpg").is_file(): print(f"\n\u001b[38;5;9merror: entry ({_entry_name}) does not exist\u001b[0m\n") - s_exit(3) + s_exit(2) if arg_count < 2 or (arg_start == 1 and arg_count < 3): if Path(f"{directory}{_entry_name}.gpg").is_file(): print(f"\n\u001b[38;5;9merror: entry ({_entry_name}) already exists\u001b[0m\n") - s_exit(4) + s_exit(3) _username = str(input('username: ')) _password = pass_gen() _url = str(input('url: ')) @@ -742,7 +742,7 @@ def copy_data(): # copies a specified field of an entry to the clipboard _entry_name = entry_name_fetch() if not Path(f"{directory}{_entry_name}.gpg").is_file(): print(f"\n\u001b[38;5;9merror: entry ({_entry_name}) does not exist\u001b[0m\n") - s_exit(3) + s_exit(2) _shm_folder, _shm_entry = shm_gen() determine_decrypt(directory + _entry_name, _shm_folder, _shm_entry) _copy_line, _index = open(f"{tmp_dir}{_shm_folder}/{_shm_entry}", 'r').readlines(), 0 @@ -826,7 +826,7 @@ if __name__ == "__main__": print('\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') print("not all necessary configuration files are present - please run 'sshyp tweak'") print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n') - s_exit(2) + s_exit(1) else: success_flag = 1 tweak() @@ -842,7 +842,7 @@ if __name__ == "__main__": copy_data() except IndexError: print(f"\n\u001b[38;5;9merror: field does not exist in entry\u001b[0m\n") - s_exit(3) + s_exit(2) elif arguments[arg_start] == 'add': if arguments[arg_start_p] == 'note' or arguments[arg_start_p] == '-n' or arguments[arg_start_p] == \ 'password' or arguments[arg_start_p] == '-p':