WIP: AWS CS controller

This commit is contained in:
fbsanchez 2019-06-22 01:10:05 +02:00
parent 5658b98f0b
commit c11cd556ce
3 changed files with 103 additions and 36 deletions

View File

@ -1048,7 +1048,7 @@ class Wizard
*/
public static function printBigButtonsList($list_data)
{
echo '<ul>';
echo '<ul class="bigbuttonlist">';
array_map('self::printBigButtonElement', $list_data);
echo '</ul>';
}

View File

@ -72,41 +72,6 @@ function credentials_get_all(
throw new Exception('[credential_get_all] Fields must be an array or "count".');
}
if (isset($order)) {
$dir = 'asc';
if ($order == 'desc') {
$dir = 'desc';
};
if (in_array(
$sort_field,
[
'group',
'identifier',
'product',
'username',
'options',
]
)
) {
$order_by = sprintf(
'ORDER BY `%s` %s',
$sort_field,
$dir
);
}
}
if (isset($limit) && $limit > 0
&& isset($offset) && $offset >= 0
) {
$pagination = sprintf(
' LIMIT %d OFFSET %d ',
$limit,
$offset
);
}
if (isset($filter['free_search']) && !empty($filter['free_search'])) {
$sql_filters[] = vsprintf(
' AND (lower(cs.username) like lower("%%%s%%")
@ -146,6 +111,48 @@ function credentials_get_all(
}
}
if (isset($filter['group_list']) && is_array($filter['group_list'])) {
$sql_filters[] = sprintf(
' AND cs.id_group IN (%s) ',
join(',', $filter['group_list'])
);
}
if (isset($order)) {
$dir = 'asc';
if ($order == 'desc') {
$dir = 'desc';
};
if (in_array(
$sort_field,
[
'group',
'identifier',
'product',
'username',
'options',
]
)
) {
$order_by = sprintf(
'ORDER BY `%s` %s',
$sort_field,
$dir
);
}
}
if (isset($limit) && $limit > 0
&& isset($offset) && $offset >= 0
) {
$pagination = sprintf(
' LIMIT %d OFFSET %d ',
$limit,
$offset
);
}
$sql = sprintf(
'SELECT %s
FROM tcredential_store cs
@ -372,3 +379,59 @@ function print_inputs($values=null)
return $return;
}
/**
* Retrieve all identifiers available for current user.
*
* @param string $product Target product.
*
* @return array Of account identifiers.
*/
function credentials_list_accounts($product)
{
global $config;
check_login();
include_once $config['homedir'].'/include/functions_users.php';
static $user_groups;
if (!isset($user_groups)) {
$user_groups = users_get_groups(
$config['id_user'],
'AW'
);
// Always add group 'ALL' because 'ALL' group credentials
// must be available for all users.
if (is_array($user_groups)) {
$user_groups = ([0] + array_keys($user_groups));
} else {
$user_groups = [0];
}
}
$creds = credentials_get_all(
['identifier'],
[
'product' => $product,
'group_list' => $user_groups,
]
);
if ($creds === false) {
return [];
}
$ret = array_reduce(
$creds,
function ($carry, $item) {
$carry[$item['identifier']] = $item['identifier'];
return $carry;
}
);
return $ret;
}

View File

@ -2,6 +2,10 @@
* Discovery css global
*/
ul.bigbuttonlist {
min-height: 200px;
}
li.discovery {
display: inline-block;
float: left;