v-delete-sys-webmail 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. source $HESTIA/func/main.sh
  20. source $HESTIA/func/domain.sh
  21. source $HESTIA/conf/hestia.conf
  22. # Additional argument formatting
  23. format_domain
  24. format_domain_idn
  25. #----------------------------------------------------------#
  26. # Verifications #
  27. #----------------------------------------------------------#
  28. check_args '2' "$#" 'USER DOMAIN [RESTART]'
  29. is_format_valid 'user' 'domain'
  30. is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
  31. is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
  32. is_system_enabled "$IMAP_SYSTEM" 'IMAP_SYSTEM'
  33. is_object_valid 'user' 'USER' "$user"
  34. is_object_unsuspended 'user' 'USER' "$user"
  35. is_object_valid 'mail' 'DOMAIN' "$domain"
  36. is_object_unsuspended 'mail' 'DOMAIN' "$domain"
  37. #----------------------------------------------------------#
  38. # Action #
  39. #----------------------------------------------------------#
  40. if [ ! -z "$WEBMAIL_ALIAS" ]; then
  41. # Delete webmail configuration
  42. del_webmail_config
  43. del_webmail_ssl_config
  44. # Ensure that corresponding DNS records are removed
  45. if [ ! -z "$DNS_SYSTEM" ]; then
  46. dns_domain=$($BIN/v-list-dns-domains $user | grep $domain | cut -d' ' -f1)
  47. webmail_record=$($BIN/v-list-dns-records $user $domain | grep -i $WEBMAIL_ALIAS | cut -d' ' -f1)
  48. if [ "$dns_domain" = "$domain" ]; then
  49. if [ ! -z "$webmail_record" ]; then
  50. $BIN/v-delete-dns-record $user $domain $webmail_record
  51. fi
  52. fi
  53. fi
  54. else
  55. echo "Error: WEBMAIL_ALIAS is not defined in hestia.conf."
  56. fi
  57. #----------------------------------------------------------#
  58. # Hestia #
  59. #----------------------------------------------------------#
  60. if [ ! -z "$3" ]; then
  61. # Restarting web server
  62. $BIN/v-restart-web $restart
  63. check_result $? "Web restart failed" >/dev/null
  64. $BIN/v-restart-proxy $restart
  65. check_result $? "Proxy restart failed" >/dev/null
  66. fi
  67. # Logging
  68. if [ "$quiet" != 'yes' ]; then
  69. log_history "disabled webmail support for $domain"
  70. fi
  71. log_event "$OK" "$ARGUMENTS"
  72. exit