v-change-sys-webmail 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. # Argument definition
  10. WEBMAIL=$1
  11. # Includes
  12. source $HESTIA/func/main.sh
  13. source $HESTIA/conf/hestia.conf
  14. #----------------------------------------------------------#
  15. # Verifications #
  16. #----------------------------------------------------------#
  17. check_args '1' "$#" 'WEBMAIL'
  18. # Check if string has leading /
  19. if [[ ! ${WEBMAIL:0:1} == "/" ]]; then
  20. WEBMAIL="/$WEBMAIL"
  21. fi
  22. #----------------------------------------------------------#
  23. # Action #
  24. #----------------------------------------------------------#
  25. # Get existing apache2 webmail alias
  26. if [ -f /etc/apache2/conf.d/roundcube.conf ]; then
  27. apache_webmail=$(tail -n+3 /etc/apache2/conf.d/roundcube.conf | grep "Alias" | { IFS=' '; read -r -a array; echo "${array[1]}"; })
  28. fi
  29. # Get existing nginx webmail alias
  30. if [ -f /etc/nginx/conf.d/webmail.inc ]; then
  31. nginx_webmail=$(cat /etc/nginx/conf.d/webmail.inc | grep "location" | { IFS=' '; read -r -a array; echo "${array[1]}"; })
  32. fi
  33. # Check if alias is different for apache2
  34. if [ ! -z "$apache_webmail" ]; then
  35. if [ ! "$apache_webmail" = "$WEBMAIL" ]; then
  36. # Replace webmail alias in config files.
  37. sed -i "s|Alias $apache_webmail|Alias $WEBMAIL|" /etc/apache2/conf.d/roundcube.conf
  38. # Replace in Backend UI
  39. sed -i "s|$apache_webmail/|$WEBMAIL/|" /usr/local/hestia/web/templates/admin/list_mail.html
  40. sed -i "s|$apache_webmail/|$WEBMAIL/|" /usr/local/hestia/web/templates/user/list_mail.html
  41. # Restart services
  42. $HESTIA/bin/v-restart-service apache2
  43. fi
  44. fi
  45. # Check if alias is different for nginx
  46. if [ ! -z "$nginx_webmail" ]; then
  47. if [ ! "$nginx_webmail" = "$WEBMAIL" ]; then
  48. # Replace webmail alias in config files.
  49. sed -i "s|$nginx_webmail|$WEBMAIL|" /etc/nginx/conf.d/webmail.inc
  50. sed -i "s|/var/lib$WEBMAIL|/var/lib/roundcube|" /etc/nginx/conf.d/webmail.inc
  51. # Replace in Backend UI
  52. sed -i "s|$nginx_webmail/|$WEBMAIL/|" /usr/local/hestia/web/templates/admin/list_mail.html
  53. sed -i "s|$nginx_webmail/|$WEBMAIL/|" /usr/local/hestia/web/templates/user/list_mail.html
  54. # Restart services
  55. $HESTIA/bin/v-restart-service nginx
  56. fi
  57. fi
  58. #----------------------------------------------------------#
  59. # Hestia #
  60. #----------------------------------------------------------#
  61. # Logging
  62. #log_event "$OK" "$ARGUMENTS"
  63. exit