update ui class and traffic stats

This commit is contained in:
envoyr
2022-03-18 12:53:34 +01:00
parent ba0d33392c
commit 69895943bd
41 changed files with 90927 additions and 16754 deletions

View File

@@ -16,6 +16,7 @@
* @package Panel
*
*/
const AREA = 'customer';
$intrafficpage = 1;
require __DIR__ . '/lib/init.php';
@@ -24,10 +25,11 @@ use Froxlor\Database\Database;
use Froxlor\Settings;
use Froxlor\UI\Panel\UI;
use Froxlor\UI\Request;
use Froxlor\UI\Response;
// redirect if this customer page is hidden via settings
if (Settings::IsInList('panel.customer_hide_options', 'traffic')) {
\Froxlor\UI\Response::redirectTo('customer_index.php');
Response::redirectTo('customer_index.php');
}
$traffic = '';
@@ -35,25 +37,22 @@ $month = null;
$year = null;
if (Request::exist('month') && Request::exist('year')) {
$month = (int) Request::get('month');
$year = (int) Request::get('year');
$month = (int)Request::get('month');
$year = (int)Request::get('year');
} elseif (isset($_GET['page']) && $_GET['page'] == 'current') {
if (date('d') != '01') {
$month = date('m');
$year = date('Y');
} elseif (date('m') == '01') {
$month = 12;
$year = date('Y') - 1;
} else {
if (date('m') == '01') {
$month = 12;
$year = date('Y') - 1;
} else {
$month = date('m') - 1;
$year = date('Y');
}
$month = date('m') - 1;
$year = date('Y');
}
}
if (! is_null($month) && ! is_null($year)) {
$traf['byte'] = 0;
if (!is_null($month) && !is_null($year)) {
$result_stmt = Database::prepare("SELECT SUM(`http`) as 'http', SUM(`ftp_up`) AS 'ftp_up', SUM(`ftp_down`) as 'ftp_down', SUM(`mail`) as 'mail', `day`, `month`, `year`
FROM `" . TABLE_PANEL_TRAFFIC . "`
WHERE `customerid`= :customerid
@@ -67,44 +66,39 @@ if (! is_null($month) && ! is_null($year)) {
"year" => $year
);
Database::pexecute($result_stmt, $params);
$traf['byte'] = 0;
$traffic_complete['http'] = 0;
$traffic_complete['ftp'] = 0;
$traffic_complete['mail'] = 0;
$show = '';
$traf['days'] = [];
$traf['http_data'] = [];
$traf['ftp_data'] = [];
$traf['mail_data'] = [];
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
$http = $row['http'];
$traf['http_data'][] = (float)$http;
$ftp = $row['ftp_up'] + $row['ftp_down'];
$traf['ftp_data'][] = (float)$ftp;
$mail = $row['mail'];
$traf['mail_data'][] = (float)$mail;
$traf['byte'] = $http + $ftp + $mail;
$traffic_complete['http'] += $http;
$traffic_complete['ftp'] += $ftp;
$traffic_complete['mail'] += $mail;
$traf['day'] = $row['day'] . '.';
if (extension_loaded('bcmath')) {
$traf['ftptext'] = bcdiv($row['ftp_up'], 1024, Settings::Get('panel.decimal_places')) . " MiB up/ " . bcdiv($row['ftp_down'], 1024, Settings::Get('panel.decimal_places')) . " MiB down (FTP)";
$traf['ftp'] = bcdiv($ftp, 1024, Settings::Get('panel.decimal_places'));
} else {
$traf['ftptext'] = round($row['ftp_up'] / 1024, Settings::Get('panel.decimal_places')) . " MiB up/ " . round($row['ftp_down'] / 1024, Settings::Get('panel.decimal_places')) . " MiB down (FTP)";
$traf['ftp'] = round($ftp / 1024, Settings::Get('panel.decimal_places'));
}
getReadableTraffic($traf,'httptext', $http, 1024, "MiB (HTTP)");
getReadableTraffic($traf,'http', $http, 1024);
getReadableTraffic($traf,'mailtext', $mail, 1024, "MiB (Mail)");
getReadableTraffic($traf,'mail', $mail, 1024);
getReadableTraffic($traf,'byte', $traf['byte'], (1024 * 1024));
eval("\$traffic.=\"" . \Froxlor\UI\Template::getTemplate('traffic/traffic_month') . "\";");
$show = $lng['traffic']['months'][intval($row['month'])] . ' ' . $row['year'];
$traf['days'][] = $row['day'];
}
$traffic_complete['http'] = \Froxlor\PhpHelper::sizeReadable($traffic_complete['http'] * 1024, 'GiB', 'bi', '%01.' . (int) Settings::Get('panel.decimal_places') . 'f %s');
$traffic_complete['ftp'] = \Froxlor\PhpHelper::sizeReadable($traffic_complete['ftp'] * 1024, 'GiB', 'bi', '%01.' . (int) Settings::Get('panel.decimal_places') . 'f %s');
$traffic_complete['mail'] = \Froxlor\PhpHelper::sizeReadable($traffic_complete['mail'] * 1024, 'GiB', 'bi', '%01.' . (int) Settings::Get('panel.decimal_places') . 'f %s');
eval("echo \"" . \Froxlor\UI\Template::getTemplate('traffic/traffic_details') . "\";");
UI::view('user/traffic.html.twig', [
'traffic_complete_http' => $traffic_complete['http'],
'traffic_complete_ftp' => $traffic_complete['ftp'],
'traffic_complete_mail' => $traffic_complete['mail'],
'traffic_complete_total' => $traf['byte'],
'labels' => $traf['days'],
'http_data' => $traf['http_data'],
'ftp_data' => $traf['ftp_data'],
'mail_data' => $traf['mail_data'],
]);
} else {
$result_stmt = Database::prepare("
SELECT `month`, `year`, SUM(`http`) AS http, SUM(`ftp_up`) AS ftp_up, SUM(`ftp_down`) AS ftp_down, SUM(`mail`) AS mail
@@ -120,12 +114,19 @@ if (! is_null($month) && ! is_null($year)) {
$traffic_complete['http'] = 0;
$traffic_complete['ftp'] = 0;
$traffic_complete['mail'] = 0;
$traf['days'] = [];
$traf['http_data'] = [];
$traf['ftp_data'] = [];
$traf['mail_data'] = [];
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
$http = $row['http'];
$traf['http_data'][] = (int)$http / 1024 / 1024;
$ftp_up = $row['ftp_up'];
$ftp_down = $row['ftp_down'];
$traf['ftp_data'][] = (int)($ftp_up + $ftp_down) / 1024 / 1024;
$mail = $row['mail'];
$traf['mail_data'][] = (int)$mail / 1024 / 1024;
$traffic_complete['http'] += $http;
$traffic_complete['ftp'] += $ftp_up + $ftp_down;
$traffic_complete['mail'] += $mail;
@@ -133,36 +134,27 @@ if (! is_null($month) && ! is_null($year)) {
$traf['year'] = $row['year'];
$traf['monthname'] = $lng['traffic']['months'][intval($row['month'])] . " " . $row['year'];
$traf['byte'] = $http + $ftp_up + $ftp_down + $mail;
if (extension_loaded('bcmath')) {
$traf['ftptext'] = bcdiv($ftp_up, 1024, Settings::Get('panel.decimal_places')) . " MiB up/ " . bcdiv($ftp_down, 1024, Settings::Get('panel.decimal_places')) . " MiB down (FTP)";
$traf['ftp'] = bcdiv(($ftp_up + $ftp_down), 1024, Settings::Get('panel.decimal_places'));
} else {
$traf['ftptext'] = round($ftp_up / 1024, Settings::Get('panel.decimal_places')) . " MiB up/ " . round($ftp_down / 1024, Settings::Get('panel.decimal_places')) . " MiB down (FTP)";
$traf['ftp'] = round(($ftp_up + $ftp_down) / 1024, Settings::Get('panel.decimal_places'));
}
getReadableTraffic($traf,'httptext', $http, 1024, "MiB (HTTP)");
getReadableTraffic($traf,'http', $http, 1024);
getReadableTraffic($traf,'mailtext', $mail, 1024, "MiB (Mail)");
getReadableTraffic($traf,'mail', $mail, 1024);
getReadableTraffic($traf,'byte', $traf['byte'], (1024 * 1024));
eval("\$traffic.=\"" . \Froxlor\UI\Template::getTemplate('traffic/traffic_traffic') . "\";");
$traf['byte_total'] = $traf['byte_total'] + $http + $ftp_up + $ftp_down + $mail;
$traf['days'][] = $traf['monthname'];
}
$traffic_complete['http'] = \Froxlor\PhpHelper::sizeReadable($traffic_complete['http'] * 1024, 'GiB', 'bi', '%01.' . (int) Settings::Get('panel.decimal_places') . 'f %s');
$traffic_complete['ftp'] = \Froxlor\PhpHelper::sizeReadable($traffic_complete['ftp'] * 1024, 'GiB', 'bi', '%01.' . (int) Settings::Get('panel.decimal_places') . 'f %s');
$traffic_complete['mail'] = \Froxlor\PhpHelper::sizeReadable($traffic_complete['mail'] * 1024, 'GiB', 'bi', '%01.' . (int) Settings::Get('panel.decimal_places') . 'f %s');
eval("echo \"" . \Froxlor\UI\Template::getTemplate('traffic/traffic') . "\";");
UI::view('user/traffic.html.twig', [
'traffic_complete_http' => $traffic_complete['http'],
'traffic_complete_ftp' => $traffic_complete['ftp'],
'traffic_complete_mail' => $traffic_complete['mail'],
'traffic_complete_total' => $traf['byte_total'],
'labels' => $traf['days'],
'http_data' => $traf['http_data'],
'ftp_data' => $traf['ftp_data'],
'mail_data' => $traf['mail_data'],
]);
}
function getReadableTraffic(&$traf, $index, $value, $divisor, $desc = "")
{
if (extension_loaded('bcmath')) {
$traf[$index] = bcdiv($value, $divisor,Settings::Get('panel.decimal_places')).(!empty($desc) ? " ".$desc : "");
$traf[$index] = bcdiv($value, $divisor, Settings::Get('panel.decimal_places')) . (!empty($desc) ? " " . $desc : "");
} else {
$traf[$index] = round($value / $divisor, Settings::Get('panel.decimal_places')).(!empty($desc) ? " ".$desc : "");
$traf[$index] = round($value / $divisor, Settings::Get('panel.decimal_places')) . (!empty($desc) ? " " . $desc : "");
}
}