v_suspend_web_domain 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/bash
  2. # info: suspend web domain
  3. # options: user domain
  4. #
  5. # The function for suspending the site's operation. After blocking it all
  6. # visitors will be redirected to a web page explaining the reason of suspend.
  7. # By blocking the site the content of all its directories remains untouched.
  8. #----------------------------------------------------------#
  9. # Variable&Function #
  10. #----------------------------------------------------------#
  11. # Argument defenition
  12. user=$1
  13. domain=$(idn -t --quiet -u "$2" )
  14. domain_idn=$(idn -t --quiet -a "$domain")
  15. # Includes
  16. source $VESTA/conf/vesta.conf
  17. source $VESTA/func/main.sh
  18. source $VESTA/func/domain.sh
  19. url="${3-$SUSPEND_URL}"
  20. restart=$4
  21. #----------------------------------------------------------#
  22. # Verifications #
  23. #----------------------------------------------------------#
  24. check_args '2' "$#" 'user domain [suspend_url]'
  25. validate_format 'user' 'domain' 'url'
  26. is_system_enabled "$WEB_SYSTEM"
  27. is_object_valid 'user' 'USER' "$user"
  28. is_object_valid 'web' 'DOMAIN' "$domain"
  29. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  30. #----------------------------------------------------------#
  31. # Action #
  32. #----------------------------------------------------------#
  33. # Parsing domain values
  34. get_domain_values 'web'
  35. tpl_file="$WEBTPL/apache_$TPL.tpl"
  36. conf="$HOMEDIR/$user/conf/web/httpd.conf"
  37. SUSPENDED='yes'
  38. # Preparing domain values for the template substitution
  39. upd_web_domain_values
  40. # Recreating vhost
  41. del_web_config
  42. add_web_config
  43. # Check ssl
  44. if [ "$SSL" = 'yes' ]; then
  45. tpl_file="$WEBTPL/apache_$TPL.stpl"
  46. conf="$HOMEDIR/$user/conf/web/shttpd.conf"
  47. del_web_config
  48. add_web_config
  49. fi
  50. # Checking nginx
  51. if [ ! -z "$NGINX" ]; then
  52. tpl_file="$WEBTPL/ngingx_vhost_$NGINX.tpl"
  53. conf="$HOMEDIR/$user/conf/web/nginx.conf"
  54. del_web_config
  55. add_web_config
  56. if [ "$SSL" = 'yes' ]; then
  57. proxy_string="rewrite ^(.*)\$ http://$url;"
  58. tpl_file="$WEBTPL/ngingx_vhost_$NGINX.stpl"
  59. conf="$HOMEDIR/$user/conf/web/snginx.conf"
  60. del_web_config
  61. add_web_config
  62. fi
  63. fi
  64. #----------------------------------------------------------#
  65. # Vesta #
  66. #----------------------------------------------------------#
  67. # Update config
  68. update_object_value 'web' 'DOMAIN' "$domain" '$SUSPENDED' 'yes'
  69. increase_user_value "$user" '$SUSPENDED_WEB'
  70. # Restart web server
  71. if [ "$restart" != 'no' ]; then
  72. $BIN/v_restart_web "$EVENT"
  73. fi
  74. # Logging
  75. log_event "$OK" "$EVENT"
  76. exit