diff --git a/app/Http/Livewire/PrivateKey/Change.php b/app/Http/Livewire/PrivateKey/Change.php index cbddfddf6..4f3ad4488 100644 --- a/app/Http/Livewire/PrivateKey/Change.php +++ b/app/Http/Livewire/PrivateKey/Change.php @@ -41,7 +41,7 @@ public function changePrivateKey() $this->private_key->private_key .= "\n"; } $this->private_key->save(); - session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get(); + refreshPrivateKey($this->private_key); } catch (\Exception $e) { return general_error_handler(err: $e, that: $this); } diff --git a/app/Http/Livewire/Server/Form.php b/app/Http/Livewire/Server/Form.php index eeb0df413..871102ada 100644 --- a/app/Http/Livewire/Server/Form.php +++ b/app/Http/Livewire/Server/Form.php @@ -49,26 +49,15 @@ public function installDocker() public function validateServer() { try { - $this->uptime = instant_remote_process(['uptime'], $this->server); - if ($this->uptime) { - $this->server->settings->is_reachable = true; - $this->server->settings->save(); - } else { - $this->uptime = 'Server not reachable.'; - throw new \Exception('Server not reachable.'); + ['uptime' => $uptime, 'dockerVersion' => $dockerVersion] = validateServer($this->server); + if ($uptime) { + $this->uptime = $uptime; } - $this->dockerVersion = instant_remote_process(['docker version|head -2|grep -i version'], $this->server, false); - if (!$this->dockerVersion) { - $this->dockerVersion = 'Not installed.'; - } else { - $this->server->settings->is_usable = true; - $this->server->settings->save(); + if ($dockerVersion) { + $this->dockerVersion = $dockerVersion; $this->emit('proxyStatusUpdated'); } } catch (\Exception $e) { - $this->server->settings->is_reachable = false; - $this->server->settings->is_usable = false; - $this->server->settings->save(); return general_error_handler(customErrorMessage: "Server is not reachable. Reason: {$e->getMessage()}", that: $this); } } diff --git a/app/Http/Livewire/Server/PrivateKey.php b/app/Http/Livewire/Server/PrivateKey.php index 36cc12bb8..54035efba 100644 --- a/app/Http/Livewire/Server/PrivateKey.php +++ b/app/Http/Livewire/Server/PrivateKey.php @@ -16,16 +16,14 @@ class PrivateKey extends Component public function checkConnection() { try { - $uptime = instant_remote_process(['uptime'], $this->server); + ['uptime' => $uptime, 'dockerVersion' => $dockerVersion] = validateServer($this->server); if ($uptime) { Toaster::success('Server is reachable with this private key.'); - $this->server->settings->is_reachable = true; - $this->server->settings->is_usable = true; + } + if ($dockerVersion) { + Toaster::success('Server is usable for Coolify.'); } } catch (\Exception $e) { - $this->server->settings->is_reachable = false; - $this->server->settings->is_usable = false; - $this->server->settings->save(); return general_error_handler(customErrorMessage: "Server is not reachable. Reason: {$e->getMessage()}", that: $this); } } @@ -34,9 +32,7 @@ public function setPrivateKey($private_key_id) $this->server->update([ 'private_key_id' => $private_key_id ]); - - // Delete the old ssh mux file to force a new one to be created - Storage::disk('ssh-mux')->delete($this->server->muxFilename()); + refreshPrivateKey($this->server->privateKey); $this->server->refresh(); $this->checkConnection(); } diff --git a/bootstrap/helpers/remoteProcess.php b/bootstrap/helpers/remoteProcess.php index cb718d8aa..93d48d77a 100644 --- a/bootstrap/helpers/remoteProcess.php +++ b/bootstrap/helpers/remoteProcess.php @@ -5,6 +5,7 @@ use App\Enums\ActivityTypes; use App\Models\Application; use App\Models\ApplicationDeploymentQueue; +use App\Models\PrivateKey; use App\Models\Server; use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; @@ -148,3 +149,44 @@ function decode_remote_command_output(?ApplicationDeploymentQueue $application_d return $formatted; } + +function refreshPrivateKey(PrivateKey $private_key) +{ + foreach ($private_key->servers as $server) { + // Delete the old ssh mux file to force a new one to be created + Storage::disk('ssh-mux')->delete($server->muxFilename()); + if (session('currentTeam')->id) { + session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get(); + } + } +} + +function validateServer(Server $server) +{ + try { + refreshPrivateKey($server->privateKey); + $uptime = instant_remote_process(['uptime'], $server); + if (!$uptime) { + $uptime = 'Server not reachable.'; + throw new \Exception('Server not reachable.'); + } + $server->settings->is_reachable = true; + + $dockerVersion = instant_remote_process(['docker version|head -2|grep -i version'], $server, false); + if (!$dockerVersion) { + $dockerVersion = 'Not installed.'; + throw new \Exception('Docker not installed.'); + } + $server->settings->is_usable = true; + return [ + "uptime" => $uptime, + "dockerVersion" => $dockerVersion, + ]; + } catch (\Exception $e) { + $server->settings->is_reachable = false; + $server->settings->is_usable = false; + throw $e; + } finally { + $server->settings->save(); + } +} diff --git a/resources/views/components/server/navbar.blade.php b/resources/views/components/server/navbar.blade.php index dcfd76dbb..8158e45c8 100644 --- a/resources/views/components/server/navbar.blade.php +++ b/resources/views/components/server/navbar.blade.php @@ -8,18 +8,18 @@ ]) }}"> - - - + + +

Private Key

+ + Save + @if ($private_key->id > 0) - - Save - Delete @@ -21,7 +21,7 @@
Private Key *
- Show + Edit
@@ -38,11 +38,7 @@ disabled />
- @if ($private_key->id === 0) - - @else - - @endif +
diff --git a/resources/views/livewire/server/form.blade.php b/resources/views/livewire/server/form.blade.php index c69d530e9..ce8285c29 100644 --- a/resources/views/livewire/server/form.blade.php +++ b/resources/views/livewire/server/form.blade.php @@ -1,48 +1,48 @@
- - -

This server will be deleted. It is not reversible.
Please think again..

-
-
- -
-
-

General

- @if ($server->id === 0) - Save - @else - Save - @endif -
-
-
- - - - {{-- --}} -
-
+ @if ($server->settings->is_reachable) + + +

This server will be deleted. It is not reversible.
Please think again..

+
+
+ + +
+

General

@if ($server->id === 0) - + Save @else - + Save @endif -
- - +
+
+
+ + + + {{-- --}} +
+
+ @if ($server->id === 0) + + @else + + @endif +
+ + +
-
-

Settings

-
- -
-

Actions

- @if ($server->settings->is_reachable) +

Settings

+
+ +
+

Actions

Check Server Details @@ -57,35 +57,35 @@ @endif
- @else -
- - Validate Server - +
+
- @endif -
- + @isset($uptime) +

Server Info

+
+

Uptime: {{ $uptime }}

+ @isset($dockerVersion) +

Docker Engine {{ $dockerVersion }}

+ @endisset +
+ @endisset + +

Danger Zone

+
Woah. I hope you know what are you doing.
+

Delete Server

+
This will remove this server from Coolify. Beware! There is no coming + back!
- @isset($uptime) -

Server Info

-
-

Uptime: {{ $uptime }}

- @isset($dockerVersion) -

Docker Engine {{ $dockerVersion }}

- @endisset + @if ($server->id !== 0 || isDev()) + + Delete + + @endif + @else +
+
+ Validate Server
- @endisset - -

Danger Zone

-
Woah. I hope you know what are you doing.
-

Delete Server

-
This will remove this server from Coolify. Beware! There is no coming - back! -
- @if ($server->id !== 0 || isDev()) - - Delete - +
@endif
diff --git a/resources/views/livewire/server/private-key.blade.php b/resources/views/livewire/server/private-key.blade.php index 10696901b..ae5877e97 100644 --- a/resources/views/livewire/server/private-key.blade.php +++ b/resources/views/livewire/server/private-key.blade.php @@ -22,17 +22,15 @@ @endif
- @if ($server->id !== 0) -

Select a different Private Key

-
- @forelse ($privateKeys as $private_key) - {{ $private_key->name }} - - @empty -
No private keys found. - -
- @endforelse -
- @endif +

Select a different Private Key

+
+ @forelse ($privateKeys as $private_key) +
{{ $private_key->name }} +
+ @empty +
No private keys found. + +
+ @endforelse +
diff --git a/routes/web.php b/routes/web.php index 10e15d77d..d08aeac20 100644 --- a/routes/web.php +++ b/routes/web.php @@ -74,7 +74,7 @@ ]))->name('server.proxy'); Route::get('/server/{server_uuid}/private-key', fn () => view('server.private-key', [ 'server' => Server::ownedByCurrentTeam()->whereUuid(request()->server_uuid)->firstOrFail(), - 'privateKeys' => PrivateKey::ownedByCurrentTeam()->where('id', '!=', 0)->get(), + 'privateKeys' => PrivateKey::ownedByCurrentTeam()->get(), ]))->name('server.private-key'); Route::get('/server/{server_uuid}/destinations', fn () => view('server.destinations', [ 'server' => Server::ownedByCurrentTeam(['name'])->whereUuid(request()->server_uuid)->firstOrFail()