provisioning tool for building opinionated architecture
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.3 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
  1. #!/bin/bash
  2. function usage {
  3. echo 'usage: <SERVER> [USERNAME PASSWORD]'
  4. exit 1
  5. }
  6. function connect_server {
  7. openssl s_client -starttls smtp -connect "$server:587" -ign_eof 2>/dev/null <<EOF
  8. quit
  9. EOF
  10. }
  11. function auth_server {
  12. base64=$(echo -ne "\0$username\0$password" | base64)
  13. openssl s_client -starttls smtp -connect "$server:587" -ign_eof 2>/dev/null <<EOF
  14. ehlo .
  15. auth plain $base64
  16. quit
  17. EOF
  18. }
  19. function check_smtp_connection {
  20. echo -n "check smtp server <$server> port 587 ... "
  21. if connect_server | grep -q CONNECTED; then
  22. echo SUCCESSFUL CONNECTION
  23. else
  24. echo wrong server connection! && exit 1
  25. fi
  26. }
  27. function check_smtp_auth {
  28. echo -n "check smtp authentication <$server> port 587 username=<$username> ... "
  29. set +e
  30. output=$(auth_server)
  31. if echo "$output" | grep -q CONNECTED; then
  32. if echo "$output" | grep -q "Authentication successful"; then
  33. echo SUCCESSFUL AUTHENTICATION
  34. else
  35. echo wrong username or password! && exit 2
  36. fi
  37. else
  38. echo wrong server connection! && exit 1
  39. fi
  40. set -e
  41. }
  42. ### MAIN
  43. set -Eeuo pipefail
  44. server=${1:-}
  45. username=${2:-}
  46. password=${3:-}
  47. [[ -z "$server" ]] && usage
  48. if [[ -z "$username" ]]; then
  49. check_smtp_connection
  50. else
  51. [[ -z "$password" ]] && usage
  52. check_smtp_auth
  53. fi