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.

64 lines
1.3 KiB

8 months ago
7 months ago
8 months ago
7 months ago
8 months ago
8 months ago
8 months ago
8 months ago
  1. #!/bin/bash
  2. function usage {
  3. echo 'usage: <SERVER> [USERNAME PASSWORD]'
  4. exit 1
  5. }
  6. function connect_server {
  7. timeout 2 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. set +e
  22. if connect_server | grep -q CONNECTED; then
  23. echo SUCCESSFUL CONNECTION
  24. else
  25. echo wrong server connection! && exit 1
  26. fi
  27. }
  28. function check_smtp_auth {
  29. echo -n "check smtp authentication <$server> port 587 username=<$username> ... "
  30. set +e
  31. output=$(auth_server)
  32. if echo "$output" | grep -q CONNECTED; then
  33. if echo "$output" | grep -q "Authentication successful"; then
  34. echo SUCCESSFUL AUTHENTICATION
  35. else
  36. echo wrong username or password! && exit 2
  37. fi
  38. else
  39. echo wrong server connection! && exit 1
  40. fi
  41. set -e
  42. }
  43. ### MAIN
  44. set -Eeuo pipefail
  45. server=${1:-}
  46. username=${2:-}
  47. password=${3:-}
  48. [[ -z "$server" ]] && usage
  49. if [[ -z "$username" ]]; then
  50. check_smtp_connection
  51. else
  52. [[ -z "$password" ]] && usage
  53. check_smtp_auth
  54. fi