From 8b4f2d9fe85523dc25ae930015b6dc3f1cff5bab Mon Sep 17 00:00:00 2001 From: boban Date: Wed, 29 Oct 2025 19:32:25 +0100 Subject: [PATCH] =?UTF-8?q?Fix:=20Mailbox=20Stats=20=C3=BCber=20Dovecot=20?= =?UTF-8?q?mit=20config/mailpool.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Livewire/Ui/Security/Fail2BanCard.php | 25 +++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/app/Livewire/Ui/Security/Fail2BanCard.php b/app/Livewire/Ui/Security/Fail2BanCard.php index 717353b..185673f 100644 --- a/app/Livewire/Ui/Security/Fail2BanCard.php +++ b/app/Livewire/Ui/Security/Fail2BanCard.php @@ -99,16 +99,33 @@ class Fail2BanCard extends Component /** Zählt die häufigsten IPs aus den letzten Fail2Ban-Logs (ban/unban Events) */ private function collectTopIps(): array { - // Zieh nur fail2ban.log, nicht auth/mail – präziser & schneller - $cmd = 'tail -n 2000 /var/log/fail2ban.log 2>/dev/null' - . ' | grep -Eo "([0-9]{1,3}\.){3}[0-9]{1,3}"' + // 1. Versuch: IPs direkt aus den Jails + $rows = []; + foreach ($this->jails as $jail) { + foreach ($jail['ips'] as $ip) { + $rows[$ip] = ($rows[$ip] ?? 0) + 1; + } + } + + if (!empty($rows)) { + arsort($rows); + return collect($rows) + ->map(fn($count, $ip) => ['ip' => $ip, 'count' => $count]) + ->values() + ->take(5) + ->toArray(); + } + + // 2. Fallback: Falls keine Jails/IPs → Logdatei + $cmd = 'grep -Eo "([0-9]{1,3}\.){3}[0-9]{1,3}" /var/log/fail2ban.log 2>/dev/null' . ' | sort | uniq -c | sort -nr | head -5'; $log = (string) @shell_exec($cmd); + $rows = []; if ($log !== '') { foreach (preg_split('/\R+/', trim($log)) as $l) { if (preg_match('/^\s*(\d+)\s+(\d+\.\d+\.\d+\.\d+)/', $l, $m)) { - $rows[] = ['ip'=>$m[2], 'count'=>(int)$m[1]]; + $rows[] = ['ip'=>$m[2],'count'=>(int)$m[1]]; } } }