v_delete_sys_ip 2.5 KB

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