v_delete_web_domain 4.3 KB

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