v-change-web-domain-ip 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/bash
  2. # info: change web domain ip address
  3. # options: USER DOMAIN IP [RESTART]
  4. #
  5. # The call is used for changing the site ip address.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. user=$1
  11. domain=$(idn -t --quiet -u "$2" )
  12. domain_idn=$(idn -t --quiet -a "$domain")
  13. ip=$3
  14. restart=$4
  15. # Includes
  16. source $VESTA/conf/vesta.conf
  17. source $VESTA/func/main.sh
  18. source $VESTA/func/domain.sh
  19. source $VESTA/func/ip.sh
  20. #----------------------------------------------------------#
  21. # Verifications #
  22. #----------------------------------------------------------#
  23. check_args '3' "$#" 'USER DOMAIN IP [RESTART]'
  24. validate_format 'user' 'domain' 'ip'
  25. is_system_enabled "$WEB_SYSTEM"
  26. is_object_valid 'user' 'USER' "$user"
  27. is_object_unsuspended 'user' 'USER' "$user"
  28. is_object_valid 'web' 'DOMAIN' "$domain"
  29. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  30. is_ip_valid
  31. is_ip_avalable
  32. #----------------------------------------------------------#
  33. # Action #
  34. #----------------------------------------------------------#
  35. # Define variable for replace
  36. get_domain_values 'web'
  37. ip=$(get_real_ip $ip)
  38. tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.tpl"
  39. conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
  40. old=$(get_real_ip $IP)
  41. new=$ip
  42. replace_web_config
  43. # Checking SSL
  44. if [ "$SSL" = 'yes' ]; then
  45. tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.stpl"
  46. conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
  47. replace_web_config
  48. fi
  49. # Checking proxy
  50. if [ ! -z "$PROXY" ]; then
  51. tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.tpl"
  52. conf="$HOMEDIR/$user/conf/web/$PROXY_SYSTEM.conf"
  53. replace_web_config
  54. fi
  55. # Checking SSL proxy
  56. if [ "$SSL" = 'yes' ] && [ ! -z "$PROXY" ]; then
  57. tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.stpl"
  58. conf="$HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf"
  59. replace_web_config
  60. fi
  61. #----------------------------------------------------------#
  62. # Vesta #
  63. #----------------------------------------------------------#
  64. # Update counters
  65. increase_ip_value "$new"
  66. decrease_ip_value "$old"
  67. # Update config
  68. update_object_value 'web' 'DOMAIN' "$domain" '$IP' "$3"
  69. # Restart web server
  70. if [ "$restart" != 'no' ]; then
  71. $BIN/v-restart-web
  72. $BIN/v-restart-proxy
  73. fi
  74. # Logging
  75. log_history "changed web domain $domain ip to $3"
  76. log_event "$OK" "$EVENT"
  77. exit