Commit cfc79e73 authored by Cédric's avatar Cédric

Ftp statistics feature

parent b6a0ab05
......@@ -638,6 +638,20 @@ CREATE TABLE `ftp_user` (
-- --------------------------------------------------------
--
-- 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`
--
......
......@@ -156,6 +156,67 @@ class quota_lib {
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;
......
......@@ -980,6 +980,21 @@ class remoting_sites extends remoting {
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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment