coolify/app/Http/Livewire/Server/ShowPrivateKey.php

59 lines
1.8 KiB
PHP
Raw Normal View History

2023-05-03 12:38:57 +02:00
<?php
namespace App\Http\Livewire\Server;
use App\Models\Server;
use Livewire\Component;
2023-08-30 11:06:44 +02:00
class ShowPrivateKey extends Component
2023-05-03 12:38:57 +02:00
{
2023-06-15 14:18:49 +02:00
public Server $server;
public $privateKeys;
2023-05-03 12:38:57 +02:00
public $parameters;
2023-06-16 13:13:09 +02:00
public function setPrivateKey($newPrivateKeyId)
{
try {
$oldPrivateKeyId = $this->server->private_key_id;
$this->server->update([
'private_key_id' => $newPrivateKeyId
]);
$this->server->refresh();
refresh_server_connection($this->server->privateKey);
$this->checkConnection();
2023-09-11 17:36:30 +02:00
} catch (\Throwable $e) {
$this->server->update([
'private_key_id' => $oldPrivateKeyId
]);
$this->server->refresh();
refresh_server_connection($this->server->privateKey);
return general_error_handler($e, that: $this);
}
}
2023-06-16 13:13:09 +02:00
public function checkConnection()
{
try {
['uptime' => $uptime, 'dockerVersion' => $dockerVersion] = validateServer($this->server);
2023-06-16 13:13:09 +02:00
if ($uptime) {
$this->emit('success', 'Server is reachable with this private key.');
} else {
2023-09-11 17:19:30 +02:00
$this->emit('error', 'Server is not reachable with this private key.');
return;
}
if ($dockerVersion) {
$this->emit('success', 'Server is usable for Coolify.');
} else {
2023-09-11 17:19:30 +02:00
$this->emit('error', 'Old (lower than 23) or no Docker version detected. Install Docker Engine on the General tab.');
2023-06-16 13:13:09 +02:00
}
2023-09-11 17:36:30 +02:00
} catch (\Throwable $e) {
throw new \Exception($e->getMessage());
2023-06-16 13:13:09 +02:00
}
}
2023-05-03 12:38:57 +02:00
public function mount()
{
$this->parameters = get_route_parameters();
2023-05-03 12:38:57 +02:00
}
}