v-delete-sys-webmail 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. $BIN/v-delete-dns-record $user $domain $webmail_record $restart
  54. fi
  55. fi
  56. fi
  57. else
  58. echo "Error: WEBMAIL_ALIAS is not defined in hestia.conf."
  59. fi
  60. # Set SSL as enabled in configuration
  61. update_object_value 'mail' 'DOMAIN' "$domain" '$WEBMAIL' ""
  62. #----------------------------------------------------------#
  63. # Hestia #
  64. #----------------------------------------------------------#
  65. if [ ! -z "$3" ]; then
  66. # Restarting web server
  67. $BIN/v-restart-web $restart
  68. check_result $? "Web restart failed" >/dev/null
  69. $BIN/v-restart-proxy $restart
  70. check_result $? "Proxy restart failed" >/dev/null
  71. fi
  72. # Logging
  73. if [ "$quiet" != 'yes' ]; then
  74. $BIN/v-log-action "$user" "Info" "Mail" "Webmail client access disabled (Domain: $domain)."
  75. fi
  76. log_event "$OK" "$ARGUMENTS"
  77. exit