mirror of
https://github.com/serghey-rodin/vesta.git
synced 2025-01-08 20:13:01 -08:00
85 lines
1.9 KiB
Bash
Executable File
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
|