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
|
|
|
|
2023-09-09 13:30:46 +00:00
|
|
|
public function setPrivateKey($newPrivateKeyId)
|
2023-08-08 09:51:36 +00:00
|
|
|
{
|
2023-09-09 13:30:46 +00:00
|
|
|
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();
|
|
|
|
} catch (\Exception $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-08-08 09:51:36 +00:00
|
|
|
}
|
|
|
|
|
2023-06-16 11:13:09 +00:00
|
|
|
public function checkConnection()
|
|
|
|
{
|
|
|
|
try {
|
2023-07-25 12:43:49 +00:00
|
|
|
['uptime' => $uptime, 'dockerVersion' => $dockerVersion] = validateServer($this->server);
|
2023-06-16 11:13:09 +00:00
|
|
|
if ($uptime) {
|
2023-09-09 13:30:46 +00:00
|
|
|
$this->emit('success', 'Server is reachable with this private key.');
|
|
|
|
} else {
|
|
|
|
throw new \Exception('Server is not reachable with this private key.');
|
2023-07-25 12:43:49 +00:00
|
|
|
}
|
|
|
|
if ($dockerVersion) {
|
2023-09-09 13:30:46 +00:00
|
|
|
$this->emit('success', 'Server is usable for Coolify.');
|
|
|
|
} else {
|
|
|
|
throw new \Exception('Old Docker version detected (lower than 23).');
|
2023-06-16 11:13:09 +00:00
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
2023-09-09 13:30:46 +00:00
|
|
|
throw new \Exception($e->getMessage());
|
2023-06-16 11:13:09 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-03 10:38:57 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
2023-08-09 13:57:53 +00:00
|
|
|
$this->parameters = get_route_parameters();
|
2023-05-03 10:38:57 +00:00
|
|
|
}
|
|
|
|
}
|