v_change_web_domain_ip 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. # info: change web domain ip address
  3. # options: user domain ip
  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. # 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'
  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. tpl_file="$WEBTPL/apache_$TPL.tpl"
  38. conf="$HOMEDIR/$user/conf/web/httpd.conf"
  39. old=$IP
  40. new=$ip
  41. replace_web_config
  42. # Checking ssl
  43. if [ "$SSL" = 'yes' ]; then
  44. tpl_file="$WEBTPL/apache_$TPL.stpl"
  45. conf="$HOMEDIR/$user/conf/web/shttpd.conf"
  46. replace_web_config
  47. fi
  48. # Checking nginx
  49. if [ ! -z "$NGINX" ]; then
  50. tpl_file="$WEBTPL/ngingx_vhost_$NGINX.tpl"
  51. conf="$HOMEDIR/$user/conf/web/nginx.conf"
  52. replace_web_config
  53. fi
  54. # Checking nginx
  55. if [ "$SSL" = 'yes' ] && [ ! -z "$NGINX" ]; then
  56. tpl_file="$WEBTPL/ngingx_vhost_$NGINX.stpl"
  57. conf="$HOMEDIR/$user/conf/web/snginx.conf"
  58. replace_web_config
  59. fi
  60. #----------------------------------------------------------#
  61. # Vesta #
  62. #----------------------------------------------------------#
  63. # Update counters
  64. increase_ip_value "$new"
  65. decrease_ip_value "$old"
  66. # Update config
  67. update_object_value 'web' 'DOMAIN' "$domain" '$IP' "$ip"
  68. # Restart web server
  69. $BIN/v_restart_web "$EVENT"
  70. # Logging
  71. log_history "$EVENT"
  72. log_event "$OK" "$EVENT"
  73. exit