v_update_sys_ip 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/bash
  2. # info: update system ip
  3. # options: [user] [ip_status]
  4. #
  5. # The function scans configured ip in the system and register them with vesta
  6. # internal database. This call is intended for use on vps servers, where ip is
  7. # set by hypervizor.
  8. #----------------------------------------------------------#
  9. # Variable&Function #
  10. #----------------------------------------------------------#
  11. # Argument defenition
  12. user=${1-admin}
  13. ip_status=${2-shared}
  14. # Importing variables
  15. source $VESTA/conf/vesta.conf # include for internal func
  16. source $VESTA/func/shared.sh
  17. source $VESTA/func/ip.sh
  18. source $VESTA/func/domain.sh
  19. #----------------------------------------------------------#
  20. # Verifications #
  21. #----------------------------------------------------------#
  22. # Checking arg number
  23. check_args '0' "$#" '[user] [ip_status]'
  24. # Checking user
  25. if [ ! -z "$1" ]; then
  26. validate_format 'user'
  27. is_object_valid 'user' 'USER' "$user" "$user"
  28. fi
  29. # Checking ip_status
  30. if [ ! -z "$2" ]; then
  31. validate_format 'ip_status'
  32. fi
  33. #----------------------------------------------------------#
  34. # Action #
  35. #----------------------------------------------------------#
  36. # Get ip list
  37. ip_list=$(/sbin/ifconfig |grep 'inet addr:'|cut -f 2 -d :|\
  38. cut -f 1 -d ' '| grep -v 127.0.0.1)
  39. # Get vesta registered ip list
  40. vesta_ip_list=$(ls $VESTA/data/ips/)
  41. # Defining config paths
  42. conf='/etc/httpd/conf.d/vesta.conf'
  43. nconf='/etc/nginx/conf.d/vesta_ip.conf'
  44. iconf='/etc/sysconfig/network-scripts/ifcfg'
  45. rconf='/etc/httpd/conf.d/rpaf.conf'
  46. # Comparing each ip
  47. for ip in $ip_list; do
  48. check_ip=$(echo $vesta_ip_list|grep -w "$ip")
  49. # Checking ip registered
  50. if [ -z "$check_ip" ]; then
  51. # Parsing additional params
  52. iface=$(/sbin/ifconfig|grep -B1 -w "$ip"|head -n 1|cut -f 1 -d ' ')
  53. interface=$(echo "$iface" | cut -f 1 -d :)
  54. mask=$(/sbin/ifconfig |grep -w "$ip"|awk -F "Mask:" '{print $2}')
  55. # Adding vesta ip
  56. ip_add_vesta
  57. # Adding namehosting support
  58. namehost_ip_support
  59. # Creating startup script
  60. if [ ! -e "$iconf-$iface" ]; then
  61. ip_add_startup
  62. fi
  63. fi
  64. # NOTE: later we'll make revers comparation
  65. done
  66. #----------------------------------------------------------#
  67. # Vesta #
  68. #----------------------------------------------------------#
  69. # Updating user conf
  70. increase_user_value "$user" '$IP_OWNED'
  71. # Adding task to the vesta pipe
  72. if [ "$web_restart" = 'yes' ]; then
  73. $BIN/v_restart_web "$EVENT"
  74. fi
  75. # Logging
  76. log_event "$OK" "$EVENT"
  77. exit