mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-08-29 05:16:27 -04:00
Use clearer if/elif "in" syntax where applicable
This commit is contained in:
+17
-17
@@ -128,7 +128,7 @@ def pass_gen(): # prompts the user for necessary information to generate a pass
|
||||
else:
|
||||
break
|
||||
_complexity = str(input('password complexity - simple (for compatibility) or complex (for security)? (s/C) '))
|
||||
if _complexity != 's' and _complexity != 'S':
|
||||
if _complexity not in ['s', 'S']:
|
||||
_complexity = 'c'
|
||||
_gen = string_gen(_complexity.lower(), _length)
|
||||
return _gen
|
||||
@@ -154,7 +154,7 @@ def decrypt(_entry_dir, _shm_folder, _shm_entry, _quick_pass,
|
||||
_unlock_method = ['gpg', '--pinentry-mode', 'loopback', '--passphrase', _quick_pass, '-qd', '--output']
|
||||
else:
|
||||
_unlock_method = ['gpg', '-qd', '--output']
|
||||
if _shm_folder == 0 and _shm_entry == 0:
|
||||
if _shm_folder == 0 and _shm_entry == 0: # TODO set to 'None'
|
||||
_output_target = ['/dev/null', expanduser('~/.config/sshyp/lock.gpg')]
|
||||
else:
|
||||
_output_target = [f"{_tmp_dir}{_shm_folder}/{_shm_entry}", f"{_entry_dir}.gpg"]
|
||||
@@ -236,7 +236,7 @@ def tweak(): # runs configuration wizard
|
||||
# config directory creation
|
||||
Path(expanduser('~/.config/sshyp/devices')).mkdir(mode=0o700, parents=True, exist_ok=True)
|
||||
if not Path(f"{expanduser('~/.config/sshyp/tmp')}").exists():
|
||||
if uname()[0] == 'Haiku' or uname()[0] == 'FreeBSD':
|
||||
if uname()[0] in ['Haiku', 'FreeBSD']:
|
||||
symlink('/tmp', expanduser('~/.config/sshyp/tmp'))
|
||||
elif Path("/data/data/com.termux").exists():
|
||||
symlink('/data/data/com.termux/files/usr/tmp', expanduser('~/.config/sshyp/tmp'))
|
||||
@@ -285,13 +285,13 @@ def tweak(): # runs configuration wizard
|
||||
_ssh_gen = (input(f"{_divider}make sure the ssh service on the remote server is running and properly "
|
||||
f"configured\n\nsync support requires a unique ssh key - would you like to have this "
|
||||
f"automatically generated? (Y/n/o(ffline)) "))
|
||||
if _ssh_gen.lower() != 'n' and _ssh_gen.lower() != 'o' and _ssh_gen.lower() != 'offline':
|
||||
if _ssh_gen.lower() not in ['n', 'o', 'offline']:
|
||||
Path(f"{expanduser('~')}/.ssh").mkdir(mode=0o700, exist_ok=True)
|
||||
run(['ssh-keygen', '-t', 'ed25519', '-f', expanduser('~/.ssh/sshyp')])
|
||||
elif _ssh_gen.lower() == 'n':
|
||||
print(f"\n\u001b[4;1mensure that the key file you are using is located at "
|
||||
f"{expanduser('~/.ssh/sshyp')}\u001b[0m")
|
||||
elif _ssh_gen.lower() == 'o' or _ssh_gen.lower() == 'offline':
|
||||
elif _ssh_gen.lower() in ['o', 'offline']:
|
||||
_offline_mode = True
|
||||
print('\nsshyp has been set to offline mode - to enable syncing, run "sshyp tweak" again')
|
||||
|
||||
@@ -347,7 +347,7 @@ def tweak(): # runs configuration wizard
|
||||
|
||||
|
||||
def print_info(): # prints help text based on argument
|
||||
if arguments[0] == 'version' or arguments[0] == '-v':
|
||||
if arguments[0] in ['version', '-v']:
|
||||
print('\nsshyp is a simple, self-hosted, sftp-synchronized password manager\nfor unix(-like) systems (haiku/'
|
||||
'freebsd/linux/termux)\n\nsshyp is a viable alternative to (and compatible with) pass/password-store\n')
|
||||
print(" .. \u001b[38;5;9m♥♥ ♥♥\u001b[0m ..\n .''.''/()\\ \u001b[38;5;13m"
|
||||
@@ -602,7 +602,7 @@ def add_entry(): # adds a new entry
|
||||
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(3)
|
||||
if arguments[arg_start_p] == 'note' or arguments[arg_start_p] == '-n': # note entry
|
||||
if arguments[arg_start_p] in ['note', '-n']: # note entry
|
||||
_shm_folder, _shm_entry = shm_gen()
|
||||
run([editor, f"{tmp_dir}{_shm_folder}/{_shm_entry}-n"])
|
||||
_notes = open(f"{tmp_dir}{_shm_folder}/{_shm_entry}-n", 'r').read()
|
||||
@@ -679,13 +679,13 @@ def edit(): # edits the contents of an entry
|
||||
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':
|
||||
if arguments[arg_start_p] in ['username', '-u']:
|
||||
_detail, _edit_line = str(input('username: ')), 1
|
||||
elif arguments[arg_start_p] == 'password' or arguments[arg_start_p] == '-p':
|
||||
elif arguments[arg_start_p] in ['password', '-p']:
|
||||
_detail, _edit_line = str(input('password: ')), 0
|
||||
elif arguments[arg_start_p] == 'url' or arguments[arg_start_p] == '-l':
|
||||
elif arguments[arg_start_p] in ['url', '-l']:
|
||||
_detail, _edit_line = str(input('url: ')), 2
|
||||
if arguments[arg_start_p] == 'note' or arguments[arg_start_p] == '-n':
|
||||
if arguments[arg_start_p] in ['note', '-n']:
|
||||
_edit_line = 2
|
||||
_new_lines = optimized_edit(edit_note(_shm_folder, _shm_entry,
|
||||
open(f"{tmp_dir}{_shm_folder}/{_shm_entry}", 'r').readlines()), None, -1)
|
||||
@@ -746,13 +746,13 @@ def copy_data(): # copies a specified field of an entry to the clipboard
|
||||
_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
|
||||
if arguments[arg_start_p] == 'username' or arguments[arg_start_p] == '-u':
|
||||
if arguments[arg_start_p] in ['username', '-u']:
|
||||
_index = 1
|
||||
elif arguments[arg_start_p] == 'password' or arguments[arg_start_p] == '-p':
|
||||
elif arguments[arg_start_p] in ['password', '-p']:
|
||||
_index = 0
|
||||
elif arguments[arg_start_p] == 'url' or arguments[arg_start_p] == '-l':
|
||||
elif arguments[arg_start_p] in ['url', '-l']:
|
||||
_index = 2
|
||||
elif arguments[arg_start_p] == 'note' or arguments[arg_start_p] == '-n':
|
||||
elif arguments[arg_start_p] in ['note', '-n']:
|
||||
_index = 3
|
||||
if 'WAYLAND_DISPLAY' in environ: # Wayland clipboard detection
|
||||
run(['wl-copy', _copy_line[_index].rstrip()])
|
||||
@@ -848,7 +848,7 @@ if __name__ == "__main__":
|
||||
if arguments[arg_start_p] in ['note', '-n', 'password', '-p']:
|
||||
success_flag, sync_flag = True, True
|
||||
add_entry()
|
||||
elif arguments[arg_start_p] == 'folder' or arguments[arg_start_p] == '-f':
|
||||
elif arguments[arg_start_p] in ['folder', '-f']:
|
||||
success_flag = 1
|
||||
add_folder()
|
||||
elif arguments[arg_start] == 'edit':
|
||||
@@ -878,7 +878,7 @@ if __name__ == "__main__":
|
||||
success_flag = True
|
||||
whitelist_setup()
|
||||
elif arg_count > 1 and arguments[arg_start] == 'whitelist':
|
||||
if arguments[arg_start_p] == 'list' or arguments[arg_start_p] == '-l':
|
||||
if arguments[arg_start_p] in ['list', '-l']:
|
||||
success_flag = True
|
||||
whitelist_list()
|
||||
elif arguments[arg_start_p] in ['add', 'del']:
|
||||
|
||||
Reference in New Issue
Block a user