Fix: mailwolt-apply-hostname Script + myhostname/aliases in apply-domains integriert
parent
6710827b81
commit
fce4f43833
|
|
@ -507,31 +507,8 @@ class SettingsForm extends Component
|
|||
$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);
|
||||
$helper = '/usr/local/sbin/mailwolt-apply-hostname';
|
||||
@shell_exec(sprintf('sudo -n %s %s 2>/dev/null', escapeshellarg($helper), escapeshellarg($safeHost)));
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
|
|
|||
|
|
@ -270,11 +270,36 @@ if [ -d "${STATE_DIR}" ]; then
|
|||
fi
|
||||
|
||||
# --- Phase 4: Postfix + Dovecot mit Mail-Domain-Zertifikat konfigurieren ---
|
||||
if [ -n "${MAIL_HOST}" ]; then
|
||||
# Hostname immer setzen, unabhängig vom Zertifikat
|
||||
if command -v postconf >/dev/null 2>&1; then
|
||||
postconf -e "myhostname = ${MAIL_HOST}"
|
||||
postconf -e "myorigin = ${MAIL_HOST}"
|
||||
postconf -e "mydestination = ${MAIL_HOST}, localhost.localdomain, localhost"
|
||||
fi
|
||||
|
||||
# /etc/aliases bereinigen: root → /dev/null verhindert Bounce-Schleife
|
||||
if [ -f /etc/aliases ]; then
|
||||
# Vorhandene root/clamav-Zeilen ersetzen oder am Ende ergänzen
|
||||
if grep -q '^root:' /etc/aliases; then
|
||||
sed -i 's|^root:.*|root: /dev/null|' /etc/aliases
|
||||
else
|
||||
echo 'root: /dev/null' >> /etc/aliases
|
||||
fi
|
||||
if grep -q '^clamav:' /etc/aliases; then
|
||||
sed -i 's|^clamav:.*|clamav: /dev/null|' /etc/aliases
|
||||
else
|
||||
echo 'clamav: /dev/null' >> /etc/aliases
|
||||
fi
|
||||
command -v newaliases >/dev/null 2>&1 && newaliases
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "${MAIL_HOST}" ] && [ "${MAIL_HAS_CERT}" = "1" ]; then
|
||||
MAIL_CERT="/etc/letsencrypt/live/${MAIL_HOST}/fullchain.pem"
|
||||
MAIL_KEY="/etc/letsencrypt/live/${MAIL_HOST}/privkey.pem"
|
||||
|
||||
# Postfix
|
||||
# Postfix TLS
|
||||
if command -v postconf >/dev/null 2>&1; then
|
||||
postconf -e "smtpd_tls_cert_file = ${MAIL_CERT}"
|
||||
postconf -e "smtpd_tls_key_file = ${MAIL_KEY}"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env bash
|
||||
# Setzt Postfix myhostname/myorigin und bereinigt /etc/aliases.
|
||||
# Wird von Mailwolt aufgerufen wenn die Mail-Domain gespeichert wird.
|
||||
set -euo pipefail
|
||||
|
||||
MAIL_HOST="${1:-}"
|
||||
if [ -z "${MAIL_HOST}" ]; then
|
||||
echo "Usage: mailwolt-apply-hostname <mail-host>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Nur sichere Hostnamen zulassen
|
||||
if ! echo "${MAIL_HOST}" | grep -qE '^[a-zA-Z0-9][a-zA-Z0-9.\-]+$'; then
|
||||
echo "Ungültiger Hostname: ${MAIL_HOST}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if command -v postconf >/dev/null 2>&1; then
|
||||
postconf -e "myhostname = ${MAIL_HOST}"
|
||||
postconf -e "myorigin = ${MAIL_HOST}"
|
||||
postconf -e "mydestination = ${MAIL_HOST}, localhost.localdomain, localhost"
|
||||
systemctl reload postfix 2>/dev/null || true
|
||||
fi
|
||||
|
||||
if [ -f /etc/aliases ]; then
|
||||
if grep -q '^root:' /etc/aliases; then
|
||||
sed -i 's|^root:.*|root: /dev/null|' /etc/aliases
|
||||
else
|
||||
echo 'root: /dev/null' >> /etc/aliases
|
||||
fi
|
||||
if grep -q '^clamav:' /etc/aliases; then
|
||||
sed -i 's|^clamav:.*|clamav: /dev/null|' /etc/aliases
|
||||
else
|
||||
echo 'clamav: /dev/null' >> /etc/aliases
|
||||
fi
|
||||
command -v newaliases >/dev/null 2>&1 && newaliases
|
||||
fi
|
||||
|
||||
echo "mailwolt-apply-hostname fertig"
|
||||
Loading…
Reference in New Issue