parent
a5d3ac08c6
commit
59c495af84
|
|
@ -34,6 +34,47 @@ class StorageProbe extends Command
|
|||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
// … oberhalb deiner probe()-Methode einfügen:
|
||||
private function detectMailRoot(): ?string
|
||||
{
|
||||
// 1) Dovecot: mail_location = maildir:/var/vmail/%d/%n/Maildir
|
||||
$ml = trim((string) @shell_exec('doveconf -n 2>/dev/null | awk -F= \'/^mail_location/ {print $2}\''));
|
||||
if ($ml !== '') {
|
||||
$ml = trim($ml);
|
||||
// maildir:/path/to/root/%d/%n/Maildir oder mdbox:/path/…/mdbox
|
||||
if (preg_match('~^(?:maildir|mdbox|sdbox):([^%]+)~i', $ml, $m)) {
|
||||
$root = rtrim($m[1]);
|
||||
// häufig endet es auf /Maildir oder /mdbox → ein Level hoch als Root nehmen
|
||||
foreach (['/Maildir', '/mdbox', '/sdbox'] as $suffix) {
|
||||
if (str_ends_with($root, $suffix)) {
|
||||
$root = dirname($root);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (is_dir($root)) return $root;
|
||||
}
|
||||
}
|
||||
|
||||
// 2) Postfix: virtual_mailbox_base = /var/vmail
|
||||
$vmb = trim((string) @shell_exec('postconf -n 2>/dev/null | awk -F= \'/^virtual_mailbox_base/ {print $2}\''));
|
||||
$vmb = $vmb !== '' ? trim($vmb) : '';
|
||||
if ($vmb !== '' && is_dir($vmb)) return $vmb;
|
||||
|
||||
// 3) Fallbacks – nimm den ersten existierenden
|
||||
foreach (['/var/vmail', '/var/mail/vhosts', '/srv/mail/vhosts', '/home/vmail'] as $cand) {
|
||||
if (is_dir($cand)) return $cand;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function duBytesDir(string $path): int
|
||||
{
|
||||
if (!is_dir($path)) return 0;
|
||||
// apparent-size zählt logisch (kleine Dateien werden nicht „weggerundet“)
|
||||
$out = @shell_exec('LC_ALL=C du -sb --apparent-size ' . escapeshellarg($path) . ' 2>/dev/null | cut -f1');
|
||||
return max(0, (int) trim((string) $out));
|
||||
}
|
||||
|
||||
protected function probe(string $target): array
|
||||
{
|
||||
// --- df: Gesamtdaten des Filesystems (inkl. Reserve) -----------------
|
||||
|
|
@ -71,7 +112,8 @@ class StorageProbe extends Command
|
|||
return max(0, $b);
|
||||
};
|
||||
|
||||
$bytesMails = $duBytes('/var/mail/vhosts');
|
||||
$mailRoot = $this->detectMailRoot();
|
||||
$bytesMails = $mailRoot ? $this->duBytesDir($mailRoot) : 0;
|
||||
$bytesBackup = $duBytes('/var/backups/mailwolt');
|
||||
|
||||
$totalBytes = (int) $totalKb * 1024;
|
||||
|
|
@ -102,6 +144,8 @@ class StorageProbe extends Command
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
//namespace App\Console\Commands;
|
||||
//
|
||||
|
|
|
|||
Loading…
Reference in New Issue