From 0deff130c6d7404da71e9ab9d8ee738112bd4f74 Mon Sep 17 00:00:00 2001
From: Florian Schaal <florian@schaal-24.de>
Date: Fri, 05 Jun 2015 10:47:18 -0400
Subject: [PATCH] add mailfilter to resync
---
interface/lib/classes/quota_lib.inc.php | 125 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 124 insertions(+), 1 deletions(-)
diff --git a/interface/lib/classes/quota_lib.inc.php b/interface/lib/classes/quota_lib.inc.php
index 613c524..24a3ce3 100644
--- a/interface/lib/classes/quota_lib.inc.php
+++ b/interface/lib/classes/quota_lib.inc.php
@@ -95,7 +95,68 @@
return $sites;
}
-
+
+ public function get_trafficquota_data($clientid = null, $lastdays = 0) {
+ global $app;
+
+ $traffic_data = array();
+
+ // select vhosts (belonging to client)
+ if($clientid != null){
+ $sql_where = " AND sys_groupid = (SELECT default_group FROM sys_user WHERE client_id=?)";
+ }
+ $sites = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE active = 'y' AND (type = 'vhost' OR type = 'vhostsubdomain' OR type = 'vhostalias')".$sql_where, $clientid);
+
+ $hostnames = array();
+ $traffic_data = array();
+
+ foreach ($sites as $site) {
+ $hostnames[] = $site['domain'];
+ $traffic_data[$site['domain']]['domain_id'] = $site['domain_id'];
+ }
+
+ // fetch all traffic-data of selected vhosts
+ if (!empty($hostnames)) {
+ $tmp_year = date('Y');
+ $tmp_month = date('m');
+ // This Month
+ $tmp_recs = $app->db->queryAllRecords("SELECT hostname, SUM(traffic_bytes) as t FROM web_traffic WHERE YEAR(traffic_date) = ? AND MONTH(traffic_date) = ? AND hostname IN ? GROUP BY hostname", $tmp_year, $tmp_month, $hostnames);
+ foreach ($tmp_recs as $tmp_rec) {
+ $traffic_data[$tmp_rec['hostname']]['this_month'] = $tmp_rec['t'];
+ }
+ // This Year
+ $tmp_recs = $app->db->queryAllRecords("SELECT hostname, SUM(traffic_bytes) as t FROM web_traffic WHERE YEAR(traffic_date) = ? AND hostname IN ? GROUP BY hostname", $tmp_year, $hostnames);
+ foreach ($tmp_recs as $tmp_rec) {
+ $traffic_data[$tmp_rec['hostname']]['this_year'] = $tmp_rec['t'];
+ }
+
+ $tmp_year = date('Y', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
+ $tmp_month = date('m', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
+ // Last Month
+ $tmp_recs = $app->db->queryAllRecords("SELECT hostname, SUM(traffic_bytes) as t FROM web_traffic WHERE YEAR(traffic_date) = ? AND MONTH(traffic_date) = ? AND hostname IN ? GROUP BY hostname", $tmp_year, $tmp_month, $hostnames);
+ foreach ($tmp_recs as $tmp_rec) {
+ $traffic_data[$tmp_rec['hostname']]['last_month'] = $tmp_rec['t'];
+ }
+
+ $tmp_year = date('Y', mktime(0, 0, 0, date("m"), date("d"), date("Y")-1));
+ // Last Year
+ $tmp_recs = $app->db->queryAllRecords("SELECT hostname, SUM(traffic_bytes) as t FROM web_traffic WHERE YEAR(traffic_date) = ? AND hostname IN ? GROUP BY hostname", $tmp_year, $hostnames);
+ foreach ($tmp_recs as $tmp_rec) {
+ $traffic_data[$tmp_rec['hostname']]['last_year'] = $tmp_rec['t'];
+ }
+
+ if (is_int($lastdays) && ($lastdays > 0)) {
+ // Last xx Days
+ $tmp_recs = $app->db->queryAllRecords("SELECT hostname, SUM(traffic_bytes) as t FROM web_traffic WHERE (traffic_date >= DATE_SUB(NOW(), INTERVAL ? DAY)) AND hostname IN ? GROUP BY hostname", $lastdays, $hostnames);
+ foreach ($tmp_recs as $tmp_rec) {
+ $traffic_data[$tmp_rec['hostname']]['lastdays'] = $tmp_rec['t'];
+ }
+ }
+ }
+
+ return $traffic_data;
+ }
+
public function get_mailquota_data($clientid = null, $readable = true) {
global $app;
@@ -160,4 +221,66 @@
return $emails;
}
+
+ public function get_databasequota_data($clientid = null, $readable = true) {
+ global $app;
+
+ $tmp_rec = $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'database_size' ORDER BY created DESC");
+ $monitor_data = array();
+ if(is_array($tmp_rec)) {
+ foreach ($tmp_rec as $tmp_mon) {
+ $tmp_array = unserialize($app->db->unquote($tmp_mon['data']));
+ if(is_array($tmp_array)) {
+ foreach($tmp_array as $key => $data) {
+ if(!isset($monitor_data[$data['database_name']]['size'])) $monitor_data[$data['database_name']]['size'] = $data['size'];
+ }
+ }
+ }
+ }
+ //print_r($monitor_data);
+
+ // select all databases belonging to client
+ $databases = $app->db->queryAllRecords("SELECT * FROM web_database".(($clientid != null)? " WHERE sys_groupid = (SELECT default_group FROM sys_user WHERE client_id=?)" : ''), $clientid);
+
+ //print_r($databases);
+ if(is_array($databases) && !empty($databases)){
+ for($i=0;$i<sizeof($databases);$i++){
+ $databasename = $databases[$i]['database_name'];
+
+ $databases[$i]['used'] = isset($monitor_data[$databasename]['size']) ? $monitor_data[$databasename]['size'] : 0;
+
+ $databases[$i]['quota_raw'] = $databases[$i]['database_quota'];
+ $databases[$i]['used_raw'] = $databases[$i]['used'];
+ $databases[$i]['used_percentage'] = (($databases[$i]['database_quota'] > 0) && ($databases[$i]['used'] > 0)) ? round($databases[$i]['used'] * 100 / $databases[$i]['database_quota']) : 0;
+
+ if ($readable) {
+ // colours
+ $databases[$i]['display_colour'] = '#000000';
+ if($databases[$i]['database_quota'] > 0){
+ $used_ratio = $databases[$i]['used']/$databases[$i]['database_quota'];
+ } else {
+ $used_ratio = 0;
+ }
+ if($used_ratio >= 0.8) $databases[$i]['display_colour'] = '#fd934f';
+ if($used_ratio >= 1) $databases[$i]['display_colour'] = '#cc0000';
+
+ if($databases[$i]['database_quota'] == 0){
+ $databases[$i]['database_quota'] = $app->lng('unlimited');
+ } else {
+ $databases[$i]['database_quota'] = round($databases[$i]['database_quota'] / 1048576, 4).' MB';
+ }
+
+
+ if($databases[$i]['used'] < 1544000) {
+ $databases[$i]['used'] = round($databases[$i]['used'] / 1024, 4).' KB';
+ } else {
+ $databases[$i]['used'] = round($databases[$i]['used'] / 1048576, 4).' MB';
+ }
+ }
+ }
+ }
+
+ return $databases;
+ }
+
}
\ No newline at end of file
--
Gitblit v1.9.1