v_change_web_domain_ip 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. The ip change will be
  6. # performed for a virtual apache host and for a configuration nginx file both.
  7. #----------------------------------------------------------#
  8. # Variable&Function #
  9. #----------------------------------------------------------#
  10. # Argument defenition
  11. user=$1
  12. domain=$(idn -t --quiet -u "$2" )
  13. domain_idn=$(idn -t --quiet -a "$domain")
  14. ip=$3
  15. restart=$4
  16. # Includes
  17. source $VESTA/conf/vesta.conf
  18. source $VESTA/func/main.sh
  19. source $VESTA/func/domain.sh
  20. source $VESTA/func/ip.sh
  21. #----------------------------------------------------------#
  22. # Verifications #
  23. #----------------------------------------------------------#
  24. check_args '3' "$#" 'user domain ip [restart]'
  25. validate_format 'user' 'domain' 'ip'
  26. is_system_enabled "$WEB_SYSTEM"
  27. is_object_valid 'user' 'USER' "$user"
  28. is_object_unsuspended 'user' 'USER' "$user"
  29. is_object_valid 'web' 'DOMAIN' "$domain"
  30. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  31. is_ip_valid
  32. is_ip_avalable
  33. #----------------------------------------------------------#
  34. # Action #
  35. #----------------------------------------------------------#
  36. # Define variable for replace
  37. get_domain_values 'web'
  38. tpl_file="$WEBTPL/apache_$TPL.tpl"
  39. conf="$HOMEDIR/$user/conf/web/httpd.conf"
  40. old=$IP
  41. new=$ip
  42. replace_web_config
  43. # Checking ssl
  44. if [ "$SSL" = 'yes' ]; then
  45. tpl_file="$WEBTPL/apache_$TPL.stpl"
  46. conf="$HOMEDIR/$user/conf/web/shttpd.conf"
  47. replace_web_config
  48. fi
  49. # Checking nginx
  50. if [ ! -z "$NGINX" ]; then
  51. tpl_file="$WEBTPL/ngingx_$NGINX.tpl"
  52. conf="$HOMEDIR/$user/conf/web/nginx.conf"
  53. replace_web_config
  54. fi
  55. # Checking nginx
  56. if [ "$SSL" = 'yes' ] && [ ! -z "$NGINX" ]; then
  57. tpl_file="$WEBTPL/ngingx_$NGINX.stpl"
  58. conf="$HOMEDIR/$user/conf/web/snginx.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' "$ip"
  69. # Restart web server
  70. if [ "$restart" != 'no' ]; then
  71. $BIN/v_restart_web "$EVENT"
  72. fi
  73. # Logging
  74. log_history "$EVENT"
  75. log_event "$OK" "$EVENT"
  76. exit