v_upd_web_domain_traff 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/bash
  2. # info: updating traffic usage for domain
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. user="$1"
  8. domain="$2"
  9. # Importing variables
  10. source $VESTA/conf/vars.conf
  11. source $V_FUNC/shared_func.sh
  12. source $V_FUNC/domain_func.sh
  13. #----------------------------------------------------------#
  14. # Verifications #
  15. #----------------------------------------------------------#
  16. # Checking arg number
  17. check_args '2' "$#" 'user domain'
  18. # Checking argument format
  19. format_validation 'user' 'domain'
  20. # Checking web system is enabled
  21. is_system_enabled 'web'
  22. # Checking user
  23. is_user_valid
  24. # Checking domain exist
  25. is_web_domain_valid
  26. # Checking domain is not suspened
  27. is_domain_suspended 'web_domains'
  28. #----------------------------------------------------------#
  29. # Action #
  30. #----------------------------------------------------------#
  31. # Defining log file
  32. log_file="/var/log/httpd/domains/$domain.bytes"
  33. # Defining bytes
  34. bytes=0
  35. # Parsing log
  36. while read line
  37. do
  38. if [[ '-' != "$line" ]] && [[ 0 -lt "$line" ]]
  39. then
  40. bytes=$(($bytes + $line))
  41. fi
  42. done < $log_file
  43. # Converting to Mb
  44. mb=$(echo "$bytes / 1024 / 1024"|bc)
  45. # Nulling log
  46. echo > $log_file
  47. #----------------------------------------------------------#
  48. # Vesta #
  49. #----------------------------------------------------------#
  50. # Parsing old value
  51. old_val=$(get_web_domain_value '$U_BANDWIDTH')
  52. # Defining new value
  53. bandwidth=$((old_val + mb))
  54. # Updating bandwidth value in config
  55. update_web_domain_value '$U_BANDWIDTH' "$bandwidth"
  56. # Logging
  57. log_event 'system' "$V_EVENT"
  58. exit $OK