install_postfix_base.sh: support relaying to non standard port (other than 25).

This commit is contained in:
Christoph 2025-01-27 17:02:08 +01:00
parent aa092ea841
commit 0b410ad6d8

View File

@ -129,6 +129,7 @@ detect_os_1 () {
DEFAULT_ADMIN_EMAIL="argus@oopen.de" DEFAULT_ADMIN_EMAIL="argus@oopen.de"
DEFAULT_RELAY_HOST="b.mx.oopen.de" DEFAULT_RELAY_HOST="b.mx.oopen.de"
DEFAULT_RELAY_PORT=25
DEFAULT_SASL_AUTH=false DEFAULT_SASL_AUTH=false
DEFAULT_REWRITE_SENDER_DOMAIN=None DEFAULT_REWRITE_SENDER_DOMAIN=None
@ -340,11 +341,12 @@ fi
# --- Some further default values depending on sasl authentification # --- Some further default values depending on sasl authentification
# ------------- # -------------
# - Set default value for relay host if sasl authentification should be # - Set default value for relay host / relay port if sasl authentification should be
# - supported and value for _RELAY_HOST not given # - supported and value for _RELAY_HOST / _RELAY_PORT not given
# - # -
if [[ "$SASL_AUTH" = "yes" ]] || $SASL_AUTH ; then if [[ "$SASL_AUTH" = "yes" ]] || $SASL_AUTH ; then
[[ -z "$_RELAY_HOST" ]] && _RELAY_HOST="$DEFAULT_RELAY_HOST" [[ -z "$_RELAY_HOST" ]] && _RELAY_HOST="$DEFAULT_RELAY_HOST"
[[ -z "$_RELAY_PORT" ]] && _RELAY_PORT="$DEFAULT_RELAY_PORT"
fi fi
if [[ -z ${_REWRITE_SENDER_DOMAIN} ]] ; then if [[ -z ${_REWRITE_SENDER_DOMAIN} ]] ; then
@ -415,6 +417,27 @@ if [[ "$SASL_AUTH" = "yes" ]] || $SASL_AUTH ; then
done done
fi fi
RELAY_PORT=
echo ""
echo "Insert the target port to connect to ${RELAY_HOST}"
echo ""
if [[ -n "$_RELAY_PORT" ]];then
echononl "(target) Port on ${RELAY_HOST} [$_RELAY_PORT]: "
read RELAY_PORT
if [[ "X${RELAY_PORT}" = "X" ]]; then
RELAY_PORT=$_RELAY_PORT
fi
else
while [[ "X${RELAY_PORT}" = "X" ]]; do
echononl "(target) Port on ${RELAY_HOST}: "
read RELAY_PORT
if [[ "X${RELAY_PORT}" = "X" ]]; then
echo -e "\n\t\033[33m\033[1mi(target) Port of ${RELAY_HOST} is reqired\033[m\n"
fi
done
fi
else else
SASL_AUTH=false SASL_AUTH=false
fi fi
@ -467,6 +490,7 @@ if $SASL_AUTH ; then
echo -e "\t sasl user.............: $SASL_USER" echo -e "\t sasl user.............: $SASL_USER"
echo -e "\t sasl password.........: $SASL_PASS" echo -e "\t sasl password.........: $SASL_PASS"
echo -e "\t Relayhost.............: $RELAY_HOST" echo -e "\t Relayhost.............: $RELAY_HOST"
echo -e "\t Port on Relayhost.....: $RELAY_PORT"
fi fi
echo "" echo ""
echononl "einverstanden (yes/no): " echononl "einverstanden (yes/no): "
@ -498,6 +522,7 @@ _SASL_AUTH=$SASL_AUTH
_SASL_USER=$SASL_USER _SASL_USER=$SASL_USER
_SASL_PASS=$SASL_PASS _SASL_PASS=$SASL_PASS
_RELAY_HOST=$RELAY_HOST _RELAY_HOST=$RELAY_HOST
_RELAY_PORT=$RELAY_PORT
_REWRITE_SENDER_DOMAIN=$REWRITE_SENDER_DOMAIN _REWRITE_SENDER_DOMAIN=$REWRITE_SENDER_DOMAIN
EOF EOF
if [[ $? -eq 0 ]] ; then if [[ $? -eq 0 ]] ; then
@ -801,9 +826,24 @@ smtp_sasl_auth_enable = yes
# Only offer SMTP AUTH when talking over an encrypted connection # Only offer SMTP AUTH when talking over an encrypted connection
smtpd_tls_auth_only = yes smtpd_tls_auth_only = yes
EOF
if [[ ${RELAY_PORT} -ne 25 ]] ; then
cat <<EOF >> /etc/postfix/main.cf
# Forwarding to the ip-adress of host b.mx.oopen.de
relayhost = [${RELAY_HOST}]:${RELAY_PORT}
EOF
else
cat <<EOF >> /etc/postfix/main.cf
# Forwarding to the ip-adress of host b.mx.oopen.de # Forwarding to the ip-adress of host b.mx.oopen.de
relayhost = [${RELAY_HOST}] relayhost = [${RELAY_HOST}]
EOF
fi
cat <<EOF >> /etc/postfix/main.cf
# File including login data # File including login data
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
@ -1064,7 +1104,11 @@ echononl " Configure SASL authentification"
if $SASL_AUTH ; then if $SASL_AUTH ; then
_failed=false _failed=false
echo "[$RELAY_HOST] ${SASL_USER}@${RELAY_HOST}:$SASL_PASS" > /etc/postfix/sasl_passwd if [[ ${RELAY_PORT} -ne 25 ]] ; then
echo "[$RELAY_HOST]:${RELAY_PORT} ${SASL_USER}@${RELAY_HOST}:$SASL_PASS" > /etc/postfix/sasl_passwd
else
echo "[$RELAY_HOST] ${SASL_USER}@${RELAY_HOST}:$SASL_PASS" > /etc/postfix/sasl_passwd
fi
if [[ "$?" != "0" ]]; then if [[ "$?" != "0" ]]; then
error "Setting \"/etc/postfix/sasl_passwd\" failed! " error "Setting \"/etc/postfix/sasl_passwd\" failed! "
_failed=true _failed=true
@ -1410,6 +1454,12 @@ else
fi fi
fi fi
if [[ ${RELAY_PORT} -ne 25 ]] ; then
echo ""
warn "Please do not forget to allow port \033[1m${RELAY_PORT}\033[m on both sides, outgoing here
on this host here and incoming on the relay host '${RELAY_HOST}'."
fi
echo "" echo ""
clean_up 0 clean_up 0