v-delete-web-domain-alias 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. if [ -z "$(echo $ALIAS | tr ',' '\n' | grep ^$dom_alias$)" ]; then
  33. echo "Error: alias $dom_alias not exist"
  34. log_event "$E_NOTEXIST" "$EVENT"
  35. exit $E_NOTEXIST
  36. fi
  37. #----------------------------------------------------------#
  38. # Action #
  39. #----------------------------------------------------------#
  40. # Defining new alias string
  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. tpl_file="$WEBTPL/apache_$TPL.tpl"
  47. conf="$HOMEDIR/$user/conf/web/httpd.conf"
  48. # Preparing domain values for the template substitution
  49. upd_web_domain_values
  50. # Recreating vhost
  51. del_web_config
  52. add_web_config
  53. if [ "$SSL" = 'yes' ]; then
  54. tpl_file="$WEBTPL/apache_$TPL.stpl"
  55. conf="$HOMEDIR/$user/conf/web/shttpd.conf"
  56. del_web_config
  57. add_web_config
  58. fi
  59. # Checking nginx
  60. if [ ! -z "$NGINX" ]; then
  61. tpl_file="$WEBTPL/nginx_$NGINX.tpl"
  62. conf="$HOMEDIR/$user/conf/web/nginx.conf"
  63. del_web_config
  64. add_web_config
  65. if [ "$SSL" = 'yes' ]; then
  66. tpl_file="$WEBTPL/nginx_$NGINX.stpl"
  67. conf="$HOMEDIR/$user/conf/web/snginx.conf"
  68. del_web_config
  69. add_web_config
  70. fi
  71. fi
  72. #----------------------------------------------------------#
  73. # Vesta #
  74. #----------------------------------------------------------#
  75. # Update config
  76. update_object_value 'web' 'DOMAIN' "$domain" '$ALIAS' "$ALIAS"
  77. # Update counters
  78. decrease_user_value "$user" '$U_WEB_ALIASES'
  79. # Restart web server
  80. if [ "$restart" != 'no' ]; then
  81. $BIN/v-restart-web "$EVENT"
  82. fi
  83. # Logging
  84. log_history "deleted alias $dom_alias on $domain"
  85. log_event "$OK" "$EVENT"
  86. exit