diff --git a/app/Console/Commands/SpamAvCollectCommand.php b/app/Console/Commands/SpamAvCollectCommand.php index ce9cab3..bed9a37 100644 --- a/app/Console/Commands/SpamAvCollectCommand.php +++ b/app/Console/Commands/SpamAvCollectCommand.php @@ -15,23 +15,34 @@ class SpamAvCollectCommand extends Command { $this->info('Collecting Spam/AV metrics…'); - $collect = function (): array { - $out = trim(@shell_exec('rspamc counters 2>/dev/null') ?? ''); - $ham = preg_match('/\bham\s*:\s*(\d+)/i', $out, $m1) ? (int)$m1[1] : 0; - $spam = preg_match('/\bspam\s*:\s*(\d+)/i', $out, $m2) ? (int)$m2[1] : 0; - $reject = preg_match('/\breject\s*:\s*(\d+)/i', $out, $m3) ? (int)$m3[1] : 0; + // Rspamd counters (kein Root nötig) + $out = trim(@shell_exec('rspamc counters 2>/dev/null') ?? ''); + $ham = preg_match('/\bham\s*:\s*(\d+)/i', $out, $m1) ? (int)$m1[1] : 0; + $spam = preg_match('/\bspam\s*:\s*(\d+)/i', $out, $m2) ? (int)$m2[1] : 0; + $reject = preg_match('/\breject\s*:\s*(\d+)/i', $out, $m3) ? (int)$m3[1] : 0; - $rspamdVer = trim(@shell_exec('rspamadm version 2>/dev/null') ?? '') ?: '–'; - $clamVer = trim(@shell_exec('clamd --version 2>/dev/null || clamscan --version 2>/dev/null') ?? '') ?: '–'; + // ClamAV Version + Signatur-Datum robust ohne Datei-Zugriff + $clamLine = trim((string) @shell_exec('clamd --version 2>/dev/null || clamscan --version 2>/dev/null')); + $clamVer = $clamLine !== '' ? $clamLine : '–'; - $sigUpdated = null; - $log = @shell_exec('grep -i "Database updated" /var/log/clamav/freshclam.log | tail -n1 2>/dev/null'); - if ($log) { $sigUpdated = trim($log); } + // Aus clamd/clamscan-Output das Datum am Ende herausziehen (Format: ".../Sun Oct 26 09:42:43 2025") + $sigUpdated = null; + if ($clamLine && preg_match('#/([^/]+\d{4})$#', $clamLine, $m)) { + // $m[1] ist z.B. "Sun Oct 26 09:42:43 2025" + $sigUpdated = $m[1]; + } - return compact('ham','spam','reject','rspamdVer','clamVer','sigUpdated') + ['ts' => time()]; - }; + $data = [ + 'ts' => time(), + 'ham' => $ham, + 'spam' => $spam, + 'reject' => $reject, + 'rspamdVer' => trim((string) @shell_exec('rspamadm version 2>/dev/null')) ?: '–', + 'clamVer' => $clamVer, + 'sigUpdated' => $sigUpdated, + ]; - $data = $collect(); + // Persistieren (DB→Redis) + kurzer UI-Cache Setting::set('spamav.metrics', $data); Cache::put('dash.spamav', $data, 60); diff --git a/app/Livewire/Ui/Security/SpamAvCard.php b/app/Livewire/Ui/Security/SpamAvCard.php index 45ab07a..620172d 100644 --- a/app/Livewire/Ui/Security/SpamAvCard.php +++ b/app/Livewire/Ui/Security/SpamAvCard.php @@ -70,31 +70,20 @@ class SpamAvCard extends Component $reject = preg_match('/\breject\s*:\s*(\d+)/i', $out, $m3) ? (int)$m3[1] : 0; // Versionen -// $rspamdVer = trim(@shell_exec('rspamadm version 2>/dev/null') ?? '') ?: '–'; -// $clamVer = trim(@shell_exec('clamd --version 2>/dev/null || clamscan --version 2>/dev/null') ?? '') ?: '–'; -// -// // Letztes Signatur-Update aus freshclam.log -// $sigUpdated = null; -// $log = @shell_exec('grep -i "Database updated" /var/log/clamav/freshclam.log | tail -n1 2>/dev/null'); -// if ($log) { -// $sigUpdated = trim($log); -// } - - $clamLine = trim(shell_exec('clamd --version 2>/dev/null || clamscan --version 2>/dev/null') ?? ''); - $clamVer = $clamLine ?: '–'; + $clamLine = trim((string) @shell_exec('clamd --version 2>/dev/null || clamscan --version 2>/dev/null')); + $clamVer = $clamLine !== '' ? $clamLine : '–'; $sigUpdated = null; - if ($clamLine && preg_match('#/([^/]+ [0-9]{2} [0-9:]{8} [0-9]{4})$#', $clamLine, $m)) { - // Beispiel-Match: "Sun Oct 26 09:42:43 2025" + if ($clamLine && preg_match('#/([^/]+\d{4})$#', $clamLine, $m)) { $sigUpdated = $m[1]; } -// Fallback: Versuch über journalctl (falls adm-Rechte vorhanden) - if (!$sigUpdated) { - $jl = trim(shell_exec('journalctl -u freshclam -n 50 --no-pager 2>/dev/null | grep -i "Database updated" | tail -n1') ?? ''); - if ($jl) $sigUpdated = $jl; - } +//// Fallback: Versuch über journalctl (falls adm-Rechte vorhanden) +// if (!$sigUpdated) { +// $jl = trim(shell_exec('journalctl -u freshclam -n 50 --no-pager 2>/dev/null | grep -i "Database updated" | tail -n1') ?? ''); +// if ($jl) $sigUpdated = $jl; +// } + - return [ 'ts' => time(), 'ham' => $ham, diff --git a/app/Livewire/Ui/System/UpdateCard.php b/app/Livewire/Ui/System/UpdateCard.php index be1d9a0..b8d0bde 100644 --- a/app/Livewire/Ui/System/UpdateCard.php +++ b/app/Livewire/Ui/System/UpdateCard.php @@ -110,7 +110,6 @@ class UpdateCard extends Component @shell_exec('nohup php /var/www/mailwolt/artisan mailwolt:restart-services >/dev/null 2>&1 &'); @shell_exec('nohup php /var/www/mailwolt/artisan settings:sync >/dev/null 2>&1 &'); @shell_exec('nohup php /var/www/mailwolt/artisan spamav:collect >/dev/null 2>&1 &'); - $this->postActionsDone = true; $ver = $this->displayCurrent ?? 'aktuelle Version';