vesta/bin/v_upd_web_domain_traff
2011-06-30 01:00:27 +03:00

85 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# info: updating traffic usage for 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_FUNC/shared_func.sh
source $V_FUNC/domain_func.sh
#----------------------------------------------------------#
# 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_domains'
#----------------------------------------------------------#
# 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 $OK