v-update-sys-ip-counters 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. # 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 '0' "$#" 'IP'
  25. if [ ! -z "$ip" ]; then
  26. is_format_valid 'ip'
  27. is_ip_valid
  28. fi
  29. # Perform verification if read-only mode is enabled
  30. check_hestia_demo_mode
  31. #----------------------------------------------------------#
  32. # Action #
  33. #----------------------------------------------------------#
  34. # Creating user_list
  35. if [ -z "$ip" ]; then
  36. ip_list=$(ls $HESTIA/data/ips)
  37. else
  38. ip_list="$ip"
  39. fi
  40. # Updating user stats
  41. for ip in $ip_list; do
  42. # Calculate usage
  43. ip_usage=$(grep -H $ip $HESTIA/data/users/*/web.conf)
  44. web_domains=$(echo "$ip_usage" | sed '/^$/d' | wc -l)
  45. sys_users=$(echo "$ip_usage" | cut -f7 -d/ | sort -u |\
  46. tr '\n' ',' | sed "s/,$//g")
  47. # Update counters
  48. update_ip_value '$U_WEB_DOMAINS' "$web_domains"
  49. update_ip_value '$U_SYS_USERS' "$sys_users"
  50. done
  51. #----------------------------------------------------------#
  52. # Hestia #
  53. #----------------------------------------------------------#
  54. # Logging
  55. log_event "$OK" "$ARGUMENTS"
  56. exit