configure-server-smtp.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. # info: setup SMTP Account for server logging
  3. # options: NONE
  4. # labels:
  5. #
  6. # example: configure-server-smtp.sh
  7. #
  8. # This function provides an user-interactive configuration of a SMTP account
  9. # for the server to use for logging, notification and warn emails etc.
  10. #----------------------------------------------------------#
  11. # Variable&Function #
  12. #----------------------------------------------------------#
  13. # Includes
  14. # shellcheck source=/etc/hestiacp/hestia.conf
  15. source /etc/hestiacp/hestia.conf
  16. # shellcheck source=/usr/local/hestia/func/main.sh
  17. source $HESTIA/func/main.sh
  18. # shellcheck source=/usr/local/hestia/conf/hestia.conf
  19. source $HESTIA/conf/hestia.conf
  20. function setupFiles {
  21. echo "Use SMTP account for server communication (Y/n): "
  22. read use_smtp_prompt
  23. use_smtp="${use_smtp_prompt:-y}"
  24. use_smtp="${use_smtp,,}"
  25. if [ "${use_smtp}" == "y" ]; then
  26. use_smtp=true
  27. echo "Enter SMTP Host:"
  28. read -i $SERVER_SMTP_HOST -e smtp_server_host
  29. echo "Enter SMTP Port:"
  30. read -i $SERVER_SMTP_PORT -e smtp_server_port
  31. echo "Enter SMTP Security:"
  32. read -i $SERVER_SMTP_SECURITY -e smtp_server_security
  33. echo "Enter SMTP Username:"
  34. read -i $SERVER_SMTP_USER -e smtp_server_user_name
  35. echo "Enter SMTP Password (stored as plaintext):"
  36. read -i $SERVER_SMTP_PASSWD -e smtp_server_password
  37. echo "Enter Email Address:"
  38. read -i $SERVER_SMTP_ADDR -e smtp_server_addr
  39. else
  40. use_smtp=false
  41. fi
  42. echo "Summary:
  43. Use SMTP: $use_smtp
  44. SMTP Host: $smtp_server_host
  45. SMTP Port: $smtp_server_port
  46. SMTP Security: $smtp_server_security
  47. SMTP Username: $smtp_server_user_name
  48. SMTP Password: $smtp_server_password
  49. Email Address: $smtp_server_addr
  50. Are these values correct? (y/N)"
  51. read correct_validation
  52. correct="${correct_validation:-n}"
  53. correct="${correct,,}"
  54. if [ "${correct}" != "y" ]; then
  55. echo "Not Proceeding. Restart or Quit (r/Q)?"
  56. read restart_quit_prompt
  57. restart_quit="${restart_quit_prompt:-q}"
  58. restart_quit="${restart_quit,,}"
  59. if [ "${restart_quit}" == "r" ]; then
  60. clear
  61. setupFiles
  62. else
  63. exit 3
  64. fi
  65. else
  66. $BIN/v-change-sys-config-value "USE_SERVER_SMTP" "${use_smtp:-}"
  67. $BIN/v-change-sys-config-value "SERVER_SMTP_HOST" "${smtp_server_host:-}"
  68. $BIN/v-change-sys-config-value "SERVER_SMTP_PORT" "${smtp_server_port:-}"
  69. $BIN/v-change-sys-config-value "SERVER_SMTP_SECURITY" "${smtp_server_security:-}"
  70. $BIN/v-change-sys-config-value "SERVER_SMTP_USER" "${smtp_server_user_name:-}"
  71. $BIN/v-change-sys-config-value "SERVER_SMTP_PASSWD" "${smtp_server_password:-}"
  72. $BIN/v-change-sys-config-value "SERVER_SMTP_ADDR" "${smtp_server_addr:-}"
  73. fi
  74. }
  75. setupFiles