From cfc79e73e49fdb1f3cc3e80238011c8c1b9dd7dd Mon Sep 17 00:00:00 2001
From: LEVEILLE Cédric <leveille.cedric@oricom.org>
Date: Mon, 18 Jan 2016 13:49:38 -0500
Subject: [PATCH] Ftp statistics feature
---
interface/lib/classes/remote.d/sites.inc.php | 15 +++++++
install/sql/ispconfig3.sql | 14 +++++++
interface/lib/classes/quota_lib.inc.php | 61 ++++++++++++++++++++++++++++++
3 files changed, 90 insertions(+), 0 deletions(-)
diff --git a/install/sql/ispconfig3.sql b/install/sql/ispconfig3.sql
index 672f94b..5053b9b 100644
--- a/install/sql/ispconfig3.sql
+++ b/install/sql/ispconfig3.sql
@@ -638,6 +638,20 @@
-- --------------------------------------------------------
+--
+-- Table structure for table `ftp_traffic`
+--
+
+CREATE TABLE `ftp_traffic` (
+ `hostname` varchar(255) NOT NULL,
+ `traffic_date` date NOT NULL,
+ `in_bytes` bigint(32) unsigned NOT NULL,
+ `out_bytes` bigint(32) unsigned NOT NULL,
+ PRIMARY KEY (`hostname`,`traffic_date`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
+
+-- --------------------------------------------------------
+
--
-- Table structure for table `help_faq`
--
diff --git a/interface/lib/classes/quota_lib.inc.php b/interface/lib/classes/quota_lib.inc.php
index 8c91139..0455dc9 100644
--- a/interface/lib/classes/quota_lib.inc.php
+++ b/interface/lib/classes/quota_lib.inc.php
@@ -156,6 +156,67 @@
return $traffic_data;
}
+
+ public function get_ftptrafficquota_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(in_bytes) AS ftp_in, SUM(out_bytes) AS ftp_out FROM ftp_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(in_bytes) AS ftp_in, SUM(out_bytes) AS ftp_out FROM ftp_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(in_bytes) AS ftp_in, SUM(out_bytes) AS ftp_out FROM ftp_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(in_bytes) AS ftp_in, SUM(out_bytes) AS ftp_out FROM ftp_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(in_bytes) AS ftp_in, SUM(out_bytes) AS ftp_out FROM ftp_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;
diff --git a/interface/lib/classes/remote.d/sites.inc.php b/interface/lib/classes/remote.d/sites.inc.php
index 8770522..e52e91d 100644
--- a/interface/lib/classes/remote.d/sites.inc.php
+++ b/interface/lib/classes/remote.d/sites.inc.php
@@ -980,6 +980,21 @@
return $app->quota_lib->get_trafficquota_data($client_id, $lastdays);
}
+ public function ftptrafficquota_data($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_ftptrafficquota_data($client_id, $lastdays);
+ }
+
public function databasequota_get_by_user($session_id, $client_id)
{
global $app;
--
Gitblit v1.9.1