CluPilotCloud/app/Livewire/Admin/ConfirmDeleteVpnPeer.php

52 lines
1.5 KiB
PHP

<?php
namespace App\Livewire\Admin;
use App\Models\VpnPeer;
use App\Provisioning\Jobs\ApplyVpnPeer;
use LivewireUI\Modal\ModalComponent;
/**
* Confirmation for revoking a VPN access for good (R5). Deleting a peer that
* belongs to a host cuts CluPilot's own management path to that machine, so the
* modal says so plainly rather than hiding the option.
*/
class ConfirmDeleteVpnPeer extends ModalComponent
{
public string $uuid;
public string $name = '';
public ?string $hostName = null;
public function mount(string $uuid): void
{
$this->authorize('vpn.manage'); // modals are reachable without the route middleware
$peer = VpnPeer::query()->with('host')->where('uuid', $uuid)->firstOrFail();
$this->uuid = $uuid;
$this->name = $peer->name;
$this->hostName = $peer->host?->name;
}
public function delete(): void
{
$this->authorize('vpn.manage');
$peer = VpnPeer::query()->where('uuid', $this->uuid)->first();
if ($peer !== null) {
// Remove from the hub first: if the row went first and the job then
// failed, the peer would keep its tunnel with nothing left to show it.
ApplyVpnPeer::dispatch($peer->public_key, null, false);
$peer->delete();
}
$this->dispatch('vpn-peer-deleted');
$this->closeModal();
}
public function render()
{
return view('livewire.admin.confirm-delete-vpn-peer');
}
}