#!/bin/bash # info: update domain bandwidth usage # options: user domain # # The function recalculates bandwidth usage for speciefic domain. #----------------------------------------------------------# # Variable&Function # #----------------------------------------------------------# # Argument defenition user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") # Importing variables source $VESTA/conf/vars.conf source $V_CONF/vesta.conf source $V_FUNC/shared.func source $V_FUNC/domain.func #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# # Checking arg number check_args '2' "$#" 'user domain' # Checking argument format format_validation 'user' 'domain' # Checking web system is enabled is_system_enabled 'web' # Checking user is_user_valid # Checking domain exist is_web_domain_valid # Checking domain is not suspened is_domain_suspended 'web' #----------------------------------------------------------# # Action # #----------------------------------------------------------# # Defining log file log_file="/var/log/httpd/domains/$domain.bytes" # Defining bytes bytes=0 # Parsing log while read line do if [[ '-' != "$line" ]] && [[ 0 -lt "$line" ]] then bytes=$(($bytes + $line)) fi done < $log_file # Converting to Mb mb=$(echo "$bytes / 1024 / 1024"|bc) # Nulling log echo > $log_file #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# # Parsing old value old_val=$(get_web_domain_value '$U_BANDWIDTH') # Defining new value bandwidth=$((old_val + mb)) # Updating bandwidth value in config update_web_domain_value '$U_BANDWIDTH' "$bandwidth" # Logging log_event 'system' "$V_EVENT" exit