Serghey Rodin пре 13 година
родитељ
комит
917b6e2c3f

+ 55 - 0
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

+ 77 - 1
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                              #

+ 27 - 5
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');

+ 4 - 4
web/templates/admin/list_rrd.html

@@ -3,10 +3,10 @@
                                     <tr>
                                         <td style="padding: 12px 0 0 16px">
                                             <div style="float:left">
-                                                <a class="add" <?php if ((empty($_GET['period'])) || ($_GET['period'] == 'daily')) echo "style='color: #34536A'" ?> href="?period=daily">Daily</a>
-                                                <a class="add" <?php if ($_GET['period'] == 'weekly') echo "style='color: #34536A'" ?> href="?period=weekly">Weekly</a>
-                                                <a class="add" <?php if ($_GET['period'] == 'monthly') echo "style='color: #34536A'" ?> href="?period=monthly">Monthly</a>
-                                                <a class="add" <?php if ($_GET['period'] == 'yearly') echo "style='color: #34536A'" ?> href="?period=yearly">Yearly</a>
+                                                <a class="vst" <?php if ((empty($_GET['period'])) || ($_GET['period'] == 'daily')) echo "style='color: #34536A'" ?> href="?period=daily">Daily</a>
+                                                <a class="vst" <?php if ($_GET['period'] == 'weekly') echo "style='color: #34536A'" ?> href="?period=weekly">Weekly</a>
+                                                <a class="vst" <?php if ($_GET['period'] == 'monthly') echo "style='color: #34536A'" ?> href="?period=monthly">Monthly</a>
+                                                <a class="vst" <?php if ($_GET['period'] == 'yearly') echo "style='color: #34536A'" ?> href="?period=yearly">Yearly</a>
                                             </div>
                                             <div style="text-align: right; float: right;">
                                                 <form action="/search/" method="get" >

+ 18 - 0
web/templates/admin/list_stats.html

@@ -3,6 +3,24 @@
                                     <tr>
                                         <td style="padding: 12px 0 0 16px">
                                             <div style="float:left">
+                                                <form action="/list/stats/" method="get" id="objects">
+                                                <a class="vst" <?php if (empty($_GET['user'])) echo "style='color: #34536A'"; ?> href='/list/stats/'>Overall Statistics</a>
+                                                <span style="padding: 0 8px;"></span>
+                                                <select style="margin:0 2px 0 0px;" name="user">
+                                                    <option value=''>show per user</option>
+                                                <?php
+                                                    foreach ($users as $key => $value) {
+                                                        echo "\t\t\t\t<option value=\"".$value."\"";
+                                                        if ((!empty($v_user)) && ( $value == $_GET['user'])){
+                                                            echo ' selected';
+                                                        }
+                                                        echo ">".$value."</option>\n";
+                                                    }
+                                                ?> 
+                                                </select>
+                                                <input type="submit" name="list" value="›" class="button" style="width: 37px;font-size: 12px; height: 24px;">
+                                            </form>
+
                                             </div>
                                             <div style="text-align: right; float: right;">
                                                 <form action="/search/" method="get" >

+ 4 - 4
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;
             }
 

+ 203 - 0
web/templates/user/list_stats.html

