v-add-sys-ip 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/bash
  2. # info: add system ip address
  3. # options: IP MASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME] [NAT_IP]
  4. #
  5. # The function adds ip address into a system. It also creates rc scripts. You
  6. # can specify ip name which will be used as root domain for temporary aliases.
  7. # For example, if you set a1.myhosting.com as name, each new domain created on
  8. # this ip will automaticaly receive alias $domain.a1.myhosting.com. Of course
  9. # you must have wildcard record *.a1.myhosting.com pointed to ip. This feature
  10. # is very handy when customer wants to test domain before dns migration.
  11. #----------------------------------------------------------#
  12. # Variable&Function #
  13. #----------------------------------------------------------#
  14. # Argument defenition
  15. ip=${1// /}
  16. mask=$2
  17. interface="${3-eth0}"
  18. user="${4-admin}"
  19. ip_status="${5-shared}" # can be dedicated as well
  20. ip_name=$6
  21. nat_ip=$7
  22. # Includes
  23. source $VESTA/conf/vesta.conf
  24. source $VESTA/func/main.sh
  25. source $VESTA/func/ip.sh
  26. source $VESTA/func/domain.sh
  27. #----------------------------------------------------------#
  28. # Verifications #
  29. #----------------------------------------------------------#
  30. check_args '2' "$#" 'IP MASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME] [NAT_IP]'
  31. validate_format 'ip' 'mask' 'interface' 'user' 'ip_status'
  32. is_ip_free
  33. is_object_valid 'user' 'USER' "$user"
  34. is_object_unsuspended 'user' 'USER' "$user"
  35. if [ ! -z "$ip_name" ] ; then
  36. validate_format 'ip_name'
  37. fi
  38. if [ ! -z "$nat_ip" ] ; then
  39. validate_format 'nat_ip'
  40. fi
  41. #----------------------------------------------------------#
  42. # Action #
  43. #----------------------------------------------------------#
  44. # Get full interface name
  45. get_ip_iface
  46. # Defining config paths
  47. conf='/etc/httpd/conf.d/vesta.conf'
  48. nconf='/etc/nginx/conf.d/vesta_ip.conf'
  49. iconf='/etc/sysconfig/network-scripts/ifcfg'
  50. rconf='/etc/httpd/conf.d/mod_extract_forwarded.conf'
  51. # Adding ip
  52. /sbin/ifconfig "$iface" "$ip" netmask "$mask"
  53. # Adding startup script
  54. create_ip_startup
  55. # Adding vesta ip
  56. create_vesta_ip
  57. # Namehosting support
  58. namehost_ip_support
  59. #----------------------------------------------------------#
  60. # Vesta #
  61. #----------------------------------------------------------#
  62. # Updating user counters
  63. increase_user_value "$user" '$IP_OWNED'
  64. if [ "$user" = 'admin' ]; then
  65. if [ "$ip_status" = 'shared' ]; then
  66. for user in $(ls $VESTA/data/users); do
  67. increase_user_value "$user" '$IP_AVAIL'
  68. done
  69. else
  70. increase_user_value 'admin' '$IP_AVAIL'
  71. fi
  72. else
  73. increase_user_value "$user" '$IP_AVAIL'
  74. increase_user_value 'admin' '$IP_AVAIL'
  75. fi
  76. # Restart web server
  77. if [ "$web_restart" = 'yes' ]; then
  78. $BIN/v-restart-web "$EVENT"
  79. fi
  80. # Logging
  81. log_history "added system ip address $ip" '' 'admin'
  82. log_event "$OK" "$EVENT"
  83. exit