v_delete_web_domain 4.1 KB

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