v-delete-web-domain-alias 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 defenition
  11. user=$1
  12. domain=$(idn -t --quiet -u "$2" )
  13. domain_idn=$(idn -t --quiet -a "$domain" )
  14. dom_alias=$(idn -t --quiet -u "$3" )
  15. dom_alias_idn=$(idn -t --quiet -a "$dom_alias" )
  16. restart="$4"
  17. # Includes
  18. source $VESTA/func/main.sh
  19. source $VESTA/func/domain.sh
  20. source $VESTA/func/ip.sh
  21. source $VESTA/conf/vesta.conf
  22. #----------------------------------------------------------#
  23. # Verifications #
  24. #----------------------------------------------------------#
  25. check_args '3' "$#" 'USER DOMAIN DOM_ALIAS [RESTART]'
  26. validate_format 'user' 'domain' 'dom_alias'
  27. is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
  28. is_object_valid 'user' 'USER' "$user"
  29. is_object_unsuspended 'user' 'USER' "$user"
  30. is_object_valid 'web' 'DOMAIN' "$domain"
  31. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  32. get_domain_values 'web'
  33. ip=$(get_real_ip $IP)
  34. if [ -z "$(echo $ALIAS | tr ',' '\n' | grep ^$dom_alias$)" ]; then
  35. echo "Error: alias $dom_alias doesn't exist"
  36. log_event "$E_NOTEXIST" "$EVENT"
  37. exit $E_NOTEXIST
  38. fi
  39. #----------------------------------------------------------#
  40. # Action #
  41. #----------------------------------------------------------#
  42. # Defining new alias string
  43. ALIAS=$(echo "$ALIAS" |\
  44. sed -e "s/,/\n/g"|\
  45. sed -e "s/^$dom_alias$//g"|\
  46. sed -e "/^$/d"|\
  47. sed -e ':a;N;$!ba;s/\n/,/g')
  48. tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.tpl"
  49. conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
  50. # Preparing domain values for the template substitution
  51. upd_web_domain_values
  52. # Recreating vhost
  53. del_web_config
  54. add_web_config
  55. if [ "$SSL" = 'yes' ]; then
  56. tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.stpl"
  57. conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
  58. del_web_config
  59. add_web_config
  60. fi
  61. # Checking proxy
  62. if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
  63. tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.tpl"
  64. conf="$HOMEDIR/$user/conf/web/$PROXY_SYSTEM.conf"
  65. del_web_config
  66. add_web_config
  67. if [ "$SSL" = 'yes' ]; then
  68. tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.stpl"
  69. conf="$HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf"
  70. del_web_config
  71. add_web_config
  72. fi
  73. fi
  74. #----------------------------------------------------------#
  75. # Vesta #
  76. #----------------------------------------------------------#
  77. # Update config
  78. update_object_value 'web' 'DOMAIN' "$domain" '$ALIAS' "$ALIAS"
  79. # Update counters
  80. decrease_user_value "$user" '$U_WEB_ALIASES'
  81. # Restarting web server
  82. if [ "$restart" != 'no' ]; then
  83. $BIN/v-restart-web
  84. check_result $? "Web restart failed" >/dev/null
  85. if [ ! -z "$PROXY_SYSTEM" ]; then
  86. $BIN/v-restart-proxy
  87. check_result $? "Proxy restart failed" >/dev/null
  88. fi
  89. fi
  90. # Logging
  91. log_history "deleted alias $dom_alias on $domain"
  92. log_event "$OK" "$EVENT"
  93. exit