v-delete-web-domain-alias 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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/conf/vesta.conf
  19. source $VESTA/func/main.sh
  20. source $VESTA/func/domain.sh
  21. #----------------------------------------------------------#
  22. # Verifications #
  23. #----------------------------------------------------------#
  24. check_args '3' "$#" 'USER DOMAIN DOM_ALIAS [RESTART]'
  25. validate_format 'user' 'domain' 'dom_alias'
  26. is_system_enabled 'WEB_SYSTEM'
  27. is_object_valid 'user' 'USER' "$user"
  28. is_object_unsuspended 'user' 'USER' "$user"
  29. is_object_valid 'web' 'DOMAIN' "$domain"
  30. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  31. get_domain_values 'web'
  32. ip=$(get_real_ip $IP)
  33. if [ -z "$(echo $ALIAS | tr ',' '\n' | grep ^$dom_alias$)" ]; then
  34. echo "Error: alias $dom_alias not exist"
  35. log_event "$E_NOTEXIST" "$EVENT"
  36. exit $E_NOTEXIST
  37. fi
  38. #----------------------------------------------------------#
  39. # Action #
  40. #----------------------------------------------------------#
  41. # Defining new alias string
  42. ALIAS=$(echo "$ALIAS" |\
  43. sed -e "s/,/\n/g"|\
  44. sed -e "s/^$dom_alias$//g"|\
  45. sed -e "/^$/d"|\
  46. sed -e ':a;N;$!ba;s/\n/,/g')
  47. tpl_file="$WEBTPL/apache_$TPL.tpl"
  48. conf="$HOMEDIR/$user/conf/web/httpd.conf"
  49. # Preparing domain values for the template substitution
  50. upd_web_domain_values
  51. # Recreating vhost
  52. del_web_config
  53. add_web_config
  54. if [ "$SSL" = 'yes' ]; then
  55. tpl_file="$WEBTPL/apache_$TPL.stpl"
  56. conf="$HOMEDIR/$user/conf/web/shttpd.conf"
  57. del_web_config
  58. add_web_config
  59. fi
  60. # Checking nginx
  61. if [ ! -z "$NGINX" ]; then
  62. tpl_file="$WEBTPL/nginx_$NGINX.tpl"
  63. conf="$HOMEDIR/$user/conf/web/nginx.conf"
  64. del_web_config
  65. add_web_config
  66. if [ "$SSL" = 'yes' ]; then
  67. tpl_file="$WEBTPL/nginx_$NGINX.stpl"
  68. conf="$HOMEDIR/$user/conf/web/snginx.conf"
  69. del_web_config
  70. add_web_config
  71. fi
  72. fi
  73. #----------------------------------------------------------#
  74. # Vesta #
  75. #----------------------------------------------------------#
  76. # Update config
  77. update_object_value 'web' 'DOMAIN' "$domain" '$ALIAS' "$ALIAS"
  78. # Update counters
  79. decrease_user_value "$user" '$U_WEB_ALIASES'
  80. # Restart web server
  81. if [ "$restart" != 'no' ]; then
  82. $BIN/v-restart-web "$EVENT"
  83. fi
  84. # Logging
  85. log_history "deleted alias $dom_alias on $domain"
  86. log_event "$OK" "$EVENT"
  87. exit