diff --git a/app/Livewire/Project/Shared/ExecuteContainerCommand.php b/app/Livewire/Project/Shared/ExecuteContainerCommand.php index 90419caed..574dfa969 100644 --- a/app/Livewire/Project/Shared/ExecuteContainerCommand.php +++ b/app/Livewire/Project/Shared/ExecuteContainerCommand.php @@ -52,6 +52,7 @@ class ExecuteContainerCommand extends Component $this->servers = $this->servers->push($server); } } + $this->loadContainers(); } elseif (data_get($this->parameters, 'database_uuid')) { $this->type = 'database'; $resource = getResourceByUuid($this->parameters['database_uuid'], data_get(auth()->user()->currentTeam(), 'id')); @@ -62,12 +63,18 @@ class ExecuteContainerCommand extends Component if ($this->resource->destination->server->isFunctional()) { $this->servers = $this->servers->push($this->resource->destination->server); } + $this->loadContainers(); } elseif (data_get($this->parameters, 'service_uuid')) { $this->type = 'service'; $this->resource = Service::where('uuid', $this->parameters['service_uuid'])->firstOrFail(); if ($this->resource->server->isFunctional()) { $this->servers = $this->servers->push($this->resource->server); } + $this->loadContainers(); + } elseif (data_get($this->parameters, 'server_uuid')) { + $this->type = 'server'; + $this->resource = Server::where('uuid', $this->parameters['server_uuid'])->firstOrFail(); + $this->server = $this->resource; } } @@ -130,6 +137,28 @@ 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'); + } + } + + #[On('connectToServer')] + public function connectToServer() + { + try { + if ($this->server->isForceDisabled()) { + throw new \RuntimeException('Server is disabled.'); + } + $this->dispatch( + 'send-terminal-command', + false, + data_get($this->server, 'name'), + data_get($this->server, 'uuid') + ); + + } catch (\Throwable $e) { + return handleError($e, $this); + } } #[On('connectToContainer')] diff --git a/app/Models/Server.php b/app/Models/Server.php index 64c495fec..4ad034d7e 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -131,6 +131,11 @@ class Server extends BaseModel protected $guarded = []; + + public function type() + { + return 'server'; + } public static function isReachable() { return Server::ownedByCurrentTeam()->whereRelation('settings', 'is_reachable', true); diff --git a/resources/views/components/server/navbar.blade.php b/resources/views/components/server/navbar.blade.php index a7033775a..ff28cdbdf 100644 --- a/resources/views/components/server/navbar.blade.php +++ b/resources/views/components/server/navbar.blade.php @@ -39,6 +39,12 @@ ]) }}"> + + +
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 927e795ec..cb39e0855 100644 --- a/resources/views/livewire/project/shared/execute-container-command.blade.php +++ b/resources/views/livewire/project/shared/execute-container-command.blade.php @@ -2,24 +2,36 @@ {{ data_get_str($resource, 'name')->limit(10) }} > Commands | Coolify - @if ($type === 'application') +

Terminal

@elseif ($type === 'database') +

Terminal

@elseif ($type === 'service') + + @elseif ($type === 'server') + @endif -
-
- Loading resources... + @if ($type === 'server') +
+ Reconnect +
+
+
-
- @if (count($containers) > 0) -
+ @else + @if (count($containers) > 0) + @if (count($containers) === 1) + + Reconnect +
+ @else +
@foreach ($containers as $container) @if ($loop->first) @@ -31,14 +43,16 @@ @endforeach - Connect + + Connect +
- @else -
No containers are running.
@endif -
-
-
- -
+
+ +
+ @else +
No containers are running.
+ @endif + @endif
diff --git a/routes/web.php b/routes/web.php index 339987bc9..eb1480b9f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -212,6 +212,7 @@ Route::middleware(['auth', 'verified'])->group(function () { Route::get('/private-key', PrivateKeyShow::class)->name('server.private-key'); Route::get('/destinations', DestinationShow::class)->name('server.destinations'); Route::get('/log-drains', LogDrains::class)->name('server.log-drains'); + Route::get('/terminal', ExecuteContainerCommand::class)->name('server.command'); }); // Route::get('/security', fn () => view('security.index'))->name('security.index');