diff --git a/app/Livewire/Ui/Security/ClamavManager.php b/app/Livewire/Ui/Security/ClamavManager.php index ecdc4aa..0858029 100644 --- a/app/Livewire/Ui/Security/ClamavManager.php +++ b/app/Livewire/Ui/Security/ClamavManager.php @@ -17,6 +17,7 @@ class ClamavManager extends Component public string $dbVersion = '—'; public ?int $ramMb = null; public string $lastError = ''; + public string $lastSuccess = ''; public bool $installing = false; public function mount(): void @@ -26,11 +27,12 @@ class ClamavManager extends Component public function refresh(): void { - $this->lastError = ''; - $this->running = $this->serviceActive(); - $this->enabled = $this->serviceEnabled(); - $this->installed = true; // Mailwolt setzt ClamAV voraus; Fehler kommen vom Wrapper - $this->ramMb = $this->running ? $this->readRamMb() : null; + $this->lastError = ''; + $this->lastSuccess = ''; + $this->running = $this->serviceActive(); + $this->enabled = $this->serviceEnabled(); + $this->installed = true; + $this->ramMb = $this->running ? $this->readRamMb() : null; [$this->dbDate, $this->dbVersion] = $this->readDbInfo(); } @@ -51,41 +53,37 @@ class ClamavManager extends Component public function enable(): void { - $out = []; - @exec('sudo -n /usr/local/sbin/mailwolt-clamav enable 2>&1', $out, $rc); - if ($rc !== 0) { - $this->lastError = implode(' ', $out) ?: 'Fehler beim Aktivieren.'; - } else { - $this->dispatch('toast', type: 'success', badge: 'ClamAV', - title: 'Aktiviert', text: 'ClamAV läuft jetzt und startet automatisch beim Booten.'); - } - $this->refresh(); + [$ok, $msg] = $this->runCmd('enable'); + if ($ok) $this->lastSuccess = 'ClamAV wurde aktiviert und gestartet.'; + else $this->lastError = $msg; + $this->running = $this->serviceActive(); + $this->enabled = $this->serviceEnabled(); } public function disable(): void { - $out = []; - @exec('sudo -n /usr/local/sbin/mailwolt-clamav disable 2>&1', $out, $rc); - if ($rc !== 0) { - $this->lastError = implode(' ', $out) ?: 'Fehler beim Deaktivieren.'; - } else { - $this->dispatch('toast', type: 'success', badge: 'ClamAV', - title: 'Deaktiviert', text: 'ClamAV wurde gestoppt und aus dem Autostart entfernt.'); - } - $this->refresh(); + [$ok, $msg] = $this->runCmd('disable'); + if ($ok) $this->lastSuccess = 'ClamAV wurde gestoppt und deaktiviert.'; + else $this->lastError = $msg; + $this->running = $this->serviceActive(); + $this->enabled = $this->serviceEnabled(); } public function updateDb(): void { - $out = []; - @exec('sudo -n /usr/local/sbin/mailwolt-clamav freshclam 2>&1', $out, $rc); - if ($rc !== 0) { - $this->lastError = implode(' ', $out) ?: 'Fehler beim Aktualisieren.'; - } else { - $this->dispatch('toast', type: 'success', badge: 'ClamAV', - title: 'Datenbank aktualisiert', text: 'Virensignaturen wurden aktualisiert.'); - } - $this->refresh(); + [$ok, $msg] = $this->runCmd('freshclam'); + if ($ok) $this->lastSuccess = 'Virensignaturen wurden aktualisiert.'; + else $this->lastError = $msg; + [$this->dbDate, $this->dbVersion] = $this->readDbInfo(); + } + + private function runCmd(string $action): array + { + $out = []; $rc = null; + exec('sudo -n /usr/local/sbin/mailwolt-clamav ' . escapeshellarg($action) . ' 2>&1', $out, $rc); + \Log::info('ClamAV ' . $action, ['rc' => $rc, 'out' => $out]); + $msg = implode(' ', $out) ?: 'Unbekannter Fehler (rc=' . $rc . ')'; + return [$rc === 0, $msg]; } private function serviceActive(): bool diff --git a/resources/views/livewire/ui/security/clamav-manager.blade.php b/resources/views/livewire/ui/security/clamav-manager.blade.php index aa6c834..3c64b81 100644 --- a/resources/views/livewire/ui/security/clamav-manager.blade.php +++ b/resources/views/livewire/ui/security/clamav-manager.blade.php @@ -19,11 +19,16 @@ - {{-- Fehler-Banner --}} + @if($lastSuccess) +