v-suspend-web-domain 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 definition
  12. user=$1
  13. domain=$(idn -t --quiet -u "$2" )
  14. domain_idn=$(idn -t --quiet -a "$domain")
  15. restart=$3
  16. # Includes
  17. source $VESTA/func/main.sh
  18. source $VESTA/func/domain.sh
  19. source $VESTA/func/ip.sh
  20. source $VESTA/conf/vesta.conf
  21. #----------------------------------------------------------#
  22. # Verifications #
  23. #----------------------------------------------------------#
  24. check_args '2' "$#" 'USER DOMAIN [RESTART]'
  25. is_format_valid 'user' 'domain'
  26. is_system_enabled "$WEB_SYSTEM" '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. SUSPENDED='yes'
  36. local_ip=$(get_real_ip $IP)
  37. # Preparing domain values for the template substitution
  38. prepare_web_domain_values
  39. # Rebuilding vhost
  40. del_web_config "$WEB_SYSTEM" "$TPL.tpl"
  41. add_web_config "$WEB_SYSTEM" "$TPL.tpl"
  42. if [ "$SSL" = 'yes' ]; then
  43. del_web_config "$WEB_SYSTEM" "$TPL.stpl"
  44. add_web_config "$WEB_SYSTEM" "$TPL.stpl"
  45. fi
  46. # Rebuilding proxy configuration
  47. if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
  48. del_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
  49. add_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
  50. if [ "$SSL" = 'yes' ]; then
  51. del_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
  52. add_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
  53. fi
  54. fi
  55. #----------------------------------------------------------#
  56. # Vesta #
  57. #----------------------------------------------------------#
  58. # Updating config
  59. update_object_value 'web' 'DOMAIN' "$domain" '$SUSPENDED' 'yes'
  60. increase_user_value "$user" '$SUSPENDED_WEB'
  61. # Restarting web server
  62. if [ "$restart" != 'no' ]; then
  63. $BIN/v-restart-web
  64. check_result $? "Web restart failed" >/dev/null
  65. if [ ! -z "$PROXY_SYSTEM" ]; then
  66. $BIN/v-restart-proxy
  67. check_result $? "Proxy restart failed" >/dev/null
  68. fi
  69. fi
  70. # Logging
  71. log_event "$OK" "$ARGUMENTS"
  72. exit