live: add additional error checks for shell run

Add checks for invalid arguments and permission errors.
master
Alejandro Sirgo Rica 2024-12-12 11:20:23 +01:00
parent bf15491435
commit 203f3e5533
1 changed files with 8 additions and 0 deletions

View File

@ -381,6 +381,9 @@ class OgLiveOperations:
cmd = request.getrun()
is_inline = request.get_inline()
if not cmd:
raise OgError("No command provided for shell run")
self._restartBrowser(self._url_log)
if is_inline:
@ -389,6 +392,9 @@ class OgLiveOperations:
cmds = shlex.split(cmd)
shell_path = '/opt/opengnsys/shell/'
if not cmds:
raise OgError("Parsed shell command list is empty")
try:
shell_path_files = os.listdir(shell_path)
except OSError as e:
@ -404,6 +410,8 @@ class OgLiveOperations:
else:
raise OgError(f'Script {cmds[0]} not found in {shell_path}')
if not os.path.isfile(cmds[0]) or not os.access(cmds[0], os.X_OK):
raise OgError(f"Command '{cmds[0]}' is not a valid executable")
try:
ogRest.proc = subprocess.Popen(
cmds,