v-delete-web-domain-alias 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. # info: delete web domain alias
  3. # options: USER DOMAIN ALIAS [RESTART]
  4. #
  5. # The function of deleting the alias domain (parked domain). By this call
  6. # default www aliase can be removed as well.
  7. #----------------------------------------------------------#
  8. # Variable&Function #
  9. #----------------------------------------------------------#
  10. # Argument definition
  11. user=$1
  12. domain=$2
  13. dom_alias=$3
  14. restart=$4
  15. # Includes
  16. source $VESTA/func/main.sh
  17. source $VESTA/func/domain.sh
  18. source $VESTA/func/ip.sh
  19. source $VESTA/conf/vesta.conf
  20. #----------------------------------------------------------#
  21. # Verifications #
  22. #----------------------------------------------------------#
  23. check_args '3' "$#" 'USER DOMAIN DOM_ALIAS [RESTART]'
  24. is_format_valid 'user' 'domain' 'dom_alias'
  25. is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
  26. is_object_valid 'user' 'USER' "$user"
  27. is_object_unsuspended 'user' 'USER' "$user"
  28. is_object_valid 'web' 'DOMAIN' "$domain"
  29. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  30. get_domain_values 'web'
  31. ip=$(get_real_ip $IP)
  32. if [ -z "$(echo $ALIAS | tr ',' '\n' | grep ^$dom_alias$)" ]; then
  33. echo "Error: alias $dom_alias doesn't exist"
  34. log_event "$E_NOTEXIST" "$ARGUMENTS"
  35. exit $E_NOTEXIST
  36. fi
  37. #----------------------------------------------------------#
  38. # Action #
  39. #----------------------------------------------------------#
  40. # Preparing domain values for the template substitution
  41. ALIAS=$(echo "$ALIAS" |\
  42. sed -e "s/,/\n/g"|\
  43. sed -e "s/^$dom_alias$//g"|\
  44. sed -e "/^$/d"|\
  45. sed -e ':a;N;$!ba;s/\n/,/g')
  46. prepare_web_domain_values
  47. # Rebuilding vhost
  48. del_web_config "$WEB_SYSTEM" "$TPL.tpl"
  49. add_web_config "$WEB_SYSTEM" "$TPL.tpl"
  50. if [ "$SSL" = 'yes' ]; then
  51. del_web_config "$WEB_SYSTEM" "$TPL.stpl"
  52. add_web_config "$WEB_SYSTEM" "$TPL.stpl"
  53. fi
  54. # Rebuilding proxy configuration
  55. if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
  56. del_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
  57. add_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
  58. if [ "$SSL" = 'yes' ]; then
  59. del_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
  60. add_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
  61. fi
  62. fi
  63. #----------------------------------------------------------#
  64. # Vesta #
  65. #----------------------------------------------------------#
  66. # Update config
  67. update_object_value 'web' 'DOMAIN' "$domain" '$ALIAS' "$ALIAS"
  68. decrease_user_value "$user" '$U_WEB_ALIASES'
  69. # Restarting web server
  70. if [ "$restart" != 'no' ]; then
  71. $BIN/v-restart-web
  72. check_result $? "Web restart failed" >/dev/null
  73. if [ ! -z "$PROXY_SYSTEM" ]; then
  74. $BIN/v-restart-proxy
  75. check_result $? "Proxy restart failed" >/dev/null
  76. fi
  77. fi
  78. # Logging
  79. log_history "deleted alias $dom_alias on $domain"
  80. log_event "$OK" "$ARGUMENTS"
  81. exit