v-change-sys-webmail 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. # info: change webmail alias url
  3. # options: WEBMAIL
  4. #
  5. # This function changes the webmail url in apache2 or nginx configuration.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Includes
  10. source $HESTIA/func/main.sh
  11. source $HESTIA/conf/hestia.conf
  12. # Get existing system webmail alias
  13. export $WEBMAIL_ALIAS
  14. # Define aliases
  15. OLD_ALIAS=$WEBMAIL_ALIAS
  16. NEW_ALIAS=$1
  17. #----------------------------------------------------------#
  18. # Action #
  19. #----------------------------------------------------------#
  20. # Delete old webmail configuration
  21. for user in `ls /usr/local/hestia/data/users/`; do
  22. for domain in $($BIN/v-list-mail-domains $user plain |cut -f 1); do
  23. $BIN/v-delete-sys-webmail $user $domain
  24. done
  25. done
  26. # Set new webmail alias
  27. $BIN/v-change-sys-config-value 'WEBMAIL_ALIAS' $NEW_ALIAS
  28. for user in `ls /usr/local/hestia/data/users/`; do
  29. for domain in $($BIN/v-list-mail-domains $user plain |cut -f 1); do
  30. $BIN/v-add-sys-webmail $user $domain
  31. done
  32. done
  33. # Update global directory alias configuration
  34. if [ "$WEB_SYSTEM" = 'apache2' ]; then
  35. sed -i "s|Alias \/$OLD_ALIAS|Alias \/$NEW_ALIAS|gI" /etc/apache2/conf.d/roundcube.conf
  36. fi
  37. if [ -e /etc/nginx/conf.d/webmail.inc ]; then
  38. sed -i "s|location \/$OLD_ALIAS|location \/$NEW_ALIAS|gI" /etc/nginx/conf.d/webmail.inc
  39. fi
  40. #----------------------------------------------------------#
  41. # Hestia #
  42. #----------------------------------------------------------#
  43. # Restart services
  44. $BIN/v-restart-web $restart
  45. $BIN/v-restart-proxy $restart
  46. # Logging
  47. log_history "changed global webmail alias to $NEW_ALIAS"
  48. log_event "$OK" "$ARGUMENTS"
  49. exit