testing api-key listing
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -58,4 +58,38 @@ class Impersonate
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public static function apiAdminCustomerLink(array $attributes)
|
||||
{
|
||||
// my own key
|
||||
$isMyKey = false;
|
||||
if (
|
||||
$attributes['fields']['adminid'] == UI::getCurrentUser()['adminid']
|
||||
&& ((AREA == 'admin' && $attributes['fields']['customerid'] == 0)
|
||||
|| (AREA == 'customer' && $attributes['fields']['customerid'] == UI::getCurrentUser()['customerid'])
|
||||
)
|
||||
) {
|
||||
// this is mine
|
||||
$isMyKey = true;
|
||||
}
|
||||
|
||||
$adminCustomerLink = "";
|
||||
if (AREA == 'admin') {
|
||||
if ($isMyKey) {
|
||||
$adminCustomerLink = $attributes['fields']['adminname'];
|
||||
} else {
|
||||
if (empty($attributes['fields']['customerid'])) {
|
||||
$adminCustomerLink = self::admin($attributes);
|
||||
} else {
|
||||
$attributes['data'] = $attributes['fields']['loginname'];
|
||||
$adminCustomerLink = self::customer($attributes);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// customer do not need links
|
||||
$adminCustomerLink = $attributes['fields']['loginname'];
|
||||
}
|
||||
|
||||
return $adminCustomerLink;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,18 @@ class Style
|
||||
return $attributes['fields']['deactivated'] ? 'bg-danger' : '';
|
||||
}
|
||||
|
||||
public static function invalidApiKey(array $attributes): string
|
||||
{
|
||||
// check whether the api key is not valid anymore
|
||||
$isValid = true;
|
||||
if ($attributes['fields']['valid_until'] >= 0) {
|
||||
if ($attributes['fields']['valid_until'] < time()) {
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
return $isValid ? '' : 'bg-danger';
|
||||
}
|
||||
|
||||
public static function diskspaceWarning(array $attributes): string
|
||||
{
|
||||
return self::getWarningStyle('diskspace', $attributes['fields'], (int)Settings::Get('system.report_webmax'));
|
||||
|
||||
@@ -47,8 +47,18 @@ class Text
|
||||
return (int)$attributes['data'] > 0 ? date('d.m.Y H:i', (int)$attributes['data']) : UI::getLng('panel.never');
|
||||
}
|
||||
|
||||
public static function timestampUntil(array $attributes): string
|
||||
{
|
||||
return (int)$attributes['data'] > 0 ? date('d.m.Y H:i', (int)$attributes['data']) : UI::getLng('panel.unlimited');
|
||||
}
|
||||
|
||||
public static function crondesc(array $attributes): string
|
||||
{
|
||||
return UI::getLng('crondesc.' . $attributes['data']);
|
||||
}
|
||||
|
||||
public static function shorten(array $attributes): string
|
||||
{
|
||||
return substr($attributes['data'], 0, 20) . '...';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,20 @@ class Listing
|
||||
];
|
||||
}
|
||||
|
||||
public static function formatFromArray(array $collection, array $tabellisting): array
|
||||
{
|
||||
return [
|
||||
'title' => $tabellisting['title'],
|
||||
'icon' => $tabellisting['icon'],
|
||||
'table' => [
|
||||
'th' => self::generateTableHeadings($tabellisting),
|
||||
'tr' => self::generateTableRows($collection['data'], $tabellisting),
|
||||
],
|
||||
'pagination' => $collection['pagination'],
|
||||
'empty_msg' => $tabellisting['empty_msg'] ?? null
|
||||
];
|
||||
}
|
||||
|
||||
private static function generateTableHeadings(array $tabellisting): array
|
||||
{
|
||||
$heading = [];
|
||||
@@ -92,7 +106,7 @@ class Listing
|
||||
} elseif ($field) {
|
||||
$rows[$row]['td'][$col]['data'] = $data;
|
||||
} else {
|
||||
throw new Exception('The visible column "'. $visible_column .'" has neither a "callback" nor a "field" set.');
|
||||
throw new Exception('The visible column "' . $visible_column . '" has neither a "callback" nor a "field" set.');
|
||||
}
|
||||
|
||||
// Set class for table-row if defined
|
||||
|
||||
85
lib/tablelisting/tablelisting.apikeys.php
Normal file
85
lib/tablelisting/tablelisting.apikeys.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Tabellisting
|
||||
*
|
||||
*/
|
||||
|
||||
use Froxlor\UI\Callbacks\Impersonate;
|
||||
use Froxlor\UI\Callbacks\Style;
|
||||
use Froxlor\UI\Callbacks\Text;
|
||||
use Froxlor\UI\Listing;
|
||||
|
||||
return [
|
||||
'apikeys_list' => [
|
||||
'title' => $lng['menue']['main']['apikeys'],
|
||||
'icon' => 'fa-solid fa-key',
|
||||
'columns' => [
|
||||
'a.loginname' => [
|
||||
'label' => $lng['login']['username'],
|
||||
'field' => 'loginname',
|
||||
'callback' => [Impersonate::class, 'apiAdminCustomerLink']
|
||||
],
|
||||
'ak.apikey' => [
|
||||
'label' => 'API-key',
|
||||
'field' => 'apikey',
|
||||
'callback' => [Text::class, 'shorten'],
|
||||
],
|
||||
'ak.secret' => [
|
||||
'label' => 'Secret',
|
||||
'field' => 'secret',
|
||||
'callback' => [Text::class, 'shorten'],
|
||||
],
|
||||
'ak.allowed_from' => [
|
||||
'label' => $lng['apikeys']['allowed_from'],
|
||||
'field' => 'allowed_from',
|
||||
],
|
||||
'ak.valid_until' => [
|
||||
'label' => $lng['apikeys']['valid_until'],
|
||||
'field' => 'valid_until',
|
||||
'callback' => [Text::class, 'timestampUntil'],
|
||||
]
|
||||
],
|
||||
'visible_columns' => Listing::getVisibleColumnsForListing('apikeys_list', [
|
||||
'a.loginname',
|
||||
'ak.apikey',
|
||||
'ak.secret',
|
||||
'ak.allowed_from',
|
||||
'ak.valid_until'
|
||||
]),
|
||||
'actions' => [
|
||||
'show' => [
|
||||
'icon' => 'fa fa-eye',
|
||||
'title' => $lng['apikeys']['clicktoview'],
|
||||
'href' => [
|
||||
'page' => 'apikeys',
|
||||
'action' => '#',
|
||||
'id' => ':id'
|
||||
],
|
||||
],
|
||||
'delete' => [
|
||||
'icon' => 'fa fa-trash',
|
||||
'title' => $lng['panel']['delete'],
|
||||
'class' => 'text-danger',
|
||||
'href' => [
|
||||
'page' => 'apikeys',
|
||||
'action' => 'delete',
|
||||
'id' => ':id'
|
||||
],
|
||||
],
|
||||
],
|
||||
'callback' => [
|
||||
[Style::class, 'invalidApiKey']
|
||||
]
|
||||
]
|
||||
];
|
||||
Reference in New Issue
Block a user