Browse Source

smtp-check

main
pvincent 7 months ago
parent
commit
72ed035132
  1. 63
      scripts/smtp-check
  2. 11
      scripts/smtp-chek
  3. 15
      scripts/ssl-check

63
scripts/smtp-check

@ -0,0 +1,63 @@
#!/bin/bash
function usage {
echo 'usage: <SERVER> [USERNAME PASSWORD]'
exit 1
}
function connect_server {
openssl s_client -starttls smtp -connect "$server:587" -ign_eof 2>/dev/null <<EOF
quit
EOF
}
function auth_server {
base64=$(echo -ne "\0$username\0$password" | base64)
openssl s_client -starttls smtp -connect "$server:587" -ign_eof 2>/dev/null <<EOF
ehlo .
auth plain $base64
quit
EOF
}
function check_smtp_connection {
echo -n "check smtp server <$server> port 587 ... "
if connect_server | grep -q CONNECTED; then
echo SUCCESS
else
echo FAILURE && exit 1
fi
}
function check_smtp_auth {
echo -n "check smtp authentication <$server> port 587 username=<$username> ... "
set +e
output=$(auth_server)
if echo "$output" | grep -q CONNECTED; then
if echo "$output" | grep -q "Authentication successful"; then
echo OK
else
echo wrong username or password! && exit 2
fi
else
echo wrong server connection! && exit 1
fi
set -e
}
### MAIN
set -Eeuo pipefail
server=${1:-}
username=${2:-}
password=${3:-}
[[ -z "$server" ]] && usage
if [[ -z "$username" ]]; then
check_smtp_connection
else
[[ -z "$password" ]] && usage
check_smtp_auth
fi

11
scripts/smtp-chek

@ -1,11 +0,0 @@
#!/bin/bash
username=postmaster@mangue-et-solidaire.re
password=
base64=$(echo -ne "\0$username\0$password" | base64)
openssl s_client -starttls smtp -connect mail1.zourit.net:587 -ign_eof <<EOF | grep "Authentication successful"
ehlo mangue-et-solidaire.re
auth plain $base64
quit
EOF

15
scripts/ssl_check → scripts/ssl-check

@ -7,7 +7,7 @@ result=0
function usage {
echo 'usage: <DOMAIN> [ https | 443 | smtps | 587 | pop3 | 993 | imap | 995 | ALL ]'
exit -1
exit 1
}
function check_ssl {
@ -20,7 +20,6 @@ function check_ssl {
echo -n "$protocol "
certificate_info=$(echo | timeout $TIMEOUT openssl s_client $extra -connect $DOMAIN:$2 2>/dev/null)
issuer=$(echo "$certificate_info" | openssl x509 -noout -text 2>/dev/null | grep Issuer: | cut -d: -f2)
@ -59,13 +58,17 @@ function check_ssl {
[[ -z "$DOMAIN" ]] && usage
case $PROTOCOL in
https | 443)
check_ssl HTTPS 443;;
check_ssl HTTPS 443
;;
smtps | 587)
check_ssl SMTPS 587;;
check_ssl SMTPS 587
;;
pop3 | 995)
check_ssl POP3 995;;
check_ssl POP3 995
;;
imap | 993)
check_ssl IMAP 993;;
check_ssl IMAP 993
;;
all | ALL)
check_ssl HTTPS 443
check_ssl SMTPS 587
Loading…
Cancel
Save