mirror of https://github.com/MISP/MISP
new: [UI] Show last key usage in index table
parent
790087ca60
commit
2b30bab9b0
|
@ -26,17 +26,21 @@ class AuthKeysController extends AppController
|
|||
$this->set('user_id', $id);
|
||||
$conditions['AND'][] = ['AuthKey.user_id' => $id];
|
||||
}
|
||||
$keyUsageEnabled = Configure::read('MISP.log_user_ips') && Configure::read('MISP.log_user_ips_authkeys');
|
||||
$this->CRUD->index([
|
||||
'filters' => ['User.username', 'authkey', 'comment', 'User.id'],
|
||||
'quickFilters' => ['authkey', 'comment'],
|
||||
'contain' => ['User.id', 'User.email'],
|
||||
'conditions' => $conditions,
|
||||
'afterFind' => function (array $authKeys) {
|
||||
$keyUsageEnabled = Configure::read('MISP.log_user_ips') && Configure::read('MISP.log_user_ips_authkeys');
|
||||
'afterFind' => function (array $authKeys) use ($keyUsageEnabled) {
|
||||
if ($keyUsageEnabled) {
|
||||
$keyIds = Hash::extract($authKeys, "{n}.AuthKey.id");
|
||||
$lastUsedById = $this->AuthKey->getLastUsageForKeys($keyIds);
|
||||
}
|
||||
foreach ($authKeys as &$authKey) {
|
||||
if ($keyUsageEnabled) {
|
||||
$lastUsed = $this->AuthKey->getKeyUsage($authKey['AuthKey']['id'])[1];
|
||||
$key['AuthKey']['last_used'] = $lastUsed ? $lastUsed->format('c') : null;
|
||||
$lastUsed = $lastUsedById[$authKey['AuthKey']['id']];
|
||||
$authKey['AuthKey']['last_used'] = $lastUsed;
|
||||
}
|
||||
unset($authKey['AuthKey']['authkey']);
|
||||
}
|
||||
|
@ -46,6 +50,7 @@ class AuthKeysController extends AppController
|
|||
if ($this->IndexFilter->isRest()) {
|
||||
return $this->restResponsePayload;
|
||||
}
|
||||
$this->set('keyUsageEnabled', $keyUsageEnabled);
|
||||
$this->set('metaGroup', $this->_isAdmin ? 'admin' : 'globalActions');
|
||||
$this->set('metaAction', 'authkeys_index');
|
||||
}
|
||||
|
|
|
@ -154,6 +154,25 @@ class AuthKey extends AppModel
|
|||
return [$output, $lastUsage];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
* @return array<DateTime|null>
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getLastUsageForKeys(array $ids)
|
||||
{
|
||||
$redis = $this->setupRedisWithException();
|
||||
$keys = array_map(function($id) {
|
||||
return "misp:authkey_last_usage:$id";
|
||||
}, $ids);
|
||||
$lastUsages = $redis->mget($keys);
|
||||
$output = [];
|
||||
foreach (array_values($ids) as $i => $id) {
|
||||
$output[$id] = $lastUsages[$i] === false ? null : (int)$lastUsages[$i];
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* When key is deleted, update after `date_modified` for user that was assigned to that key, so session data
|
||||
* will be realoaded and canceled.
|
||||
|
|
|
@ -56,6 +56,12 @@
|
|||
'data_path' => 'AuthKey.expiration',
|
||||
'element' => 'expiration'
|
||||
],
|
||||
[
|
||||
'name' => ('Last used'),
|
||||
'data_path' => 'AuthKey.last_used',
|
||||
'element' => 'datetime',
|
||||
'requirements' => $keyUsageEnabled,
|
||||
],
|
||||
[
|
||||
'name' => __('Comment'),
|
||||
'sort' => 'AuthKey.comment',
|
||||
|
|
Loading…
Reference in New Issue