From 0b410ad6d88ae3cb5f0e886907130e48df850fdc Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 27 Jan 2025 17:02:08 +0100 Subject: [PATCH] install_postfix_base.sh: support relaying to non standard port (other than 25). --- install_postfix_base.sh | 56 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/install_postfix_base.sh b/install_postfix_base.sh index 1d305bd..b93285f 100755 --- a/install_postfix_base.sh +++ b/install_postfix_base.sh @@ -129,6 +129,7 @@ detect_os_1 () { DEFAULT_ADMIN_EMAIL="argus@oopen.de" DEFAULT_RELAY_HOST="b.mx.oopen.de" +DEFAULT_RELAY_PORT=25 DEFAULT_SASL_AUTH=false DEFAULT_REWRITE_SENDER_DOMAIN=None @@ -340,11 +341,12 @@ fi # --- Some further default values depending on sasl authentification # ------------- -# - Set default value for relay host if sasl authentification should be -# - supported and value for _RELAY_HOST not given +# - Set default value for relay host / relay port if sasl authentification should be +# - supported and value for _RELAY_HOST / _RELAY_PORT not given # - if [[ "$SASL_AUTH" = "yes" ]] || $SASL_AUTH ; then [[ -z "$_RELAY_HOST" ]] && _RELAY_HOST="$DEFAULT_RELAY_HOST" + [[ -z "$_RELAY_PORT" ]] && _RELAY_PORT="$DEFAULT_RELAY_PORT" fi if [[ -z ${_REWRITE_SENDER_DOMAIN} ]] ; then @@ -415,6 +417,27 @@ if [[ "$SASL_AUTH" = "yes" ]] || $SASL_AUTH ; then done 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 SASL_AUTH=false fi @@ -467,6 +490,7 @@ if $SASL_AUTH ; then echo -e "\t sasl user.............: $SASL_USER" echo -e "\t sasl password.........: $SASL_PASS" echo -e "\t Relayhost.............: $RELAY_HOST" + echo -e "\t Port on Relayhost.....: $RELAY_PORT" fi echo "" echononl "einverstanden (yes/no): " @@ -498,6 +522,7 @@ _SASL_AUTH=$SASL_AUTH _SASL_USER=$SASL_USER _SASL_PASS=$SASL_PASS _RELAY_HOST=$RELAY_HOST +_RELAY_PORT=$RELAY_PORT _REWRITE_SENDER_DOMAIN=$REWRITE_SENDER_DOMAIN EOF if [[ $? -eq 0 ]] ; then @@ -801,9 +826,24 @@ smtp_sasl_auth_enable = yes # Only offer SMTP AUTH when talking over an encrypted connection smtpd_tls_auth_only = yes +EOF + + if [[ ${RELAY_PORT} -ne 25 ]] ; then + cat <> /etc/postfix/main.cf + +# Forwarding to the ip-adress of host b.mx.oopen.de +relayhost = [${RELAY_HOST}]:${RELAY_PORT} +EOF + else + cat <> /etc/postfix/main.cf # Forwarding to the ip-adress of host b.mx.oopen.de relayhost = [${RELAY_HOST}] +EOF + + fi + + cat <> /etc/postfix/main.cf # File including login data smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd @@ -1064,7 +1104,11 @@ echononl " Configure SASL authentification" if $SASL_AUTH ; then _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 error "Setting \"/etc/postfix/sasl_passwd\" failed! " _failed=true @@ -1410,6 +1454,12 @@ else 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 "" clean_up 0