Keep the user in device ID add/remove menus until they select "BACK", optimize menu logic

This commit is contained in:
2024-01-07 16:25:43 -05:00
parent 6789e3e3de
commit 2f7b548360
+39 -33
View File
@@ -339,21 +339,21 @@ def refresh_encryption():
# PORT START WHITELIST-SERVER # PORT START WHITELIST-SERVER
# removes a registered device id from the server-side pool and prunes the quick-unlock whitelist # removes a registered device id from the server-side pool and prunes the quick-unlock whitelist
def registered_dev_id_remover(): def registered_dev_id_remover(_back=False):
_device_ids = listdir(f"{home}/.config/sshyp/devices") _device_ids = listdir(f"{home}/.config/sshyp/devices") + ['BACK']
_whitelisted_ids = listdir(f"{home}/.config/sshyp/whitelist") _whitelisted_ids = listdir(f"{home}/.config/sshyp/whitelist")
while not _back:
_choices = _device_ids + ['BACK'] _del_id = curses_radio(_device_ids, 'registered device id to remove:')
_del_id = curses_radio(_choices, 'registered device id to remove:') if _del_id == len(_device_ids) - 1:
if _del_id == len(_choices)-1: _back = True
return else:
remove(f"{home}/.config/sshyp/devices/{_device_ids[_del_id]}") # remove deleted device id from whitelist
del _device_ids[_del_id] if _device_ids[_del_id] in _whitelisted_ids:
remove(f"{home}/.config/sshyp/whitelist/{_whitelisted_ids[_del_id]}")
# prune deleted device ids from whitelist _whitelisted_ids = [_id for _id in _whitelisted_ids if _id != _device_ids[_del_id]]
for _id in _whitelisted_ids: # remove deleted device id from device pool
if _id not in _device_ids: remove(f"{home}/.config/sshyp/devices/{_device_ids[_del_id]}")
remove(f"{home}/.config/sshyp/whitelist/{_id}") del _device_ids[_del_id]
# takes input from the user to set up quick-unlock pin # takes input from the user to set up quick-unlock pin
@@ -394,27 +394,33 @@ def whitelist_setup():
# adds or removes quick-unlock whitelisted device ids # adds or removes quick-unlock whitelisted device ids
def whitelist_manage(_action): def whitelist_manage(_action, _back=False):
_whitelisted_ids = listdir(f"{home}/.config/sshyp/whitelist") _whitelisted_ids = listdir(f"{home}/.config/sshyp/whitelist") + ['BACK']
_device_ids = listdir(f"{home}/.config/sshyp/devices") _device_ids = listdir(f"{home}/.config/sshyp/devices")
# a value of True indicates adding _unwhitelisted_ids = []
if _action: for _id in _device_ids:
_unwhitelisted_ids = [] if _id not in _whitelisted_ids:
for _id in _device_ids: _unwhitelisted_ids.append(_id)
if _id not in _whitelisted_ids: _unwhitelisted_ids.append('BACK')
_unwhitelisted_ids.append(_id)
_unwhitelisted_ids.append('BACK') while not _back:
_add_id = curses_radio(_unwhitelisted_ids, 'id to add to whitelist:') # _action == True indicates adding
if _add_id == len(_unwhitelisted_ids)-1: if _action:
return _add_id = curses_radio(_unwhitelisted_ids, 'id to add to whitelist:')
open(f"{home}/.config/sshyp/whitelist/{_unwhitelisted_ids[_add_id]}", 'w').write('') if _add_id == len(_unwhitelisted_ids) - 1:
else: _back = True
_whitelisted_choices = _whitelisted_ids + ['BACK'] else:
_del_id = curses_radio(_whitelisted_choices, 'id to remove from whitelist:') open(f"{home}/.config/sshyp/whitelist/{_unwhitelisted_ids[_add_id]}", 'w').write('')
if _del_id == len(_whitelisted_choices)-1: del _unwhitelisted_ids[_add_id]
return # _action == False indicates removing
remove(f"{home}/.config/sshyp/whitelist/{_whitelisted_ids[_del_id]}") else:
_del_id = curses_radio(_whitelisted_ids, 'id to remove from whitelist:')
if _del_id == len(_whitelisted_ids) - 1:
_back = True
else:
remove(f"{home}/.config/sshyp/whitelist/{_whitelisted_ids[_del_id]}")
del _whitelisted_ids[_del_id]
# runs quick-unlock configuration menu # runs quick-unlock configuration menu