v-change-web-domain-ip 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #----------------------------------------------------------#
  20. # Verifications #
  21. #----------------------------------------------------------#
  22. check_args '3' "$#" 'USER DOMAIN IP [RESTART]'
  23. is_format_valid 'user' 'domain' 'ip'
  24. is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
  25. is_object_valid 'user' 'USER' "$user"
  26. is_object_unsuspended 'user' 'USER' "$user"
  27. is_object_valid 'web' 'DOMAIN' "$domain"
  28. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  29. is_ip_valid "$ip" "$user"
  30. #----------------------------------------------------------#
  31. # Action #
  32. #----------------------------------------------------------#
  33. # Preparing variables for vhost replace
  34. get_domain_values 'web'
  35. old=$(get_real_ip $IP)
  36. new=$ip
  37. if [[ "$domain" = *[![:ascii:]]* ]]; then
  38. domain_idn=$(idn -t --quiet -a $domain)
  39. else
  40. domain_idn=$domain
  41. fi
  42. # Replacing vhost
  43. replace_web_config "$WEB_SYSTEM" "$TPL.tpl"
  44. if [ "$SSL" = 'yes' ]; then
  45. replace_web_config "$WEB_SYSTEM" "$TPL.stpl"
  46. fi
  47. # Replacing proxy vhost
  48. if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
  49. replace_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
  50. if [ "$SSL" = 'yes' ]; then
  51. replace_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
  52. fi
  53. fi
  54. #----------------------------------------------------------#
  55. # Vesta #
  56. #----------------------------------------------------------#
  57. # Update counters
  58. increase_ip_value "$new"
  59. decrease_ip_value "$old"
  60. # Update config
  61. update_object_value 'web' 'DOMAIN' "$domain" '$IP' "$3"
  62. # Restart web server
  63. if [ "$restart" != 'no' ]; then
  64. $BIN/v-restart-web
  65. check_result $? "WEB restart failed" >/dev/null
  66. if [ ! -z "$PROXY_SYSTEM" ]; then
  67. $BIN/v-restart-proxy
  68. check_result $? "Proxy restart failed" >/dev/null
  69. fi
  70. fi
  71. # Logging
  72. log_history "changed web domain $domain ip to $3"
  73. log_event "$OK" "$ARGUMENTS"
  74. exit