v-delete-web-domain-alias 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. if [ -z "$(echo $ALIAS |tr ',' '\n' |grep ^$dom_alias$)" ]; then
  32. check_result $E_NOTEXIST "alias $dom_alias doesn't exist"
  33. fi
  34. #----------------------------------------------------------#
  35. # Action #
  36. #----------------------------------------------------------#
  37. # Preparing domain values for the template substitution
  38. local_ip=$(get_real_ip $IP)
  39. ALIAS=$(echo "$ALIAS" |\
  40. sed -e "s/,/\n/g"|\
  41. sed -e "s/^$dom_alias$//g"|\
  42. sed -e "/^$/d"|\
  43. sed -e ':a;N;$!ba;s/\n/,/g')
  44. prepare_web_domain_values
  45. # Rebuilding vhost
  46. del_web_config "$WEB_SYSTEM" "$TPL.tpl"
  47. add_web_config "$WEB_SYSTEM" "$TPL.tpl"
  48. if [ "$SSL" = 'yes' ]; then
  49. del_web_config "$WEB_SYSTEM" "$TPL.stpl"
  50. add_web_config "$WEB_SYSTEM" "$TPL.stpl"
  51. fi
  52. # Rebuilding proxy configuration
  53. if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
  54. del_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
  55. add_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
  56. if [ "$SSL" = 'yes' ]; then
  57. del_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
  58. add_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
  59. fi
  60. fi
  61. #----------------------------------------------------------#
  62. # Vesta #
  63. #----------------------------------------------------------#
  64. # Update config
  65. update_object_value 'web' 'DOMAIN' "$domain" '$ALIAS' "$ALIAS"
  66. decrease_user_value "$user" '$U_WEB_ALIASES'
  67. # Restarting web server
  68. $BIN/v-restart-web $restart
  69. check_result $? "Web restart failed" >/dev/null
  70. $BIN/v-restart-proxy $restart
  71. check_result $? "Proxy restart failed" >/dev/null
  72. # Logging
  73. log_history "deleted alias $dom_alias on $domain"
  74. log_event "$OK" "$ARGUMENTS"
  75. exit