diff --git a/app/Livewire/Project/Shared/Terminal.php b/app/Livewire/Project/Shared/Terminal.php index d8f101277..a3d1aa10f 100644 --- a/app/Livewire/Project/Shared/Terminal.php +++ b/app/Livewire/Project/Shared/Terminal.php @@ -9,6 +9,8 @@ use Livewire\Component; class Terminal extends Component { + public bool $hasShell = true; + public function getListeners() { $teamId = auth()->user()->currentTeam()->id; @@ -23,6 +25,21 @@ class Terminal extends Component $this->dispatch('reloadWindow'); } + private function checkShellAvailability(Server $server, string $container): bool + { + $escapedContainer = escapeshellarg($container); + try { + instant_remote_process([ + "docker exec {$escapedContainer} bash -c 'exit 0' 2>/dev/null || ". + "docker exec {$escapedContainer} sh -c 'exit 0' 2>/dev/null", + ], $server); + + return true; + } catch (\Throwable) { + return false; + } + } + #[On('send-terminal-command')] public function sendTerminalCommand($isContainer, $identifier, $serverUuid) { @@ -40,6 +57,12 @@ class Terminal extends Component return; } + // Check shell availability + $this->hasShell = $this->checkShellAvailability($server, $identifier); + if (! $this->hasShell) { + return; + } + // Escape the identifier for shell usage $escapedIdentifier = escapeshellarg($identifier); $command = SshMultiplexingHelper::generateSshCommand($server, "docker exec -it {$escapedIdentifier} sh -c 'PATH=\$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin && if [ -f ~/.profile ]; then . ~/.profile; fi && if [ -n \"\$SHELL\" ]; then exec \$SHELL; else sh; fi'"); diff --git a/resources/views/livewire/project/shared/terminal.blade.php b/resources/views/livewire/project/shared/terminal.blade.php index edf870ca7..f35624b60 100644 --- a/resources/views/livewire/project/shared/terminal.blade.php +++ b/resources/views/livewire/project/shared/terminal.blade.php @@ -1,23 +1,39 @@
-
-
- - -
+ @if(!$hasShell) +
+
+
+ + + +
+

Terminal Not Available

+

No shell (bash/sh) is available in this container. Please ensure either bash or sh is installed to use the terminal.

+
+
+
+
+ @else +
+
+ + +
+ @endif @script