v-change-web-domain-ip 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/bash
  2. # info: change web domain ip
  3. # options: USER DOMAIN DOMAIN [RESTART]
  4. #
  5. # The call is used for changing domain ip
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. user=$1
  11. domain=$2
  12. ip=$3
  13. restart=$4
  14. # Includes
  15. source $VESTA/func/main.sh
  16. source $VESTA/func/domain.sh
  17. source $VESTA/func/ip.sh
  18. source $VESTA/conf/vesta.conf
  19. # Additional argument formatting
  20. format_domain
  21. format_domain_idn
  22. #----------------------------------------------------------#
  23. # Verifications #
  24. #----------------------------------------------------------#
  25. check_args '3' "$#" 'USER DOMAIN IP [RESTART]'
  26. is_format_valid 'user' 'domain' 'ip'
  27. is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
  28. is_object_valid 'user' 'USER' "$user"
  29. is_object_unsuspended 'user' 'USER' "$user"
  30. is_object_valid 'web' 'DOMAIN' "$domain"
  31. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  32. is_ip_valid "$ip" "$user"
  33. #----------------------------------------------------------#
  34. # Action #
  35. #----------------------------------------------------------#
  36. # Preparing variables for vhost replace
  37. get_domain_values 'web'
  38. old=$(get_real_ip $IP)
  39. new=$ip
  40. # Replacing vhost
  41. replace_web_config "$WEB_SYSTEM" "$TPL.tpl"
  42. if [ "$SSL" = 'yes' ]; then
  43. replace_web_config "$WEB_SYSTEM" "$TPL.stpl"
  44. fi
  45. # Replacing proxy vhost
  46. if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
  47. replace_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
  48. if [ "$SSL" = 'yes' ]; then
  49. replace_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
  50. fi
  51. fi
  52. #----------------------------------------------------------#
  53. # Vesta #
  54. #----------------------------------------------------------#
  55. # Update counters
  56. increase_ip_value "$new"
  57. decrease_ip_value "$old"
  58. # Update config
  59. update_object_value 'web' 'DOMAIN' "$domain" '$IP' "$3"
  60. # Restart web server
  61. $BIN/v-restart-web $restart
  62. check_result $? "WEB restart failed" >/dev/null
  63. $BIN/v-restart-proxy $restart
  64. check_result $? "Proxy restart failed" >/dev/null
  65. # Logging
  66. log_history "changed web domain $domain ip to $3"
  67. log_event "$OK" "$ARGUMENTS"
  68. exit