v-delete-sys-ip 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. # info: delete system ip
  3. # options: IP
  4. #
  5. # The function for deleting a system ip. It does not allow to delete first ip
  6. # on interface and do not allow to delete ip which is used by a web domain.
  7. #----------------------------------------------------------#
  8. # Variable&Function #
  9. #----------------------------------------------------------#
  10. # Argument defenition
  11. ip=$1
  12. # Includes
  13. source $VESTA/conf/vesta.conf
  14. source $VESTA/func/main.sh
  15. source $VESTA/func/ip.sh
  16. source $VESTA/func/domain.sh
  17. #----------------------------------------------------------#
  18. # Verifications #
  19. #----------------------------------------------------------#
  20. check_args '1' "$#" 'IP'
  21. validate_format 'ip'
  22. is_ip_valid "$ip"
  23. is_ip_key_empty '$U_WEB_DOMAINS'
  24. is_ip_key_empty '$U_SYS_USERS'
  25. #----------------------------------------------------------#
  26. # Action #
  27. #----------------------------------------------------------#
  28. # Defining config paths
  29. conf='/etc/httpd/conf.d/vesta.conf'
  30. nconf='/etc/nginx/conf.d/vesta_ip.conf'
  31. iconf='/etc/sysconfig/network-scripts/ifcfg'
  32. rconf='/etc/httpd/conf.d/mod_extract_forwarded.conf'
  33. # Get ip owner
  34. user="$(get_ip_value '$OWNER')"
  35. ip_status="$(get_ip_value '$STATUS')"
  36. # Deleting interface
  37. interface=$(/sbin/ifconfig |grep -B1 "addr:$ip "|head -n 1 |cut -f 1 -d ' ')
  38. if [ ! -z "$interface" ] && [ -z "$(echo $interface|cut -s -f2 -d :)" ]; then
  39. echo "Error: Main IP on interface"
  40. log_event "$E_FORBIDEN" "$EVENT"
  41. exit $E_FORBIDEN
  42. fi
  43. if [ ! -z "$interface" ]; then
  44. /sbin/ifconfig "$interface" down
  45. iconf='/etc/sysconfig/network-scripts/ifcfg'
  46. rm -f $iconf-$interface
  47. fi
  48. # Deleting vesta ip
  49. rm -f $VESTA/data/ips/$ip
  50. # Deleting namehosting support
  51. namehost_ip_disable
  52. #----------------------------------------------------------#
  53. # Vesta #
  54. #----------------------------------------------------------#
  55. # Updating user conf
  56. if [ ! -z "$user" ]; then
  57. decrease_user_value "$user" '$IP_OWNED'
  58. fi
  59. if [ "$user" = 'admin' ]; then
  60. if [ "$ip_status" = 'shared' ]; then
  61. for user in $(ls $VESTA/data/users/); do
  62. decrease_user_value "$user" '$IP_AVAIL'
  63. done
  64. else
  65. decrease_user_value 'admin' '$IP_AVAIL'
  66. fi
  67. else
  68. decrease_user_value "$user" '$IP_AVAIL'
  69. decrease_user_value 'admin' '$IP_AVAIL'
  70. fi
  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_history "delted system ip address $ip" '' 'admin'
  77. log_event "$OK" "$EVENT"
  78. exit