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

43 lines
1.1 KiB
PHP
Raw Normal View History

2023-05-03 10:38:57 +00:00
<?php
namespace App\Http\Livewire\Server;
use App\Models\Server;
2023-05-16 09:39:18 +00:00
use Illuminate\Support\Facades\Storage;
2023-05-03 10:38:57 +00:00
use Livewire\Component;
2023-06-16 11:13:09 +00:00
use Masmerise\Toaster\Toaster;
2023-05-03 10:38:57 +00:00
class PrivateKey extends Component
{
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 checkConnection()
{
try {
2023-06-22 19:02:32 +00:00
$uptime = instant_remote_process(['uptime'], $this->server);
2023-06-16 11:13:09 +00:00
if ($uptime) {
Toaster::success('Server is reachable with this private key.');
}
} catch (\Exception $e) {
2023-06-22 19:02:32 +00:00
return general_error_handler(customErrorMessage: "Server is not reachable. Reason: {$e->getMessage()}", that: $this);
2023-06-16 11:13:09 +00:00
}
}
2023-05-03 10:38:57 +00:00
public function setPrivateKey($private_key_id)
{
2023-06-15 12:18:49 +00:00
$this->server->update([
2023-05-03 10:38:57 +00:00
'private_key_id' => $private_key_id
]);
2023-06-15 12:18:49 +00:00
2023-05-16 09:39:18 +00:00
// Delete the old ssh mux file to force a new one to be created
2023-06-16 11:13:09 +00:00
Storage::disk('ssh-mux')->delete($this->server->muxFilename());
2023-06-15 12:18:49 +00:00
$this->server->refresh();
2023-06-16 11:13:09 +00:00
$this->checkConnection();
2023-05-03 10:38:57 +00:00
}
public function mount()
{
2023-06-15 07:15:41 +00:00
$this->parameters = getRouteParameters();
2023-05-03 10:38:57 +00:00
}
}