diff --git a/app/Livewire/Project/Shared/ExecuteContainerCommand.php b/app/Livewire/Project/Shared/ExecuteContainerCommand.php index d12d8e26a..f993480c7 100644 --- a/app/Livewire/Project/Shared/ExecuteContainerCommand.php +++ b/app/Livewire/Project/Shared/ExecuteContainerCommand.php @@ -27,6 +27,8 @@ class ExecuteContainerCommand extends Component public Collection $servers; + public bool $hasShell = true; + protected $rules = [ 'server' => 'required', 'container' => 'required', @@ -141,6 +143,16 @@ class ExecuteContainerCommand extends Component } } + private function checkShellAvailability(Server $server, string $container): bool + { + $escapedContainer = escapeshellarg($container); + $result = instant_remote_process([ + "docker exec {$escapedContainer} which bash || docker exec {$escapedContainer} which sh", + ], $server, false); + + return ! empty($result); + } + #[On('connectToServer')] public function connectToServer() { @@ -148,6 +160,7 @@ class ExecuteContainerCommand extends Component if ($this->server->isForceDisabled()) { throw new \RuntimeException('Server is disabled.'); } + $this->hasShell = true; $this->dispatch( 'send-terminal-command', false, @@ -201,6 +214,11 @@ class ExecuteContainerCommand extends Component throw new \RuntimeException('Server ownership verification failed.'); } + $this->hasShell = $this->checkShellAvailability($server, data_get($container, 'container.Names')); + if (! $this->hasShell) { + return; + } + $this->dispatch( 'send-terminal-command', true, diff --git a/resources/views/livewire/project/shared/execute-container-command.blade.php b/resources/views/livewire/project/shared/execute-container-command.blade.php index f9760ed65..b6a559927 100644 --- a/resources/views/livewire/project/shared/execute-container-command.blade.php +++ b/resources/views/livewire/project/shared/execute-container-command.blade.php @@ -16,43 +16,58 @@ @elseif ($type === 'server') @endif - @if ($type === 'server') -
- Reconnect -
-
- + + @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 - @if (count($containers) > 0) - @if (count($containers) === 1) -
- Reconnect -
- @else -
- - @foreach ($containers as $container) - @if ($loop->first) - - @endif - - @endforeach - - - Connect - -
- @endif + @if ($type === 'server') +
+ Reconnect +
@else -
No containers are running.
+ @if (count($containers) === 0) +
No containers are running.
+ @else + @if (count($containers) === 1) +
+ Reconnect +
+ @else +
+ + @foreach ($containers as $container) + @if ($loop->first) + + @endif + + @endforeach + + Connect +
+ @endif +
+ +
+ @endif @endif @endif
diff --git a/resources/views/livewire/project/shared/terminal.blade.php b/resources/views/livewire/project/shared/terminal.blade.php index 26388cc0d..edf870ca7 100644 --- a/resources/views/livewire/project/shared/terminal.blade.php +++ b/resources/views/livewire/project/shared/terminal.blade.php @@ -1,9 +1,4 @@
- {{--
-
- -
-
--}}