From 31992f4d02a13feeeca0529405fbea436ac1bbd6 Mon Sep 17 00:00:00 2001
From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com>
Date: Tue, 21 Jan 2025 18:36:38 +0100
Subject: [PATCH] fix(ui):show error on terminal if container has no shell
(bash/sh)
---
.../Shared/ExecuteContainerCommand.php | 18 +++++
.../execute-container-command.blade.php | 77 +++++++++++--------
.../project/shared/terminal.blade.php | 5 --
3 files changed, 64 insertions(+), 36 deletions(-)
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')
No shell (bash/sh) is available in this container. Please ensure either bash or sh is installed to use the terminal.
+