v-delete-sys-ip 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. get_current_interface
  38. /sbin/ifconfig "$interface" down
  39. # Deleting startup script
  40. rm -f $iconf-$interface
  41. # Deleting vesta ip
  42. rm -f $VESTA/data/ips/$ip
  43. # Deleting namehosting support
  44. namehost_ip_disable
  45. #----------------------------------------------------------#
  46. # Vesta #
  47. #----------------------------------------------------------#
  48. # Updating user conf
  49. if [ ! -z "$user" ]; then
  50. decrease_user_value "$user" '$IP_OWNED'
  51. fi
  52. if [ "$user" = 'admin' ]; then
  53. if [ "$ip_status" = 'shared' ]; then
  54. for user in $(ls $VESTA/data/users/); do
  55. decrease_user_value "$user" '$IP_AVAIL'
  56. done
  57. else
  58. decrease_user_value 'admin' '$IP_AVAIL'
  59. fi
  60. else
  61. decrease_user_value "$user" '$IP_AVAIL'
  62. decrease_user_value 'admin' '$IP_AVAIL'
  63. fi
  64. # Adding task to the vesta pipe
  65. if [ "$web_restart" = 'yes' ]; then
  66. $BIN/v-restart-web "$EVENT"
  67. fi
  68. # Logging
  69. log_history "delted system ip address $ip" '' 'admin'
  70. log_event "$OK" "$EVENT"
  71. exit