v_delete_sys_ip 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. # Importing variables
  13. source $VESTA/conf/vesta.conf
  14. source $VESTA/func/shared.sh
  15. source $VESTA/func/ip.sh
  16. source $VESTA/func/domain.sh
  17. #----------------------------------------------------------#
  18. # Verifications #
  19. #----------------------------------------------------------#
  20. # Checking arg number
  21. check_args '1' "$#" 'ip'
  22. # Checking argument format
  23. validate_format 'ip'
  24. # Checking system ip
  25. is_sys_ip_valid "$ip"
  26. # Checking webdomains on ip
  27. is_ip_key_empty '$U_WEB_DOMAINS'
  28. # Checking users on ip
  29. is_ip_key_empty '$U_SYS_USERS'
  30. # Checking interface
  31. interface=$(get_current_interface)
  32. #----------------------------------------------------------#
  33. # Action #
  34. #----------------------------------------------------------#
  35. # Defining config paths
  36. conf='/etc/httpd/conf.d/vesta.conf'
  37. nconf='/etc/nginx/conf.d/vesta_ip.conf'
  38. iconf='/etc/sysconfig/network-scripts/ifcfg'
  39. rconf='/etc/httpd/conf.d/rpaf.conf'
  40. # Get ip owner
  41. user="$(get_sys_ip_value '$OWNER')"
  42. ip_status="$(get_sys_ip_value '$STATUS')"
  43. # Deleting interface
  44. /sbin/ifconfig "$interface" down
  45. # Deleting startup script
  46. rm -f $iconf-$interface
  47. # Deleting vesta ip
  48. rm -f $VESTA/data/ips/$ip
  49. # Importing main config
  50. source $VESTA/conf/vesta.conf
  51. # Deleting namehosting support
  52. namehost_ip_disable
  53. #----------------------------------------------------------#
  54. # Vesta #
  55. #----------------------------------------------------------#
  56. # Updating user conf
  57. if [ ! -z "$user" ]; then
  58. decrease_user_value "$user" '$IP_OWNED'
  59. fi
  60. if [ "$user" = 'admin' ]; then
  61. if [ "$ip_status" = 'shared' ]; then
  62. for user in $(ls $V_USERS/); do
  63. decrease_user_value "$user" '$IP_AVAIL'
  64. done
  65. else
  66. decrease_user_value 'admin' '$IP_AVAIL'
  67. fi
  68. else
  69. decrease_user_value "$user" '$IP_AVAIL'
  70. decrease_user_value 'admin' '$IP_AVAIL'
  71. fi
  72. # Adding task to the vesta pipe
  73. if [ "$web_restart" = 'yes' ]; then
  74. $BIN/v_restart_web
  75. fi
  76. # Logging
  77. log_event "$OK" "$EVENT"
  78. exit