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.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
refactor: terminal / run command
Andras Bacsai8967315c49be
diff --git a/app/Livewire/RunCommand.php b/app/Livewire/RunCommand.phpdeleted file mode 100644index 3650f2e41a..0000000000--- a/app/Livewire/RunCommand.php+++ /dev/null@@ -1,71 +0,0 @@-<?php--namespace App\Livewire;--use App\Models\Server;-use Livewire\Attributes\On;-use Livewire\Component;--class RunCommand extends Component-{- public $selected_uuid = 'default';-- public $servers = [];-- public $containers = [];-- public function mount()- {- if (! auth()->user()->isAdmin()) {- abort(403);- }- $this->servers = Server::isReachable()->get();- $this->containers = $this->getAllActiveContainers();- }-- private function getAllActiveContainers()- {- return collect($this->servers)->flatMap(function ($server) {- if (! $server->isFunctional()) {- return [];- }-- return $server->loadAllContainers()->map(function ($container) use ($server) {- $state = data_get_str($container, 'State')->lower();- if ($state->contains('running')) {- return [- 'name' => data_get($container, 'Names'),- 'connection_name' => data_get($container, 'Names'),- 'uuid' => data_get($container, 'Names'),- 'status' => data_get_str($container, 'State')->lower(),- 'server' => $server,- 'server_uuid' => $server->uuid,- ];- }-- return null;- })->filter();- });- }-- public function updatedSelectedUuid()- {- $this->connectToContainer();- }-- #[On('connectToContainer')]- public function connectToContainer()- {- if ($this->selected_uuid === 'default') {- $this->dispatch('error', 'Please select a server or a container.');-- return;- }- $container = collect($this->containers)->firstWhere('uuid', $this->selected_uuid);- $this->dispatch('send-terminal-command',- isset($container),- $container['connection_name'] ?? $this->selected_uuid,- $container['server_uuid'] ?? $this->selected_uuid- );- }-}diff --git a/app/Livewire/Terminal/Index.php b/app/Livewire/Terminal/Index.phpindex 8c59bdcbf6..945b25714e 100644--- a/app/Livewire/Terminal/Index.php+++ b/app/Livewire/Terminal/Index.php@@ -2,10 +2,73 @@namespace App\Livewire\Terminal;+use App\Models\Server;+use Livewire\Attributes\On;use Livewire\Component;class Index extends Component{+ public $selected_uuid = 'default';++ public $servers = [];++ public $containers = [];++ public function mount()+ {+ if (! auth()->user()->isAdmin()) {+ abort(403);+ }+ $this->servers = Server::isReachable()->get();+ $this->containers = $this->getAllActiveContainers();+ }++ private function getAllActiveContainers()+ {+ return collect($this->servers)->flatMap(function ($server) {+ if (! $server->isFunctional()) {+ return [];+ }++ return $server->loadAllContainers()->map(function ($container) use ($server) {+ $state = data_get_str($container, 'State')->lower();+ if ($state->contains('running')) {+ return [+ 'name' => data_get($container, 'Names'),+ 'connection_name' => data_get($container, 'Names'),+ 'uuid' => data_get($container, 'Names'),+ 'status' => data_get_str($container, 'State')->lower(),+ 'server' => $server,+ 'server_uuid' => $server->uuid,+ ];+ }++ return null;+ })->filter();+ });+ }++ public function updatedSelectedUuid()+ {+ $this->connectToContainer();+ }++ #[On('connectToContainer')]+ public function connectToContainer()+ {+ if ($this->selected_uuid === 'default') {+ $this->dispatch('error', 'Please select a server or a container.');++ return;+ }+ $container = collect($this->containers)->firstWhere('uuid', $this->selected_uuid);+ $this->dispatch('send-terminal-command',+ isset($container),+ $container['connection_name'] ?? $this->selected_uuid,+ $container['server_uuid'] ?? $this->selected_uuid+ );+ }+public function render(){return view('livewire.terminal.index');diff --git a/resources/views/livewire/run-command.blade.php b/resources/views/livewire/run-command.blade.phpdeleted file mode 100644index 4330e94cfc..0000000000--- a/resources/views/livewire/run-command.blade.php+++ /dev/null@@ -1,22 +0,0 @@-<div>- <form class="flex flex-col gap-2 justify-center xl:items-end xl:flex-row"- wire:submit="$dispatchSelf('connectToContainer')">- <x-forms.select id="server" required wire:model.live="selected_uuid">- @foreach ($servers as $server)- @if ($loop->first)- <option disabled value="default">Select a server or container</option>- @endif- <option value="{{ $server->uuid }}">{{ $server->name }}</option>- @foreach ($containers as $container)- @if ($container['server_uuid'] == $server->uuid)- <option value="{{ $container['uuid'] }}">- {{ $server->name }} -> {{ $container['name'] }}- </option>- @endif- @endforeach- @endforeach- </x-forms.select>- <x-forms.button type="submit">Connect</x-forms.button>- </form>- <livewire:project.shared.terminal />-</div>diff --git a/resources/views/livewire/terminal/index.blade.php b/resources/views/livewire/terminal/index.blade.phpindex 34a2d4c213..3572950022 100644--- a/resources/views/livewire/terminal/index.blade.php+++ b/resources/views/livewire/terminal/index.blade.php@@ -8,5 +8,27 @@<x-helperhelper="If you're having trouble connecting to your server, make sure that the port is open.<br><br><a class='underline' href='https://coolify.io/docs/knowledge-base/server/firewall/#terminal' target='_blank'>Documentation</a>"></x-helper></div>- <livewire:run-command />+ <div>+ <form class="flex flex-col gap-2 justify-center xl:items-end xl:flex-row"+ wire:submit="$dispatchSelf('connectToContainer')">+ <x-forms.select id="server" required wire:model.live="selected_uuid">+ @foreach ($servers as $server)+ @if ($loop->first)+ <option disabled value="default">Select a server or container</option>+ @endif+ <option value="{{ $server->uuid }}">{{ $server->name }}</option>+ @foreach ($containers as $container)+ @if ($container['server_uuid'] == $server->uuid)+ <option value="{{ $container['uuid'] }}">+ {{ $server->name }} -> {{ $container['name'] }}+ </option>+ @endif+ @endforeach+ @endforeach+ </x-forms.select>+ <x-forms.button type="submit">Connect</x-forms.button>+ </form>+ <livewire:project.shared.terminal />+ </div>+</div>