v_delete_web_domain 4.3 KB

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