v_delete_web_domain 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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'
  31. # Checking user
  32. is_user_valid
  33. # Checking user is active
  34. is_user_suspended
  35. # Checking domain exist
  36. is_web_domain_valid
  37. # Checking domain is not suspened
  38. is_domain_suspended 'web'
  39. #----------------------------------------------------------#
  40. # Action #
  41. #----------------------------------------------------------#
  42. # Get template name
  43. get_web_domain_values
  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 ssl
  49. if [ "$SSL" = 'yes' ]; then
  50. tpl_file="$V_WEBTPL/apache_$TPL.stpl"
  51. conf="$V_HOME/$user/conf/web/shttpd.conf"
  52. del_web_config
  53. # Deleting certificates
  54. rm -f $V_HOME/$user/conf/web/ssl.$domain.*
  55. rm -f $V_USERS/$user/ssl/$domain.*
  56. fi
  57. # Checking nginx
  58. if [ ! -z "$NGINX" ]; then
  59. tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.tpl"
  60. conf="$V_HOME/$user/conf/web/nginx.conf"
  61. del_web_config
  62. if [ "$SSL" = 'yes' ]; then
  63. proxy_string="proxy_pass https://$ip:$WEB_SSL_PORT;"
  64. tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
  65. conf="$V_HOME/$user/conf/web/snginx.conf"
  66. del_web_config
  67. fi
  68. fi
  69. # Checking stats
  70. if [ ! -z "$STATS" ] && [ "$STATS" != 'no' ]; then
  71. sed -i "/ $domain$/d" $V_QUEUE/stats.pipe
  72. rm -f $V_HOME/$user/conf/web/$STATS.$domain.conf
  73. fi
  74. # Deleting directory
  75. rm -rf $V_HOME/$user/web/$domain
  76. # Deleting logs
  77. rm -f /var/log/httpd/domains/$domain.log*
  78. rm -f /var/log/httpd/domains/$domain.bytes
  79. rm -f /var/log/httpd/domains/$domain.error*
  80. #----------------------------------------------------------#
  81. # Vesta #
  82. #----------------------------------------------------------#
  83. # Deleting domain
  84. del_web_domain
  85. # Checking last ssl domain
  86. ssl_dom=$(grep "SSL='yes'" $V_USERS/$user/web.conf | wc -l)
  87. if [ "$ssl_dom" -eq '0' ]; then
  88. sed -i "s/ Include /#Include /" $V_HOME/$user/conf/web/httpd.conf
  89. fi
  90. # Checking last domain
  91. domains=$(wc -l $V_USERS/$user/web.conf|cut -f 1 -d ' ')
  92. if [ "$domains" -eq '0' ]; then
  93. conf='/etc/httpd/conf.d/vesta.conf'
  94. line=$(grep -n "$V_HOME/$user/conf/web/httpd.conf" $conf | cut -f 1 -d : )
  95. if [ ! -z "$line" ]; then
  96. sed -i "$line d" $conf
  97. fi
  98. fi
  99. # Checking last nginx domain
  100. conf='/etc/nginx/conf.d/vesta_users.conf'
  101. last_nginx=$(grep -v "NGINX=''" $V_USERS/$user/web.conf)
  102. last_snginx=$(echo "$last_nginx" | grep "SSL='yes'")
  103. if [ -z "$last_snginx" ]; then
  104. sline=$(grep -n "$V_HOME/$user/conf/web/snginx.conf" $conf |cut -f 1 -d :)
  105. if [ ! -z "$sline" ]; then
  106. sed -i "$sline d" $conf
  107. fi
  108. rm -f $V_HOME/$user/conf/web/snginx.conf
  109. fi
  110. if [ -z "$last_nginx" ]; then
  111. line=$(grep -n "$V_HOME/$user/conf/web/nginx.conf" $conf | cut -f 1 -d : )
  112. if [ ! -z "$line" ]; then
  113. sed -i "$line d" $conf
  114. fi
  115. rm -f $V_HOME/$user/conf/web/nginx.conf
  116. fi
  117. # Decreasing ip value
  118. decrease_ip_value "$IP"
  119. # Decreasing domain value
  120. decrease_user_value "$user" '$U_WEB_DOMAINS'
  121. # Adding task to the vesta pipe
  122. restart_schedule 'web'
  123. # Logging
  124. log_history "$V_EVENT"
  125. log_event 'system' "$V_EVENT"
  126. exit