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
|
|
|
|
2023-09-09 15:30:46 +02:00
|
|
|
public function setPrivateKey($newPrivateKeyId)
|
2023-08-08 11:51:36 +02:00
|
|
|
{
|
2023-09-09 15:30:46 +02:00
|
|
|
try {
|
|
|
|
$oldPrivateKeyId = $this->server->private_key_id;
|
2023-09-28 13:40:58 +02:00
|
|
|
refresh_server_connection($this->server->privateKey);
|
2023-09-09 15:30:46 +02:00
|
|
|
$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) {
|
2023-09-09 15:30:46 +02:00
|
|
|
$this->server->update([
|
|
|
|
'private_key_id' => $oldPrivateKeyId
|
|
|
|
]);
|
|
|
|
$this->server->refresh();
|
2023-09-14 10:12:58 +02:00
|
|
|
refresh_server_connection($this->server->privateKey);
|
2023-09-15 15:34:25 +02:00
|
|
|
return handleError($e, $this);
|
2023-09-09 15:30:46 +02:00
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
}
|
|
|
|
|
2023-10-09 15:08:28 +02:00
|
|
|
public function checkConnection()
|
2023-06-16 13:13:09 +02:00
|
|
|
{
|
|
|
|
try {
|
2023-10-09 11:00:18 +02:00
|
|
|
$uptime = $this->server->validateConnection();
|
2023-06-16 13:13:09 +02:00
|
|
|
if ($uptime) {
|
2023-10-09 15:08:28 +02:00
|
|
|
$this->emit('success', 'Server is reachable.');
|
2023-09-09 15:30:46 +02:00
|
|
|
} else {
|
2023-10-09 15:08:28 +02:00
|
|
|
$this->emit('error', 'Server is not reachable. Please check your connection and private key configuration.');
|
2023-10-09 11:00:18 +02:00
|
|
|
return;
|
2023-06-16 13:13:09 +02:00
|
|
|
}
|
2023-09-11 17:36:30 +02:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 15:34:25 +02:00
|
|
|
return handleError($e, $this);
|
2023-06-16 13:13:09 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-05-03 12:38:57 +02:00
|
|
|
public function mount()
|
|
|
|
{
|
2023-08-09 15:57:53 +02:00
|
|
|
$this->parameters = get_route_parameters();
|
2023-05-03 12:38:57 +02:00
|
|
|
}
|
|
|
|
}
|