IMAP/SMTP Authentication tests

From QmailToaster
Jump to navigation Jump to search

Back

 IMAPS, SMTPS, & Submission connection test script 
  
  #!/bin/bash

  read -p "Enter a valid remote email account to which QMT will send mail: " ruser
  if [ -z "$ruser" ]
  then
     echo "No remote user entered, exiting..."
     exit 1
  fi

  user=postmaster
  host=`hostname -I`

  DOMAINS=/home/vpopmail/domains
  user=postmaster
  DOMAINS=/home/vpopmail/domains

  for domain in `ls $DOMAINS`
  do
     pass=`/home/vpopmail/bin/vuserinfo $user@$domain | grep "clear passwd: " | sed 's/clear passwd: //'`
  done
  if [ -z "$domain" ]
  then
     echo "No domain..."
     exit 1
  fi

  curl -v --insecure -I imaps://${user}%40${domain}:${pass}@localhost &> ./xxx
  yyy=`cat ./xxx | grep "OK Logged in"`
  if [[ ! -z $yyy ]]
  then
     echo -n "IMAPS: $user@$domain --> " && tput setaf 2 && echo "success" && tput sgr0
  else
     echo -n "IMAPS: $user@$domain --> " && tput setaf 1 && echo "failure" && tput sgr0
  fi

  dswak=/usr/local/bin
  [ ! -f $dswak/swaks ] && \
     wget -P $dswak http://www.jetmore.org/john/code/swaks/latest/swaks &> /dev/null && chown root.root $dswak/swaks && chmod +x $dswak/swaks
  swaks --to $ruser --from $user@$domain --server $host --port 587 --ehlo test -tls --auth login \
   --auth-user $user@$domain --auth-password $pass &> ./xxx
  yyy=`cat xxx | grep "250 ok "`
  if [[ ! -z $yyy ]]
  then
     echo -n "Submission: $user@$doain --> " && tput setaf 2 && echo "success" && tput sgr0
  else
     echo -n "Submission: $user@$domain --> " && tput setaf 1 && echo "failure" && tput sgr0
  fi
  rm -f ./xxx
  swaks --to $ruser --from $user@$domain --server $host --port 465 --ehlo test -tlsc --auth login \
   --auth-user $user@$domain --auth-password $pass &> ./xxx
  yyy=`cat xxx | grep "250 ok "`
  if [[ ! -z $yyy ]]
  then
     echo -n "SMTPS: $user@$domain --> " && tput setaf 2 && echo "success" && tput sgr0
  else
     echo -n "SMTPS: $user@$domain --> " && tput setaf 1 && echo "failure" && tput sgr0
  fi
  rm -f ./xxx
  

 Check passwords
  # vpopmailpasswd=`cat filepasswd`  
  # echo "select pw_passwd from localdomain_tld where pw_name='user'" | \
    mysql -u root -p$vpopmailpasswd vpopmail | grep -v pw_passwd | sed 's/\$1\$//' | cut -f1 -d"$" > saltfile
  # usersalt=`cat saltfile`
  # userpasswd=`cat fileuserpasswd` /* Put your user's password in this file */
  # userhash0=`openssl passwd -1 -salt $usersalt $userpasswd`
  # userhash1=`echo "select pw_passwd from localdomain_tld where pw_name='user'" | \
    mysql -u root -p$vpopmailpasswd vpopmail | grep -v pw_passwd`
  # [ "$userhash0" = "$userhash1" ] && echo "Matched passwords" || echo "Unmatched passwords"

 Script to test all IMAP accounts (post migration)
  
  #!/bin/bash

  # Change fqdn to suit
  fqdn=mail.whitehorsetc.com

  for domain in `ls /home/vpopmail/domains`
  do
     for user in `ls /home/vpopmail/domains/$domain`
     do
        pass=`/home/vpopmail/bin/vuserinfo $user@$domain | grep "clear passwd: " | sed 's/clear passwd: //'`
        [ ! -z $pass ] && curl -v imaps://${user}%40${domain}:${pass}@${fqdn}/ &> tmpcon && \
           tmpconok=`cat tmpcon | grep "OK Logged in"` && \
           [[ ! -z $tmpconok ]] && (echo "$user@$domain --> success"  || echo "$user@$domain --> failed")
     done
  done

  rm tmpcon
  exit 0