/** * @param $formData * @param string $entryPoint * @return bool */ function tryImportSubmit( $formData, $entryPoint = 'internal' ) { global $wgOpenStackManagerNovaKeypairStorage; if ( $wgOpenStackManagerNovaKeypairStorage == 'ldap' ) { $success = $this->userLDAP->importKeypair( $formData['key'] ); if ( ! $success ) { $this->getOutput()->addWikiMsg( 'openstackmanager-keypairimportfailed' ); return false; } $this->getOutput()->addWikiMsg( 'openstackmanager-keypairimported' ); } elseif ( $wgOpenStackManagerNovaKeypairStorage == 'nova' ) { # wgOpenStackManagerNovaKeypairStorage == 'nova' # OpenStack's EC2 API doesn't yet support importing keys, use # of this option isn't currently recommended $keypair = $this->userNova->importKeypair( $formData['keyname'], $formData['key'] ); $this->getOutput()->addWikiMsg( 'openstackmanager-keypairimportedfingerprint', $keypair->getKeyName(), $keypair->getKeyFingerprint() ); } else { $this->getOutput()->addWikiMsg( 'openstackmanager-invalidkeypair' ); } $out = '<br />'; $out .= Linker::link( $this->getTitle(), wfMsgHtml( 'openstackmanager-addadditionalkey' ) ); $this->getOutput()->addHTML( $out ); return true; }
/** * @param $formData * @param string $entryPoint * @return bool */ function tryImportSubmit($formData, $entryPoint = 'internal') { global $wgOpenStackManagerNovaKeypairStorage; $key = trim($formData['key']); # Because people copy paste it with an accidental newline $returnto = Title::newFromText($formData['returnto']); if (!preg_match('/(^| )ssh-(rsa|dss) /', $key)) { # This doesn't look like openssh format, it's probably a # Windows user providing it in PuTTY format. $key = self::opensshFormatKey($key); if ($key === false) { $this->getOutput()->addWikiMsg('openstackmanager-keypairformatwrong'); if ($returnto) { $this->getOutput()->addReturnTo($returnto); } return false; } $this->getOutput()->addWikiMsg('openstackmanager-keypairformatconverted'); } if ($wgOpenStackManagerNovaKeypairStorage === 'ldap') { $success = $this->userLDAP->importKeypair($key); if ($success) { $this->getOutput()->addWikiMsg('openstackmanager-keypairimported'); } else { $this->getOutput()->addWikiMsg('openstackmanager-keypairimportfailed'); if ($returnto) { $this->getOutput()->addReturnTo($returnto); } return false; } } elseif ($wgOpenStackManagerNovaKeypairStorage === 'nova') { $keypair = $this->userNova->importKeypair($formData['keyname'], $key); $this->getOutput()->addWikiMsg('openstackmanager-keypairimportedfingerprint', $keypair->getKeyName(), $keypair->getKeyFingerprint()); } else { $this->getOutput()->addWikiMsg('openstackmanager-invalidkeypair'); } if ($returnto) { $this->getOutput()->addReturnTo($returnto); } return true; }