v-delete-user-ips 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. # info: delete user ips
  3. # options: USER
  4. # labels: panel
  5. #
  6. # example: v-delete-user-ips admin
  7. #
  8. # The function deletes all user's ip addresses.
  9. #----------------------------------------------------------#
  10. # Variable&Function #
  11. #----------------------------------------------------------#
  12. # Argument definition
  13. user=$1
  14. # Includes
  15. # shellcheck source=/usr/local/hestia/func/main.sh
  16. source $HESTIA/func/main.sh
  17. # shellcheck source=/usr/local/hestia/func/ip.sh
  18. source $HESTIA/func/ip.sh
  19. # shellcheck source=/usr/local/hestia/conf/hestia.conf
  20. source $HESTIA/conf/hestia.conf
  21. #----------------------------------------------------------#
  22. # Verifications #
  23. #----------------------------------------------------------#
  24. check_args '1' "$#" 'USER'
  25. is_format_valid 'user'
  26. is_object_valid 'user' 'USER' "$user"
  27. if [ "$user" = 'admin' ]; then
  28. exit
  29. fi
  30. # Perform verification if read-only mode is enabled
  31. check_hestia_demo_mode
  32. #----------------------------------------------------------#
  33. # Action #
  34. #----------------------------------------------------------#
  35. # Parsing user ips
  36. ip_list=$(grep -H "OWNER='$user'" $HESTIA/data/ips/* | cut -f 1 -d:)
  37. for ip in $ip_list; do
  38. ip=$(basename $ip)
  39. # Checking webdomains and users
  40. is_ip_key_empty '$U_WEB_DOMAINS'
  41. is_ip_key_empty '$U_SYS_USERS'
  42. # Assig ip to main account
  43. update_ip_value '$OWNER' 'admin'
  44. update_ip_value '$STATUS' 'dedicated'
  45. increase_user_value 'admin' '$IP_OWNED'
  46. increase_user_value 'admin' '$IP_AVAIL'
  47. done
  48. #----------------------------------------------------------#
  49. # Hestia #
  50. #----------------------------------------------------------#
  51. # Logging
  52. log_event "$OK" "$ARGUMENTS"
  53. exit