Fix: Mailbox Stats über Dovecot mit config/mailpool.php

main v1.0.116
boban 2025-10-31 03:27:36 +01:00
parent c4b906223c
commit 8058f9b814
1 changed files with 50 additions and 11 deletions

View File

@ -190,23 +190,62 @@ class Fail2BanJailModal extends ModalComponent
$sqlite = $this->bin('sqlite3'); $sqlite = $this->bin('sqlite3');
$db = $this->getDbFile(); $db = $this->getDbFile();
$q = sprintf( // 1) Spalten ermitteln
"SELECT timeofban, expiretime $cmdCols = "$sudo -n $sqlite -readonly ".escapeshellarg($db)." ".escapeshellarg("PRAGMA table_info(bans);");
FROM bans $colsRaw = trim((string)@shell_exec($cmdCols));
WHERE jail=%s AND ip=%s AND (expiretime=-1 OR expiretime>STRFTIME('%%s','now')) if ($colsRaw === '') return null;
ORDER BY timeofban DESC LIMIT 1",
$this->sql($jail),
$this->sql($ip)
);
$hasExpire = strpos($colsRaw, "|expiretime|") !== false;
$hasBantime= strpos($colsRaw, "|bantime|") !== false;
// 2) Query bauen nach Schema
if ($hasExpire) {
$q = sprintf(
"SELECT timeofban, expiretime FROM bans
WHERE jail=%s AND ip=%s
ORDER BY timeofban DESC LIMIT 1",
$this->sql($jail), $this->sql($ip)
);
$cmd = "$sudo -n $sqlite -readonly ".escapeshellarg($db).' '.escapeshellarg($q);
$out = trim((string)@shell_exec($cmd));
if ($out === '') return null;
[$timeofban, $expire] = array_map('intval', explode('|', $out)) + [null, null];
return ['banned_at' => $timeofban ?: null, 'expire' => $expire ?? null];
}
if ($hasBantime) {
$q = sprintf(
"SELECT timeofban, bantime FROM bans
WHERE jail=%s AND ip=%s
ORDER BY timeofban DESC LIMIT 1",
$this->sql($jail), $this->sql($ip)
);
$cmd = "$sudo -n $sqlite -readonly ".escapeshellarg($db).' '.escapeshellarg($q);
$out = trim((string)@shell_exec($cmd));
if ($out === '') return null;
[$timeofban, $bantime] = array_map('intval', explode('|', $out)) + [null, null];
$expire = ($timeofban && $bantime) ? ($timeofban + $bantime) : null;
return ['banned_at' => $timeofban ?: null, 'expire' => $expire];
}
// Fallback: nur timeofban vorhanden → aktuelles Jail-Bantime verwenden
$q = sprintf(
"SELECT timeofban FROM bans
WHERE jail=%s AND ip=%s
ORDER BY timeofban DESC LIMIT 1",
$this->sql($jail), $this->sql($ip)
);
$cmd = "$sudo -n $sqlite -readonly ".escapeshellarg($db).' '.escapeshellarg($q); $cmd = "$sudo -n $sqlite -readonly ".escapeshellarg($db).' '.escapeshellarg($q);
$out = trim((string)@shell_exec($cmd)); $out = trim((string)@shell_exec($cmd));
if ($out === '') return null; if ($out === '') return null;
[$timeofban, $expire] = array_map('intval', explode('|', $out)) + [null, null]; $timeofban = (int)$out;
return ['banned_at' => $timeofban ?: null, 'expire' => $expire ?? null]; $bantime = $this->getBantime($jail); // aktuell konfiguriert (z. B. 3600)
$expire = $timeofban ? ($timeofban + max(0, $bantime)) : null;
return ['banned_at' => $timeofban ?: null, 'expire' => $expire];
} }
private function isStillBanned(string $jail, string $ip): bool private function isStillBanned(string $jail, string $ip): bool
{ {
// 1) Direkt: banip // 1) Direkt: banip