mirror of https://github.com/MISP/MISP
chg: [user:updateToAdvancedAuthKeys] Functionality accessible via the CLI
parent
4e1a6c5221
commit
e7fd73e50e
|
@ -716,4 +716,12 @@ class AdminShell extends AppShell
|
|||
$this->out('Dropping default galaxy clusters. This process might take some time...');
|
||||
$this->GalaxyCluster->wipe_default();
|
||||
}
|
||||
|
||||
public function updateToAdvancedAuthKeys()
|
||||
{
|
||||
$this->loadModel('User');
|
||||
$updated = $this->User->updateToAdvancedAuthKeys();
|
||||
$message = __('The upgrade process is complete, %s authkey(s) generated.', $updated);
|
||||
$this->out($message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2730,30 +2730,7 @@ class UsersController extends AppController
|
|||
if (!$this->request->is('post')) {
|
||||
throw new MethodNotAllowedException(__('This endpoint can only be triggered via POST requests.'));
|
||||
}
|
||||
$users = $this->User->find('all', [
|
||||
'recursive' => -1,
|
||||
'contain' => ['AuthKey'],
|
||||
'fields' => ['id', 'authkey']
|
||||
]);
|
||||
$updated = 0;
|
||||
foreach ($users as $user) {
|
||||
if (!empty($user['AuthKey'])) {
|
||||
$currentKeyStart = substr($user['User']['authkey'], 0, 4);
|
||||
$currentKeyEnd = substr($user['User']['authkey'], -4);
|
||||
foreach ($user['AuthKey'] as $authkey) {
|
||||
if ($authkey['authkey_start'] === $currentKeyStart && $authkey['authkey_end'] === $currentKeyEnd) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->User->AuthKey->create();
|
||||
$this->User->AuthKey->save([
|
||||
'authkey' => $user['User']['authkey'],
|
||||
'expiration' => 0,
|
||||
'user_id' => $user['User']['id']
|
||||
]);
|
||||
$updated += 1;
|
||||
}
|
||||
$updated = $this->User->updateToAdvancedAuthKeys();
|
||||
$message = __('The upgrade process is complete, %s authkey(s) generated.', $updated);
|
||||
if ($this->_isRest()) {
|
||||
return $this->RestResponse->saveSuccessResponse('User', 'acceptRegistrations', false, $this->response->type(), $message);
|
||||
|
|
|
@ -1398,4 +1398,33 @@ class User extends AppModel
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function updateToAdvancedAuthKeys()
|
||||
{
|
||||
$users = $this->find('all', [
|
||||
'recursive' => -1,
|
||||
'contain' => ['AuthKey'],
|
||||
'fields' => ['id', 'authkey']
|
||||
]);
|
||||
$updated = 0;
|
||||
foreach ($users as $user) {
|
||||
if (!empty($user['AuthKey'])) {
|
||||
$currentKeyStart = substr($user['User']['authkey'], 0, 4);
|
||||
$currentKeyEnd = substr($user['User']['authkey'], -4);
|
||||
foreach ($user['AuthKey'] as $authkey) {
|
||||
if ($authkey['authkey_start'] === $currentKeyStart && $authkey['authkey_end'] === $currentKeyEnd) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->AuthKey->create();
|
||||
$this->AuthKey->save([
|
||||
'authkey' => $user['User']['authkey'],
|
||||
'expiration' => 0,
|
||||
'user_id' => $user['User']['id']
|
||||
]);
|
||||
$updated += 1;
|
||||
}
|
||||
return $updated;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue