From 673edb1e4404bbdab44ccfb69c866a1317fcb7a5 Mon Sep 17 00:00:00 2001 From: Alex Resnick Date: Tue, 30 Jun 2020 20:22:26 -0500 Subject: [PATCH] Allow you to mannually set the API key for automation purposes --- app/Console/Command/AuthkeyShell.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Console/Command/AuthkeyShell.php b/app/Console/Command/AuthkeyShell.php index 1bc07a674..0d74a20e6 100644 --- a/app/Console/Command/AuthkeyShell.php +++ b/app/Console/Command/AuthkeyShell.php @@ -14,7 +14,7 @@ class AuthkeyShell extends AppShell { public function main() { $this->ConfigLoad->execute(); - if (!isset($this->args[0]) || empty($this->args[0])) echo 'MISP authkey reset command line tool.' . PHP_EOL . 'To assign a new authkey for a user:' . PHP_EOL . APP . 'Console/cake Authkey [email]' . PHP_EOL; + if (!isset($this->args[0]) || empty($this->args[0])) echo 'MISP authkey reset command line tool.' . PHP_EOL . 'To assign a new authkey for a user:' . PHP_EOL . APP . 'Console/cake Authkey [email] [auth_key | optional]' . PHP_EOL; else { // get the users that need their password hashed $user = $this->User->find('first', array('conditions' => array('email' => $this->args[0]), 'recursive' => -1, 'contain' => 'Organisation')); @@ -24,6 +24,14 @@ class AuthkeyShell extends AppShell { } $this->User->id = $user['User']['id']; $newkey = $this->User->generateAuthKey(); + if (isset($this->args[1]) && !empty($this->args[1])) { + $newkey = $this->args[1]; + if(!ctype_alnum($this->args[1]) || strlen($this->args[1]) != 40) { + echo 'MISP authkey reset command line tool.' . PHP_EOL . 'To assign a new authkey for a user:' . PHP_EOL . APP . 'Console/cake Authkey [email] [api_key | optional]' . PHP_EOL; + echo 'Authkey must be a 40 character Alphanumeric string.' . PHP_EOL; + exit; + } + } if ($this->User->saveField('authkey', $newkey)) { $logTitle = 'Authentication key for user ' . $user['User']['id'] . ' (' . $user['User']['email'] . ')'; $this->Log->createLogEntry('SYSTEM', 'reset_auth_key', 'User', $user['User']['id'], $logTitle, array('authkey' => array($user['User']['authkey'], $newkey)));