r78353 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78352‎ | r78353 | r78354 >
Date:02:09, 14 December 2010
Author:laner
Status:deferred
Tags:
Comment:
Fix key deletion
Modified paths:
  • /trunk/extensions/OpenStackManager/OpenStackNovaUser.php (modified) (history)
  • /trunk/extensions/OpenStackManager/SpecialNovaKey.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenStackManager/OpenStackNovaUser.php
@@ -6,10 +6,13 @@
77 var $userInfo;
88
99 function __construct() {
 10+ $this->connect();
 11+ $this->fetchUserInfo();
 12+ }
 13+
 14+ function fetchUserInfo() {
1015 global $wgAuth, $wgUser;
11 - global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
1216
13 - $this->connect();
1417 $this->userDN = $wgAuth->getUserDN( strtolower( $wgUser->getName() ) );
1518 $this->userInfo = $wgAuth->userInfo;
1619 }
@@ -30,21 +33,20 @@
3134 }
3235
3336 function getKeypairs() {
34 - if ( isset( $this->userInfo[0]['sshpublickey'] ) ) {
 37+ global $wgAuth;
 38+
 39+ $this->fetchUserInfo();
 40+ if ( $this->userInfo[0]['sshpublickey'] ) {
3541 $keys = $this->userInfo[0]['sshpublickey'];
3642 $keypairs = array();
37 - if ( is_array( $keys ) ) {
38 - array_shift( $keys );
39 - foreach ( $keys as $key ) {
40 - $hash = md5( $key );
41 - $keypairs["$hash"] = $key;
42 - }
43 - } else {
44 - $hash = md5( $keys );
45 - $keypairs["$hash"] = $keys;
 43+ array_shift( $keys );
 44+ foreach ( $keys as $key ) {
 45+ $hash = md5( $key );
 46+ $keypairs["$hash"] = $key;
4647 }
4748 return $keypairs;
4849 } else {
 50+ $wgAuth->printDebug( "No keypairs found", NONSENSITIVE );
4951 return array();
5052 }
5153 }
@@ -140,8 +142,6 @@
141143 function importKeypair( $key ) {
142144 global $wgAuth;
143145
144 - $this->connect();
145 -
146146 $keypairs = array();
147147 if ( isset( $this->userInfo[0]['sshpublickey'] ) ) {
148148 $keypairs = $this->userInfo[0]['sshpublickey'];
@@ -172,10 +172,9 @@
173173 } else {
174174 unset( $keypairs[$index] );
175175 }
176 - if ( sizeof( $keypairs ) == 1 ) {
177 - $values['sshpublickey'] = $keypairs[0];
178 - } else {
179 - $values['sshpublickey'] = $keypairs;
 176+ $values['sshpublickey'] = array();
 177+ foreach ( $keypairs as $keypair ) {
 178+ $values['sshpublickey'][] = $keypair;
180179 }
181180 $success = @ldap_modify( $wgAuth->ldapconn, $this->userDN, $values );
182181 if ( $success ) {
@@ -183,8 +182,6 @@
184183 return true;
185184 } else {
186185 $wgAuth->printDebug( "Failed to delete the user's sshpublickey", NONSENSITIVE );
187 - $wgAuth->printDebug( "KEY: $key", NONSENSITIVE );
188 - $wgAuth->printDebug( "sshpublickey: ", NONSENSITIVE, $values['sshpublickey'] );
189186 return false;
190187 }
191188 } else {
Index: trunk/extensions/OpenStackManager/SpecialNovaKey.php
@@ -103,12 +103,24 @@
104104
105105 $this->setHeaders();
106106 $wgOut->setPagetitle("Delete key");
 107+
 108+ $keyInfo = Array();
 109+
107110 if ( $wgOpenStackManagerNovaKeypairStorage == 'nova' ) {
 111+ $keyname = $wgRequest->getVal('keyname');
108112 $project = $wgRequest->getVal('project');
109113 if ( $project && ! $this->userLDAP->inProject( $project ) ) {
110114 $this->notInProject();
111115 return true;
112116 }
 117+ $keyInfo['keyname'] = array(
 118+ 'type' => 'hidden',
 119+ 'default' => $project,
 120+ );
 121+ $keyInfo['project'] = array(
 122+ 'type' => 'hidden',
 123+ 'default' => $keyname,
 124+ );
113125 } else if ( $wgOpenStackManagerNovaKeypairStorage == 'ldap' ) {
114126 $hash = $wgRequest->getVal( 'hash' );
115127 $keypairs = $this->userLDAP->getKeypairs();
@@ -117,28 +129,25 @@
118130 $out .= Html::element( 'p', array(), 'Are you sure you wish to delete the above key?' );
119131 $wgOut->addHTML( $out );
120132 }
121 -
122 - $keyInfo = Array();
123 -
124133 $keyInfo['hash'] = array(
125134 'type' => 'hidden',
126135 'default' => $hash,
127136 );
128 - $keyInfo['key'] = array(
129 - 'type' => 'hidden',
130 - 'default' => $keypairs[$hash],
131 - );
132 - $keyInfo['action'] = array(
133 - 'type' => 'hidden',
134 - 'default' => 'delete',
135 - );
136 - $keyForm = new SpecialNovaKeyForm( $keyInfo, 'novakey-form' );
137 - $keyForm->setTitle( SpecialPage::getTitleFor( 'NovaKey' ));
138 - $keyForm->setSubmitID( 'novakey-form-deletekeysubmit' );
139 - $keyForm->setSubmitCallback( array( $this, 'tryDeleteSubmit' ) );
140 - $keyForm->setSubmitText( 'confirm' );
141 - $keyForm->show();
142137 }
 138+ $keyInfo['key'] = array(
 139+ 'type' => 'hidden',
 140+ 'default' => $keypairs[$hash],
 141+ );
 142+ $keyInfo['action'] = array(
 143+ 'type' => 'hidden',
 144+ 'default' => 'delete',
 145+ );
 146+ $keyForm = new SpecialNovaKeyForm( $keyInfo, 'novakey-form' );
 147+ $keyForm->setTitle( SpecialPage::getTitleFor( 'NovaKey' ));
 148+ $keyForm->setSubmitID( 'novakey-form-deletekeysubmit' );
 149+ $keyForm->setSubmitCallback( array( $this, 'tryDeleteSubmit' ) );
 150+ $keyForm->setSubmitText( 'confirm' );
 151+ $keyForm->show();
143152 return true;
144153 }
145154
@@ -150,7 +159,9 @@
151160 $wgOut->setPagetitle("Key list");
152161
153162 $out = '';
 163+ $sk = $wgUser->getSkin();
154164 if ( $wgOpenStackManagerNovaKeypairStorage == 'nova' ) {
 165+ $out .= $sk->link( $this->getTitle(), 'Import a new key', array(), array( 'action' => 'import' ), array() );
155166 $projects = $this->userLDAP->getProjects();
156167 foreach( $projects as $project ) {
157168 $userCredentials = $this->userLDAP->getCredentials( $project );
@@ -170,11 +181,11 @@
171182 $out .= Html::rawElement( 'table', array( 'id' => 'novakeylist', 'class' => 'wikitable' ), $projectOut );
172183 }
173184 } else if ( $wgOpenStackManagerNovaKeypairStorage == 'ldap' ) {
 185+ $out .= $sk->link( $this->getTitle(), 'Import a new key', array(), array( 'action' => 'import' ), array() );
174186 $keypairs = $this->userLDAP->getKeypairs();
175187 $keysOut = '';
176188 foreach ( $keypairs as $hash => $key ) {
177189 $keyOut = Html::element( 'td', array(), $key );
178 - $sk = $wgUser->getSkin();
179190 $link = $sk->link( $this->getTitle(), 'delete', array(), array( 'action' => 'delete', 'hash' => $hash ), array() );
180191 $keyOut .= Html::rawElement( 'td', array(), $link );
181192 $keysOut .= Html::rawElement( 'tr', array(), $keyOut );
@@ -188,7 +199,7 @@
189200 }
190201
191202 function tryImportSubmit( $formData, $entryPoint = 'internal' ) {
192 - global $wgOut;
 203+ global $wgOut, $wgUser;
193204 global $wgOpenStackManagerNovaKeypairStorage;
194205
195206 if ( $wgOpenStackManagerNovaKeypairStorage == 'ldap' ) {
@@ -208,13 +219,15 @@
209220 } else {
210221 $out = Html::element( 'p', array(), 'Invalid keypair location configured' );
211222 }
212 -
 223+ $out .= '<br />';
 224+ $sk = $wgUser->getSkin();
 225+ $out .= $sk->link( $this->getTitle(), 'Back to key list', array(), array(), array() );
213226 $wgOut->addHTML( $out );
214227 return true;
215228 }
216229
217230 function tryDeleteSubmit( $formData, $entryPoint = 'internal' ) {
218 - global $wgOut;
 231+ global $wgOut, $wgUser;
219232 global $wgOpenStackManagerNovaKeypairStorage;
220233
221234 $success = $this->userLDAP->deleteKeypair( $formData['key'] );
@@ -223,7 +236,11 @@
224237 } else {
225238 $out = Html::element( 'p', array(), 'Failed to delete key' );
226239 }
 240+ $out .= '<br />';
 241+ $sk = $wgUser->getSkin();
 242+ $out .= $sk->link( $this->getTitle(), 'Back to key list', array(), array(), array() );
227243 $wgOut->addHTML( $out );
 244+ return true;
228245 }
229246 }
230247

Status & tagging log