v_suspend_web_domains 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/bin/bash
  2. # info: suspening web domains (with ssl)
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. user="$1"
  8. # Importing variables
  9. source $VESTA/conf/vars.conf
  10. source $V_FUNC/shared_func.sh
  11. source $V_FUNC/domain_func.sh
  12. # Defining url
  13. url="${2-$V_SUSPEND_URL}"
  14. #----------------------------------------------------------#
  15. # Verifications #
  16. #----------------------------------------------------------#
  17. # Checking arg number
  18. check_args '1' "$#" 'user [suspend_url]'
  19. # Checking argument format
  20. format_validation 'user' 'url'
  21. # Checking web system is enabled
  22. is_system_enabled 'web'
  23. # Checking user
  24. is_user_valid
  25. #----------------------------------------------------------#
  26. # Action #
  27. #----------------------------------------------------------#
  28. # Defining config
  29. conf="$V_USERS/$user/web.conf"
  30. # Defining fileds to select
  31. field='$DOMAIN'
  32. # Defining search string
  33. search_string="SUSPEND='no'"
  34. # Parsing unsuspeneded domains
  35. domains=$(dom_clear_search)
  36. # Starting suspend loop
  37. for domain in $domains; do
  38. domain_idn=$(idn -t --quiet -a "$domain")
  39. # Get template name
  40. tpl_name=$(get_web_domain_value '$TPL')
  41. tpl_file="$V_WEBTPL/apache_$tpl_name.tpl"
  42. # Defining config
  43. conf="$V_HOME/$user/conf/httpd.conf"
  44. # Defining search phrase
  45. search_phrase='DocumentRoot '
  46. # Defining replace string
  47. str_repl=" Redirect / http://$url/"
  48. # Suspending vhost
  49. change_web_config
  50. # Check ssl vhost
  51. cert=$(get_web_domain_value '$SSL_CERT')
  52. if [ ! -z "$cert" ]; then
  53. # Defining teplate name
  54. tpl_file="$V_WEBTPL/apache_$tpl_name.stpl"
  55. # Defining config
  56. conf="$V_HOME/$user/conf/shttpd.conf"
  57. # Reefining replace string - old str_repl contains escaped chars
  58. str_repl=" Redirect / http://$url/"
  59. # Suspending vhost
  60. change_web_config
  61. fi
  62. # Check nginx vhost
  63. nginx=$(get_web_domain_value '$NGINX')
  64. if [ ! -z "$nginx" ]; then
  65. tpl_file="$V_WEBTPL/ngingx_vhost_$nginx.tpl"
  66. conf="$V_HOME/$user/conf/nginx.conf"
  67. search_phrase='proxy_pass'
  68. str_repl=" rewrite ^(.*)\$ http://$url;"
  69. change_web_config
  70. fi
  71. if [ ! -z "$nginx" ] && [ ! -z "$cert" ]; then
  72. tpl_file="$V_WEBTPL/ngingx_vhost_$nginx.stpl"
  73. conf="$V_HOME/$user/conf/snginx.conf"
  74. search_phrase='proxy_pass'
  75. str_repl=" rewrite ^(.*)\$ http://$url;"
  76. change_web_config
  77. fi
  78. # Adding suspend in config
  79. update_web_domain_value '$SUSPEND' 'yes'
  80. done
  81. #----------------------------------------------------------#
  82. # Vesta #
  83. #----------------------------------------------------------#
  84. # Adding task to the vesta pipe
  85. restart_schedule 'web'
  86. # Logging
  87. log_event 'system' "$V_EVENT"
  88. exit $OK