diff --git a/lib/Controller/DaemonConfigController.php b/lib/Controller/DaemonConfigController.php index 04f8dfa2..8f8ebf5e 100644 --- a/lib/Controller/DaemonConfigController.php +++ b/lib/Controller/DaemonConfigController.php @@ -173,10 +173,16 @@ public function startTestDeploy(string $name): Response { return new JSONResponse(['error' => $this->l10n->t('Daemon config not found')], Http::STATUS_NOT_FOUND); } - if (!$this->service->runOccCommand( - sprintf("app_api:app:register --silent %s %s --info-xml %s --test-deploy-mode", - Application::TEST_DEPLOY_APPID, $daemonConfig->getName(), Application::TEST_DEPLOY_INFO_XML) - )) { + $commandParts = [ + 'app_api:app:register', + '--silent', + Application::TEST_DEPLOY_APPID, + $daemonConfig->getName(), + '--info-xml', + Application::TEST_DEPLOY_INFO_XML, + '--test-deploy-mode', + ]; + if (!$this->service->runOccCommand($commandParts)) { return new JSONResponse(['error' => $this->l10n->t('Error starting install of ExApp')], Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -199,7 +205,13 @@ public function startTestDeploy(string $name): Response { public function stopTestDeploy(string $name): Response { $exApp = $this->exAppService->getExApp(Application::TEST_DEPLOY_APPID); if ($exApp !== null) { - $this->service->runOccCommand(sprintf("app_api:app:unregister --silent --force %s", Application::TEST_DEPLOY_APPID)); + $commandParts = [ + 'app_api:app:unregister', + '--silent', + '--force', + Application::TEST_DEPLOY_APPID, + ]; + $this->service->runOccCommand($commandParts); $elapsedTime = 0; while ($elapsedTime < 5000000 && $this->exAppService->getExApp(Application::TEST_DEPLOY_APPID) !== null) { usleep(150000); // 0.15 diff --git a/lib/Controller/ExAppsPageController.php b/lib/Controller/ExAppsPageController.php index ae6fddb7..f60aeecf 100644 --- a/lib/Controller/ExAppsPageController.php +++ b/lib/Controller/ExAppsPageController.php @@ -320,23 +320,32 @@ public function enableApp(string $appId, array $deployOptions = []): JSONRespons $envOptions = isset($deployOptions['environment_variables']) ? array_keys($deployOptions['environment_variables']) : []; - $envOptionsString = ''; + $envArgs = []; foreach ($envOptions as $envOption) { - $envOptionsString .= sprintf(' --env %s=%s', $envOption, $deployOptions['environment_variables'][$envOption]); + $envArgs[] = '--env'; + $envArgs[] = sprintf('%s=%s', $envOption, $deployOptions['environment_variables'][$envOption]); } - $envOptionsString = trim($envOptionsString); $mountOptions = $deployOptions['mounts'] ?? []; - $mountOptionsString = ''; + $mountArgs = []; foreach ($mountOptions as $mountOption) { $readonlyModifier = $mountOption['readonly'] ? 'ro' : 'rw'; - $mountOptionsString .= sprintf(' --mount %s:%s:%s', $mountOption['hostPath'], $mountOption['containerPath'], $readonlyModifier); + $mountArgs[] = '--mount'; + $mountArgs[] = sprintf('%s:%s:%s', $mountOption['hostPath'], $mountOption['containerPath'], $readonlyModifier); } - $mountOptionsString = trim($mountOptionsString); // If ExApp is not registered - then it's a "Deploy and Enable" action. if (!$exApp) { - if (!$this->service->runOccCommand(sprintf("app_api:app:register --silent %s %s %s", $appId, $envOptionsString, $mountOptionsString))) { + $commandParts = array_merge( + [ + 'app_api:app:register', + '--silent', + $appId, + ], + $envArgs, + $mountArgs + ); + if (!$this->service->runOccCommand($commandParts)) { return new JSONResponse(['data' => ['message' => $this->l10n->t('Error starting install of ExApp')]], Http::STATUS_INTERNAL_SERVER_ERROR); } $elapsedTime = 0; @@ -394,7 +403,12 @@ public function updateApp(string $appId): JSONResponse { } $exAppOldVersion = $this->exAppService->getExApp($appId)->getVersion(); - if (!$this->service->runOccCommand(sprintf("app_api:app:update --silent %s", $appId))) { + $commandParts = [ + 'app_api:app:update', + '--silent', + $appId, + ]; + if (!$this->service->runOccCommand($commandParts)) { return new JSONResponse(['data' => ['message' => $this->l10n->t('Error starting update of ExApp')]], Http::STATUS_INTERNAL_SERVER_ERROR); } diff --git a/lib/Service/AppAPIService.php b/lib/Service/AppAPIService.php index 03891131..47d2f0e2 100644 --- a/lib/Service/AppAPIService.php +++ b/lib/Service/AppAPIService.php @@ -426,17 +426,16 @@ public function dispatchExAppInitInternal(ExApp $exApp): void { /** * Dispatch ExApp initialization step, that may take a long time to display the progress of initialization. */ - public function runOccCommand(string $command): bool { - $args = array_map(function ($arg) { - return $arg === '' ? null : escapeshellarg($arg); - }, explode(' ', $command)); - $args = array_filter($args, fn ($arg) => $arg !== null); - $args[] = '--no-ansi --no-warnings'; + public function runOccCommand(array $commandParts): bool { + $args = array_filter($commandParts, static fn ($part) => $part !== null); + $args[] = '--no-ansi'; + $args[] = '--no-warnings'; return $this->runOccCommandInternal($args); } public function runOccCommandInternal(array $args): bool { - $args = implode(' ', $args); + $escapedArgs = array_map('escapeshellarg', $args); + $args = implode(' ', $escapedArgs); $descriptors = [ 0 => ['pipe', 'r'], 1 => ['pipe', 'w'],