@@ -0,0 +1,203 @@
+
+                                <table class="sub-menu" style="background: white;">
+                                    <tr>
+                                        <td style="padding: 12px 0 0 16px">
+                                            <div style="float:left">
+                                            </div>
+                                            <div style="text-align: right; float: right;">
+                                                <form action="/search/" method="get" >
+                                                <input type="text" size="30" style="padding: 3px 80px 3px 0; margin: 0 2px 0 0;" name="q">
+                                                <input type="submit" value="Search"class="button" style="font-size: 12px; height: 24px;">
+                                                </form>
+                                            </div>
+                                        </td>
+                                    </tr>
+                                </table>
+                            </td>
+                        </tr>
+                    </table>
+
+                    <div id="vstobjects">
+                        <table class='data'>
+
+                            <?php
+                                foreach ($data as $key => $value) {
+                                    ++$i;
+                            ?>
+
+                            <tr class="data-row">
+                                <td class="data-dotted" style="padding: 0px 10px 0px 0px" width="150px">
+                                    <table class="data-col1" width="150">
+                                        <tr><td style="padding: 24 0 4 0;"><a class="data-date" title="<?php echo $data[$key]['DATE']."  ".$data[$key]['TIME'] ?>"><?php echo date("d M Y", strtotime($key))?></a></td></tr>
+                                    </table>
+                                </td>
+                                <td class="data-dotted" width="830px" style="vertical-align:top;">
+                                    <table width="830px">
+                                        <tr>
+                                            <td></td>
+                                        </tr>
+                                    </table>
+
+                                    <table class="data-col2" width="830px">
+                                        <tr>
+                                            <td colspan=3 class="username" style="padding: 10 0 0 4px;">
+                                                <b><?php echo date("M Y", strtotime($key))?></b>
+                                            </td>
+                                        </tr>
+                                        <tr>
+                                            <td style="vertical-align:top;" >
+                                                <table>
+                                                    <tr>
+                                                        <td colspan=2 class="counter-name"  style="padding: 2px 0px 6px 2px;">
+                                                            [<?php echo $data[$key]['PACKAGE']?>] package
+                                                        </td>
+                                                    </tr>
+                                                    <tr>
+                                                        <td class="chart1" colspan=2 style="padding: 0 0 0 2px;">
+                                                            Bandwidth: <?php echo get_percentage($data[$key]['U_BANDWIDTH'],$data[$key]['BANDWIDTH']) ?>% (<?php echo humanize_usage($data[$key]['U_BANDWIDTH']) ?>)
+                                                            <div style="width:160px; height:6px; font-size:0;background-color:#c7d5b3;">
+                                                                <div style="width:<?php echo get_percentage($data[$key]['U_BANDWIDTH'],$data[$key]['BANDWIDTH']) ?>%; height:6px; background-color:#9bbb62; border-right:1px #9bbb62 solid;"></div>
+                                                            </div>
+                                                        </td>
+                                                    </tr>
+                                                    <tr>
+                                                        <td class="chart1" colspan=2 style="padding: 0 0 0 2px;">
+                                                            Disk: <?php echo get_percentage($data[$key]['U_DISK'],$data[$key]['DISK_QUOTA']) ?>% (<?php echo humanize_usage($data[$key]['U_DISK']) ?>)
+                                                            <div style="width:160px; height:6px; font-size:0;background-color:#c7d5b3;">
+                                                                <div style="width:<?php echo get_percentage($data[$key]['U_DISK'],$data[$key]['DISK_QUOTA']) ?>%; height:6px; background-color:#9bbb62; border-right:1px #9bbb62 solid;"></div>
+                                                            </div>
+                                                        </td>
+                                                    </tr>
+                                                    <tr>
+                                                        <td colspan=2>
+                                                            <table class="chart2">
+                                                                <tr>
+                                                                    <td>
+                                                                        Web: <?php echo humanize_usage($data[$key]['U_DISK_WEB'])?><br>
+                                                                        Mail: <?php echo humanize_usage($data[$key]['U_DISK_MAIL'])?><br>
+                                                                    </td>
+                                                                    <td style="padding: 0px 10px 0px 8px">
+                                                                        Databases: <?php echo humanize_usage($data[$key]['U_DISK_DB'])?><br>
+                                                                        User Dirs: <?php echo humanize_usage($data[$key]['U_DISK_DIRS'])?><br>
+                                                                    </td>
+                                                                </tr>
+                                                            </table>
+                                                        </td>
+                                                    </tr>
+                                                </table>
+                                            </td>
+                                            <td style="vertical-align:top;" width="280">
+                                                <table width="280">
+                                                    <tr>
+                                                        <td class="counter-name" width="37%">
+                                                            Web Domains:
+                                                        </td>
+                                                        <td class="counter-value">
+                                                            <?php echo $data[$key]['U_WEB_DOMAINS'] ?> 
+                                                        </td>
+                                                    </tr>
+                                                    <tr>
+                                                        <td class="counter-name">
+                                                            Web SSL:
+                                                        </td>
+                                                        <td class="counter-value">
+                                                            <?php echo $data[$key]['U_WEB_SSL'] ?> 
+                                                        </td>
+                                                    </tr>
+                                                    <tr>
+                                                        <td class="counter-name">
+                                                            Web Aliases:
+                                                        </td>
+                                                        <td class="counter-value">
+                                                            <?php echo $data[$key]['U_WEB_ALIASES'] ?> 
+                                                        </td>
+                                                    </tr>
+                                                    <tr>
+                                                        <td class="counter-name">
+                                                            Dns Domains:
+                                                        </td>
+                                                        <td class="counter-value">
+                                                            <?php echo $data[$key]['U_DNS_DOMAINS'] ?> 
+                                                        </td>
+                                                    </tr>
+                                                    <tr>
+                                                        <td class="counter-name">
+                                                            Dns Records:
+                                                        </td>
+                                                        <td class="counter-value">
+                                                            <?php echo $data[$key]['U_DNS_RECORDS'] ?>
+                                                        </td>
+                                                    </tr>
+                                                </table>
+                                            </td>
+                                            <td style="vertical-align:top;" width="250">
+                                                <table class="data-col4" width="250">
+                                                    <tr>
+                                                        <td class="counter-name" width="43%">
+                                                            Mail Domains:
+                                                        </td>
+                                                        <td class="counter-value">
+                                                            <?php echo $data[$key]['U_MAIL_DOMAINS'] ?>
+                                                        </td>
+                                                    </tr>
+                                                    <tr>
+                                                        <td class="counter-name">
+                                                            Mail Accounts:
+                                                        </td>
+                                                        <td class="counter-value">
+                                                            <?php echo $data[$key]['U_MAIL_ACCOUNTS'] ?> 
+                                                        </td>
+                                                    </tr>
+                                                    <tr>
+                                                        <td class="counter-name">
+                                                            Databases:
+                                                        </td>
+                                                        <td class="counter-value">
+                                                            <?php echo $data[$key]['U_DATABASES'] ?> 
+                                                        </td>
+                                                    </tr>
+                                                    <tr>
+                                                        <td class="counter-name">
+                                                            Cron Jobs:
+                                                        </td>
+                                                        <td class="counter-value">
+                                                            <?php echo $data[$key]['U_CRON_JOBS'] ?>
+                                                        </td>
+                                                    </tr>
+                                                    <tr>
+                                                        <td class="counter-name">
+                                                            Dedicated IP:
+                                                        </td>
+                                                        <td class="counter-value">
+                                                            <?php echo $data[$key]['IP_OWNED'] ?> 
+                                                        </td>
+                                                    </tr>
+                                                </table>
+                                            </td>
+                                        </tr>
+                                    </table>
+                                </td>
+                            </tr>
+
+                            <?php
+                                }
+                            ?> 
+
+                        </table>
+
+                        <table class="data-count">
+                            <tr>
+                                <td width="160px"></td>
+                                <td>
+                                    <?php
+                                        if ( $i == 1) {
+                                            echo "1 month ";
+                                        } else {
+                                            echo "$i months ";
+                                        }
+                                    ?>
+                                </td>
+                            </tr>
+                        </table>
+                    </div>
+