feat(terminal): show terminal unavailable if the container does not have a shell on the global terminal UI
This commit is contained in:
@@ -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'");
|
||||
|
||||
Reference in New Issue
Block a user