Fix: Postfix myhostname + /etc/aliases beim Domain-Speichern automatisch aktualisieren

main v1.1.437
boban 2026-04-27 20:09:03 +02:00
parent f20a30839f
commit 6710827b81
1 changed files with 36 additions and 0 deletions

View File

@ -229,6 +229,10 @@ class SettingsForm extends Component
$warnings[] = 'System-Domain: ' . $sysmailErr;
}
if ($this->mail_domain) {
$this->applyPostfixHostname($this->mail_domain);
}
$this->loadSslStatus();
if ($warnings) {
@ -498,6 +502,38 @@ class SettingsForm extends Component
file_put_contents($path, $content);
}
private function applyPostfixHostname(string $mailHost): void
{
$safeHost = preg_replace('/[^a-zA-Z0-9.\-]/', '', $mailHost);
if (!$safeHost) return;
$destination = "{$safeHost}, localhost.localdomain, localhost";
@shell_exec('sudo -n /usr/sbin/postconf -e ' . escapeshellarg("myhostname={$safeHost}") . ' 2>/dev/null');
@shell_exec('sudo -n /usr/sbin/postconf -e ' . escapeshellarg("myorigin={$safeHost}") . ' 2>/dev/null');
@shell_exec('sudo -n /usr/sbin/postconf -e ' . escapeshellarg("mydestination={$destination}") . ' 2>/dev/null');
@shell_exec('sudo -n /usr/sbin/postfix reload 2>/dev/null');
// root-Alias → /dev/null verhindert Bounce-Schleife bei System-Mails von www-data
$this->sudoTee('/etc/aliases', "# Managed by Mailwolt\npostmaster: root\nroot: /dev/null\nclamav: /dev/null\n");
@shell_exec('sudo -n /usr/bin/newaliases 2>/dev/null');
}
private function sudoTee(string $target, string $content): void
{
$proc = proc_open(
sprintf('sudo -n /usr/bin/tee %s >/dev/null', escapeshellarg($target)),
[0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']],
$pipes
);
if (!is_resource($proc)) return;
fwrite($pipes[0], $content);
fclose($pipes[0]);
stream_get_contents($pipes[1]);
stream_get_contents($pipes[2]);
proc_close($proc);
}
public function render()
{
if (!in_array($this->tab, self::VALID_TABS, true)) {