Froxlor/admin_traffic.php

144 lines
3.8 KiB
PHP
Raw Normal View History

<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
2022-04-28 18:48:00 +00:00
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
2022-04-28 18:48:00 +00:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
2022-04-28 18:48:00 +00:00
* You should have received a copy of the GNU General Public License
* along with this program; if not, you can also view it online at
* https://files.froxlor.org/misc/COPYING.txt
*
* @copyright the authors
* @author Froxlor team <team@froxlor.org>
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
*/
const AREA = 'admin';
require __DIR__ . '/lib/init.php';
use Froxlor\Database\Database;
2022-04-28 18:48:00 +00:00
use Froxlor\PhpHelper;
use Froxlor\Settings;
2022-03-18 11:53:34 +00:00
use Froxlor\UI\Panel\UI;
use Froxlor\UI\Request;
2022-04-28 18:48:00 +00:00
$id = (int)Request::get('id');
2022-04-28 18:48:00 +00:00
$months = [
'0' => 'empty',
'1' => 'jan',
'2' => 'feb',
'3' => 'mar',
'4' => 'apr',
'5' => 'may',
'6' => 'jun',
'7' => 'jul',
'8' => 'aug',
'9' => 'sep',
'10' => 'oct',
'11' => 'nov',
'12' => 'dec'
2022-04-28 18:48:00 +00:00
];
if ($page == 'overview' || $page == 'customers') {
$minyear_stmt = Database::query("SELECT `year` FROM `" . TABLE_PANEL_TRAFFIC . "` ORDER BY `year` ASC LIMIT 1");
$minyear = $minyear_stmt->fetch(PDO::FETCH_ASSOC);
2022-04-28 18:48:00 +00:00
if (!isset($minyear['year']) || $minyear['year'] == 0) {
$maxyears = 0;
} else {
$maxyears = date("Y") - $minyear['year'];
}
$params = [];
if ($userinfo['customers_see_all'] == '0') {
$params = [
'id' => $userinfo['adminid']
];
}
2022-03-18 11:53:34 +00:00
$customer_name_list_stmt = Database::prepare("
SELECT `customerid`,`company`,`name`,`firstname`
FROM `" . TABLE_PANEL_CUSTOMERS . "`
2022-03-18 11:53:34 +00:00
WHERE `deactivated`='0'" . ($userinfo['customers_see_all'] ? '' : ' AND `adminid` = :id') . "
2022-04-28 18:48:00 +00:00
ORDER BY name");
$traffic_list_stmt = Database::prepare("
SELECT month, SUM(http+ftp_up+ftp_down+mail)*1024 AS traffic
FROM `" . TABLE_PANEL_TRAFFIC . "`
WHERE year = :year AND `customerid` = :id
2022-04-28 18:48:00 +00:00
GROUP BY month ORDER BY month");
2022-03-18 11:53:34 +00:00
$stats = [];
2022-04-28 18:48:00 +00:00
for ($years = 0; $years <= $maxyears; $years++) {
$totals = [
'jan' => 0,
'feb' => 0,
'mar' => 0,
'apr' => 0,
'may' => 0,
'jun' => 0,
'jul' => 0,
'aug' => 0,
'sep' => 0,
'oct' => 0,
'nov' => 0,
'dec' => 0
2022-04-28 18:48:00 +00:00
];
Database::pexecute($customer_name_list_stmt, $params);
2022-03-18 11:53:34 +00:00
$data = [];
while ($customer_name = $customer_name_list_stmt->fetch(PDO::FETCH_ASSOC)) {
2022-04-28 18:48:00 +00:00
$virtual_host = [
'name' => ($customer_name['company'] == '' ? $customer_name['name'] . ", " . $customer_name['firstname'] : $customer_name['company']),
'customerid' => $customer_name['customerid'],
'jan' => '-',
'feb' => '-',
'mar' => '-',
'apr' => '-',
'may' => '-',
'jun' => '-',
'jul' => '-',
'aug' => '-',
'sep' => '-',
'oct' => '-',
'nov' => '-',
'dec' => '-'
2022-04-28 18:48:00 +00:00
];
2022-04-28 18:48:00 +00:00
Database::pexecute($traffic_list_stmt, [
'year' => (date("Y") - $years),
'id' => $customer_name['customerid']
2022-04-28 18:48:00 +00:00
]);
while ($traffic_month = $traffic_list_stmt->fetch(PDO::FETCH_ASSOC)) {
2022-04-28 18:48:00 +00:00
$virtual_host[$months[(int)$traffic_month['month']]] = PhpHelper::sizeReadable($traffic_month['traffic'], 'GiB', 'bi', '%01.' . (int)Settings::Get('panel.decimal_places') . 'f %s');
$totals[$months[(int)$traffic_month['month']]] += $traffic_month['traffic'];
}
2022-03-18 11:53:34 +00:00
$data = $virtual_host;
}
2022-03-18 11:53:34 +00:00
$stats[] = [
'year' => date("Y") - $years,
2022-04-28 18:48:00 +00:00
'type' => lng('traffic.customer'),
2022-03-18 11:53:34 +00:00
'data' => $data,
];
}
2022-03-18 11:53:34 +00:00
UI::view('user/traffic.html.twig', [
'stats' => $stats
]);
}