v-update-sys-ip-counters 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash
  2. # info: update IP usage counters
  3. # options: IP
  4. # labels: panel
  5. #
  6. # example: v-update-sys-ip-counters
  7. #
  8. # Function updates usage U_WEB_ADOMAINS and U_SYS_USERS counters.
  9. #----------------------------------------------------------#
  10. # Variable&Function #
  11. #----------------------------------------------------------#
  12. # Argument definition
  13. ip=$1
  14. # Includes
  15. source $HESTIA/func/main.sh
  16. source $HESTIA/func/ip.sh
  17. source $HESTIA/conf/hestia.conf
  18. #----------------------------------------------------------#
  19. # Verifications #
  20. #----------------------------------------------------------#
  21. check_args '0' "$#" 'IP'
  22. if [ ! -z "$ip" ]; then
  23. is_format_valid 'ip'
  24. is_ip_valid
  25. fi
  26. #----------------------------------------------------------#
  27. # Action #
  28. #----------------------------------------------------------#
  29. # Creating user_list
  30. if [ -z "$ip" ]; then
  31. ip_list=$(ls $HESTIA/data/ips)
  32. else
  33. ip_list="$ip"
  34. fi
  35. # Updating user stats
  36. for ip in $ip_list; do
  37. # Calculate usage
  38. ip_usage=$(grep -H $ip $HESTIA/data/users/*/web.conf)
  39. web_domains=$(echo "$ip_usage" | sed '/^$/d' | wc -l)
  40. sys_users=$(echo "$ip_usage" | cut -f7 -d/ | sort -u |\
  41. tr '\n' ',' | sed "s/,$//g")
  42. # Update counters
  43. update_ip_value '$U_WEB_DOMAINS' "$web_domains"
  44. update_ip_value '$U_SYS_USERS' "$sys_users"
  45. done
  46. #----------------------------------------------------------#
  47. # Hestia #
  48. #----------------------------------------------------------#
  49. # Logging
  50. log_event "$OK" "$ARGUMENTS"
  51. exit