Index: trunk/extensions/OpenStackManager/OpenStackNovaUser.php |
— | — | @@ -6,10 +6,13 @@ |
7 | 7 | var $userInfo; |
8 | 8 | |
9 | 9 | function __construct() { |
| 10 | + $this->connect(); |
| 11 | + $this->fetchUserInfo(); |
| 12 | + } |
| 13 | + |
| 14 | + function fetchUserInfo() { |
10 | 15 | global $wgAuth, $wgUser; |
11 | | - global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword; |
12 | 16 | |
13 | | - $this->connect(); |
14 | 17 | $this->userDN = $wgAuth->getUserDN( strtolower( $wgUser->getName() ) ); |
15 | 18 | $this->userInfo = $wgAuth->userInfo; |
16 | 19 | } |
— | — | @@ -30,21 +33,20 @@ |
31 | 34 | } |
32 | 35 | |
33 | 36 | function getKeypairs() { |
34 | | - if ( isset( $this->userInfo[0]['sshpublickey'] ) ) { |
| 37 | + global $wgAuth; |
| 38 | + |
| 39 | + $this->fetchUserInfo(); |
| 40 | + if ( $this->userInfo[0]['sshpublickey'] ) { |
35 | 41 | $keys = $this->userInfo[0]['sshpublickey']; |
36 | 42 | $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; |
46 | 47 | } |
47 | 48 | return $keypairs; |
48 | 49 | } else { |
| 50 | + $wgAuth->printDebug( "No keypairs found", NONSENSITIVE ); |
49 | 51 | return array(); |
50 | 52 | } |
51 | 53 | } |
— | — | @@ -140,8 +142,6 @@ |
141 | 143 | function importKeypair( $key ) { |
142 | 144 | global $wgAuth; |
143 | 145 | |
144 | | - $this->connect(); |
145 | | - |
146 | 146 | $keypairs = array(); |
147 | 147 | if ( isset( $this->userInfo[0]['sshpublickey'] ) ) { |
148 | 148 | $keypairs = $this->userInfo[0]['sshpublickey']; |
— | — | @@ -172,10 +172,9 @@ |
173 | 173 | } else { |
174 | 174 | unset( $keypairs[$index] ); |
175 | 175 | } |
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; |
180 | 179 | } |
181 | 180 | $success = @ldap_modify( $wgAuth->ldapconn, $this->userDN, $values ); |
182 | 181 | if ( $success ) { |
— | — | @@ -183,8 +182,6 @@ |
184 | 183 | return true; |
185 | 184 | } else { |
186 | 185 | $wgAuth->printDebug( "Failed to delete the user's sshpublickey", NONSENSITIVE ); |
187 | | - $wgAuth->printDebug( "KEY: $key", NONSENSITIVE ); |
188 | | - $wgAuth->printDebug( "sshpublickey: ", NONSENSITIVE, $values['sshpublickey'] ); |
189 | 186 | return false; |
190 | 187 | } |
191 | 188 | } else { |
Index: trunk/extensions/OpenStackManager/SpecialNovaKey.php |
— | — | @@ -103,12 +103,24 @@ |
104 | 104 | |
105 | 105 | $this->setHeaders(); |
106 | 106 | $wgOut->setPagetitle("Delete key"); |
| 107 | + |
| 108 | + $keyInfo = Array(); |
| 109 | + |
107 | 110 | if ( $wgOpenStackManagerNovaKeypairStorage == 'nova' ) { |
| 111 | + $keyname = $wgRequest->getVal('keyname'); |
108 | 112 | $project = $wgRequest->getVal('project'); |
109 | 113 | if ( $project && ! $this->userLDAP->inProject( $project ) ) { |
110 | 114 | $this->notInProject(); |
111 | 115 | return true; |
112 | 116 | } |
| 117 | + $keyInfo['keyname'] = array( |
| 118 | + 'type' => 'hidden', |
| 119 | + 'default' => $project, |
| 120 | + ); |
| 121 | + $keyInfo['project'] = array( |
| 122 | + 'type' => 'hidden', |
| 123 | + 'default' => $keyname, |
| 124 | + ); |
113 | 125 | } else if ( $wgOpenStackManagerNovaKeypairStorage == 'ldap' ) { |
114 | 126 | $hash = $wgRequest->getVal( 'hash' ); |
115 | 127 | $keypairs = $this->userLDAP->getKeypairs(); |
— | — | @@ -117,28 +129,25 @@ |
118 | 130 | $out .= Html::element( 'p', array(), 'Are you sure you wish to delete the above key?' ); |
119 | 131 | $wgOut->addHTML( $out ); |
120 | 132 | } |
121 | | - |
122 | | - $keyInfo = Array(); |
123 | | - |
124 | 133 | $keyInfo['hash'] = array( |
125 | 134 | 'type' => 'hidden', |
126 | 135 | 'default' => $hash, |
127 | 136 | ); |
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(); |
142 | 137 | } |
| 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(); |
143 | 152 | return true; |
144 | 153 | } |
145 | 154 | |
— | — | @@ -150,7 +159,9 @@ |
151 | 160 | $wgOut->setPagetitle("Key list"); |
152 | 161 | |
153 | 162 | $out = ''; |
| 163 | + $sk = $wgUser->getSkin(); |
154 | 164 | if ( $wgOpenStackManagerNovaKeypairStorage == 'nova' ) { |
| 165 | + $out .= $sk->link( $this->getTitle(), 'Import a new key', array(), array( 'action' => 'import' ), array() ); |
155 | 166 | $projects = $this->userLDAP->getProjects(); |
156 | 167 | foreach( $projects as $project ) { |
157 | 168 | $userCredentials = $this->userLDAP->getCredentials( $project ); |
— | — | @@ -170,11 +181,11 @@ |
171 | 182 | $out .= Html::rawElement( 'table', array( 'id' => 'novakeylist', 'class' => 'wikitable' ), $projectOut ); |
172 | 183 | } |
173 | 184 | } else if ( $wgOpenStackManagerNovaKeypairStorage == 'ldap' ) { |
| 185 | + $out .= $sk->link( $this->getTitle(), 'Import a new key', array(), array( 'action' => 'import' ), array() ); |
174 | 186 | $keypairs = $this->userLDAP->getKeypairs(); |
175 | 187 | $keysOut = ''; |
176 | 188 | foreach ( $keypairs as $hash => $key ) { |
177 | 189 | $keyOut = Html::element( 'td', array(), $key ); |
178 | | - $sk = $wgUser->getSkin(); |
179 | 190 | $link = $sk->link( $this->getTitle(), 'delete', array(), array( 'action' => 'delete', 'hash' => $hash ), array() ); |
180 | 191 | $keyOut .= Html::rawElement( 'td', array(), $link ); |
181 | 192 | $keysOut .= Html::rawElement( 'tr', array(), $keyOut ); |
— | — | @@ -188,7 +199,7 @@ |
189 | 200 | } |
190 | 201 | |
191 | 202 | function tryImportSubmit( $formData, $entryPoint = 'internal' ) { |
192 | | - global $wgOut; |
| 203 | + global $wgOut, $wgUser; |
193 | 204 | global $wgOpenStackManagerNovaKeypairStorage; |
194 | 205 | |
195 | 206 | if ( $wgOpenStackManagerNovaKeypairStorage == 'ldap' ) { |
— | — | @@ -208,13 +219,15 @@ |
209 | 220 | } else { |
210 | 221 | $out = Html::element( 'p', array(), 'Invalid keypair location configured' ); |
211 | 222 | } |
212 | | - |
| 223 | + $out .= '<br />'; |
| 224 | + $sk = $wgUser->getSkin(); |
| 225 | + $out .= $sk->link( $this->getTitle(), 'Back to key list', array(), array(), array() ); |
213 | 226 | $wgOut->addHTML( $out ); |
214 | 227 | return true; |
215 | 228 | } |
216 | 229 | |
217 | 230 | function tryDeleteSubmit( $formData, $entryPoint = 'internal' ) { |
218 | | - global $wgOut; |
| 231 | + global $wgOut, $wgUser; |
219 | 232 | global $wgOpenStackManagerNovaKeypairStorage; |
220 | 233 | |
221 | 234 | $success = $this->userLDAP->deleteKeypair( $formData['key'] ); |
— | — | @@ -223,7 +236,11 @@ |
224 | 237 | } else { |
225 | 238 | $out = Html::element( 'p', array(), 'Failed to delete key' ); |
226 | 239 | } |
| 240 | + $out .= '<br />'; |
| 241 | + $sk = $wgUser->getSkin(); |
| 242 | + $out .= $sk->link( $this->getTitle(), 'Back to key list', array(), array(), array() ); |
227 | 243 | $wgOut->addHTML( $out ); |
| 244 | + return true; |
228 | 245 | } |
229 | 246 | } |
230 | 247 | |