v_update_web_domains_traff 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. # info: updating traffic usage for domains
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. user=$1
  8. # Importing variables
  9. source $VESTA/conf/vars.conf
  10. source $V_CONF/vesta.conf
  11. source $V_FUNC/shared.func
  12. source $V_FUNC/domain.func
  13. #----------------------------------------------------------#
  14. # Verifications #
  15. #----------------------------------------------------------#
  16. # Checking arg number
  17. check_args '1' "$#" 'user'
  18. # Checking argument format
  19. format_validation 'user'
  20. # Checking web system is enabled
  21. is_system_enabled 'web'
  22. # Checking user
  23. is_user_valid "$user"
  24. #----------------------------------------------------------#
  25. # Action #
  26. #----------------------------------------------------------#
  27. # Defining config
  28. conf="$V_USERS/$user/web.conf"
  29. # Defining fileds to select
  30. field='$DOMAIN'
  31. # Defining search string
  32. search_string="SUSPEND='no'"
  33. # Parsing unsuspeneded domains
  34. domains=$(dom_clear_search)
  35. # Starting suspend loop
  36. for domain in $domains; do
  37. # Defining log file
  38. log_file="/var/log/httpd/domains/$domain.bytes"
  39. # Defining bytes
  40. bytes=0
  41. # Parsing log
  42. while read line; do
  43. if [[ '-' != "$line" ]] && [[ 0 -lt "$line" ]]; then
  44. bytes=$(($bytes + $line))
  45. fi
  46. done < $log_file
  47. # Converting to Mb
  48. mb=$(echo "$bytes / 1024 / 1024"|bc)
  49. # Nulling log
  50. echo > $log_file
  51. # Parsing old value
  52. old_val=$(get_web_domain_value '$U_BANDWIDTH')
  53. # Defining new value
  54. bandwidth=$((old_val + mb))
  55. # Updating bandwidth value in config
  56. update_web_domain_value '$U_BANDWIDTH' "$bandwidth"
  57. done
  58. #----------------------------------------------------------#
  59. # Vesta #
  60. #----------------------------------------------------------#
  61. # Recalculating user bandwidth
  62. traff_size=$(get_usr_traff)
  63. update_user_value "$user" '$U_BANDWIDTH' "$traff_size"
  64. # Logging
  65. log_event 'system' "$V_EVENT"
  66. exit