v-add-sys-ip 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. # info: add system ip address
  3. # options: ip mask [interface] [user] [ip_status] [ip_name]
  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. # Includes
  22. source $VESTA/conf/vesta.conf
  23. source $VESTA/func/main.sh
  24. source $VESTA/func/ip.sh
  25. source $VESTA/func/domain.sh
  26. #----------------------------------------------------------#
  27. # Verifications #
  28. #----------------------------------------------------------#
  29. check_args '2' "$#" 'ip mask [interface] [user] [ip_status] [ip_name]'
  30. validate_format 'ip' 'mask' 'interface' 'user' 'ip_status'
  31. is_ip_free
  32. is_object_valid 'user' 'USER' "$user"
  33. is_object_unsuspended 'user' 'USER' "$user"
  34. if [ ! -z "$ip_name" ] ; then
  35. validate_format 'ip_name'
  36. fi
  37. #----------------------------------------------------------#
  38. # Action #
  39. #----------------------------------------------------------#
  40. # Get full interface name
  41. get_ip_iface
  42. # Defining config paths
  43. conf='/etc/httpd/conf.d/vesta.conf'
  44. nconf='/etc/nginx/conf.d/vesta_ip.conf'
  45. iconf='/etc/sysconfig/network-scripts/ifcfg'
  46. rconf='/etc/httpd/conf.d/mod_extract_forwarded.conf'
  47. # Adding ip
  48. /sbin/ifconfig "$iface" "$ip" netmask "$mask"
  49. # Adding startup script
  50. create_ip_startup
  51. # Adding vesta ip
  52. create_vesta_ip
  53. # Namehosting support
  54. namehost_ip_support
  55. #----------------------------------------------------------#
  56. # Vesta #
  57. #----------------------------------------------------------#
  58. # Updating user counters
  59. increase_user_value "$user" '$IP_OWNED'
  60. if [ "$user" = 'admin' ]; then
  61. if [ "$ip_status" = 'shared' ]; then
  62. for user in $(ls $VESTA/data/users); do
  63. increase_user_value "$user" '$IP_AVAIL'
  64. done
  65. else
  66. increase_user_value 'admin' '$IP_AVAIL'
  67. fi
  68. else
  69. increase_user_value "$user" '$IP_AVAIL'
  70. increase_user_value 'admin' '$IP_AVAIL'
  71. fi
  72. # Restart web server
  73. if [ "$web_restart" = 'yes' ]; then
  74. $BIN/v-restart-web "$EVENT"
  75. fi
  76. # Logging
  77. log_history "added system ip address $ip" '' 'admin'
  78. log_event "$OK" "$EVENT"
  79. exit