Guest User

External SMTP relay enabler

a guest
Aug 20th, 2016
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.06 KB | None | 0 0
  1. #!/bin/sh
  2. ## External (remote) smtp relay enabler ## airwolfx86
  3. ## info@binarisk.com
  4. ## FOR POSTIFX
  5. LOOP=1
  6. unset OPTION1
  7. unset RELAYHOST
  8. unset USERNAME
  9. unset PASSWORD
  10. OPTION2=$1
  11. DATEXT=$(date +"%T")
  12. if [ $OPTION2 = "config" ]
  13.     then
  14.         clear
  15.         while [ $LOOP -gt 0 ]; do
  16.             echo "Your remote SMTP server IP :"
  17.             read RELAYHOST
  18.             echo "Your remote SMTP username :"
  19.             read USERNAME
  20.             echo "Your remote SMTP password :"
  21.             read -s PASSWORD
  22.             echo " "
  23.             echo "Now you will save this information to the postfix service:"
  24.             echo "[Server]: $RELAYHOST [Username]: $USERNAME [Password]: $PASSWORD"
  25.             echo " "
  26.             echo "Save and exit (YES) / Retry (R) / Quit (Q) :"
  27.             read OPTION1
  28.             if [ "$OPTION1" = "YES" ] || [ "$OPTION1" = "yes" ] || [ "$OPTION1" = "Y" ] || [ "$OPTION1" = "y" ]
  29.                 then
  30.                     cp /etc/postfix/main.cf "/etc/postfix/main_cf_$DATEXT" # main.cf backup
  31.                     cp /etc/postfix/sasl_passwd "/etc/postfix/sasl_passwd_$DATEXT" # sasl_passwd backup
  32.                     postconf -e "relayhost = $relayhost"
  33.                     postconf -e "smtp_sasl_auth_enable = yes"
  34.                     postconf -e "smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd"
  35.                     postconf -e "smtp_sasl_security_options ="
  36.                     echo "$relayhost $username:$password" >> /etc/postfix/sasl_passwd
  37.                     chown root:root /etc/postfix/sasl_passwd
  38.                     chmod 600 /etc/postfix/sasl_passwd
  39.                     postmap /etc/postfix/sasl_passwd # create postfix passwd db
  40.                     /etc/init.d/postfix restart
  41.                     clear
  42.                     echo "Your backup files main.cf and sasl_passwd are stored with date and time"
  43.                     echo "Done..."
  44.                     LOOP=0
  45.             fi
  46.             if [ "$OPTION1" = "R" ] || [ "$OPTION1" = "r" ]
  47.                 then
  48.                     clear
  49.                     LOOP=1
  50.             fi
  51.             if [ "$OPTION1" = "Q" ] || [ "$OPTION1" = "q" ]
  52.                 then
  53.                     clear
  54.                     echo "No changes where made..."
  55.                     LOOP=0
  56.             fi
  57.         done
  58.         exit
  59. fi     
  60. if [ $OPTION2 = "help" ]
  61.     then
  62.         clear
  63.         echo "[ Remote SMTP Postfix Help ]"
  64.         echo "You must have POSTFIX installed"
  65.         echo "A valid email username / password in the remote smtp server"
  66.         exit
  67. fi
  68. clear
  69.         echo "Usage : backupcode-relay config | help "
  70. exit
Add Comment
Please, Sign In to add comment