mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-08-28 04:46:34 -04:00
Added extension removal functionality
Former-commit-id: ed236f56d17c89a942332c25fb5ae8a45d408750 Former-commit-id: 9f20e5ddeed271363ffd4b7f13d55891f0b67ed2
This commit is contained in:
+38
-25
@@ -373,10 +373,6 @@ def extension_downloader():
|
||||
f"{_pointer.get(_selected, 'usage')}")
|
||||
# if installing the extension...
|
||||
if _choice == 1:
|
||||
# ensure a supported privilege escalation utility is installed before downloading files
|
||||
if which('doas') is None and which('sudo') is None:
|
||||
return "\n\u001b[38;5;9merror: could not escalate privileges - " \
|
||||
"neither 'doas' nor 'sudo' were found\u001b[0m\n", False
|
||||
# download extension files to temporary directory
|
||||
_exe_dir, _ini_dir = f"{gettempdir()}/sshyp_exe", f"{gettempdir()}/sshyp_ini"
|
||||
_ext_exe = urlretrieve(_pointer.get(_selected, 'exe'), _exe_dir)
|
||||
@@ -388,36 +384,45 @@ def extension_downloader():
|
||||
return False, False
|
||||
|
||||
|
||||
# change ownership and install using system commands - requires running outside of curses (text input)
|
||||
def extension_install(_ext_name):
|
||||
from tempfile import gettempdir
|
||||
_exe_dir, _ini_dir = f"{gettempdir()}/sshyp_exe", f"{gettempdir()}/sshyp_ini"
|
||||
# determine which of the supported privilege escalation utilities is installed
|
||||
if which('doas') is not None:
|
||||
_escalator = 'doas'
|
||||
else:
|
||||
# it is assumed at least one of these is installed,
|
||||
# as an error would have been thrown in a previous step, otherwise
|
||||
_escalator = 'sudo'
|
||||
run((_escalator, 'chown', 'root:root', _exe_dir, _ini_dir), check=True)
|
||||
run((_escalator, 'mv', _exe_dir, f"/usr/lib/sshyp/{_ext_name}"), check=True)
|
||||
run((_escalator, 'mv', _ini_dir, f"/usr/lib/sshyp/extensions/{_ext_name}.ini"), check=True)
|
||||
# uninstalls/deletes selected extensions
|
||||
def extension_remover():
|
||||
_installed = []
|
||||
for _extension in listdir('/usr/lib/sshyp/extensions'):
|
||||
_installed.append(_extension[:-4])
|
||||
_choice = curses_radio(_installed, 'select an extension to uninstall')
|
||||
_sure = curses_radio(('no', 'yes'), f"are you sure you want to remove {_installed[_choice]}?")
|
||||
if _sure == 0:
|
||||
return False, False
|
||||
return False, _installed[_choice]
|
||||
|
||||
|
||||
# provides options for managing extensions
|
||||
def extension_menu():
|
||||
_term_message, _ext_name = False, False
|
||||
_term_message, _ext_name, _action = False, False, False
|
||||
# determine which of the supported privilege escalation utilities is installed
|
||||
if which('doas') is not None:
|
||||
_escalator = 'doas'
|
||||
elif which('sudo') is not None:
|
||||
_escalator = 'sudo'
|
||||
else:
|
||||
# throw an error if no supported privilege escalation utility is found
|
||||
return "\n\u001b[38;5;9merror: privilege escalation required\n\n" \
|
||||
"neither 'doas' nor 'sudo' were found in the system's $PATH\u001b[0m\n", False, None, None
|
||||
while True:
|
||||
_choice = curses_radio(('download/update extensions', 'remove extensions', 'exit/done'), 'extension management')
|
||||
if _choice == 0:
|
||||
_term_message, _ext_name = extension_downloader()
|
||||
if _ext_name:
|
||||
# True represents installation
|
||||
_action = True
|
||||
break
|
||||
elif _choice == 1:
|
||||
pass
|
||||
_term_message, _ext_name = extension_remover()
|
||||
if _ext_name:
|
||||
break
|
||||
else:
|
||||
break
|
||||
return _term_message, _ext_name
|
||||
return _term_message, _ext_name, _escalator, _action
|
||||
|
||||
|
||||
# runs secondary configuration menu
|
||||
@@ -484,14 +489,22 @@ def global_menu(_device_type, _top_message):
|
||||
_term_message = '\n\u001b[38;5;9merror: re-encryption failed: ' \
|
||||
'entry directory not found\u001b[0m\n'
|
||||
elif _choice == 7:
|
||||
_term_message, _ext_name = extension_menu()
|
||||
_term_message, _ext_name, _escalator, _action = extension_menu()
|
||||
else:
|
||||
_exit_signal = True
|
||||
curses_terminate(_term_message)
|
||||
# if an extension needs installed...
|
||||
# if root is needed for extension management...
|
||||
if _ext_name:
|
||||
# run escalated installer function outside of curses
|
||||
extension_install(_ext_name)
|
||||
if _action:
|
||||
# install with privilege escalation (outside of curses)
|
||||
from tempfile import gettempdir
|
||||
_exe_dir, _ini_dir = f"{gettempdir()}/sshyp_exe", f"{gettempdir()}/sshyp_ini"
|
||||
run((_escalator, 'chown', 'root:root', _exe_dir, _ini_dir))
|
||||
run((_escalator, 'mv', _exe_dir, f"/usr/lib/sshyp/{_ext_name}"))
|
||||
run((_escalator, 'mv', _ini_dir, f"/usr/lib/sshyp/extensions/{_ext_name}.ini"))
|
||||
else:
|
||||
# uninstall with privilege escalation (outside of curses)
|
||||
run((_escalator, 'rm', '-I', f"/usr/lib/sshyp/{_ext_name}", f"/usr/lib/sshyp/extensions/{_ext_name}.ini"))
|
||||
break
|
||||
except KeyboardInterrupt:
|
||||
curses_terminate(False)
|
||||
|
||||
Reference in New Issue
Block a user