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

73 lines
2.3 KiB
PHP
Raw Normal View History

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