v-delete-sys-webmail 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/bash
  2. # info: delete webmail support for a domain
  3. # options: USER DOMAIN [RESTART] [QUIET]
  4. # labels: hestia
  5. #
  6. # example: v-delete-sys-webmail user demo.com
  7. #
  8. # this function removes support for webmail from
  9. # a specified mail domain.
  10. #----------------------------------------------------------#
  11. # Variable&Function #
  12. #----------------------------------------------------------#
  13. # Argument definition
  14. user=$1
  15. domain=$2
  16. restart="$3"
  17. quiet=$4
  18. # Includes
  19. # shellcheck source=/usr/local/hestia/func/main.sh
  20. source $HESTIA/func/main.sh
  21. # shellcheck source=/usr/local/hestia/func/domain.sh
  22. source $HESTIA/func/domain.sh
  23. # shellcheck source=/usr/local/hestia/conf/hestia.conf
  24. source $HESTIA/conf/hestia.conf
  25. # Additional argument formatting
  26. format_domain
  27. format_domain_idn
  28. #----------------------------------------------------------#
  29. # Verifications #
  30. #----------------------------------------------------------#
  31. check_args '2' "$#" 'USER DOMAIN [RESTART]'
  32. is_format_valid 'user' 'domain'
  33. is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
  34. is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
  35. is_system_enabled "$IMAP_SYSTEM" 'IMAP_SYSTEM'
  36. is_object_valid 'user' 'USER' "$user"
  37. is_object_valid 'mail' 'DOMAIN' "$domain"
  38. # Perform verification if read-only mode is enabled
  39. check_hestia_demo_mode
  40. #----------------------------------------------------------#
  41. # Action #
  42. #----------------------------------------------------------#
  43. if [ ! -z "$WEBMAIL_ALIAS" ]; then
  44. # Delete webmail configuration
  45. del_webmail_config
  46. del_webmail_ssl_config
  47. # Ensure that corresponding DNS records are removed
  48. if [ ! -z "$DNS_SYSTEM" ]; then
  49. dns_domain=$($BIN/v-list-dns-domains $user | grep $domain | cut -d' ' -f1)
  50. webmail_record=$($BIN/v-list-dns-records $user $domain | grep -i $WEBMAIL_ALIAS | cut -d' ' -f1)
  51. if [ "$dns_domain" = "$domain" ]; then
  52. if [ ! -z "$webmail_record" ]; then
  53. if [ "$quiet" = "yes" ]; then
  54. $BIN/v-delete-dns-record $user $domain $webmail_record $restart 'yes'
  55. else
  56. $BIN/v-delete-dns-record $user $domain $webmail_record $restart
  57. fi
  58. fi
  59. fi
  60. fi
  61. else
  62. echo "Error: WEBMAIL_ALIAS is not defined in hestia.conf."
  63. fi
  64. # Set SSL as enabled in configuration
  65. update_object_value 'mail' 'DOMAIN' "$domain" '$WEBMAIL' ""
  66. #----------------------------------------------------------#
  67. # Hestia #
  68. #----------------------------------------------------------#
  69. if [ ! -z "$3" ]; then
  70. # Restarting web server
  71. $BIN/v-restart-web $restart
  72. check_result $? "Web restart failed" >/dev/null
  73. $BIN/v-restart-proxy $restart
  74. check_result $? "Proxy restart failed" >/dev/null
  75. fi
  76. # Logging
  77. if [ "$quiet" != 'yes' ]; then
  78. $BIN/v-log-action "$user" "Info" "Mail" "Webmail access disabled (Domain: $domain)."
  79. fi
  80. log_event "$OK" "$ARGUMENTS"
  81. exit