mirror of
https://github.com/myvesta/vesta.git
synced 2024-12-21 11:31:21 -08:00
144 lines
4.5 KiB
Bash
Executable File
144 lines
4.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# info: list overall user stats
|
|
# options: [FORMAT]
|
|
#
|
|
# The function for listing overall user statistics
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Variable&Function #
|
|
#----------------------------------------------------------#
|
|
|
|
# Argument definition
|
|
format=${1-shell}
|
|
|
|
# Includes
|
|
source $VESTA/func/main.sh
|
|
|
|
# JSON list function
|
|
json_list() {
|
|
IFS=$'\n'
|
|
i=1
|
|
objects=$(grep DATE $VESTA/data/users/admin/overall_stats.log |wc -l)
|
|
echo "{"
|
|
while read str; do
|
|
eval $str
|
|
echo -n ' "'$DATE'": {
|
|
"TIME": "'$TIME'",
|
|
"PACKAGE": "'$PACKAGE'",
|
|
"IP_OWNED": "'$IP_OWNED'",
|
|
"DISK_QUOTA": "'$DISK_QUOTA'",
|
|
"U_DISK": "'$U_DISK'",
|
|
"U_DISK_DIRS": "'$U_DISK_DIRS'",
|
|
"U_DISK_WEB": "'$U_DISK_WEB'",
|
|
"U_DISK_MAIL": "'$U_DISK_MAIL'",
|
|
"U_DISK_DB": "'$U_DISK_DB'",
|
|
"BANDWIDTH": "'$BANDWIDTH'",
|
|
"U_BANDWIDTH": "'$U_BANDWIDTH'",
|
|
"U_WEB_DOMAINS": "'$U_WEB_DOMAINS'",
|
|
"U_WEB_SSL": "'$U_WEB_SSL'",
|
|
"U_WEB_ALIASES": "'$U_WEB_ALIASES'",
|
|
"U_DNS_DOMAINS": "'$U_DNS_DOMAINS'",
|
|
"U_DNS_RECORDS": "'$U_DNS_RECORDS'",
|
|
"U_MAIL_DOMAINS": "'$U_MAIL_DOMAINS'",
|
|
"U_MAIL_DKIM": "'$U_MAIL_DKIM'",
|
|
"U_MAIL_ACCOUNTS": "'$U_MAIL_ACCOUNTS'",
|
|
"U_DATABASES": "'$U_DATABASES'",
|
|
"U_CRON_JOBS": "'$U_CRON_JOBS'",
|
|
"U_BACKUPS": "'$U_BACKUPS'",
|
|
"U_USERS": "'$U_USERS'"
|
|
}'
|
|
if [ "$i" -lt "$objects" ]; then
|
|
echo ','
|
|
else
|
|
echo
|
|
fi
|
|
((i++))
|
|
done < <(cat $VESTA/data/users/admin/overall_stats.log)
|
|
echo '}'
|
|
}
|
|
|
|
# SHELL list function
|
|
shell_list() {
|
|
IFS=$'\n'
|
|
echo "DATE USER WEB DNS MAIL DB BACKUPS IP DISK BW"
|
|
echo "---- ---- --- --- ---- -- ------- -- ---- --"
|
|
while read str; do
|
|
eval $str
|
|
if [ -z "$U_USERS" ]; then
|
|
U_USERS=1
|
|
fi
|
|
echo -n "$DATE $U_USERS $U_WEB_DOMAINS $U_DNS_DOMAINS "
|
|
echo -n "$U_MAIL_DOMAINS $U_DATABASES $U_BACKUPS $IP_OWNED "
|
|
echo "$U_DISK $U_BANDWIDTH"
|
|
done < <(cat $VESTA/data/users/admin/overall_stats.log)
|
|
}
|
|
|
|
# PLAIN list function
|
|
plain_list() {
|
|
IFS=$'\n'
|
|
while read str; do
|
|
eval $str
|
|
echo -ne "$DATE\t$TIME\t$PACKAGE\t$IP_OWNED\t$DISK_QUOTA\t$U_DISK\t"
|
|
echo -ne "$U_DISK_DIRS\t$U_DISK_WEB\t$U_DISK_MAIL\t$U_DISK_DB\t"
|
|
echo -ne "$BANDWIDTH\t$U_BANDWIDTH\t$U_WEB_DOMAINS\t$U_WEB_SSL\t"
|
|
echo -ne "$U_WEB_ALIASES\t$U_DNS_DOMAINS\t$U_DNS_RECORDS\t"
|
|
echo -ne "$U_MAIL_DOMAINS\t$U_MAIL_DKIM\t$U_MAIL_ACCOUNTS\t"
|
|
echo -e "$U_DATABASES\t$U_CRON_JOBS\t$U_BACKUPS\t$U_USERS"
|
|
done < <(cat $VESTA/data/users/admin/overall_stats.log)
|
|
}
|
|
|
|
# CSV list function
|
|
csv_list() {
|
|
IFS=$'\n'
|
|
echo -n "DATE,TIME,PACKAGE,IP_OWNED,DISK_QUOTA,U_DISK,"
|
|
echo -n "U_DISK_DIRS,U_DISK_WEB,U_DISK_MAIL,U_DISK_DB,"
|
|
echo -n "BANDWIDTH,U_BANDWIDTH,U_WEB_DOMAINS,U_WEB_SSL,"
|
|
echo -n "U_WEB_ALIASES,U_DNS_DOMAINS,U_DNS_RECORDS,"
|
|
echo -n "U_MAIL_DOMAINS,U_MAIL_DKIM,U_MAIL_ACCOUNTS,"
|
|
echo "U_DATABASES,U_CRON_JOBS,U_BACKUPS,U_USERS"
|
|
|
|
while read str; do
|
|
eval $str
|
|
echo -n "$DATE,$TIME,$PACKAGE,$IP_OWNED,$DISK_QUOTA,$U_DISK,"
|
|
echo -n "$U_DISK_DIRS,$U_DISK_WEB,$U_DISK_MAIL,$U_DISK_DB,"
|
|
echo -n "$BANDWIDTH,$U_BANDWIDTH,$U_WEB_DOMAINS,$U_WEB_SSL,"
|
|
echo -n "$U_WEB_ALIASES,$U_DNS_DOMAINS,$U_DNS_RECORDS,"
|
|
echo -n "$U_MAIL_DOMAINS,$U_MAIL_DKIM,$U_MAIL_ACCOUNTS,"
|
|
echo "$U_DATABASES,$U_CRON_JOBS,$U_BACKUPS,$U_USERS"
|
|
done < <(cat $VESTA/data/users/admin/overall_stats.log)
|
|
}
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Verifications #
|
|
#----------------------------------------------------------#
|
|
|
|
check_args '0' "$#" '[FORMAT]'
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Action #
|
|
#----------------------------------------------------------#
|
|
|
|
# Defining config
|
|
conf=$VESTA/data/users/admin/overall_stats.log
|
|
if [ ! -e "$conf" ]; then
|
|
touch $conf
|
|
fi
|
|
|
|
# Listing data
|
|
case $format in
|
|
json) json_list ;;
|
|
plain) plain_list ;;
|
|
csv) csv_list ;;
|
|
shell) shell_list |column -t ;;
|
|
esac
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Vesta #
|
|
#----------------------------------------------------------#
|
|
|
|
exit
|