2023-05-03 10:38:57 +00:00
< ? php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Server ;
2023-05-03 10:38:57 +00:00
2024-09-19 10:06:56 +00:00
use App\Models\PrivateKey ;
2023-05-03 10:38:57 +00:00
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 ;
2024-06-10 20:43:34 +00:00
2023-06-15 12:18:49 +00:00
public $privateKeys ;
2024-06-10 20:43:34 +00:00
2023-05-03 10:38:57 +00:00
public $parameters ;
2023-06-16 11:13:09 +00:00
2024-09-16 17:52:55 +00:00
public function setPrivateKey ( $privateKeyId )
2023-08-08 09:51:36 +00:00
{
2023-09-09 13:30:46 +00:00
try {
2024-09-16 17:52:55 +00:00
$privateKey = PrivateKey :: findOrFail ( $privateKeyId );
2024-09-17 12:33:24 +00:00
$this -> server -> update ([ 'private_key_id' => $privateKey -> id ]);
$this -> server -> refresh ();
$this -> dispatch ( 'success' , 'Private key updated successfully.' );
2024-09-16 17:52:55 +00:00
} catch ( \Exception $e ) {
2024-09-19 10:06:56 +00:00
$this -> dispatch ( 'error' , 'Failed to update private key: ' . $e -> getMessage ());
2023-09-09 13:30:46 +00:00
}
2023-08-08 09:51:36 +00:00
}
2023-10-09 13:08:28 +00:00
public function checkConnection ()
2023-06-16 11:13:09 +00:00
{
try {
2024-04-16 13:42:38 +00:00
[ 'uptime' => $uptime , 'error' => $error ] = $this -> server -> validateConnection ();
2023-06-16 11:13:09 +00:00
if ( $uptime ) {
2023-12-07 18:06:32 +00:00
$this -> dispatch ( 'success' , 'Server is reachable.' );
2023-09-09 13:30:46 +00:00
} else {
2024-04-16 13:42:38 +00:00
ray ( $error );
2024-09-19 10:06:56 +00:00
$this -> dispatch ( 'error' , 'Server is not reachable.<br><br>Check this <a target="_blank" class="underline" href="https://coolify.io/docs/knowledge-base/server/openssh">documentation</a> for further help.<br><br>Error: ' . $error );
2024-06-10 20:43:34 +00:00
2023-10-09 09:00:18 +00:00
return ;
2023-06-16 11:13:09 +00:00
}
2023-09-11 15:36:30 +00:00
} catch ( \Throwable $e ) {
2023-09-15 13:34:25 +00:00
return handleError ( $e , $this );
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
}
}