v-delete-web-domain 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. fi
  72. # Deleting ftp account
  73. if [ ! -z "$FTP_USER" ]; then
  74. /usr/sbin/userdel $FTP_USER
  75. fi
  76. # Deleting directory
  77. rm -rf $HOMEDIR/$user/web/$domain
  78. # Deleting logs
  79. rm -f /var/log/httpd/domains/$domain.log*
  80. rm -f /var/log/httpd/domains/$domain.bytes
  81. rm -f /var/log/httpd/domains/$domain.error*
  82. #----------------------------------------------------------#
  83. # Vesta #
  84. #----------------------------------------------------------#
  85. # Deleting domain
  86. sed -i "/DOMAIN='$domain'/ d" $USER_DATA/web.conf
  87. # Checking last ssl domain
  88. ssl_dom=$(grep "SSL='yes'" $USER_DATA/web.conf | wc -l)
  89. if [ "$ssl_dom" -eq '0' ]; then
  90. sed -i "s/ Include /#Include /" $HOMEDIR/$user/conf/web/httpd.conf
  91. fi
  92. # Checking last domain
  93. domains=$(wc -l $USER_DATA/web.conf|cut -f 1 -d ' ')
  94. if [ "$domains" -eq '0' ]; then
  95. conf='/etc/httpd/conf.d/vesta.conf'
  96. line=$(grep -n "$HOMEDIR/$user/conf/web/httpd.conf" $conf | cut -f 1 -d : )
  97. if [ ! -z "$line" ]; then
  98. sed -i "$line d" $conf
  99. fi
  100. fi
  101. # Checking last nginx domain
  102. conf='/etc/nginx/conf.d/vesta_users.conf'
  103. last_nginx=$(grep -v "NGINX=''" $USER_DATA/web.conf)
  104. last_snginx=$(echo "$last_nginx" | grep "SSL='yes'")
  105. if [ -z "$last_snginx" ]; then
  106. sline=$(grep -n "$HOMEDIR/$user/conf/web/snginx.conf" $conf |cut -f 1 -d :)
  107. if [ ! -z "$sline" ]; then
  108. sed -i "$sline d" $conf
  109. fi
  110. rm -f $HOMEDIR/$user/conf/web/snginx.conf
  111. fi
  112. if [ -z "$last_nginx" ]; then
  113. line=$(grep -n "$HOMEDIR/$user/conf/web/nginx.conf" $conf | cut -f 1 -d : )
  114. if [ ! -z "$line" ]; then
  115. sed -i "$line d" $conf
  116. fi
  117. rm -f $HOMEDIR/$user/conf/web/nginx.conf
  118. fi
  119. # Decrease counters
  120. decrease_ip_value "$IP"
  121. decrease_user_value "$user" '$U_WEB_DOMAINS'
  122. decrease_user_value "$user" '$U_WEB_ALIASES' "$aliases"
  123. if [ "$SSL" = 'yes' ]; then
  124. decrease_user_value "$user" '$U_WEB_SSL'
  125. fi
  126. # Restart web server
  127. if [ "$restart" != 'no' ]; then
  128. $BIN/v-restart-web "$EVENT"
  129. fi
  130. # Logging
  131. log_history "deleted web domain $domain"
  132. log_event "$OK" "$EVENT"
  133. exit