v_delete_web_domain 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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/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/shttpd.conf"
  52. del_web_config
  53. # Deleting certificates
  54. rm -f $V_HOME/$user/conf/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/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/snginx.conf"
  66. del_web_config
  67. fi
  68. fi
  69. # Checking stats
  70. if [ ! -z "$STATS" ] && [ "$STATS" != 'no' ]; then
  71. # Parsing pipe line
  72. line=$(grep -n "$STATS.$domain.conf" $V_QUEUE/stats.pipe | \
  73. cut -f 1 -d : | head -n 1 )
  74. # Deleting pipe command
  75. if [ ! -z "$line" ]; then
  76. sed -i "$line d" $V_QUEUE/stats.pipe
  77. fi
  78. # Deleteing config
  79. rm -f $V_HOME/$user/conf/$STATS.$domain.conf
  80. fi
  81. # Deleting directory
  82. rm -rf $V_HOME/$user/web/$domain
  83. # Deleting logs
  84. rm -rf /var/log/httpd/domains/$domain.log*
  85. rm -rf /var/log/httpd/domains/$domain.bytes
  86. rm -rf /var/log/httpd/domains/$domain.error*
  87. #----------------------------------------------------------#
  88. # Vesta #
  89. #----------------------------------------------------------#
  90. # Deleting domain
  91. del_web_domain
  92. # Checking last ssl domain
  93. ssl_dom=$(grep "SSL='yes'" $V_USERS/$user/web.conf | wc -l)
  94. if [ "$ssl_dom" -eq '0' ]; then
  95. sed -i "s/ Include /#Include /" $V_HOME/$user/conf/httpd.conf
  96. fi
  97. # Checking last domain
  98. domains=$(wc -l $V_USERS/$user/web.conf|cut -f 1 -d ' ')
  99. if [ "$domains" -eq '0' ]; then
  100. conf='/etc/httpd/conf.d/vesta.conf'
  101. line=$(grep -n "$V_HOME/$user/conf/httpd.conf" $conf | cut -f 1 -d : )
  102. if [ ! -z "$line" ]; then
  103. sed -i "$line d" $conf
  104. fi
  105. fi
  106. # Checking last nginx domain
  107. conf='/etc/nginx/conf.d/vesta_users.conf'
  108. last_nginx=$(grep -v "NGINX=''" $V_USERS/$user/web.conf)
  109. last_snginx=$(echo "$last_nginx" | grep "SSL='yes'")
  110. if [ -z "$last_snginx" ]; then
  111. sline=$(grep -n "$V_HOME/$user/conf/snginx.conf" $conf | cut -f 1 -d : )
  112. if [ ! -z "$sline" ]; then
  113. sed -i "$sline d" $conf
  114. fi
  115. rm -f $V_HOME/$user/conf/snginx.conf
  116. fi
  117. if [ -z "$last_nginx" ]; then
  118. line=$(grep -n "$V_HOME/$user/conf/nginx.conf" $conf | cut -f 1 -d : )
  119. if [ ! -z "$line" ]; then
  120. sed -i "$line d" $conf
  121. fi
  122. rm -f $V_HOME/$user/conf/nginx.conf
  123. fi
  124. # Decreasing ip value
  125. decrease_ip_value "$IP"
  126. # Decreasing domain value
  127. decrease_user_value "$user" '$U_WEB_DOMAINS'
  128. # Adding task to the vesta pipe
  129. restart_schedule 'web'
  130. # Logging
  131. log_history "$V_EVENT"
  132. log_event 'system' "$V_EVENT"
  133. exit