user()?->can('manage-fleet'), 403); $this->serverId = $serverId; $this->serverName = Server::find($serverId)?->name ?? ''; } public static function modalMaxWidth(): string { return 'lg'; } public function run(SshKeyProvisioner $provisioner): void { // Re-gate on run: refuse a demoted user / hand-crafted /livewire/update after mount. abort_unless(auth()->user()?->can('manage-fleet'), 403); if ($this->done) { return; } $server = Server::find($this->serverId); if (! $server) { $this->error = __('common.server_not_found'); return; } try { $result = $provisioner->enableKeyOnlyAccess($server); } catch (\Throwable $e) { $this->done = true; $this->ok = false; $this->error = $e->getMessage(); // credentialChanged already triggers the FULL page reload on Show (key list + // credential + security state) — no extra hardeningApplied needed. $this->dispatch('credentialChanged'); $this->dispatch('notify', message: __('modals.ssh_key_provision.notify_failed')); return; } $this->done = true; $this->ok = $result['ok']; $this->privateKey = $result['privateKey'] ?? null; $this->publicKey = $result['publicKey'] ?? null; $this->error = $result['ok'] ? null : ($result['error'] ?? __('modals.ssh_key_provision.error_unknown')); $this->dispatch('credentialChanged'); $this->dispatch('notify', message: $this->ok ? __('modals.ssh_key_provision.notify_ok', ['server' => $this->serverName]) : __('modals.ssh_key_provision.notify_failed')); } public function render() { return view('livewire.modals.ssh-key-provision'); } }