v_del_web_domain 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_FUNC/shared_func.sh
  13. source $V_FUNC/domain_func.sh
  14. source $V_FUNC/ip_func.sh
  15. #----------------------------------------------------------#
  16. # Verifications #
  17. #----------------------------------------------------------#
  18. # Checking arg number
  19. check_args '2' "$#" 'user domain'
  20. # Checking argument format
  21. format_validation 'user' 'domain'
  22. # Checking web system is enabled
  23. is_system_enabled 'web'
  24. # Checking user
  25. is_user_valid
  26. # Checking user is active
  27. is_user_suspended
  28. # Checking domain exist
  29. is_web_domain_valid
  30. # Checking domain is not suspened
  31. is_domain_suspended 'web'
  32. #----------------------------------------------------------#
  33. # Action #
  34. #----------------------------------------------------------#
  35. # Get template name
  36. tpl_name=$(get_web_domain_value '$TPL')
  37. old_ip=$(get_web_domain_value '$IP')
  38. tpl_file="$V_WEBTPL/apache_$tpl_name.tpl"
  39. conf="$V_HOME/$user/conf/httpd.conf"
  40. # Deleting domain
  41. del_web_config
  42. # Checking ssl
  43. cert=$(get_web_domain_value '$SSL_CERT')
  44. if [ ! -z "$cert" ]; then
  45. # Get tpl
  46. tpl_file="$V_WEBTPL/apache_$tpl_name.stpl"
  47. conf="$V_HOME/$user/conf/shttpd.conf"
  48. # Deleting domain
  49. del_web_config
  50. fi
  51. # Checking stats
  52. stats_type=$(get_web_domain_value '$STATS')
  53. if [ ! -z "$stats_type" ] && [ "$stats_type" != 'no' ]; then
  54. # Parsing pipe line
  55. line=$(grep -n "$type.$domain.conf" $V_QUEUE/stats.pipe | \
  56. cut -f 1 -d : | head -n 1 )
  57. # Deleting pipe command
  58. if [ ! -z "$line" ]; then
  59. sed -i "$line d" $V_QUEUE/stats.pipe
  60. fi
  61. # Deleteing config
  62. rm -f $V_HOME/$user/conf/$type.$domain.conf
  63. fi
  64. # Deleting directory
  65. rm -rf $V_HOME/$user/web/$domain
  66. # Deleting logs
  67. rm -rf /var/log/httpd/domains/$domain.log*
  68. rm -rf /var/log/httpd/domains/$domain.bytes
  69. rm -rf /var/log/httpd/domains/$domain.error*
  70. #----------------------------------------------------------#
  71. # Vesta #
  72. #----------------------------------------------------------#
  73. # Deleting domain
  74. del_web_domain
  75. # Checking last ssl domain
  76. ssl_dom=$(grep -v "SSL_CERT=''" $V_USERS/$user/web.conf | wc -l)
  77. if [ "$ssl_dom" -eq '0' ]; then
  78. sed -i "s/ Include /#Include /" $V_HOME/$user/conf/httpd.conf
  79. fi
  80. # Checking last domain
  81. domains=$(wc -l $V_USERS/$user/web.conf|cut -f 1 -d ' ')
  82. if [ "$domains" -eq '0' ]; then
  83. conf='/etc/httpd/conf.d/vesta.conf'
  84. line=$(grep -n "$V_HOME/$user/conf/httpd.conf" $conf | cut -f 1 -d : )
  85. if [ ! -z "$line" ]; then
  86. sed -i "$line d" $conf
  87. fi
  88. fi
  89. # Checking last nginx domain
  90. conf='/etc/nginx/conf.d/vesta_users.conf'
  91. last_nginx=$(grep -v "NGINX=''" $V_USERS/$user/web.conf)
  92. last_snginx=$(echo "$last_nginx" | grep -v "SSL_CERT=''")
  93. if [ -z "$last_snginx" ]; then
  94. sline=$(grep -n "$V_HOME/$user/conf/snginx.conf" $conf | cut -f 1 -d : )
  95. if [ ! -z "$sline" ]; then
  96. sed -i "$sline d" $conf
  97. fi
  98. rm -f $V_HOME/$user/conf/snginx.conf
  99. fi
  100. if [ -z "$last_nginx" ]; then
  101. line=$(grep -n "$V_HOME/$user/conf/nginx.conf" $conf | cut -f 1 -d : )
  102. if [ ! -z "$line" ]; then
  103. sed -i "$line d" $conf
  104. fi
  105. rm -f $V_HOME/$user/conf/nginx.conf
  106. fi
  107. # Decreasing ip value
  108. decrease_ip_value "$old_ip"
  109. # Decreasing domain value
  110. decrease_user_value "$user" '$U_WEB_DOMAINS'
  111. # Adding task to the vesta pipe
  112. restart_schedule 'web'
  113. # Logging
  114. log_history "$V_EVENT"
  115. log_event 'system' "$V_EVENT"
  116. exit $OK