Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

refactor(ui): terminal

Andras Bacsaif7daddce5867
diff --git a/app/Livewire/Project/Shared/ExecuteContainerCommand.php b/app/Livewire/Project/Shared/ExecuteContainerCommand.php
index 97131c75ca..ca1597d4f0 100644
--- a/app/Livewire/Project/Shared/ExecuteContainerCommand.php
+++ b/app/Livewire/Project/Shared/ExecuteContainerCommand.php
@@ -13,8 +13,6 @@ class ExecuteContainerCommand extends Component
{
public $selected_container = 'default';
- public $container;
-
public Collection $containers;
public $parameters;
@@ -23,13 +21,9 @@ class ExecuteContainerCommand extends Component
public string $type;
- public Server $server;
-
public Collection $servers;
- public bool $hasShell = true;
-
- public bool $isConnecting = true;
+ public bool $isConnecting = false;
protected $rules = [
'server' => 'required',
@@ -78,8 +72,9 @@ class ExecuteContainerCommand extends Component
} elseif (data_get($this->parameters, 'server_uuid')) {
$this->type = 'server';
$this->resource = Server::where('uuid', $this->parameters['server_uuid'])->firstOrFail();
- $this->server = $this->resource;
+ $this->servers = $this->servers->push($this->resource);
}
+ $this->servers = $this->servers->sortByDesc(fn ($server) => $server->isTerminalEnabled());
}
public function loadContainers()
@@ -97,7 +92,7 @@ class ExecuteContainerCommand extends Component
}
foreach ($containers as $container) {
// if container state is running
- if (data_get($container, 'State') === 'running') {
+ if (data_get($container, 'State') === 'running' && $server->isTerminalEnabled()) {
$payload = [
'server' => $server,
'container' => $container,
@@ -106,7 +101,7 @@ class ExecuteContainerCommand extends Component
}
}
} elseif (data_get($this->parameters, 'database_uuid')) {
- if ($this->resource->isRunning()) {
+ if ($this->resource->isRunning() && $server->isTerminalEnabled()) {
$this->containers = $this->containers->push([
'server' => $server,
'container' => [
@@ -116,7 +111,7 @@ class ExecuteContainerCommand extends Component
}
} elseif (data_get($this->parameters, 'service_uuid')) {
$this->resource->applications()->get()->each(function ($application) {
- if ($application->isRunning()) {
+ if ($application->isRunning() && $this->resource->server->isTerminalEnabled()) {
$this->containers->push([
'server' => $this->resource->server,
'container' => [
@@ -137,41 +132,24 @@ class ExecuteContainerCommand extends Component
});
}
}
- if ($this->containers->count() > 0) {
- $this->container = $this->containers->first();
- }
if ($this->containers->count() === 1) {
$this->selected_container = data_get($this->containers->first(), 'container.Names');
}
}
- 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('connectToServer')]
public function connectToServer()
{
try {
- if ($this->server->isForceDisabled()) {
+ $server = $this->servers->first();
+ if ($server->isForceDisabled()) {
throw new \RuntimeException('Server is disabled.');
}
$this->dispatch(
'send-terminal-command',
false,
- data_get($this->server, 'name'),
- data_get($this->server, 'uuid')
+ data_get($server, 'name'),
+ data_get($server, 'uuid')
);
} catch (\Throwable $e) {
return handleError($e, $this);
@@ -222,11 +200,6 @@ 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/app/Livewire/Project/Shared/Terminal.php b/app/Livewire/Project/Shared/Terminal.php
index 52b2095299..819d364e29 100644
--- a/app/Livewire/Project/Shared/Terminal.php
+++ b/app/Livewire/Project/Shared/Terminal.php
@@ -45,7 +45,7 @@ class Terminal extends Component
{
$server = Server::ownedByCurrentTeam()->whereUuid($serverUuid)->firstOrFail();
if (! $server->isTerminalEnabled() || $server->isForceDisabled()) {
- throw new \RuntimeException('Terminal access is disabled on this server.');
+ abort(403, 'Terminal access is disabled on this server.');
}
if ($isContainer) {
diff --git a/resources/js/terminal.js b/resources/js/terminal.js
index d556baaf10..10535f3ea1 100644
--- a/resources/js/terminal.js
+++ b/resources/js/terminal.js
@@ -514,7 +514,6 @@ export function initializeTerminalComponent() {
const currentRows = this.term.rows;
if (cols !== currentCols || rows !== currentRows) {
- console.log(`[Terminal] Resizing terminal: ${currentCols}x${currentRows} -> ${cols}x${rows}`);
this.term.resize(cols, rows);
this.sendMessage({
resize: { cols: cols, rows: rows }
diff --git a/resources/views/livewire/project/application/configuration.blade.php b/resources/views/livewire/project/application/configuration.blade.php
index b907117e3e..bf169077ce 100644
--- a/resources/views/livewire/project/application/configuration.blade.php
+++ b/resources/views/livewire/project/application/configuration.blade.php
@@ -6,7 +6,7 @@
<livewire:project.shared.configuration-checker :resource="$application" />
<livewire:project.application.heading :application="$application" />
- <div class="flex flex-col h-full gap-8 pt-6 sm:flex-row">
+ <div class="flex flex-col h-full gap-8 sm:flex-row">
<div class="flex flex-col items-start gap-2 min-w-fit">
<a class='menu-item' wire:current.exact="menu-item-active"
href="{{ route('project.application.configuration', ['project_uuid' => $project->uuid, 'environment_uuid' => $environment->uuid, 'application_uuid' => $application->uuid]) }}">General</a>
diff --git a/resources/views/livewire/project/application/heading.blade.php b/resources/views/livewire/project/application/heading.blade.php
index 6b5c33cdbf..bc568bfe3b 100644
--- a/resources/views/livewire/project/application/heading.blade.php
+++ b/resources/views/livewire/project/application/heading.blade.php
@@ -1,4 +1,4 @@
-<nav wire:poll.10000ms="checkStatus">
+<nav wire:poll.10000ms="checkStatus" class="pb-6">
<x-resources.breadcrumbs :resource="$application" :parameters="$parameters" :title="$lastDeploymentInfo" :lastDeploymentLink="$lastDeploymentLink" />
<div class="navbar-main">
<nav class="flex shrink-0 gap-6 items-center whitespace-nowrap scrollbar min-h-10">
diff --git a/resources/views/livewire/project/database/configuration.blade.php b/resources/views/livewire/project/database/configuration.blade.php
index f968acacd9..5e16004614 100644
--- a/resources/views/livewire/project/database/configuration.blade.php
+++ b/resources/views/livewire/project/database/configuration.blade.php
@@ -5,7 +5,7 @@
<h1>Configuration</h1>
<livewire:project.shared.configuration-checker :resource="$database" />
<livewire:project.database.heading :database="$database" />
- <div class="flex flex-col h-full gap-8 pt-6 sm:flex-row">
+ <div class="flex flex-col h-full gap-8 sm:flex-row">
<div class="flex flex-col items-start gap-2 min-w-fit">
<a class='menu-item' wire:current.exact="menu-item-active"
href="{{ route('project.database.configuration', ['project_uuid' => $project->uuid, 'environment_uuid' => $environment->uuid, 'database_uuid' => $database->uuid]) }}">General</a>
diff --git a/resources/views/livewire/project/database/heading.blade.php b/resources/views/livewire/project/database/heading.blade.php
index 8ecbaba44a..43fa44eca5 100644
--- a/resources/views/livewire/project/database/heading.blade.php
+++ b/resources/views/livewire/project/database/heading.blade.php
@@ -1,4 +1,4 @@
-<nav wire:poll.10000ms="checkStatus">
+<nav wire:poll.10000ms="checkStatus" class="pb-6">
<x-resources.breadcrumbs :resource="$database" :parameters="$parameters" />
<x-slide-over @startdatabase.window="slideOverOpen = true" closeWithX fullScreen>
<x-slot:title>Database Startup</x-slot:title>
diff --git a/resources/views/livewire/project/service/configuration.blade.php b/resources/views/livewire/project/service/configuration.blade.php
index abb7229c6f..94f0bd4442 100644
--- a/resources/views/livewire/project/service/configuration.blade.php
+++ b/resources/views/livewire/project/service/configuration.blade.php
@@ -4,7 +4,7 @@
</x-slot>
<livewire:project.service.heading :service="$service" :parameters="$parameters" :query="$query" />
- <div class="flex flex-col h-full gap-8 pt-6 sm:flex-row">
+ <div class="flex flex-col h-full gap-8 sm:flex-row">
<div class="flex flex-col items-start gap-2 min-w-fit">
<a class="menu-item sm:min-w-fit" target="_blank" href="{{ $service->documentation() }}">Documentation
<x-external-link /></a>
diff --git a/resources/views/livewire/project/service/heading.blade.php b/resources/views/livewire/project/service/heading.blade.php
index 2bd3925999..c13ca59b7f 100644
--- a/resources/views/livewire/project/service/heading.blade.php
+++ b/resources/views/livewire/project/service/heading.blade.php
@@ -1,4 +1,4 @@
-<div wire:poll.10000ms="checkStatus">
+<div wire:poll.10000ms="checkStatus" class="pb-6">
<livewire:project.shared.configuration-checker :resource="$service" />
<x-slide-over @startservice.window="slideOverOpen = true" closeWithX fullScreen>
<x-slot:title>Service Startup</x-slot:title>
diff --git a/resources/views/livewire/project/service/index.blade.php b/resources/views/livewire/project/service/index.blade.php
index 36d934e939..99f126391b 100644
--- a/resources/views/livewire/project/service/index.blade.php
+++ b/resources/views/livewire/project/service/index.blade.php
@@ -1,6 +1,6 @@
<div x-data="{ activeTab: window.location.hash ? window.location.hash.substring(1) : 'general' }">
<livewire:project.service.heading :service="$service" :parameters="$parameters" :query="$query" />
- <div class="flex flex-col h-full gap-8 pt-6 sm:flex-row">
+ <div class="flex flex-col h-full gap-8 sm:flex-row">
<div class="flex flex-col items-start gap-2 min-w-fit">
<a class="menu-item"
class="{{ request()->routeIs('project.service.configuration') ? 'menu-item-active' : '' }}"
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 ff0cf619ce..afb7ced2f5 100644
--- a/resources/views/livewire/project/shared/execute-container-command.blade.php
+++ b/resources/views/livewire/project/shared/execute-container-command.blade.php
@@ -13,69 +13,51 @@
@elseif ($type === 'service')
<livewire:project.shared.configuration-checker :resource="$resource" />
<livewire:project.service.heading :service="$resource" :parameters="$parameters" title="Terminal" />
- @elseif ($type === 'server')
- <livewire:server.navbar :server="$server" />
@endif
- @if (!$hasShell)
- <div class="flex items-center justify-center w-full py-4 mx-auto">
- <div class="p-4 w-full rounded border dark:bg-coolgray-100 dark:border-coolgray-300">
- <div class="flex flex-col items-center justify-center space-y-4">
- <svg class="w-12 h-12 text-red-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
- d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
- </svg>
- <div class="text-center">
- <h3 class="text-lg font-medium">Terminal Not Available</h3>
- <p class="mt-2 text-sm text-gray-500">No shell (bash/sh) is available in this container. Please
- ensure either bash or sh is installed to use the terminal.</p>
- </div>
- </div>
+ @if ($type === 'application' || $type === 'database' || $type === 'service')
+ <h2 class="pb-4">Terminal</h2>
+ @if (count($containers) === 0)
+ <div>No containers are running or terminal access is disabled on this server.</div>
+ @else
+ @foreach ($containers as $container)
+ <form class="w-full flex gap-2 items-end" wire:submit="$dispatchSelf('connectToContainer')">
+ <x-forms.select label="Container" id="container" required wire:model="selected_container">
+ @foreach ($containers as $container)
+ @if ($loop->first)
+ <option disabled value="default">Select a container</option>
+ @endif
+ <option value="{{ data_get($container, 'container.Names') }}">
+ {{ data_get($container, 'container.Names') }}
+ ({{ data_get($container, 'server.name') }})
+ </option>
+ @endforeach
+ </x-forms.select>
+ <x-forms.button :disabled="$isConnecting"
+ type="submit">{{ $isConnecting ? 'Connecting...' : 'Connect' }}</x-forms.button>
+ </form>
+ @endforeach
+ <div class="mx-auto w-full">
+ <livewire:project.shared.terminal />
</div>
- </div>
- @else
- @if ($type === 'server')
+ @endif
+ @endif
+
+ @if ($type === 'server')
+ <livewire:server.navbar :server="$servers->first()" />
+ <h2 class="pb-4">Terminal</h2>
+ @if ($servers->first()->isTerminalEnabled())
<form class="w-full flex gap-2 items-start" wire:submit="$dispatchSelf('connectToServer')"
wire:init="$dispatchSelf('connectToServer')">
<h2 class="pb-4">Terminal</h2>
<x-forms.button :disabled="$isConnecting"
- type="submit">{{ $isConnecting ? 'Connecting...' : 'Reconnect' }}</x-forms.button>
+ type="submit">{{ $isConnecting ? 'Connecting...' : 'Connect' }}</x-forms.button>
</form>
<div class="mx-auto w-full">
<livewire:project.shared.terminal />
</div>
@else
- @if (count($containers) === 0)
- <div class="pt-4">No containers are running.</div>
- @else
- @if (count($containers) === 1)
- <form class="w-full flex gap-2 items-start pt-4" wire:submit="$dispatchSelf('connectToContainer')"
- wire:init="$dispatchSelf('connectToContainer')">
- <h2 class="pb-4">Terminal</h2>
- <x-forms.button :disabled="$isConnecting"
- type="submit">{{ $isConnecting ? 'Connecting...' : 'Reconnect' }}</x-forms.button>
- </form>
- @else
- <form class="w-full pt-4 flex gap-2 flex-col" wire:submit="$dispatchSelf('connectToContainer')">
- <x-forms.select label="Container" id="container" required wire:model="selected_container">
- @foreach ($containers as $container)
- @if ($loop->first)
- <option disabled value="default">Select a container</option>
- @endif
- <option value="{{ data_get($container, 'container.Names') }}">
- {{ data_get($container, 'container.Names') }}
- ({{ data_get($container, 'server.name') }})
- </option>
- @endforeach
- </x-forms.select>
- <x-forms.button :disabled="$isConnecting" class="w-full"
- type="submit">{{ $isConnecting ? 'Connecting...' : 'Connect' }}</x-forms.button>
- </form>
- @endif
- <div class="mx-auto w-full">
- <livewire:project.shared.terminal />
- </div>
- @endif
+ <div>Terminal access is disabled on this server.</div>
@endif
@endif
</div>
diff --git a/resources/views/livewire/server/navbar.blade.php b/resources/views/livewire/server/navbar.blade.php
index 334e1922c7..0b843aba0a 100644
--- a/resources/views/livewire/server/navbar.blade.php
+++ b/resources/views/livewire/server/navbar.blade.php
@@ -55,7 +55,7 @@
<div class="subtitle">{{ data_get($server, 'name') }}</div>
<div class="navbar-main">
<nav
- class="flex items-center gap-6 overflow-x-scroll sm:overflow-x-hidden scrollbar min-h-10 whitespace-nowrap">
+ class="flex items-center gap-6 overflow-x-scroll sm:overflow-x-hidden scrollbar min-h-10 whitespace-nowrap pt-2">
<a class="{{ request()->routeIs('server.show') ? 'dark:text-white' : '' }}"
href="{{ route('server.show', [
'server_uuid' => data_get($server, 'uuid'),