v-delete-sys-webmail 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. # Perform verification if read-only mode is enabled
  38. check_hestia_demo_mode
  39. #----------------------------------------------------------#
  40. # Action #
  41. #----------------------------------------------------------#
  42. if [ ! -z "$WEBMAIL_ALIAS" ]; then
  43. # Delete webmail configuration
  44. del_webmail_config
  45. del_webmail_ssl_config
  46. # Ensure that corresponding DNS records are removed
  47. if [ ! -z "$DNS_SYSTEM" ]; then
  48. dns_domain=$($BIN/v-list-dns-domains $user | grep $domain | cut -d' ' -f1)
  49. webmail_record=$($BIN/v-list-dns-records $user $domain | grep -i $WEBMAIL_ALIAS | cut -d' ' -f1)
  50. if [ "$dns_domain" = "$domain" ]; then
  51. if [ ! -z "$webmail_record" ]; then
  52. $BIN/v-delete-dns-record $user $domain $webmail_record
  53. fi
  54. fi
  55. fi
  56. else
  57. echo "Error: WEBMAIL_ALIAS is not defined in hestia.conf."
  58. fi
  59. # Set SSL as enabled in configuration
  60. update_object_value 'mail' 'DOMAIN' "$domain" '$WEBMAIL' ""
  61. #----------------------------------------------------------#
  62. # Hestia #
  63. #----------------------------------------------------------#
  64. if [ ! -z "$3" ]; then
  65. # Restarting web server
  66. $BIN/v-restart-web $restart
  67. check_result $? "Web restart failed" >/dev/null
  68. $BIN/v-restart-proxy $restart
  69. check_result $? "Proxy restart failed" >/dev/null
  70. fi
  71. # Logging
  72. if [ "$quiet" != 'yes' ]; then
  73. log_history "disabled webmail support for $domain"
  74. fi
  75. log_event "$OK" "$ARGUMENTS"
  76. exit