v_change_web_domain_ip 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. # Importing variables
  16. source $VESTA/conf/vars.conf
  17. source $V_CONF/vesta.conf
  18. source $V_FUNC/shared.func
  19. source $V_FUNC/domain.func
  20. source $V_FUNC/ip.func
  21. #----------------------------------------------------------#
  22. # Verifications #
  23. #----------------------------------------------------------#
  24. # Checking arg number
  25. check_args '3' "$#" 'user domain ip'
  26. # Checking argument format
  27. format_validation 'user' 'domain' 'ip'
  28. # Checking web system is enabled
  29. is_system_enabled 'web'
  30. # Checking user
  31. is_user_valid
  32. # Checking user is active
  33. is_user_suspended
  34. # Checking domain exist
  35. is_web_domain_valid
  36. # Checking domain is not suspened
  37. is_domain_suspended 'web'
  38. # Checking ip
  39. is_ip_avalable
  40. #----------------------------------------------------------#
  41. # Action #
  42. #----------------------------------------------------------#
  43. # Define variable for replace
  44. get_web_domain_values
  45. tpl_file="$V_WEBTPL/apache_$TPL.tpl"
  46. conf="$V_HOME/$user/conf/httpd.conf"
  47. old=$IP
  48. new=$ip
  49. replace_web_config
  50. # Checking ssl
  51. if [ "$SSL" = 'yes' ]; then
  52. tpl_file="$V_WEBTPL/apache_$TPL.stpl"
  53. conf="$V_HOME/$user/conf/shttpd.conf"
  54. replace_web_config
  55. fi
  56. # Checking nginx
  57. if [ ! -z "$NGINX" ]; then
  58. tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.tpl"
  59. conf="$V_HOME/$user/conf/nginx.conf"
  60. replace_web_config
  61. fi
  62. # Checking nginx
  63. if [ "$SSL" = 'yes' ] && [ ! -z "$NGINX" ]; then
  64. tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
  65. conf="$V_HOME/$user/conf/snginx.conf"
  66. replace_web_config
  67. fi
  68. #----------------------------------------------------------#
  69. # Vesta #
  70. #----------------------------------------------------------#
  71. # Increasing ip value
  72. increase_ip_value "$new"
  73. # Decreasing old ip value
  74. decrease_ip_value "$old"
  75. # Adding ip in config
  76. update_web_domain_value '$IP' "$new"
  77. # Adding task to the vesta pipe
  78. restart_schedule 'web'
  79. # Logging
  80. log_history "$V_EVENT" "$V_SCRIPT $user $domain $old_ip"
  81. log_event 'system' "$V_EVENT"
  82. exit