show traffic details in admin and customer listings with the info-icon

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-11-06 11:27:32 +01:00
parent 78945768ec
commit 1f70327112
2 changed files with 25 additions and 2 deletions

View File

@@ -25,6 +25,7 @@
namespace Froxlor\UI\Callbacks; namespace Froxlor\UI\Callbacks;
use Froxlor\Traffic\Traffic;
use Froxlor\PhpHelper; use Froxlor\PhpHelper;
use Froxlor\Settings; use Froxlor\Settings;
@@ -89,6 +90,28 @@ class ProgressBar
*/ */
public static function traffic(array $attributes): array public static function traffic(array $attributes): array
{ {
return self::pbData('traffic', $attributes['fields'], 1024, (int)Settings::Get('system.report_trafficmax')); $result = Traffic::getCustomerStats($attributes['fields'], 'currentmonth');
$infotext = null;
if (isset($result['metrics']['http'])) {
$infotext = lng('panel.used') . ':' . PHP_EOL;
$infotext .= 'http: ' . PhpHelper::sizeReadable($result['metrics']['http'], null, 'bi') . PHP_EOL;
$infotext .= 'ftp: ' . PhpHelper::sizeReadable($result['metrics']['ftp'], null, 'bi') . PHP_EOL;
$infotext .= 'mail: ' . PhpHelper::sizeReadable($result['metrics']['mail'], null, 'bi');
}
return self::pbData('traffic', $attributes['fields'], 1024, (int)Settings::Get('system.report_trafficmax'), $infotext);
}
/**
* get progressbar data for traffic for the admin overview
* (key is to set 'adminsession' for the admin-users so the traffic-API selects
* the correct customer data for the corresponsing admin/reseller)
*
* @param array $attributes ['fields']
* @return array
*/
public static function traffic_admins(array $attributes): array
{
$attributes['fields']['adminsession'] = 1;
return self::traffic($attributes);
} }
} }

View File

@@ -74,7 +74,7 @@ return [
'traffic' => [ 'traffic' => [
'label' => lng('customer.traffic'), 'label' => lng('customer.traffic'),
'field' => 'traffic', 'field' => 'traffic',
'callback' => [ProgressBar::class, 'traffic'], 'callback' => [ProgressBar::class, 'traffic_admins'],
], ],
'caneditphpsettings' => [ 'caneditphpsettings' => [
'label' => lng('admin.caneditphpsettings'), 'label' => lng('admin.caneditphpsettings'),