v_delete_web_domain 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. # Importing variables
  17. source $VESTA/conf/vars.conf
  18. source $V_CONF/vesta.conf
  19. source $V_FUNC/shared.func
  20. source $V_FUNC/domain.func
  21. source $V_FUNC/ip.func
  22. #----------------------------------------------------------#
  23. # Verifications #
  24. #----------------------------------------------------------#
  25. # Checking arg number
  26. check_args '2' "$#" 'user domain'
  27. # Checking argument format
  28. format_validation 'user' 'domain'
  29. # Checking web system is enabled
  30. is_system_enabled 'WEB_SYSTEM'
  31. # Checking user
  32. is_user_valid
  33. # Checking user is active
  34. is_user_suspended
  35. # Checking domain exist
  36. is_domain_valid 'web'
  37. # Checking domain is not suspened
  38. is_domain_suspended 'web'
  39. #----------------------------------------------------------#
  40. # Action #
  41. #----------------------------------------------------------#
  42. # Get template name
  43. get_domain_values 'web'
  44. tpl_file="$V_WEBTPL/apache_$TPL.tpl"
  45. conf="$V_HOME/$user/conf/web/httpd.conf"
  46. # Deleting domain
  47. del_web_config
  48. # Checking aliases
  49. if [ ! -z "$ALIAS" ]; then
  50. aliases=$(echo $ALIAS | tr ',' '\n' | wc -l )
  51. else
  52. aliases=0
  53. fi
  54. # Checking ssl
  55. if [ "$SSL" = 'yes' ]; then
  56. tpl_file="$V_WEBTPL/apache_$TPL.stpl"
  57. conf="$V_HOME/$user/conf/web/shttpd.conf"
  58. del_web_config
  59. # Deleting certificates
  60. rm -f $V_HOME/$user/conf/web/ssl.$domain.*
  61. rm -f $V_USERS/$user/ssl/$domain.*
  62. fi
  63. # Checking nginx
  64. if [ ! -z "$NGINX" ]; then
  65. tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.tpl"
  66. conf="$V_HOME/$user/conf/web/nginx.conf"
  67. del_web_config
  68. if [ "$SSL" = 'yes' ]; then
  69. proxy_string="proxy_pass https://$ip:$WEB_SSL_PORT;"
  70. tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
  71. conf="$V_HOME/$user/conf/web/snginx.conf"
  72. del_web_config
  73. fi
  74. fi
  75. # Checking stats
  76. if [ ! -z "$STATS" ] && [ "$STATS" != 'no' ]; then
  77. sed -i "/ $domain$/d" $V_QUEUE/stats.pipe
  78. rm -f $V_HOME/$user/conf/web/$STATS.$domain.conf
  79. fi
  80. # Deleting directory
  81. rm -rf $V_HOME/$user/web/$domain
  82. # Deleting logs
  83. rm -f /var/log/httpd/domains/$domain.log*
  84. rm -f /var/log/httpd/domains/$domain.bytes
  85. rm -f /var/log/httpd/domains/$domain.error*
  86. #----------------------------------------------------------#
  87. # Vesta #
  88. #----------------------------------------------------------#
  89. # Deleting domain
  90. del_web_domain
  91. # Checking last ssl domain
  92. ssl_dom=$(grep "SSL='yes'" $V_USERS/$user/web.conf | wc -l)
  93. if [ "$ssl_dom" -eq '0' ]; then
  94. sed -i "s/ Include /#Include /" $V_HOME/$user/conf/web/httpd.conf
  95. fi
  96. # Checking last domain
  97. domains=$(wc -l $V_USERS/$user/web.conf|cut -f 1 -d ' ')
  98. if [ "$domains" -eq '0' ]; then
  99. conf='/etc/httpd/conf.d/vesta.conf'
  100. line=$(grep -n "$V_HOME/$user/conf/web/httpd.conf" $conf | cut -f 1 -d : )
  101. if [ ! -z "$line" ]; then
  102. sed -i "$line d" $conf
  103. fi
  104. fi
  105. # Checking last nginx domain
  106. conf='/etc/nginx/conf.d/vesta_users.conf'
  107. last_nginx=$(grep -v "NGINX=''" $V_USERS/$user/web.conf)
  108. last_snginx=$(echo "$last_nginx" | grep "SSL='yes'")
  109. if [ -z "$last_snginx" ]; then
  110. sline=$(grep -n "$V_HOME/$user/conf/web/snginx.conf" $conf |cut -f 1 -d :)
  111. if [ ! -z "$sline" ]; then
  112. sed -i "$sline d" $conf
  113. fi
  114. rm -f $V_HOME/$user/conf/web/snginx.conf
  115. fi
  116. if [ -z "$last_nginx" ]; then
  117. line=$(grep -n "$V_HOME/$user/conf/web/nginx.conf" $conf | cut -f 1 -d : )
  118. if [ ! -z "$line" ]; then
  119. sed -i "$line d" $conf
  120. fi
  121. rm -f $V_HOME/$user/conf/web/nginx.conf
  122. fi
  123. # Decreasing ip value
  124. decrease_ip_value "$IP"
  125. # Decreasing domain value
  126. decrease_user_value "$user" '$U_WEB_DOMAINS'
  127. # Decreasing web aliases
  128. decrease_user_value "$user" '$U_WEB_ALIASES' "$aliases"
  129. # Decreasing web ssl
  130. if [ "$SSL" = 'yes' ]; then
  131. decrease_user_value "$user" '$U_WEB_SSL'
  132. fi
  133. # Adding task to the vesta pipe
  134. restart_schedule 'web'
  135. # Logging
  136. log_history "$V_EVENT"
  137. log_event 'system' "$V_EVENT"
  138. exit