LEVEILLE Cédric
2016-01-18 cfc79e73e49fdb1f3cc3e80238011c8c1b9dd7dd
Ftp statistics feature
3 files modified
90 ■■■■■ changed files
install/sql/ispconfig3.sql 14 ●●●●● patch | view | raw | blame | history
interface/lib/classes/quota_lib.inc.php 61 ●●●●● patch | view | raw | blame | history
interface/lib/classes/remote.d/sites.inc.php 15 ●●●●● patch | view | raw | blame | history
install/sql/ispconfig3.sql
@@ -639,6 +639,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`
--
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;
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;