v-delete-web-domain 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. # Deleting domain
  40. del_web_config
  41. # Checking aliases
  42. if [ ! -z "$ALIAS" ]; then
  43. aliases=$(echo $ALIAS | tr ',' '\n' | wc -l )
  44. else
  45. aliases=0
  46. fi
  47. # Checking ssl
  48. if [ "$SSL" = 'yes' ]; then
  49. tpl_file="$WEBTPL/apache_$TPL.stpl"
  50. conf="$HOMEDIR/$user/conf/web/shttpd.conf"
  51. del_web_config
  52. # Deleting certificates
  53. rm -f $HOMEDIR/$user/conf/web/ssl.$domain.*
  54. rm -f $USER_DATA/ssl/$domain.*
  55. fi
  56. # Checking nginx
  57. if [ ! -z "$NGINX" ]; then
  58. tpl_file="$WEBTPL/nginx_$NGINX.tpl"
  59. conf="$HOMEDIR/$user/conf/web/nginx.conf"
  60. del_web_config
  61. if [ "$SSL" = 'yes' ]; then
  62. tpl_file="$WEBTPL/nginx_$NGINX.stpl"
  63. conf="$HOMEDIR/$user/conf/web/snginx.conf"
  64. del_web_config
  65. fi
  66. fi
  67. # Checking stats
  68. if [ ! -z "$STATS" ] && [ "$STATS" != 'no' ]; then
  69. sed -i "/ $domain$/d" $VESTA/data/queue/webstats.pipe
  70. rm -f $HOMEDIR/$user/conf/web/$STATS.$domain.conf
  71. rm -f /etc/awstats/$STATS.$domain.conf
  72. fi
  73. # Deleting ftp account
  74. if [ ! -z "$FTP_USER" ]; then
  75. /usr/sbin/userdel $FTP_USER
  76. fi
  77. # Deleting directory
  78. rm -rf $HOMEDIR/$user/web/$domain
  79. # Deleting logs
  80. rm -f /var/log/httpd/domains/$domain.log*
  81. rm -f /var/log/httpd/domains/$domain.bytes
  82. rm -f /var/log/httpd/domains/$domain.error*
  83. #----------------------------------------------------------#
  84. # Vesta #
  85. #----------------------------------------------------------#
  86. # Deleting domain
  87. sed -i "/DOMAIN='$domain'/ d" $USER_DATA/web.conf
  88. # Checking last ssl domain
  89. ssl_dom=$(grep "SSL='yes'" $USER_DATA/web.conf | wc -l)
  90. if [ "$ssl_dom" -eq '0' ]; then
  91. sed -i "s/ Include /#Include /" $HOMEDIR/$user/conf/web/httpd.conf
  92. fi
  93. # Checking last domain
  94. domains=$(wc -l $USER_DATA/web.conf|cut -f 1 -d ' ')
  95. if [ "$domains" -eq '0' ]; then
  96. conf='/etc/httpd/conf.d/vesta.conf'
  97. line=$(grep -n "$HOMEDIR/$user/conf/web/httpd.conf" $conf | cut -f 1 -d : )
  98. if [ ! -z "$line" ]; then
  99. sed -i "$line d" $conf
  100. fi
  101. fi
  102. # Checking last nginx domain
  103. conf='/etc/nginx/conf.d/vesta_users.conf'
  104. last_nginx=$(grep -v "NGINX=''" $USER_DATA/web.conf)
  105. last_snginx=$(echo "$last_nginx" | grep "SSL='yes'")
  106. if [ -z "$last_snginx" ]; then
  107. sline=$(grep -n "$HOMEDIR/$user/conf/web/snginx.conf" $conf |cut -f 1 -d :)
  108. if [ ! -z "$sline" ]; then
  109. sed -i "$sline d" $conf
  110. fi
  111. rm -f $HOMEDIR/$user/conf/web/snginx.conf
  112. fi
  113. if [ -z "$last_nginx" ]; then
  114. line=$(grep -n "$HOMEDIR/$user/conf/web/nginx.conf" $conf | cut -f 1 -d : )
  115. if [ ! -z "$line" ]; then
  116. sed -i "$line d" $conf
  117. fi
  118. rm -f $HOMEDIR/$user/conf/web/nginx.conf
  119. fi
  120. # Decrease counters
  121. decrease_ip_value "$IP"
  122. decrease_user_value "$user" '$U_WEB_DOMAINS'
  123. decrease_user_value "$user" '$U_WEB_ALIASES' "$aliases"
  124. if [ "$SSL" = 'yes' ]; then
  125. decrease_user_value "$user" '$U_WEB_SSL'
  126. fi
  127. # Restart web server
  128. if [ "$restart" != 'no' ]; then
  129. $BIN/v-restart-web "$EVENT"
  130. fi
  131. # Logging
  132. log_history "deleted web domain $domain"
  133. log_event "$OK" "$EVENT"
  134. exit