From 3dc6299457c24e0081baae684f6992b5def630ef Mon Sep 17 00:00:00 2001
From: Marius Cramer <m.cramer@pixcept.de>
Date: Tue, 03 Feb 2015 02:22:55 -0500
Subject: [PATCH] Merge branch 'master' into 'master'
---
interface/lib/classes/remote.d/sites.inc.php | 15 +++++++
interface/web/client/lib/remote.conf.php | 2
interface/lib/classes/quota_lib.inc.php | 63 +++++++++++++++++++++++++++++++
3 files changed, 78 insertions(+), 2 deletions(-)
diff --git a/interface/lib/classes/quota_lib.inc.php b/interface/lib/classes/quota_lib.inc.php
index da3c7c6..794db53 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=".$clientid.")";
+ }
+ $sites = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE active = 'y' AND (type = 'vhost' OR type = 'vhostsubdomain' OR type = 'vhostalias')".$sql_where);
+
+ $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 ('".join("','",$hostnames)."') GROUP BY hostname", $tmp_year, $tmp_month);
+ 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 ('".join("','",$hostnames)."') GROUP BY hostname", $tmp_year);
+ 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 ('".join("','",$hostnames)."') GROUP BY hostname", $tmp_year, $tmp_month);
+ 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 ('".join("','",$hostnames)."') GROUP BY hostname", $tmp_year);
+ 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 ".$app->db->quote($lastdays)." DAY)) AND hostname IN ('".join("','",$hostnames)."') GROUP BY hostname");
+ 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;
diff --git a/interface/lib/classes/remote.d/sites.inc.php b/interface/lib/classes/remote.d/sites.inc.php
index 7db245a..05ba482 100644
--- a/interface/lib/classes/remote.d/sites.inc.php
+++ b/interface/lib/classes/remote.d/sites.inc.php
@@ -966,6 +966,21 @@
return $app->quota_lib->get_quota_data($client_id, false);
}
+ public function trafficquota_get_by_user($session_id, $client_id, $lastdays = 0)
+ {
+ global $app;
+ $app->uses('quota_lib');
+
+ if(!$this->checkPerm($session_id, 'trafficquota_get_by_user')) {
+ $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
+ return false;
+ }
+ if ($client_id != null)
+ $client_id = $app->functions->intval($client_id);
+
+ return $app->quota_lib->get_trafficquota_data($client_id, $lastdays);
+ }
+
public function databasequota_get_by_user($session_id, $client_id)
{
global $app;
diff --git a/interface/web/client/lib/remote.conf.php b/interface/web/client/lib/remote.conf.php
index c47206f..6ac8ae1 100644
--- a/interface/web/client/lib/remote.conf.php
+++ b/interface/web/client/lib/remote.conf.php
@@ -2,7 +2,7 @@
$function_list['client_get_all,client_get,client_add,client_update,client_delete,client_get_sites_by_user,client_get_by_username,client_change_password,client_get_id,client_delete_everything,client_get_emailcontact'] = 'Client functions';
$function_list['domains_domain_get,domains_domain_add,domains_domain_delete,domains_get_all_by_user'] = 'Domaintool functions';
-$function_list['quota_get_by_user,mailquota_get_by_user,databasequota_get_by_user'] = 'Quota functions';
+$function_list['quota_get_by_user,trafficquota_get_by_user,mailquota_get_by_user,databasequota_get_by_user'] = 'Quota functions';
?>
--
Gitblit v1.9.1