47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Admin;
|
|
|
|
use App\Models\Host;
|
|
use App\Services\Wireguard\WireguardHub;
|
|
use LivewireUI\Modal\ModalComponent;
|
|
|
|
/**
|
|
* Confirmation for the destructive "remove host" action (R5). Deregisters the
|
|
* CluPilot record only — it does not touch the physical server.
|
|
*/
|
|
class ConfirmRemoveHost extends ModalComponent
|
|
{
|
|
public string $uuid;
|
|
|
|
public string $name = '';
|
|
|
|
public function mount(string $uuid): void
|
|
{
|
|
$this->uuid = $uuid;
|
|
$this->name = Host::query()->where('uuid', $uuid)->value('name') ?? '';
|
|
}
|
|
|
|
public function remove(WireguardHub $hub)
|
|
{
|
|
$host = Host::query()->where('uuid', $this->uuid)->first();
|
|
|
|
if ($host !== null) {
|
|
// Drop the hub peer first so its wg_ip can't later be reused while a
|
|
// stale peer still routes to the removed server.
|
|
if (filled($host->wg_pubkey)) {
|
|
$hub->removePeer($host->wg_pubkey);
|
|
}
|
|
$host->runs()->delete(); // cascades run_resources + step_events
|
|
$host->delete();
|
|
}
|
|
|
|
return $this->redirectRoute('admin.hosts', navigate: true);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.admin.confirm-remove-host');
|
|
}
|
|
}
|