Skip to content

Commit

Permalink
typecast parameter values for sizeReadable(), fixes #1103
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
  • Loading branch information
d00p committed Feb 28, 2023
1 parent fb57a8a commit bf7d22a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
26 changes: 12 additions & 14 deletions lib/Froxlor/Cron/Traffic/ReportsCron.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
use Exception;
use Froxlor\Cron\FroxlorCron;
use Froxlor\Database\Database;
use Froxlor\FileDir;
use Froxlor\Froxlor;
use Froxlor\FroxlorLogger;
use Froxlor\PhpHelper;
use Froxlor\Settings;
Expand Down Expand Up @@ -99,8 +97,8 @@ public static function run()
'COMPANY' => $rep_userinfo['company'],
'USERNAME' => $rep_userinfo['loginname'],
'CUSTOMER_NO' => $rep_userinfo['customernumber'],
'TRAFFIC' => PhpHelper::sizeReadable($row['traffic'], null, 'bi'),
'TRAFFICUSED' => PhpHelper::sizeReadable($row['traffic_used'], null, 'bi'),
'TRAFFIC' => PhpHelper::sizeReadable((int)$row['traffic'], null, 'bi'),
'TRAFFICUSED' => PhpHelper::sizeReadable((int)$row['traffic_used'], null, 'bi'),
'USAGE_PERCENT' => round(($row['traffic_used'] * 100) / $row['traffic'], 2),
'MAX_PERCENT' => Settings::Get('system.report_trafficmax')
];
Expand Down Expand Up @@ -182,8 +180,8 @@ public static function run()
if (isset($row['traffic']) && $row['traffic'] > 0 && (($row['traffic_used_total'] * 100) / ($row['traffic'])) >= (int)Settings::Get('system.report_trafficmax')) {
$replace_arr = [
'NAME' => $row['name'],
'TRAFFIC' => PhpHelper::sizeReadable($row['traffic'], null, 'bi'),
'TRAFFICUSED' => PhpHelper::sizeReadable($row['traffic_used_total'], null, 'bi'),
'TRAFFIC' => PhpHelper::sizeReadable((int)$row['traffic'], null, 'bi'),
'TRAFFICUSED' => PhpHelper::sizeReadable((int)$row['traffic_used_total'], null, 'bi'),
'USAGE_PERCENT' => round(($row['traffic_used_total'] * 100) / $row['traffic'], 2),
'MAX_PERCENT' => Settings::Get('system.report_trafficmax')
];
Expand Down Expand Up @@ -265,10 +263,10 @@ public static function run()

while ($customer = $customers_stmt->fetch(PDO::FETCH_ASSOC)) {
$customer['traffic'] *= 1024;
$t = $customer['traffic_used_total'] * 1024;
$t = (int) $customer['traffic_used_total'] * 1024;
if ($customer['traffic'] > 0) {
$p = (($t * 100) / $customer['traffic']);
$tg = $customer['traffic'];
$tg = (int) $customer['traffic'];
$str = sprintf('%s ( %00.1f %% )', PhpHelper::sizeReadable($t, null, 'bi'), $p);
$mail_body .= sprintf('%-15s', $customer['loginname']) . ' ' . sprintf('%-25s', $str) . ' ' . sprintf('%s', PhpHelper::sizeReadable($tg, null, 'bi')) . "\n";
} elseif ($customer['traffic'] == 0) {
Expand All @@ -282,10 +280,10 @@ public static function run()

$mail_body .= '---------------------------------------------------------------' . "\n";

$t = $row['traffic_used_total'];
$t = (int) $row['traffic_used_total'];
if ($row['traffic'] > 0) {
$p = (($t * 100) / $row['traffic']);
$tg = $row['traffic'];
$tg = (int) $row['traffic'];
$str = sprintf('%s ( %00.1f %% )', PhpHelper::sizeReadable($t, null, 'bi'), $p);
$mail_body .= sprintf('%-15s', $row['loginname']) . ' ' . sprintf('%-25s', $str) . ' ' . sprintf('%s', PhpHelper::sizeReadable($tg, null, 'bi')) . "\n";
} elseif ($row['traffic'] == 0) {
Expand Down Expand Up @@ -369,8 +367,8 @@ private static function usageDiskspace()
'COMPANY' => $rep_userinfo['company'],
'USERNAME' => $rep_userinfo['loginname'],
'CUSTOMER_NO' => $rep_userinfo['customernumber'],
'DISKAVAILABLE' => PhpHelper::sizeReadable($row['diskspace'], null, 'bi'),
'DISKUSED' => PhpHelper::sizeReadable($row['diskspace_used'], null, 'bi'),
'DISKAVAILABLE' => PhpHelper::sizeReadable((int)$row['diskspace'], null, 'bi'),
'DISKUSED' => PhpHelper::sizeReadable((int)$row['diskspace_used'], null, 'bi'),
'USAGE_PERCENT' => round(($row['diskspace_used'] * 100) / $row['diskspace'], 2),
'MAX_PERCENT' => Settings::Get('system.report_webmax')
];
Expand Down Expand Up @@ -443,8 +441,8 @@ private static function usageDiskspace()
if (isset($row['diskspace']) && $row['diskspace_used'] != null && $row['diskspace_used'] > 0 && (($row['diskspace_used'] * 100) / $row['diskspace']) >= (int)Settings::Get('system.report_webmax')) {
$replace_arr = [
'NAME' => $row['name'],
'DISKAVAILABLE' => PhpHelper::sizeReadable($row['diskspace'], null, 'bi'),
'DISKUSED' => PhpHelper::sizeReadable($row['diskspace_used'], null, 'bi'),
'DISKAVAILABLE' => PhpHelper::sizeReadable((int)$row['diskspace'], null, 'bi'),
'DISKUSED' => PhpHelper::sizeReadable((int)$row['diskspace_used'], null, 'bi'),
'USAGE_PERCENT' => ($row['diskspace_used'] * 100) / $row['diskspace'],
'MAX_PERCENT' => Settings::Get('system.report_webmax')
];
Expand Down
10 changes: 5 additions & 5 deletions lib/Froxlor/Cron/Traffic/TrafficCron.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static function run()
// Fork failed
return 1;
}
} else if (!defined('CRON_NOFORK_FLAG')) {
} elseif (!defined('CRON_NOFORK_FLAG')) {
if (extension_loaded('pcntl')) {
$msg = "PHP compiled with pcntl but pcntl_fork function is not available.";
} else {
Expand Down Expand Up @@ -406,7 +406,7 @@ public static function run()
} else {
// Use the old fashioned way with "du"
if (file_exists($row['documentroot']) && is_dir($row['documentroot'])) {
$back = FileDir::safe_exec('du -sk ' . escapeshellarg($row['documentroot']) . '');
$back = FileDir::safe_exec('du -sk ' . escapeshellarg($row['documentroot']));
foreach ($back as $backrow) {
$webspaceusage = explode(' ', $backrow);
}
Expand All @@ -426,7 +426,7 @@ public static function run()

$maildir = FileDir::makeCorrectDir(Settings::Get('system.vmail_homedir') . $row['loginname']);
if (file_exists($maildir) && is_dir($maildir)) {
$back = FileDir::safe_exec('du -sk ' . escapeshellarg($maildir) . '');
$back = FileDir::safe_exec('du -sk ' . escapeshellarg($maildir));
foreach ($back as $backrow) {
$emailusage = explode(' ', $backrow);
}
Expand Down Expand Up @@ -627,7 +627,7 @@ public static function run()
* @param string $caption Caption for webalizer output
* @param array $monthyear_arr
* @param int $current_stamp
*
*
* @return int Used traffic
*/
private static function callGoaccessGetTraffic($customerid, $logfile, $outputdir, $caption, array $monthyear_arr = [], int $current_stamp = 0)
Expand Down Expand Up @@ -705,7 +705,7 @@ private static function callGoaccessGetTraffic($customerid, $logfile, $outputdir
* @param string $outputdir Place where stats should be build
* @param string $caption Caption for webalizer output
* @param array $usersdomainlist
*
*
* @return float Used traffic
*/
private static function callWebalizerGetTraffic($logfile, $outputdir, $caption, array $usersdomainlist = [])
Expand Down

0 comments on commit bf7d22a

Please sign in to comment.