2017-12-13 17:38:22 +01:00
< ? php
2021-08-24 17:35:09 +02:00
/**
2017-12-13 17:38:22 +01:00
* Reset a password
*
* arg0 = email
* arg1 = new password
2021-08-24 17:35:09 +02:00
* @ deprecated Use UserShell instead
2017-12-13 17:38:22 +01:00
*/
class AuthkeyShell extends AppShell {
2020-02-10 15:15:59 +01:00
public $uses = array ( 'User' , 'Log' );
2017-12-13 17:38:22 +01:00
2020-02-10 15:15:59 +01:00
public function main ()
{
2024-01-12 11:57:02 +01:00
$this -> deprecated ( 'cake user change_authkey [user] [authkey]' );
2021-12-19 14:05:27 +01:00
2020-07-01 03:22:26 +02:00
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 ;
2020-02-10 15:15:59 +01:00
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' ));
if ( empty ( $user )) {
echo 'User not found. Make sure you use the correct syntax: /var/www/MISP/app/Console/cake Authkey [email]' . PHP_EOL ;
exit ;
}
$this -> User -> id = $user [ 'User' ][ 'id' ];
$newkey = $this -> User -> generateAuthKey ();
2020-07-01 03:22:26 +02:00
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 ;
}
}
2020-02-10 15:15:59 +01:00
if ( $this -> User -> saveField ( 'authkey' , $newkey )) {
2020-05-04 15:13:17 +02:00
$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 )));
2020-02-10 15:15:59 +01:00
echo $newkey . PHP_EOL ;
} else {
echo 'Could not update account for User.id = ' , $user [ 'User' ][ 'id' ], PHP_EOL ;
echo json_encode ( $this -> User -> validationErrors ) . PHP_EOL ;
$this -> out ( print_r ( $this -> User -> invalidFields (), true ));
}
}
exit ;
}
2017-12-13 17:38:22 +01:00
}