diff options
Diffstat (limited to 'src/live/ogOperations.py')
-rw-r--r-- | src/live/ogOperations.py | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py index ef18e33..ee83c4a 100644 --- a/src/live/ogOperations.py +++ b/src/live/ogOperations.py @@ -38,8 +38,6 @@ from src.utils.hw_inventory import get_hardware_inventory, legacy_list_hardware_ from src.log import OgError -OG_SHELL = '/bin/bash' - class OgLiveOperations: def __init__(self, config): self._url = config['opengnsys']['url'] @@ -381,32 +379,38 @@ class OgLiveOperations: def shellrun(self, request, ogRest): cmd = request.getrun() - cmds = cmd.split(";|\n\r") + is_inline = request.get_inline() self._restartBrowser(self._url_log) - shell_path = '/opt/opengnsys/shell/' + if is_inline: + cmds = cmd + else: + cmds = shlex.split(cmd) + shell_path = '/opt/opengnsys/shell/' - restricted_mode = False + try: + shell_path_files = os.listdir(shell_path) + except OSError as e: + raise OgError(f'Error accessing {shell_path}: {e}') from e - for file_name in os.listdir(shell_path): - file_path = os.path.join(shell_path, file_name) + for file_name in shell_path_files: + file_path = os.path.join(shell_path, file_name) - if cmds[0] == file_name: - cmds[0] = file_path - restricted_mode = True - break + if cmds[0] == file_name: + cmds[0] = file_path + cmd = " ".join(cmds) + break + else: + raise OgError(f'Script {cmds[0]} not found in {shell_path}') try: - if restricted_mode: - ogRest.proc = subprocess.Popen(cmds, stdout=subprocess.PIPE) - else: - ogRest.proc = subprocess.Popen(cmds, - stdout=subprocess.PIPE, - shell=True, - executable=OG_SHELL) + ogRest.proc = subprocess.Popen( + cmds, + stdout=subprocess.PIPE, + shell=is_inline) (output, error) = ogRest.proc.communicate() - except OSError as e: + except (OSError, subprocess.SubprocessError) as e: raise OgError(f'Error when running "shell run" subprocess: {e}') from e if ogRest.proc.returncode != 0: @@ -416,7 +420,8 @@ class OgLiveOperations: self.refresh(ogRest) - return (ogRest.proc.returncode, " ".join(cmds), output.decode('utf-8')) + output = output.decode('utf-8-sig', errors='replace') + return (ogRest.proc.returncode, cmd, output) def session(self, request, ogRest): disk = request.getDisk() |