v-delete-web-domain 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #!/bin/bash
  2. # info: delete web domain
  3. # options: USER DOMAIN
  4. #
  5. # The call of function leads to the removal of domain and all its components
  6. # (statistics, folders contents, ssl certificates, etc.). This operation is
  7. # not fully supported by "undo" function, so the data recovery is possible
  8. # only with a help of reserve copy.
  9. #----------------------------------------------------------#
  10. # Variable&Function #
  11. #----------------------------------------------------------#
  12. # Argument defenition
  13. user=$1
  14. domain=$(idn -t --quiet -u "$2" )
  15. domain_idn=$(idn -t --quiet -a "$domain")
  16. restart=$3
  17. # Includes
  18. source $VESTA/conf/vesta.conf
  19. source $VESTA/func/main.sh
  20. source $VESTA/func/domain.sh
  21. source $VESTA/func/ip.sh
  22. #----------------------------------------------------------#
  23. # Verifications #
  24. #----------------------------------------------------------#
  25. check_args '2' "$#" 'USER DOMAIN'
  26. validate_format 'user' 'domain'
  27. is_system_enabled "$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. #----------------------------------------------------------#
  33. # Action #
  34. #----------------------------------------------------------#
  35. # Get template name
  36. get_domain_values 'web'
  37. tpl_file="$WEBTPL/apache_$TPL.tpl"
  38. conf="$HOMEDIR/$user/conf/web/httpd.conf"
  39. ip=$(get_real_ip $IP)
  40. # Deleting domain
  41. del_web_config
  42. # Checking aliases
  43. if [ ! -z "$ALIAS" ]; then
  44. aliases=$(echo $ALIAS | tr ',' '\n' | wc -l )
  45. else
  46. aliases=0
  47. fi
  48. # Checking ssl
  49. if [ "$SSL" = 'yes' ]; then
  50. tpl_file="$WEBTPL/apache_$TPL.stpl"
  51. conf="$HOMEDIR/$user/conf/web/shttpd.conf"
  52. del_web_config
  53. # Deleting certificates
  54. rm -f $HOMEDIR/$user/conf/web/ssl.$domain.*
  55. rm -f $USER_DATA/ssl/$domain.*
  56. fi
  57. # Checking nginx
  58. if [ ! -z "$NGINX" ]; then
  59. tpl_file="$WEBTPL/nginx_$NGINX.tpl"
  60. conf="$HOMEDIR/$user/conf/web/nginx.conf"
  61. del_web_config
  62. if [ "$SSL" = 'yes' ]; then
  63. tpl_file="$WEBTPL/nginx_$NGINX.stpl"
  64. conf="$HOMEDIR/$user/conf/web/snginx.conf"
  65. del_web_config
  66. fi
  67. fi
  68. # Checking stats
  69. if [ ! -z "$STATS" ] && [ "$STATS" != 'no' ]; then
  70. sed -i "/ $domain$/d" $VESTA/data/queue/webstats.pipe
  71. rm -f $HOMEDIR/$user/conf/web/$STATS.$domain.conf
  72. rm -f /etc/awstats/$STATS.$domain.conf
  73. fi
  74. # Deleting ftp account
  75. if [ ! -z "$FTP_USER" ]; then
  76. /usr/sbin/userdel -f $FTP_USER >> /dev/null 2>&1
  77. fi
  78. # Deleting directory
  79. rm -rf $HOMEDIR/$user/web/$domain
  80. # Deleting logs
  81. rm -f /var/log/httpd/domains/$domain.log*
  82. rm -f /var/log/httpd/domains/$domain.bytes
  83. rm -f /var/log/httpd/domains/$domain.error*
  84. #----------------------------------------------------------#
  85. # Vesta #
  86. #----------------------------------------------------------#
  87. # Deleting domain
  88. sed -i "/DOMAIN='$domain'/ d" $USER_DATA/web.conf
  89. # Checking last ssl domain
  90. ssl_dom=$(grep "SSL='yes'" $USER_DATA/web.conf | wc -l)
  91. if [ "$ssl_dom" -eq '0' ]; then
  92. sed -i "s/ Include /#Include /" $HOMEDIR/$user/conf/web/httpd.conf
  93. fi
  94. # Checking last domain
  95. domains=$(wc -l $USER_DATA/web.conf|cut -f 1 -d ' ')
  96. if [ "$domains" -eq '0' ]; then
  97. conf='/etc/httpd/conf.d/vesta.conf'
  98. line=$(grep -n "$HOMEDIR/$user/conf/web/httpd.conf" $conf | cut -f 1 -d : )
  99. if [ ! -z "$line" ]; then
  100. sed -i "$line d" $conf
  101. fi
  102. fi
  103. # Checking last nginx domain
  104. conf='/etc/nginx/conf.d/vesta_users.conf'
  105. last_nginx=$(grep -v "NGINX=''" $USER_DATA/web.conf)
  106. last_snginx=$(echo "$last_nginx" | grep "SSL='yes'")
  107. if [ -z "$last_snginx" ]; then
  108. sline=$(grep -n "$HOMEDIR/$user/conf/web/snginx.conf" $conf |cut -f 1 -d :)
  109. if [ ! -z "$sline" ]; then
  110. sed -i "$sline d" $conf
  111. fi
  112. rm -f $HOMEDIR/$user/conf/web/snginx.conf
  113. fi
  114. if [ -z "$last_nginx" ]; then
  115. line=$(grep -n "$HOMEDIR/$user/conf/web/nginx.conf" $conf | cut -f 1 -d : )
  116. if [ ! -z "$line" ]; then
  117. sed -i "$line d" $conf
  118. fi
  119. rm -f $HOMEDIR/$user/conf/web/nginx.conf
  120. fi
  121. # Decrease counters
  122. decrease_ip_value "$ip"
  123. decrease_user_value "$user" '$U_WEB_DOMAINS'
  124. decrease_user_value "$user" '$U_WEB_ALIASES' "$aliases"
  125. if [ "$SSL" = 'yes' ]; then
  126. decrease_user_value "$user" '$U_WEB_SSL'
  127. fi
  128. # Restart web server
  129. if [ "$restart" != 'no' ]; then
  130. $BIN/v-restart-web "$EVENT"
  131. fi
  132. # Logging
  133. log_history "deleted web domain $domain"
  134. log_event "$OK" "$EVENT"
  135. exit