v_delete_user_ips 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. # info: delete user ips
  3. # options: user
  4. #
  5. # The function deletes all user's ip addresses.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. user=$1
  11. # Importing variables
  12. source $VESTA/conf/vesta.conf
  13. source $VESTA/func/shared.sh
  14. source $VESTA/func/ip.sh
  15. #----------------------------------------------------------#
  16. # Verifications #
  17. #----------------------------------------------------------#
  18. # Checking arg number
  19. check_args '1' "$#" 'user'
  20. # Checking argument format
  21. validate_format 'user'
  22. # Checking user
  23. is_object_valid 'user' 'USER' "$user"
  24. # Checking user is active
  25. is_object_unsuspended 'user' 'USER' "$user"
  26. # Checking user vesta
  27. if [ "$user" = 'admin' ]; then
  28. exit
  29. fi
  30. #----------------------------------------------------------#
  31. # Action #
  32. #----------------------------------------------------------#
  33. # Parsing user ips
  34. ip_list=$(grep -H "OWNER='$user'" $VESTA/data/ips/* | cut -f 1 -d:)
  35. for ip in $ip_list; do
  36. ip=$(basename $ip)
  37. # Checking webdomains and users
  38. is_ip_key_empty '$U_WEB_DOMAINS'
  39. is_ip_key_empty '$U_SYS_USERS'
  40. # Assig ip to main account
  41. update_sys_ip_value '$OWNER' 'admin'
  42. update_sys_ip_value '$STATUS' 'dedicated'
  43. increase_user_value 'admin' '$IP_OWNED'
  44. increase_user_value 'admin' '$IP_AVAIL'
  45. done
  46. #----------------------------------------------------------#
  47. # Vesta #
  48. #----------------------------------------------------------#
  49. # Logging
  50. log_event "$OK" "$EVENT"
  51. exit