Created
August 22, 2019 10:11
-
-
Save jsm222/edc0c89ae726a03ea0d72cf50c36c9a5 to your computer and use it in GitHub Desktop.
passbolt_cli read only users.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Shell/Task/RegisterUserTask.php b/src/Shell/Task/RegisterUserTask.php | |
index 074f06893b..a22e27db4d 100644 | |
--- a/src/Shell/Task/RegisterUserTask.php | |
+++ b/src/Shell/Task/RegisterUserTask.php | |
@@ -17,6 +17,7 @@ namespace App\Shell\Task; | |
use App\Controller\Events\EmailNotificationsListener; | |
use App\Error\Exception\ValidationException; | |
use App\Model\Entity\Role; | |
+use App\Model\Entity\Gpgkey; | |
use App\Shell\AppShell; | |
use App\Utility\UserAccessControl; | |
use App\Utility\UuidFactory; | |
@@ -25,6 +26,7 @@ use Cake\Event\EventManager; | |
use Cake\Http\Exception\InternalErrorException; | |
use Cake\ORM\TableRegistry; | |
use Cake\Routing\Router; | |
+use Cake\Core\Configure; | |
use Ramsey\Uuid\Uuid; | |
class RegisterUserTask extends AppShell | |
@@ -43,6 +45,7 @@ class RegisterUserTask extends AppShell | |
$this->loadModel('Users'); | |
$this->loadModel('Roles'); | |
$this->loadModel('AuthenticationTokens'); | |
+ $this->loadModel('Gpgkeys'); | |
} | |
/** | |
@@ -67,6 +70,11 @@ class RegisterUserTask extends AppShell | |
'default' => 3, | |
'help' => __('Enable interactive mode') | |
]) | |
+ ->addOption('pubkeyfile', [ | |
+ 'short' =>'p', | |
+ 'help' => __('The users public key file full path'), | |
+ 'optional' => true | |
+ ]) | |
->addOption('username', [ | |
'short' => 'u', | |
'help' => __('The user email aka username') | |
@@ -121,7 +129,29 @@ class RegisterUserTask extends AppShell | |
$attempt++; | |
$data = $this->_getUserData(); | |
try { | |
+ $pubkeyfile = $this->param('pubkeyfile'); | |
$user = $this->Users->register($data, $accessControl); | |
+ if (!empty($pubkeyfile) && file_exists($pubkeyfile)) { | |
+ $gpgKey = new Gpgkey([ | |
+ 'user_id' => $user->id, | |
+ 'armored_key' => file_get_contents($pubkeyfile)]); | |
+ $this->out(Configure::read('passbolt.gpg.keyring')); | |
+ putenv('GNUPGHOME=' . Configure::read('passbolt.gpg.keyring')); | |
+ $imported_key = gnupg_import(gnupg_init(),$gpgKey->armored_key); | |
+ if($imported_key) { | |
+ $gpgKey->fingerprint=$imported_key['fingerprint']; | |
+ $gpgKey->key_id=substr($imported_key['fingerprint'],-8); | |
+ $gpgKey->key_created=time(); | |
+ $gpgKey->created=time(); | |
+ $gpgKey->type='RSA'; | |
+ $this->Gpgkeys->save($gpgKey); | |
+ $user->active=1; | |
+ $this->Users->save($user); | |
+ } else { | |
+ $this->out(__('Failed importing key')); | |
+ } | |
+ | |
+ } | |
$result = true; | |
break; | |
} catch (ValidationException $exception) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment