v-update-sys-ip 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. # Includes
  15. source $VESTA/conf/vesta.conf # include for internal func
  16. source $VESTA/func/main.sh
  17. source $VESTA/func/ip.sh
  18. source $VESTA/func/domain.sh
  19. #----------------------------------------------------------#
  20. # Verifications #
  21. #----------------------------------------------------------#
  22. check_args '0' "$#" '[user] [ip_status]'
  23. validate_format 'user' 'ip_status'
  24. is_object_valid 'user' 'USER' "$user" "$user"
  25. #----------------------------------------------------------#
  26. # Action #
  27. #----------------------------------------------------------#
  28. # Get ip list
  29. ip_list=$(/sbin/ifconfig | grep 'inet addr:' | cut -f 2 -d : | \
  30. cut -f 1 -d ' '| grep -v 127.0.0.1)
  31. # Get vesta registered ip list
  32. vesta_ip_list=$(ls $VESTA/data/ips/)
  33. # Defining config paths
  34. conf='/etc/httpd/conf.d/vesta.conf'
  35. nconf='/etc/nginx/conf.d/vesta_ip.conf'
  36. iconf='/etc/sysconfig/network-scripts/ifcfg'
  37. rconf='/etc/httpd/conf.d/mod_extract_forwarded.conf'
  38. # Comparing each ip
  39. for ip in $ip_list; do
  40. check_ip=$(echo $vesta_ip_list | grep -w "$ip")
  41. # Checking ip registered
  42. if [ -z "$check_ip" ]; then
  43. # Parsing additional params
  44. iface=$(/sbin/ifconfig |grep -B1 -w $ip |head -n 1 |cut -f 1 -d ' ')
  45. interface=$(echo "$iface" | cut -f 1 -d :)
  46. mask=$(/sbin/ifconfig |grep -w $ip |awk -F "Mask:" '{print $2}')
  47. # Adding vesta ip
  48. create_vesta_ip
  49. # Adding namehosting support
  50. namehost_ip_support
  51. # Creating startup script
  52. if [ ! -e "$iconf-$iface" ]; then
  53. create_vesta_ip
  54. fi
  55. fi
  56. # TBD: revers comparation
  57. done
  58. #----------------------------------------------------------#
  59. # Vesta #
  60. #----------------------------------------------------------#
  61. # Updating user conf
  62. increase_user_value "$user" '$IP_OWNED'
  63. # Restart web server
  64. if [ "$web_restart" = 'yes' ]; then
  65. $BIN/v-restart-web "$EVENT"
  66. fi
  67. # Logging
  68. log_event "$OK" "$EVENT"
  69. exit