From 917b6e2c3f3e523c4e0a46791330707aff559ea1 Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Sat, 22 Dec 2012 14:31:45 +0200 Subject: [PATCH] added overall stats --- bin/v-list-users-stats | 55 ++++++++ bin/v-update-user-stats | 78 ++++++++++- web/list/stats/index.php | 32 ++++- web/templates/admin/list_rrd.html | 8 +- web/templates/admin/list_stats.html | 18 +++ web/templates/header.html | 8 +- web/templates/user/list_stats.html | 203 ++++++++++++++++++++++++++++ 7 files changed, 388 insertions(+), 14 deletions(-) create mode 100755 bin/v-list-users-stats create mode 100644 web/templates/user/list_stats.html diff --git a/bin/v-list-users-stats b/bin/v-list-users-stats new file mode 100755 index 000000000..b731747d4 --- /dev/null +++ b/bin/v-list-users-stats @@ -0,0 +1,55 @@ +#!/bin/bash +# info: list overall user stats +# options: [format] +# +# The function for listing overall user statistics + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +format=${1-shell} + +# Includes +source $VESTA/func/main.sh + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +check_args '0' "$#" '[format]' + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Defining config +conf=$VESTA/data/users/admin/overall_stats.log + +# Defining fileds to select +fields="\$DATE \$TIME \$PACKAGE \$IP_OWNED \$DISK_QUOTA \$U_DISK \$U_DISK_DIRS" +fields="$fields \$U_DISK_WEB \$U_DISK_MAIL \$U_DISK_DB \$BANDWIDTH" +fields="$fields \$U_BANDWIDTH \$U_WEB_DOMAINS \$U_WEB_SSL \$U_WEB_ALIASES" +fields="$fields \$U_DNS_DOMAINS \$U_DNS_RECORDS \$U_MAIL_DOMAINS \$U_MAIL_DKIM" +fields="$fields \$U_MAIL_ACCOUNTS \$U_DATABASES \$U_CRON_JOBS \$U_BACKUPS" + +# Listing domains +case $format in + json) json_list ;; + plain) nohead=1; shell_list ;; + shell) fields='$DATE $U_DISK $U_BANDWIDTH $U_WEB_DOMAINS $U_DATABASES'; + fields="$fields \$U_DATABASES" + shell_list | column -t ;; + *) check_args '1' '0' '[format]' +esac + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit diff --git a/bin/v-update-user-stats b/bin/v-update-user-stats index d2415eabd..b62945274 100755 --- a/bin/v-update-user-stats +++ b/bin/v-update-user-stats @@ -44,11 +44,32 @@ else user_list="$user" fi +# Reset overal statistics +TOTAL_IP_OWNED=0 +TOTAL_U_DISK=0 +TOTAL_U_DISK_DIRS=0 +TOTAL_U_DISK_WEB=0 +TOTAL_U_DISK_MAIL=0 +TOTAL_U_DISK_DB=0 +TOTAL_U_BANDWIDTH=0 +TOTAL_U_WEB_DOMAINS=0 +TOTAL_U_WEB_SSL=0 +TOTAL_U_WEB_ALIASES=0 +TOTAL_U_DNS_DOMAINS=0 +TOTAL_U_DNS_RECORDS=0 +TOTAL_U_MAIL_DOMAINS=0 +TOTAL_U_MAIL_DKIM=0 +TOTAL_U_MAIL_ACCOUNTS=0 +TOTAL_U_DATABASES=0 +TOTAL_U_CRON_JOBS=0 +TOTAL_U_BACKUPS=0 + # Updating user stats for user in $user_list; do USER_DATA=$VESTA/data/users/$user source $USER_DATA/user.conf - DATE=$(date -d "$(date +'%m/01' -d "+ 1 month") -1day" +%F) + next_month=$(date +'%m/01' -d '+ 1 month') + DATE=$(date -d "$next_month -1day" +%F) # Compiling report string s="DATE='$DATE' TIME='$TIME' PACKAGE='$PACKAGE' IP_OWNED='$IP_OWNED'" @@ -80,8 +101,63 @@ for user in $user_list; do echo "$s" >$stats chmod 660 $stats fi + + # Increase overall counters + TOTAL_IP_OWNED=$((TOTAL_IP_OWNED + IP_OWNED)) + TOTAL_U_DISK=$((TOTAL_U_DISK + U_DISK)) + TOTAL_U_DISK_DIRS=$((TOTAL_U_DISK_DIRS + U_DISK_DIRS)) + TOTAL_U_DISK_WEB=$((TOTAL_U_DISK_WEB + U_DISK_WEB)) + TOTAL_U_DISK_MAIL=$((TOTAL_U_DISK_MAIL + U_DISK_MAIL)) + TOTAL_U_DISK_DB=$((TOTAL_U_DISK_DB + U_DISK_DB)) + TOTAL_U_BANDWIDTH=$((TOTAL_U_BANDWIDTH + U_BANDWIDTH)) + TOTAL_U_WEB_DOMAINS=$((TOTAL_U_WEB_DOMAINS + U_WEB_DOMAINS)) + TOTAL_U_WEB_SSL=$((TOTAL_U_WEB_SSL + U_WEB_SSL)) + TOTAL_U_WEB_ALIASES=$((TOTAL_U_WEB_ALIASES + U_WEB_ALIASES)) + TOTAL_U_DNS_DOMAINS=$((TOTAL_U_DNS_DOMAINS + U_DNS_DOMAINS)) + TOTAL_U_DNS_RECORDS=$((TOTAL_U_DNS_RECORDS + U_DNS_RECORDS)) + TOTAL_U_MAIL_DOMAINS=$((TOTAL_U_MAIL_DOMAINS + U_MAIL_DOMAINS)) + TOTAL_U_MAIL_DKIM=$((TOTAL_U_MAIL_DKIM + U_MAIL_DKIM)) + TOTAL_U_MAIL_ACCOUNTS=$((TOTAL_U_MAIL_ACCOUNTS + U_MAIL_ACCOUNTS)) + TOTAL_U_DATABASES=$((TOTAL_U_DATABASES + U_DATABASES)) + TOTAL_U_CRON_JOBS=$((TOTAL_U_CRON_JOBS + U_CRON_JOBS)) + TOTAL_U_BACKUPS=$((TOTAL_U_BACKUPS + U_BACKUPS)) + done +# Updating overall stats +stats="$VESTA/data/users/admin/overall_stats.log" + +s="DATE='$DATE' TIME='$TIME' PACKAGE='default' IP_OWNED='$TOTAL_IP_OWNED'" +s="$s DISK_QUOTA='0' U_DISK='$TOTAL_U_DISK' U_DISK_DIRS='$TOTAL_U_DISK_DIRS'" +s="$s U_DISK_WEB='$TOTAL_U_DISK_WEB' U_DISK_MAIL='$TOTAL_U_DISK_MAIL'" +s="$s U_DISK_DB='$TOTAL_U_DISK_DB' BANDWIDTH='0'" +s="$s U_BANDWIDTH='$TOTAL_U_BANDWIDTH' U_WEB_DOMAINS='$TOTAL_U_WEB_DOMAINS'" +s="$s U_WEB_SSL='$TOTAL_U_WEB_SSL' U_WEB_ALIASES='$TOTAL_U_WEB_ALIASES'" +s="$s U_DNS_DOMAINS='$TOTAL_U_DNS_DOMAINS'" +s="$s U_DNS_RECORDS='$TOTAL_U_DNS_RECORDS'" +s="$s U_MAIL_DOMAINS='$TOTAL_U_MAIL_DOMAINS' U_MAIL_DKIM='$TOTAL_U_MAIL_DKIM'" +s="$s U_MAIL_ACCOUNTS='$TOTAL_U_MAIL_ACCOUNTS'" +s="$s U_DATABASES='$TOTAL_U_DATABASES'" +s="$s U_CRON_JOBS='$TOTAL_U_CRON_JOBS' U_BACKUPS='$TOTAL_U_BACKUPS'" + +if [ -e "$stats" ]; then + # Checking dublicates + check_month=$(grep -n "DATE='$DATE'" $stats|cut -f 1 -d :) + if [ -z "$check_month" ]; then + # Updating as there no dublicates + echo "$s" >> $stats + chmod 660 $stats + else + # Replacing string with new data + sed -i "$check_month s/.*/$s/" $stats + fi +else + # Creating stats log + echo "$s" >$stats + chmod 660 $stats +fi + + #----------------------------------------------------------# # Vesta # diff --git a/web/list/stats/index.php b/web/list/stats/index.php index a8a936334..41e490c9b 100644 --- a/web/list/stats/index.php +++ b/web/list/stats/index.php @@ -13,11 +13,33 @@ include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html'); top_panel($user,$TAB); // Data -exec (VESTA_CMD."v-list-user-stats $user json", $output, $return_var); -$data = json_decode(implode('', $output), true); -$data = array_reverse($data); -unset($output); -include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_stats.html'); +if ($_SESSION['user'] == 'admin') { + + if (empty($_GET['user'])) { + exec (VESTA_CMD."v-list-users-stats json", $output, $return_var); + $data = json_decode(implode('', $output), true); + $data = array_reverse($data); + unset($output); + } else { + $v_user = escapeshellarg($_GET['user']); + exec (VESTA_CMD."v-list-user-stats $v_user json", $output, $return_var); + $data = json_decode(implode('', $output), true); + $data = array_reverse($data); + unset($output); + } + + exec (VESTA_CMD."v-list-sys-users 'json'", $output, $return_var); + $users = json_decode(implode('', $output), true); + unset($output); + + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_stats.html'); +} else { + exec (VESTA_CMD."v-list-user-stats $user json", $output, $return_var); + $data = json_decode(implode('', $output), true); + $data = array_reverse($data); + unset($output); + include($_SERVER['DOCUMENT_ROOT'].'/templates/user/list_stats.html'); +} // Footer include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html'); diff --git a/web/templates/admin/list_rrd.html b/web/templates/admin/list_rrd.html index f5a274298..0d3697ccc 100644 --- a/web/templates/admin/list_rrd.html +++ b/web/templates/admin/list_rrd.html @@ -3,10 +3,10 @@
- href="?period=daily">Daily - href="?period=weekly">Weekly - href="?period=monthly">Monthly - href="?period=yearly">Yearly + href="?period=daily">Daily + href="?period=weekly">Weekly + href="?period=monthly">Monthly + href="?period=yearly">Yearly
diff --git a/web/templates/admin/list_stats.html b/web/templates/admin/list_stats.html index 0bb657702..35eb13093 100644 --- a/web/templates/admin/list_stats.html +++ b/web/templates/admin/list_stats.html @@ -3,6 +3,24 @@
+ + href='/list/stats/'>Overall Statistics + + + + +
diff --git a/web/templates/header.html b/web/templates/header.html index a642c610c..be23b3f54 100644 --- a/web/templates/header.html +++ b/web/templates/header.html @@ -205,8 +205,8 @@ text-decoration: underline; } - .add { - padding: 0 8px 0 3px; + .vst { + padding: 0 8px 0 0; margin: 0; font-family: Arial, sans-serif; text-decoration: none; @@ -214,11 +214,11 @@ font-size: 12pt; } - .add:hover { + .vst:hover { text-decoration: underline; } - .add:active { + .vst:active { color: #34536A; } diff --git a/web/templates/user/list_stats.html b/web/templates/user/list_stats.html new file mode 100644 index 000000000..0bb657702 --- /dev/null +++ b/web/templates/user/list_stats.html @@ -0,0 +1,203 @@ + + + + + + + + + + +
+ + + $value) { + ++$i; + ?> + + + + + + + + +
+ + +
">
+
+ + + + +
+ + + + + + + + + + +
+ +
+ + + + + + + + + + + + + +
+ [] package +
+ Bandwidth: % () +
+
+
+
+ Disk: % () +
+
+
+
+ + + + + +
+ Web:
+ Mail:
+
+ Databases:
+ User Dirs:
+
+
+
+ + + + + + + + + + + + + + + + + + + + + +
+ Web Domains: + + +
+ Web SSL: + + +
+ Web Aliases: + + +
+ Dns Domains: + + +
+ Dns Records: + + +
+
+ + + + + + + + + + + + + + + + + + + + + +
+ Mail Domains: + + +
+ Mail Accounts: + + +
+ Databases: + + +
+ Cron Jobs: + + +
+ Dedicated IP: + + +
+
+
+ + + + + + +
+ +
+
+