v_del_web_domain_nginx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/bin/bash
  2. # info: deliting web domain nginx config
  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. #----------------------------------------------------------#
  15. # Verifications #
  16. #----------------------------------------------------------#
  17. # Checking arg number
  18. check_args '2' "$#" 'user domain'
  19. # Checking argument format
  20. format_validation 'user' 'domain'
  21. # Checking web system is enabled
  22. is_system_enabled 'web'
  23. # Checking user
  24. is_user_valid
  25. # Checking user is active
  26. is_user_suspended
  27. # Checking domain exist
  28. is_web_domain_valid
  29. # Checking domain is not suspened
  30. is_domain_suspended 'web'
  31. # Checking ssl is added
  32. is_web_domain_value_exist '$NGINX'
  33. #----------------------------------------------------------#
  34. # Action #
  35. #----------------------------------------------------------#
  36. # Get domain values
  37. tpl_name=$(get_web_domain_value '$NGINX')
  38. tpl_file="$V_WEBTPL/ngingx_vhost_$tpl_name.tpl"
  39. conf="$V_HOME/$user/conf/nginx.conf"
  40. ext=$(get_web_domain_value '$NGINX_EXT' )
  41. # Deleting domain
  42. del_web_config
  43. # Checking ssl
  44. cert=$(get_web_domain_value '$SSL_CERT')
  45. if [ ! -z "$cert" ]; then
  46. tpl_file="$V_WEBTPL/ngingx_vhost_$tpl_name.stpl"
  47. conf="$V_HOME/$user/conf/snginx.conf"
  48. del_web_config
  49. fi
  50. #----------------------------------------------------------#
  51. # Vesta #
  52. #----------------------------------------------------------#
  53. # Deleting nginx keys
  54. update_web_domain_value '$NGINX' ''
  55. update_web_domain_value '$NGINX_EXT' ''
  56. # Checking last nginx domain
  57. conf='/etc/nginx/conf.d/vesta_users.conf'
  58. last_nginx=$(grep -v "NGINX=''" $V_USERS/$user/web.conf)
  59. last_snginx=$(echo "$last_nginx" | grep -v "SSL_CERT=''")
  60. if [ -z "$last_snginx" ]; then
  61. sline=$(grep -n "$V_HOME/$user/conf/snginx.conf" $conf | cut -f 1 -d : )
  62. if [ ! -z "$sline" ]; then
  63. sed -i "$sline d" $conf
  64. fi
  65. rm -f $V_HOME/$user/conf/snginx.conf
  66. fi
  67. if [ -z "$last_nginx" ]; then
  68. line=$(grep -n "$V_HOME/$user/conf/nginx.conf" $conf | cut -f 1 -d : )
  69. if [ ! -z "$line" ]; then
  70. sed -i "$line d" $conf
  71. fi
  72. rm -f $V_HOME/$user/conf/nginx.conf
  73. fi
  74. # Adding task to the vesta pipe
  75. restart_schedule 'web'
  76. # Logging
  77. log_history "$V_EVENT" "v_add_web_domain_nginx $user $domain $tpl_name $ext"
  78. log_event 'system' "$V_EVENT"
  79. exit $OK