[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorAuthSSHKeyGenerateController 4 extends PhabricatorAuthSSHKeyController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $viewer = $this->getViewer(); 8 9 $key = $this->newKeyForObjectPHID($request->getStr('objectPHID')); 10 if (!$key) { 11 return new Aphront404Response(); 12 } 13 14 $cancel_uri = $key->getObject()->getSSHPublicKeyManagementURI($viewer); 15 16 $token = id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession( 17 $viewer, 18 $request, 19 $cancel_uri); 20 21 if ($request->isFormPost()) { 22 $default_name = $key->getObject()->getSSHKeyDefaultName(); 23 24 $keys = PhabricatorSSHKeyGenerator::generateKeypair(); 25 list($public_key, $private_key) = $keys; 26 27 $file = PhabricatorFile::buildFromFileDataOrHash( 28 $private_key, 29 array( 30 'name' => $default_name.'.key', 31 'ttl' => time() + (60 * 10), 32 'viewPolicy' => $viewer->getPHID(), 33 )); 34 35 $public_key = PhabricatorAuthSSHPublicKey::newFromRawKey($public_key); 36 37 $type = $public_key->getType(); 38 $body = $public_key->getBody(); 39 40 $key 41 ->setName($default_name) 42 ->setKeyType($type) 43 ->setKeyBody($body) 44 ->setKeyComment(pht('Generated')) 45 ->save(); 46 47 // NOTE: We're disabling workflow on submit so the download works. We're 48 // disabling workflow on cancel so the page reloads, showing the new 49 // key. 50 51 return $this->newDialog() 52 ->setTitle(pht('Download Private Key')) 53 ->setDisableWorkflowOnCancel(true) 54 ->setDisableWorkflowOnSubmit(true) 55 ->setSubmitURI($file->getDownloadURI()) 56 ->appendParagraph( 57 pht( 58 'A keypair has been generated, and the public key has been '. 59 'added as a recognized key. Use the button below to download '. 60 'the private key.')) 61 ->appendParagraph( 62 pht( 63 'After you download the private key, it will be destroyed. '. 64 'You will not be able to retrieve it if you lose your copy.')) 65 ->addSubmitButton(pht('Download Private Key')) 66 ->addCancelButton($cancel_uri, pht('Done')); 67 } 68 69 try { 70 PhabricatorSSHKeyGenerator::assertCanGenerateKeypair(); 71 72 return $this->newDialog() 73 ->setTitle(pht('Generate New Keypair')) 74 ->addHiddenInput('objectPHID', $key->getObject()->getPHID()) 75 ->appendParagraph( 76 pht( 77 'This workflow will generate a new SSH keypair, add the public '. 78 'key, and let you download the private key.')) 79 ->appendParagraph( 80 pht( 81 'Phabricator will not retain a copy of the private key.')) 82 ->addSubmitButton(pht('Generate New Keypair')) 83 ->addCancelButton($cancel_uri); 84 } catch (Exception $ex) { 85 return $this->newDialog() 86 ->setTitle(pht('Unable to Generate Keys')) 87 ->appendParagraph($ex->getMessage()) 88 ->addCancelButton($cancel_uri); 89 } 90 } 91 92 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |