v-delete-user-ips 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. # Includes
  12. source $VESTA/conf/vesta.conf
  13. source $VESTA/func/main.sh
  14. source $VESTA/func/ip.sh
  15. #----------------------------------------------------------#
  16. # Verifications #
  17. #----------------------------------------------------------#
  18. check_args '1' "$#" 'user'
  19. validate_format 'user'
  20. is_object_valid 'user' 'USER' "$user"
  21. is_object_unsuspended 'user' 'USER' "$user"
  22. if [ "$user" = 'admin' ]; then
  23. exit
  24. fi
  25. #----------------------------------------------------------#
  26. # Action #
  27. #----------------------------------------------------------#
  28. # Parsing user ips
  29. ip_list=$(grep -H "OWNER='$user'" $VESTA/data/ips/* | cut -f 1 -d:)
  30. for ip in $ip_list; do
  31. ip=$(basename $ip)
  32. # Checking webdomains and users
  33. is_ip_key_empty '$U_WEB_DOMAINS'
  34. is_ip_key_empty '$U_SYS_USERS'
  35. # Assig ip to main account
  36. update_ip_value '$OWNER' 'admin'
  37. update_ip_value '$STATUS' 'dedicated'
  38. increase_user_value 'admin' '$IP_OWNED'
  39. increase_user_value 'admin' '$IP_AVAIL'
  40. done
  41. #----------------------------------------------------------#
  42. # Vesta #
  43. #----------------------------------------------------------#
  44. # Logging
  45. log_event "$OK" "$EVENT"
  46. exit