serverId = $serverId; $this->action = $action; $this->enable = $enable; $server = Server::find($serverId); if (! $server) { $this->error = 'Server nicht gefunden.'; return; } try { $hardening = app(HardeningService::class); $this->heading = $hardening->title($action, $enable); $this->description = $hardening->description($action, $enable); $this->preview = $hardening->preview($server, $action, $enable); } catch (Throwable $e) { $this->error = $e->getMessage(); } } public static function modalMaxWidth(): string { return 'lg'; } public function apply(): void { if ($this->error !== null || $this->done) { return; } $server = Server::find($this->serverId); if (! $server) { $this->error = 'Server nicht gefunden.'; return; } try { $result = app(HardeningService::class)->apply($server, $this->action, $this->enable); } catch (Throwable $e) { $this->done = true; $this->ok = false; $this->output = $e->getMessage(); return; } $this->done = true; $this->ok = $result['ok']; $this->output = $result['output'] !== '' ? $result['output'] : ($result['ok'] ? 'Erfolgreich angewendet.' : 'Fehlgeschlagen.'); AuditEvent::create([ 'user_id' => Auth::id(), 'server_id' => $server->id, 'actor' => Auth::user()?->name ?? 'system', 'action' => 'harden.'.$this->action.($this->enable ? '.on' : '.off'), 'target' => $server->name.' · '.$this->heading.($this->ok ? '' : ' (fehlgeschlagen)'), 'ip' => request()->ip(), ]); if ($this->ok) { $this->dispatch('hardeningApplied'); $this->dispatch('notify', message: $this->heading.' angewendet.'); } else { $this->dispatch('notify', message: $this->heading.' fehlgeschlagen.'); } } public function render() { return view('livewire.modals.hardening-action'); } }