vesta/bin/v-update-sys-ip-counters
2016-06-09 16:55:35 +03:00

66 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# info: update IP usage counters
# options: IP
#
# Function updates usage U_WEB_ADOMAINS and U_SYS_USERS counters.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
ip=$1
# Includes
source $VESTA/func/main.sh
source $VESTA/func/ip.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '0' "$#" 'IP'
if [ ! -z "$ip" ]; then
is_format_valid 'ip'
is_ip_valid
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Creating user_list
if [ -z "$ip" ]; then
ip_list=$(ls $VESTA/data/ips)
else
ip_list="$ip"
fi
# Updating user stats
for ip in $ip_list; do
# Calculate usage
ip_usage=$(grep -H $ip $VESTA/data/users/*/web.conf)
web_domains=$(echo "$ip_usage" | sed '/^$/d' | wc -l)
sys_users=$(echo "$ip_usage" | cut -f7 -d/ | sort -u |\
tr '\n' ',' | sed "s/,$//g")
# Update counters
update_ip_value '$U_WEB_DOMAINS' "$web_domains"
update_ip_value '$U_SYS_USERS' "$sys_users"
done
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
exit