@@ -53,14 +53,14 @@ |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | switch ($_GET['token']) { |
56 | - case "SELF-REGISTER": |
|
57 | - $token = "SELF-REGISTER"; |
|
58 | - $checkval = \core\UserManagement::TOKENSTATUS_OK_NEW; |
|
59 | - $federation = CONFIG_CONFASSISTANT['CONSORTIUM']['selfservice_registration']; |
|
60 | - break; |
|
61 | - default: |
|
62 | - $token = $validator->token(filter_input(INPUT_GET,'token',FILTER_SANITIZE_STRING)); |
|
63 | - $checkval = $usermgmt->checkTokenValidity($token); |
|
56 | + case "SELF-REGISTER": |
|
57 | + $token = "SELF-REGISTER"; |
|
58 | + $checkval = \core\UserManagement::TOKENSTATUS_OK_NEW; |
|
59 | + $federation = CONFIG_CONFASSISTANT['CONSORTIUM']['selfservice_registration']; |
|
60 | + break; |
|
61 | + default: |
|
62 | + $token = $validator->token(filter_input(INPUT_GET,'token',FILTER_SANITIZE_STRING)); |
|
63 | + $checkval = $usermgmt->checkTokenValidity($token); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | if ($checkval < 0) { |
@@ -99,84 +99,84 @@ |
||
99 | 99 | } |
100 | 100 | |
101 | 101 | switch ($operationMode) { |
102 | - case OPERATION_MODE_EDIT: |
|
103 | - $idp = $validator->IdP($_GET['inst_id']); |
|
104 | - // editing IdPs is done from within the popup. When we're done, send the |
|
105 | - // user back to the popup (append the result of the operation later) |
|
106 | - $redirect_destination = "manageAdmins.inc.php?inst_id=" . $idp->identifier . "&"; |
|
107 | - $mailaddress = abortOnBogusMail($newmailaddress, $redirect_destination); |
|
108 | - // is the user primary admin of this IdP? |
|
109 | - $is_owner = $idp->isPrimaryOwner($_SESSION['user']); |
|
110 | - // check if he is (also) federation admin for the federation this IdP is in. His invitations have more blessing then. |
|
111 | - $fedadmin = $userObject->isFederationAdmin($idp->federation); |
|
112 | - // check if he is either one, if not, complain |
|
113 | - if (!$is_owner && !$fedadmin) { |
|
114 | - echo "<p>" . sprintf(_("Something's wrong... you are a %s admin, but not for the %s the requested %s belongs to!"), $uiElements->nomenclatureFed, $uiElements->nomenclatureFed, $uiElements->nomenclatureInst) . "</p>"; |
|
115 | - exit(1); |
|
116 | - } |
|
102 | + case OPERATION_MODE_EDIT: |
|
103 | + $idp = $validator->IdP($_GET['inst_id']); |
|
104 | + // editing IdPs is done from within the popup. When we're done, send the |
|
105 | + // user back to the popup (append the result of the operation later) |
|
106 | + $redirect_destination = "manageAdmins.inc.php?inst_id=" . $idp->identifier . "&"; |
|
107 | + $mailaddress = abortOnBogusMail($newmailaddress, $redirect_destination); |
|
108 | + // is the user primary admin of this IdP? |
|
109 | + $is_owner = $idp->isPrimaryOwner($_SESSION['user']); |
|
110 | + // check if he is (also) federation admin for the federation this IdP is in. His invitations have more blessing then. |
|
111 | + $fedadmin = $userObject->isFederationAdmin($idp->federation); |
|
112 | + // check if he is either one, if not, complain |
|
113 | + if (!$is_owner && !$fedadmin) { |
|
114 | + echo "<p>" . sprintf(_("Something's wrong... you are a %s admin, but not for the %s the requested %s belongs to!"), $uiElements->nomenclatureFed, $uiElements->nomenclatureFed, $uiElements->nomenclatureInst) . "</p>"; |
|
115 | + exit(1); |
|
116 | + } |
|
117 | 117 | |
118 | - $prettyprintname = $idp->name; |
|
119 | - $newtokens = $mgmt->createTokens($fedadmin, $mailaddress, $idp); |
|
120 | - $loggerInstance->writeAudit($_SESSION['user'], "NEW", "IdP " . $idp->identifier . " - Token created for " . implode(",", $mailaddress)); |
|
121 | - $introtext = "CO-ADMIN"; |
|
122 | - break; |
|
123 | - case OPERATION_MODE_NEWUNLINKED: |
|
124 | - $redirect_destination = "../overview_federation.php?"; |
|
125 | - $mailaddress = abortOnBogusMail($newmailaddress, $redirect_destination); |
|
126 | - // run an input check and conversion of the raw inputs... just in case |
|
127 | - $newinstname = $validator->string($_POST['name']); |
|
128 | - $newcountry = $validator->string($_POST['country']); |
|
129 | - $new_idp_authorized_fedadmin = $userObject->isFederationAdmin($newcountry); |
|
130 | - if ($new_idp_authorized_fedadmin !== TRUE) { |
|
131 | - throw new Exception("Something's wrong... you want to create a new " . $uiElements->nomenclatureInst . ", but are not a " . $uiElements->nomenclatureFed . " admin for the " . $uiElements->nomenclatureFed . " it should be in!"); |
|
132 | - } |
|
133 | - $federation = $validator->Federation($newcountry); |
|
134 | - $prettyprintname = $newinstname; |
|
135 | - $introtext = "NEW-FED"; |
|
136 | - // send the user back to his federation overview page, append the result of the operation later |
|
137 | - // do the token creation magic |
|
138 | - $newtokens = $mgmt->createTokens(TRUE, $mailaddress, $newinstname, 0, $newcountry); |
|
139 | - $loggerInstance->writeAudit($_SESSION['user'], "NEW", "IdP FUTURE - Token created for " . implode(",", $mailaddress)); |
|
140 | - break; |
|
141 | - case OPERATION_MODE_NEWFROMDB: |
|
142 | - $redirect_destination = "../overview_federation.php?"; |
|
143 | - $mailaddress = abortOnBogusMail($newmailaddress, $redirect_destination); |
|
144 | - // a real external DB entry was submitted and all the required parameters are there |
|
145 | - $newexternalid = $validator->string($_POST['externals']); |
|
146 | - $extinfo = $catInstance->getExternalDBEntityDetails($newexternalid); |
|
147 | - $new_idp_authorized_fedadmin = $userObject->isFederationAdmin($extinfo['country']); |
|
148 | - if ($new_idp_authorized_fedadmin !== TRUE) { |
|
149 | - throw new Exception("Something's wrong... you want to create a new " . $uiElements->nomenclatureInst . ", but are not a " . $uiElements->nomenclatureFed . " admin for the " . $uiElements->nomenclatureFed . " it should be in!"); |
|
150 | - } |
|
151 | - $federation = $validator->Federation($extinfo['country']); |
|
152 | - $newcountry = $extinfo['country']; |
|
153 | - // see if the inst name is defined in the currently set language; if not, pick its English name; if N/A, pick the last in the list |
|
154 | - $prettyprintname = ""; |
|
155 | - foreach ($extinfo['names'] as $lang => $name) { |
|
156 | - if ($lang == $languageInstance->getLang()) { |
|
157 | - $prettyprintname = $name; |
|
118 | + $prettyprintname = $idp->name; |
|
119 | + $newtokens = $mgmt->createTokens($fedadmin, $mailaddress, $idp); |
|
120 | + $loggerInstance->writeAudit($_SESSION['user'], "NEW", "IdP " . $idp->identifier . " - Token created for " . implode(",", $mailaddress)); |
|
121 | + $introtext = "CO-ADMIN"; |
|
122 | + break; |
|
123 | + case OPERATION_MODE_NEWUNLINKED: |
|
124 | + $redirect_destination = "../overview_federation.php?"; |
|
125 | + $mailaddress = abortOnBogusMail($newmailaddress, $redirect_destination); |
|
126 | + // run an input check and conversion of the raw inputs... just in case |
|
127 | + $newinstname = $validator->string($_POST['name']); |
|
128 | + $newcountry = $validator->string($_POST['country']); |
|
129 | + $new_idp_authorized_fedadmin = $userObject->isFederationAdmin($newcountry); |
|
130 | + if ($new_idp_authorized_fedadmin !== TRUE) { |
|
131 | + throw new Exception("Something's wrong... you want to create a new " . $uiElements->nomenclatureInst . ", but are not a " . $uiElements->nomenclatureFed . " admin for the " . $uiElements->nomenclatureFed . " it should be in!"); |
|
158 | 132 | } |
159 | - } |
|
160 | - if ($prettyprintname == "" && isset($extinfo['names']['en'])) { |
|
161 | - $prettyprintname = $extinfo['names']['en']; |
|
162 | - } |
|
163 | - if ($prettyprintname == "") { |
|
164 | - foreach ($extinfo['names'] as $name) { |
|
165 | - $prettyprintname = $name; |
|
133 | + $federation = $validator->Federation($newcountry); |
|
134 | + $prettyprintname = $newinstname; |
|
135 | + $introtext = "NEW-FED"; |
|
136 | + // send the user back to his federation overview page, append the result of the operation later |
|
137 | + // do the token creation magic |
|
138 | + $newtokens = $mgmt->createTokens(TRUE, $mailaddress, $newinstname, 0, $newcountry); |
|
139 | + $loggerInstance->writeAudit($_SESSION['user'], "NEW", "IdP FUTURE - Token created for " . implode(",", $mailaddress)); |
|
140 | + break; |
|
141 | + case OPERATION_MODE_NEWFROMDB: |
|
142 | + $redirect_destination = "../overview_federation.php?"; |
|
143 | + $mailaddress = abortOnBogusMail($newmailaddress, $redirect_destination); |
|
144 | + // a real external DB entry was submitted and all the required parameters are there |
|
145 | + $newexternalid = $validator->string($_POST['externals']); |
|
146 | + $extinfo = $catInstance->getExternalDBEntityDetails($newexternalid); |
|
147 | + $new_idp_authorized_fedadmin = $userObject->isFederationAdmin($extinfo['country']); |
|
148 | + if ($new_idp_authorized_fedadmin !== TRUE) { |
|
149 | + throw new Exception("Something's wrong... you want to create a new " . $uiElements->nomenclatureInst . ", but are not a " . $uiElements->nomenclatureFed . " admin for the " . $uiElements->nomenclatureFed . " it should be in!"); |
|
166 | 150 | } |
167 | - } |
|
168 | - // fill the rest of the text |
|
169 | - $introtext = "EXISTING-FED"; |
|
170 | - // do the token creation magic |
|
171 | - $newtokens = $mgmt->createTokens(TRUE, $mailaddress, $prettyprintname, $newexternalid); |
|
172 | - $loggerInstance->writeAudit($_SESSION['user'], "NEW", "IdP FUTURE - Token created for " . implode(",", $mailaddress)); |
|
173 | - break; |
|
174 | - default: // includes OPERATION_MODE_INVALID |
|
175 | - $wrongcontent = print_r($_POST, TRUE); |
|
176 | - echo "<pre>Wrong parameters in POST: |
|
151 | + $federation = $validator->Federation($extinfo['country']); |
|
152 | + $newcountry = $extinfo['country']; |
|
153 | + // see if the inst name is defined in the currently set language; if not, pick its English name; if N/A, pick the last in the list |
|
154 | + $prettyprintname = ""; |
|
155 | + foreach ($extinfo['names'] as $lang => $name) { |
|
156 | + if ($lang == $languageInstance->getLang()) { |
|
157 | + $prettyprintname = $name; |
|
158 | + } |
|
159 | + } |
|
160 | + if ($prettyprintname == "" && isset($extinfo['names']['en'])) { |
|
161 | + $prettyprintname = $extinfo['names']['en']; |
|
162 | + } |
|
163 | + if ($prettyprintname == "") { |
|
164 | + foreach ($extinfo['names'] as $name) { |
|
165 | + $prettyprintname = $name; |
|
166 | + } |
|
167 | + } |
|
168 | + // fill the rest of the text |
|
169 | + $introtext = "EXISTING-FED"; |
|
170 | + // do the token creation magic |
|
171 | + $newtokens = $mgmt->createTokens(TRUE, $mailaddress, $prettyprintname, $newexternalid); |
|
172 | + $loggerInstance->writeAudit($_SESSION['user'], "NEW", "IdP FUTURE - Token created for " . implode(",", $mailaddress)); |
|
173 | + break; |
|
174 | + default: // includes OPERATION_MODE_INVALID |
|
175 | + $wrongcontent = print_r($_POST, TRUE); |
|
176 | + echo "<pre>Wrong parameters in POST: |
|
177 | 177 | " . htmlspecialchars($wrongcontent) . " |
178 | 178 | </pre>"; |
179 | - exit(1); |
|
179 | + exit(1); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | // send, and invalidate the token immediately if the mail could not be sent! |
@@ -115,213 +115,213 @@ discard block |
||
115 | 115 | } |
116 | 116 | |
117 | 117 | switch ($inputDecoded['ACTION']) { |
118 | - case web\lib\admin\API::ACTION_NEWINST: |
|
119 | - // create the inst, no admin, no attributes |
|
120 | - $idp = new \core\IdP($fed->newIdP("PENDING", "API")); |
|
121 | - // now add all submitted attributes |
|
122 | - $inputs = $adminApi->uglify($scrubbedParameters); |
|
123 | - $optionParser->processSubmittedFields($idp, $inputs["POST"], $inputs["FILES"]); |
|
124 | - $adminApi->returnSuccess([web\lib\admin\API::AUXATTRIB_CAT_INST_ID => $idp->identifier]); |
|
125 | - break; |
|
126 | - case web\lib\admin\API::ACTION_DELINST: |
|
127 | - try { |
|
128 | - $idp = $validator->IdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID)); |
|
129 | - } catch (Exception $e) { |
|
130 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
|
131 | - exit(1); |
|
132 | - } |
|
133 | - $idp->destroy(); |
|
134 | - $adminApi->returnSuccess([]); |
|
135 | - break; |
|
136 | - case web\lib\admin\API::ACTION_ADMIN_LIST: |
|
137 | - try { |
|
138 | - $idp = $validator->IdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID)); |
|
139 | - } catch (Exception $e) { |
|
140 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
|
141 | - exit(1); |
|
142 | - } |
|
143 | - $adminApi->returnSuccess($idp->listOwners()); |
|
144 | - break; |
|
145 | - case web\lib\admin\API::ACTION_ADMIN_ADD: |
|
146 | - // IdP in question |
|
147 | - try { |
|
148 | - $idp = $validator->IdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID)); |
|
149 | - } catch (Exception $e) { |
|
150 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
|
151 | - exit(1); |
|
152 | - } |
|
153 | - // here is the token |
|
154 | - $mgmt = new core\UserManagement(); |
|
155 | - // we know we have an admin ID but scrutinizer wants this checked more explicitly |
|
156 | - $admin = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_ADMINID); |
|
157 | - if ($admin === FALSE) { |
|
158 | - throw new Exception("A required parameter is missing, and this wasn't caught earlier?!"); |
|
159 | - } |
|
160 | - $newtokens = $mgmt->createTokens(true, [$admin], $idp); |
|
161 | - $URL = "https://" . $_SERVER['SERVER_NAME'] . dirname($_SERVER['SCRIPT_NAME']) . "/action_enrollment.php?token=" . array_keys($newtokens)[0]; |
|
162 | - $success = ["TOKEN URL" => $URL, "TOKEN" => array_keys($newtokens)[0]]; |
|
163 | - // done with the essentials - display in response. But if we also have an email address, send it there |
|
164 | - $email = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_TARGETMAIL); |
|
165 | - if ($email !== FALSE) { |
|
166 | - $sent = \core\common\OutsideComm::adminInvitationMail($email, "EXISTING-FED", array_keys($newtokens)[0], $idp->name, $fed); |
|
167 | - $success["EMAIL SENT"] = $sent["SENT"]; |
|
168 | - if ($sent["SENT"] === TRUE) { |
|
169 | - $success["EMAIL TRANSPORT SECURE"] = $sent["TRANSPORT"]; |
|
170 | - } |
|
171 | - } |
|
172 | - $adminApi->returnSuccess($success); |
|
173 | - break; |
|
174 | - case web\lib\admin\API::ACTION_ADMIN_DEL: |
|
175 | - // IdP in question |
|
176 | - try { |
|
177 | - $idp = $validator->IdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID)); |
|
178 | - } catch (Exception $e) { |
|
179 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
|
180 | - exit(1); |
|
181 | - } |
|
182 | - $currentAdmins = $idp->listOwners(); |
|
183 | - $toBeDeleted = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_ADMINID); |
|
184 | - if ($toBeDeleted === FALSE) { |
|
185 | - throw new Exception("A required parameter is missing, and this wasn't caught earlier?!"); |
|
186 | - } |
|
187 | - $found = FALSE; |
|
188 | - foreach ($currentAdmins as $oneAdmin) { |
|
189 | - if ($oneAdmin['MAIL'] == $toBeDeleted) { |
|
190 | - $found = TRUE; |
|
191 | - $mgmt = new core\UserManagement(); |
|
192 | - $mgmt->removeAdminFromIdP($idp, $oneAdmin['ID']); |
|
118 | + case web\lib\admin\API::ACTION_NEWINST: |
|
119 | + // create the inst, no admin, no attributes |
|
120 | + $idp = new \core\IdP($fed->newIdP("PENDING", "API")); |
|
121 | + // now add all submitted attributes |
|
122 | + $inputs = $adminApi->uglify($scrubbedParameters); |
|
123 | + $optionParser->processSubmittedFields($idp, $inputs["POST"], $inputs["FILES"]); |
|
124 | + $adminApi->returnSuccess([web\lib\admin\API::AUXATTRIB_CAT_INST_ID => $idp->identifier]); |
|
125 | + break; |
|
126 | + case web\lib\admin\API::ACTION_DELINST: |
|
127 | + try { |
|
128 | + $idp = $validator->IdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID)); |
|
129 | + } catch (Exception $e) { |
|
130 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
|
131 | + exit(1); |
|
193 | 132 | } |
194 | - } |
|
195 | - if ($found) { |
|
133 | + $idp->destroy(); |
|
196 | 134 | $adminApi->returnSuccess([]); |
197 | - } |
|
198 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "The admin with ID $toBeDeleted is not associated to IdP " . $idp->identifier); |
|
199 | - break; |
|
200 | - case web\lib\admin\API::ACTION_STATISTICS_FED: |
|
201 | - $adminApi->returnSuccess($fed->downloadStats("array")); |
|
202 | - break; |
|
203 | - case \web\lib\admin\API::ACTION_FEDERATION_LISTIDP: |
|
204 | - $retArray = []; |
|
205 | - $idpIdentifier = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID); |
|
206 | - if ($idpIdentifier === FALSE) { |
|
207 | - $allIdPs = $fed->listIdentityProviders(0); |
|
208 | - foreach ($allIdPs as $instanceId => $oneIdP) { |
|
209 | - $theIdP = $oneIdP["instance"]; |
|
210 | - $retArray[$instanceId] = $theIdP->getAttributes(); |
|
211 | - } |
|
212 | - } else { |
|
135 | + break; |
|
136 | + case web\lib\admin\API::ACTION_ADMIN_LIST: |
|
213 | 137 | try { |
214 | - $thisIdP = $validator->IdP($idpIdentifier); |
|
138 | + $idp = $validator->IdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID)); |
|
215 | 139 | } catch (Exception $e) { |
216 | 140 | $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
217 | 141 | exit(1); |
218 | 142 | } |
219 | - $retArray[$idpIdentifier] = $thisIdP->getAttributes(); |
|
220 | - } |
|
221 | - foreach ($retArray as $instNumber => $oneInstData) { |
|
222 | - foreach ($oneInstData as $attribNumber => $oneAttrib) { |
|
223 | - if ($oneAttrib['name'] == "general:logo_file") { |
|
224 | - // JSON doesn't cope well with raw binary data, so b64 it |
|
225 | - $retArray[$instNumber][$attribNumber]['value'] = base64_encode($oneAttrib['value']); |
|
143 | + $adminApi->returnSuccess($idp->listOwners()); |
|
144 | + break; |
|
145 | + case web\lib\admin\API::ACTION_ADMIN_ADD: |
|
146 | + // IdP in question |
|
147 | + try { |
|
148 | + $idp = $validator->IdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID)); |
|
149 | + } catch (Exception $e) { |
|
150 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
|
151 | + exit(1); |
|
152 | + } |
|
153 | + // here is the token |
|
154 | + $mgmt = new core\UserManagement(); |
|
155 | + // we know we have an admin ID but scrutinizer wants this checked more explicitly |
|
156 | + $admin = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_ADMINID); |
|
157 | + if ($admin === FALSE) { |
|
158 | + throw new Exception("A required parameter is missing, and this wasn't caught earlier?!"); |
|
159 | + } |
|
160 | + $newtokens = $mgmt->createTokens(true, [$admin], $idp); |
|
161 | + $URL = "https://" . $_SERVER['SERVER_NAME'] . dirname($_SERVER['SCRIPT_NAME']) . "/action_enrollment.php?token=" . array_keys($newtokens)[0]; |
|
162 | + $success = ["TOKEN URL" => $URL, "TOKEN" => array_keys($newtokens)[0]]; |
|
163 | + // done with the essentials - display in response. But if we also have an email address, send it there |
|
164 | + $email = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_TARGETMAIL); |
|
165 | + if ($email !== FALSE) { |
|
166 | + $sent = \core\common\OutsideComm::adminInvitationMail($email, "EXISTING-FED", array_keys($newtokens)[0], $idp->name, $fed); |
|
167 | + $success["EMAIL SENT"] = $sent["SENT"]; |
|
168 | + if ($sent["SENT"] === TRUE) { |
|
169 | + $success["EMAIL TRANSPORT SECURE"] = $sent["TRANSPORT"]; |
|
226 | 170 | } |
227 | 171 | } |
228 | - } |
|
229 | - $adminApi->returnSuccess($retArray); |
|
230 | - break; |
|
231 | - case \web\lib\admin\API::ACTION_NEWPROF_RADIUS: |
|
232 | - // fall-through intended: both get mostly identical treatment |
|
233 | - case web\lib\admin\API::ACTION_NEWPROF_SB: |
|
234 | - try { |
|
235 | - $idp = $validator->IdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID)); |
|
236 | - } catch (Exception $e) { |
|
237 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
|
238 | - exit(1); |
|
239 | - } |
|
240 | - if ($inputDecoded['ACTION'] == web\lib\admin\API::ACTION_NEWPROF_RADIUS) { |
|
241 | - $type = "RADIUS"; |
|
242 | - } else { |
|
243 | - $type = "SILVERBULLET"; |
|
244 | - } |
|
245 | - $profile = $idp->newProfile($type); |
|
246 | - if ($profile === NULL) { |
|
247 | - $adminApi->returnError(\web\lib\admin\API::ERROR_INTERNAL_ERROR, "Unable to create a new Profile, for no apparent reason. Please contact support."); |
|
248 | - exit(1); |
|
249 | - } |
|
250 | - $inputs = $adminApi->uglify($scrubbedParameters); |
|
251 | - $optionParser->processSubmittedFields($profile, $inputs["POST"], $inputs["FILES"]); |
|
252 | - if ($inputDecoded['ACTION'] == web\lib\admin\API::ACTION_NEWPROF_SB) { |
|
253 | - // auto-accept ToU? |
|
254 | - if ($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_TOU) !== FALSE) { |
|
255 | - $profile->addAttribute("hiddenprofile:tou_accepted", NULL, 1); |
|
256 | - } |
|
257 | - // we're done at this point |
|
258 | - $adminApi->returnSuccess([\web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID => $profile->identifier]); |
|
259 | - continue; |
|
260 | - } |
|
261 | - if (!$profile instanceof core\ProfileRADIUS) { |
|
262 | - throw new Exception("Can't be. This is only here to convince Scrutinizer that we're really talking RADIUS."); |
|
263 | - } |
|
264 | - /* const AUXATTRIB_PROFILE_REALM = 'ATTRIB-PROFILE-REALM'; |
|
265 | - const AUXATTRIB_PROFILE_OUTERVALUE = 'ATTRIB-PROFILE-OUTERVALUE'; */ |
|
266 | - $realm = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_REALM); |
|
267 | - $outer = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_OUTERVALUE); |
|
268 | - if ($realm !== FALSE) { |
|
269 | - if ($outer === FALSE) { |
|
270 | - $outer = ""; |
|
271 | - $profile->setAnonymousIDSupport(FALSE); |
|
172 | + $adminApi->returnSuccess($success); |
|
173 | + break; |
|
174 | + case web\lib\admin\API::ACTION_ADMIN_DEL: |
|
175 | + // IdP in question |
|
176 | + try { |
|
177 | + $idp = $validator->IdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID)); |
|
178 | + } catch (Exception $e) { |
|
179 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
|
180 | + exit(1); |
|
181 | + } |
|
182 | + $currentAdmins = $idp->listOwners(); |
|
183 | + $toBeDeleted = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_ADMINID); |
|
184 | + if ($toBeDeleted === FALSE) { |
|
185 | + throw new Exception("A required parameter is missing, and this wasn't caught earlier?!"); |
|
186 | + } |
|
187 | + $found = FALSE; |
|
188 | + foreach ($currentAdmins as $oneAdmin) { |
|
189 | + if ($oneAdmin['MAIL'] == $toBeDeleted) { |
|
190 | + $found = TRUE; |
|
191 | + $mgmt = new core\UserManagement(); |
|
192 | + $mgmt->removeAdminFromIdP($idp, $oneAdmin['ID']); |
|
193 | + } |
|
194 | + } |
|
195 | + if ($found) { |
|
196 | + $adminApi->returnSuccess([]); |
|
197 | + } |
|
198 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "The admin with ID $toBeDeleted is not associated to IdP " . $idp->identifier); |
|
199 | + break; |
|
200 | + case web\lib\admin\API::ACTION_STATISTICS_FED: |
|
201 | + $adminApi->returnSuccess($fed->downloadStats("array")); |
|
202 | + break; |
|
203 | + case \web\lib\admin\API::ACTION_FEDERATION_LISTIDP: |
|
204 | + $retArray = []; |
|
205 | + $idpIdentifier = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID); |
|
206 | + if ($idpIdentifier === FALSE) { |
|
207 | + $allIdPs = $fed->listIdentityProviders(0); |
|
208 | + foreach ($allIdPs as $instanceId => $oneIdP) { |
|
209 | + $theIdP = $oneIdP["instance"]; |
|
210 | + $retArray[$instanceId] = $theIdP->getAttributes(); |
|
211 | + } |
|
272 | 212 | } else { |
273 | - $outer = $outer . "@"; |
|
274 | - $profile->setAnonymousIDSupport(TRUE); |
|
213 | + try { |
|
214 | + $thisIdP = $validator->IdP($idpIdentifier); |
|
215 | + } catch (Exception $e) { |
|
216 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
|
217 | + exit(1); |
|
218 | + } |
|
219 | + $retArray[$idpIdentifier] = $thisIdP->getAttributes(); |
|
275 | 220 | } |
276 | - $profile->setRealm($outer . $realm); |
|
277 | - } |
|
278 | - /* const AUXATTRIB_PROFILE_TESTUSER = 'ATTRIB-PROFILE-TESTUSER'; */ |
|
279 | - $testuser = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_TESTUSER); |
|
280 | - if ($testuser !== FALSE) { |
|
281 | - $profile->setRealmCheckUser(TRUE, $testuser); |
|
282 | - } |
|
283 | - /* const AUXATTRIB_PROFILE_INPUT_HINT = 'ATTRIB-PROFILE-HINTREALM'; |
|
221 | + foreach ($retArray as $instNumber => $oneInstData) { |
|
222 | + foreach ($oneInstData as $attribNumber => $oneAttrib) { |
|
223 | + if ($oneAttrib['name'] == "general:logo_file") { |
|
224 | + // JSON doesn't cope well with raw binary data, so b64 it |
|
225 | + $retArray[$instNumber][$attribNumber]['value'] = base64_encode($oneAttrib['value']); |
|
226 | + } |
|
227 | + } |
|
228 | + } |
|
229 | + $adminApi->returnSuccess($retArray); |
|
230 | + break; |
|
231 | + case \web\lib\admin\API::ACTION_NEWPROF_RADIUS: |
|
232 | + // fall-through intended: both get mostly identical treatment |
|
233 | + case web\lib\admin\API::ACTION_NEWPROF_SB: |
|
234 | + try { |
|
235 | + $idp = $validator->IdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID)); |
|
236 | + } catch (Exception $e) { |
|
237 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
|
238 | + exit(1); |
|
239 | + } |
|
240 | + if ($inputDecoded['ACTION'] == web\lib\admin\API::ACTION_NEWPROF_RADIUS) { |
|
241 | + $type = "RADIUS"; |
|
242 | + } else { |
|
243 | + $type = "SILVERBULLET"; |
|
244 | + } |
|
245 | + $profile = $idp->newProfile($type); |
|
246 | + if ($profile === NULL) { |
|
247 | + $adminApi->returnError(\web\lib\admin\API::ERROR_INTERNAL_ERROR, "Unable to create a new Profile, for no apparent reason. Please contact support."); |
|
248 | + exit(1); |
|
249 | + } |
|
250 | + $inputs = $adminApi->uglify($scrubbedParameters); |
|
251 | + $optionParser->processSubmittedFields($profile, $inputs["POST"], $inputs["FILES"]); |
|
252 | + if ($inputDecoded['ACTION'] == web\lib\admin\API::ACTION_NEWPROF_SB) { |
|
253 | + // auto-accept ToU? |
|
254 | + if ($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_TOU) !== FALSE) { |
|
255 | + $profile->addAttribute("hiddenprofile:tou_accepted", NULL, 1); |
|
256 | + } |
|
257 | + // we're done at this point |
|
258 | + $adminApi->returnSuccess([\web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID => $profile->identifier]); |
|
259 | + continue; |
|
260 | + } |
|
261 | + if (!$profile instanceof core\ProfileRADIUS) { |
|
262 | + throw new Exception("Can't be. This is only here to convince Scrutinizer that we're really talking RADIUS."); |
|
263 | + } |
|
264 | + /* const AUXATTRIB_PROFILE_REALM = 'ATTRIB-PROFILE-REALM'; |
|
265 | + const AUXATTRIB_PROFILE_OUTERVALUE = 'ATTRIB-PROFILE-OUTERVALUE'; */ |
|
266 | + $realm = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_REALM); |
|
267 | + $outer = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_OUTERVALUE); |
|
268 | + if ($realm !== FALSE) { |
|
269 | + if ($outer === FALSE) { |
|
270 | + $outer = ""; |
|
271 | + $profile->setAnonymousIDSupport(FALSE); |
|
272 | + } else { |
|
273 | + $outer = $outer . "@"; |
|
274 | + $profile->setAnonymousIDSupport(TRUE); |
|
275 | + } |
|
276 | + $profile->setRealm($outer . $realm); |
|
277 | + } |
|
278 | + /* const AUXATTRIB_PROFILE_TESTUSER = 'ATTRIB-PROFILE-TESTUSER'; */ |
|
279 | + $testuser = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_TESTUSER); |
|
280 | + if ($testuser !== FALSE) { |
|
281 | + $profile->setRealmCheckUser(TRUE, $testuser); |
|
282 | + } |
|
283 | + /* const AUXATTRIB_PROFILE_INPUT_HINT = 'ATTRIB-PROFILE-HINTREALM'; |
|
284 | 284 | const AUXATTRIB_PROFILE_INPUT_VERIFY = 'ATTRIB-PROFILE-VERIFYREALM'; */ |
285 | - $hint = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_INPUT_HINT); |
|
286 | - $enforce = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_INPUT_VERIFY); |
|
287 | - if ($enforce !== FALSE) { |
|
288 | - $profile->setInputVerificationPreference($enforce, $hint); |
|
289 | - } |
|
290 | - /* const AUXATTRIB_PROFILE_EAPTYPE */ |
|
291 | - $iterator = 1; |
|
292 | - foreach ($scrubbedParameters as $oneParam) { |
|
293 | - if ($oneParam['NAME'] == web\lib\admin\API::AUXATTRIB_PROFILE_EAPTYPE && is_int($oneParam["VALUE"])) { |
|
294 | - $type = new \core\common\EAP($oneParam["VALUE"]); |
|
295 | - $profile->addSupportedEapMethod($type, $iterator); |
|
296 | - $iterator = $iterator + 1; |
|
285 | + $hint = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_INPUT_HINT); |
|
286 | + $enforce = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_INPUT_VERIFY); |
|
287 | + if ($enforce !== FALSE) { |
|
288 | + $profile->setInputVerificationPreference($enforce, $hint); |
|
297 | 289 | } |
298 | - } |
|
299 | - // reinstantiate $profile freshly from DB - it was updated in the process |
|
300 | - $profileFresh = new core\ProfileRADIUS($profile->identifier); |
|
301 | - $profileFresh->prepShowtime(); |
|
302 | - $adminApi->returnSuccess([\web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID => $profileFresh->identifier]); |
|
303 | - break; |
|
304 | - case web\lib\admin\API::ACTION_ENDUSER_NEW: |
|
305 | - // fall-through intentional, those two actions are doing nearly identical things |
|
306 | - case web\lib\admin\API::ACTION_ENDUSER_CHANGEEXPIRY: |
|
307 | - $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
308 | - if ($prof_id === FALSE) { |
|
309 | - exit(1); |
|
310 | - } |
|
311 | - $evaluation = commonSbProfileChecks($fed, $prof_id); |
|
312 | - if ($evaluation === FALSE) { |
|
313 | - exit(1); |
|
314 | - } |
|
315 | - list($idp, $profile) = $evaluation; |
|
316 | - $user = $validator->string($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERNAME)); |
|
317 | - $expiryRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_EXPIRY); |
|
318 | - if ($expiryRaw === FALSE) { |
|
319 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "The expiry date wasn't found in the request."); |
|
290 | + /* const AUXATTRIB_PROFILE_EAPTYPE */ |
|
291 | + $iterator = 1; |
|
292 | + foreach ($scrubbedParameters as $oneParam) { |
|
293 | + if ($oneParam['NAME'] == web\lib\admin\API::AUXATTRIB_PROFILE_EAPTYPE && is_int($oneParam["VALUE"])) { |
|
294 | + $type = new \core\common\EAP($oneParam["VALUE"]); |
|
295 | + $profile->addSupportedEapMethod($type, $iterator); |
|
296 | + $iterator = $iterator + 1; |
|
297 | + } |
|
298 | + } |
|
299 | + // reinstantiate $profile freshly from DB - it was updated in the process |
|
300 | + $profileFresh = new core\ProfileRADIUS($profile->identifier); |
|
301 | + $profileFresh->prepShowtime(); |
|
302 | + $adminApi->returnSuccess([\web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID => $profileFresh->identifier]); |
|
320 | 303 | break; |
321 | - } |
|
322 | - $expiry = new DateTime($expiryRaw); |
|
323 | - try { |
|
324 | - switch ($inputDecoded['ACTION']) { |
|
304 | + case web\lib\admin\API::ACTION_ENDUSER_NEW: |
|
305 | + // fall-through intentional, those two actions are doing nearly identical things |
|
306 | + case web\lib\admin\API::ACTION_ENDUSER_CHANGEEXPIRY: |
|
307 | + $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
308 | + if ($prof_id === FALSE) { |
|
309 | + exit(1); |
|
310 | + } |
|
311 | + $evaluation = commonSbProfileChecks($fed, $prof_id); |
|
312 | + if ($evaluation === FALSE) { |
|
313 | + exit(1); |
|
314 | + } |
|
315 | + list($idp, $profile) = $evaluation; |
|
316 | + $user = $validator->string($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERNAME)); |
|
317 | + $expiryRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_EXPIRY); |
|
318 | + if ($expiryRaw === FALSE) { |
|
319 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "The expiry date wasn't found in the request."); |
|
320 | + break; |
|
321 | + } |
|
322 | + $expiry = new DateTime($expiryRaw); |
|
323 | + try { |
|
324 | + switch ($inputDecoded['ACTION']) { |
|
325 | 325 | case web\lib\admin\API::ACTION_ENDUSER_NEW: |
326 | 326 | $retval = $profile->addUser($user, $expiry); |
327 | 327 | break; |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | $retval = 1; // function doesn't have any failure vectors not raising an Exception and doesn't return a value |
335 | 335 | } |
336 | 336 | break; |
337 | - } |
|
337 | + } |
|
338 | 338 | } catch (Exception $e) { |
339 | 339 | $adminApi->returnError(web\lib\admin\API::ERROR_INTERNAL_ERROR, "The operation failed. Maybe a duplicate username, or malformed expiry date?"); |
340 | 340 | exit(1); |
@@ -345,25 +345,25 @@ discard block |
||
345 | 345 | } |
346 | 346 | $adminApi->returnSuccess([web\lib\admin\API::AUXATTRIB_SB_USERNAME => $user, \web\lib\admin\API::AUXATTRIB_SB_USERID => $retval]); |
347 | 347 | break; |
348 | - case \web\lib\admin\API::ACTION_ENDUSER_DEACTIVATE: |
|
349 | - // fall-through intended: both actions are very similar |
|
350 | - case \web\lib\admin\API::ACTION_TOKEN_NEW: |
|
351 | - $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
352 | - if ($profile_id === FALSE) { |
|
353 | - exit(1); |
|
354 | - } |
|
355 | - $evaluation = commonSbProfileChecks($fed, $profile_id); |
|
356 | - if ($evaluation === FALSE) { |
|
357 | - exit(1); |
|
358 | - } |
|
359 | - list($idp, $profile) = $evaluation; |
|
360 | - $userId = $validator->integer($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID)); |
|
361 | - if ($userId === FALSE) { |
|
362 | - $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "User ID is not an integer."); |
|
363 | - exit(1); |
|
364 | - } |
|
365 | - $additionalInfo = []; |
|
366 | - switch ($inputDecoded['ACTION']) { // this is where the two differ |
|
348 | + case \web\lib\admin\API::ACTION_ENDUSER_DEACTIVATE: |
|
349 | + // fall-through intended: both actions are very similar |
|
350 | + case \web\lib\admin\API::ACTION_TOKEN_NEW: |
|
351 | + $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
352 | + if ($profile_id === FALSE) { |
|
353 | + exit(1); |
|
354 | + } |
|
355 | + $evaluation = commonSbProfileChecks($fed, $profile_id); |
|
356 | + if ($evaluation === FALSE) { |
|
357 | + exit(1); |
|
358 | + } |
|
359 | + list($idp, $profile) = $evaluation; |
|
360 | + $userId = $validator->integer($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID)); |
|
361 | + if ($userId === FALSE) { |
|
362 | + $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "User ID is not an integer."); |
|
363 | + exit(1); |
|
364 | + } |
|
365 | + $additionalInfo = []; |
|
366 | + switch ($inputDecoded['ACTION']) { // this is where the two differ |
|
367 | 367 | case \web\lib\admin\API::ACTION_ENDUSER_DEACTIVATE: |
368 | 368 | $result = $profile->deactivateUser($userId); |
369 | 369 | break; |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | } |
397 | 397 | } |
398 | 398 | break; |
399 | - } |
|
399 | + } |
|
400 | 400 | |
401 | 401 | if ($result !== TRUE) { |
402 | 402 | $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "These parameters did not lead to an existing, active user."); |
@@ -404,70 +404,70 @@ discard block |
||
404 | 404 | } |
405 | 405 | $adminApi->returnSuccess($additionalInfo); |
406 | 406 | break; |
407 | - case \web\lib\admin\API::ACTION_ENDUSER_IDENTIFY: |
|
408 | - $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
409 | - if ($profile_id === FALSE) { |
|
410 | - exit(1); |
|
411 | - } |
|
412 | - $evaluation = commonSbProfileChecks($fed, $profile_id); |
|
413 | - if ($evaluation === FALSE) { |
|
414 | - exit(1); |
|
415 | - } |
|
416 | - list($idp, $profile) = $evaluation; |
|
417 | - $userId = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID); |
|
418 | - $userName = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERNAME); |
|
419 | - $certSerial = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL); |
|
420 | - if ($userId === FALSE && $userName === FALSE && $certSerial === FALSE) { |
|
421 | - // we need at least one of those |
|
422 | - $adminApi->returnError(\web\lib\admin\API::ERROR_MISSING_PARAMETER, "At least one of User ID, Username, or certificate serial is required."); |
|
423 | - } |
|
424 | - $userlist = $profile->listAllUsers(); |
|
425 | - if ($userName === FALSE && $certSerial === FALSE) { // we got a user ID |
|
426 | - if (!isset($userlist[$userId])) { |
|
427 | - $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "This user ID does not exist in this profile."); |
|
407 | + case \web\lib\admin\API::ACTION_ENDUSER_IDENTIFY: |
|
408 | + $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
409 | + if ($profile_id === FALSE) { |
|
410 | + exit(1); |
|
411 | + } |
|
412 | + $evaluation = commonSbProfileChecks($fed, $profile_id); |
|
413 | + if ($evaluation === FALSE) { |
|
414 | + exit(1); |
|
415 | + } |
|
416 | + list($idp, $profile) = $evaluation; |
|
417 | + $userId = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID); |
|
418 | + $userName = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERNAME); |
|
419 | + $certSerial = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL); |
|
420 | + if ($userId === FALSE && $userName === FALSE && $certSerial === FALSE) { |
|
421 | + // we need at least one of those |
|
422 | + $adminApi->returnError(\web\lib\admin\API::ERROR_MISSING_PARAMETER, "At least one of User ID, Username, or certificate serial is required."); |
|
423 | + } |
|
424 | + $userlist = $profile->listAllUsers(); |
|
425 | + if ($userName === FALSE && $certSerial === FALSE) { // we got a user ID |
|
426 | + if (!isset($userlist[$userId])) { |
|
427 | + $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "This user ID does not exist in this profile."); |
|
428 | + break; |
|
429 | + } |
|
430 | + $adminApi->returnSuccess([$userId => $userlist[$userId]]); |
|
428 | 431 | break; |
429 | 432 | } |
430 | - $adminApi->returnSuccess([$userId => $userlist[$userId]]); |
|
431 | - break; |
|
432 | - } |
|
433 | - if ($userId === FALSE && $certSerial === FALSE) { // we got a username |
|
434 | - $key = array_search($userName, $userlist); |
|
435 | - if ($key === FALSE) { |
|
436 | - $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "This username does not exist in this profile."); |
|
433 | + if ($userId === FALSE && $certSerial === FALSE) { // we got a username |
|
434 | + $key = array_search($userName, $userlist); |
|
435 | + if ($key === FALSE) { |
|
436 | + $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "This username does not exist in this profile."); |
|
437 | + break; |
|
438 | + } |
|
439 | + $adminApi->returnSuccess([$key => $userlist[$key]]); |
|
440 | + break; |
|
441 | + } |
|
442 | + if ($userId === FALSE && $userName === FALSE) { // we got a cert serial |
|
443 | + $serial = explode(":", $certSerial); |
|
444 | + $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]); |
|
445 | + if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) { |
|
446 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found."); |
|
447 | + } |
|
448 | + if ($cert->profileId != $profile->identifier) { |
|
449 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile."); |
|
450 | + } |
|
451 | + $adminApi->returnSuccess([$cert->userId => $userlist[$cert->userId]]); |
|
437 | 452 | break; |
438 | 453 | } |
439 | - $adminApi->returnSuccess([$key => $userlist[$key]]); |
|
454 | + $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "Only exactly one of User ID, username or cert serial can be specified."); |
|
440 | 455 | break; |
441 | - } |
|
442 | - if ($userId === FALSE && $userName === FALSE) { // we got a cert serial |
|
443 | - $serial = explode(":", $certSerial); |
|
444 | - $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]); |
|
445 | - if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) { |
|
446 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found."); |
|
456 | + case \web\lib\admin\API::ACTION_ENDUSER_LIST: |
|
457 | + // fall-through: those two are similar |
|
458 | + case \web\lib\admin\API::ACTION_TOKEN_LIST: |
|
459 | + $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
460 | + if ($profile_id === FALSE) { |
|
461 | + exit(1); |
|
447 | 462 | } |
448 | - if ($cert->profileId != $profile->identifier) { |
|
449 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile."); |
|
463 | + $evaluation = commonSbProfileChecks($fed, $profile_id); |
|
464 | + if ($evaluation === FALSE) { |
|
465 | + exit(1); |
|
450 | 466 | } |
451 | - $adminApi->returnSuccess([$cert->userId => $userlist[$cert->userId]]); |
|
452 | - break; |
|
453 | - } |
|
454 | - $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "Only exactly one of User ID, username or cert serial can be specified."); |
|
455 | - break; |
|
456 | - case \web\lib\admin\API::ACTION_ENDUSER_LIST: |
|
457 | - // fall-through: those two are similar |
|
458 | - case \web\lib\admin\API::ACTION_TOKEN_LIST: |
|
459 | - $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
460 | - if ($profile_id === FALSE) { |
|
461 | - exit(1); |
|
462 | - } |
|
463 | - $evaluation = commonSbProfileChecks($fed, $profile_id); |
|
464 | - if ($evaluation === FALSE) { |
|
465 | - exit(1); |
|
466 | - } |
|
467 | - list($idp, $profile) = $evaluation; |
|
468 | - $allUsers = $profile->listAllUsers(); |
|
469 | - // this is where they differ |
|
470 | - switch ($inputDecoded['ACTION']) { |
|
467 | + list($idp, $profile) = $evaluation; |
|
468 | + $allUsers = $profile->listAllUsers(); |
|
469 | + // this is where they differ |
|
470 | + switch ($inputDecoded['ACTION']) { |
|
471 | 471 | case \web\lib\admin\API::ACTION_ENDUSER_LIST: |
472 | 472 | $adminApi->returnSuccess($allUsers); |
473 | 473 | break; |
@@ -486,105 +486,105 @@ discard block |
||
486 | 486 | $infoSet[$oneTokenObject->userId] = [\web\lib\admin\API::AUXATTRIB_TOKEN => $oneTokenObject->invitationTokenString, "STATUS" => $oneTokenObject->invitationTokenStatus]; |
487 | 487 | } |
488 | 488 | $adminApi->returnSuccess($infoSet); |
489 | - } |
|
490 | - break; |
|
491 | - case \web\lib\admin\API::ACTION_TOKEN_REVOKE: |
|
492 | - $tokenRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_TOKEN); |
|
493 | - if ($tokenRaw === FALSE) { |
|
494 | - exit(1); |
|
495 | - } |
|
496 | - $token = new core\SilverbulletInvitation($tokenRaw); |
|
497 | - if ($token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_VALID && $token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_PARTIALLY_REDEEMED) { |
|
498 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "This is not a currently valid token."); |
|
499 | - exit(1); |
|
500 | - } |
|
501 | - $token->revokeInvitation(); |
|
502 | - $adminApi->returnSuccess([]); |
|
503 | - break; |
|
504 | - case \web\lib\admin\API::ACTION_CERT_LIST: |
|
505 | - $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
506 | - $user_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID); |
|
507 | - if ($prof_id === FALSE || !is_int($user_id)) { |
|
508 | - exit(1); |
|
509 | - } |
|
510 | - $evaluation = commonSbProfileChecks($fed, $prof_id); |
|
511 | - if ($evaluation === FALSE) { |
|
512 | - exit(1); |
|
513 | - } |
|
514 | - list($idp, $profile) = $evaluation; |
|
515 | - $invitations = $profile->userStatus($user_id); |
|
516 | - // now pull out cert information from the object |
|
517 | - $certs = []; |
|
518 | - foreach ($invitations as $oneInvitation) { |
|
519 | - $certs = array_merge($certs, $oneInvitation->associatedCertificates); |
|
520 | - } |
|
521 | - // extract relevant subset of information from cert objects |
|
522 | - $certDetails = []; |
|
523 | - foreach ($certs as $cert) { |
|
524 | - $certDetails[$cert->ca_type . ":" . $cert->serial] = ["ISSUED" => $cert->issued, "EXPIRY" => $cert->expiry, "STATUS" => $cert->status, "DEVICE" => $cert->device, "CN" => $cert->username, "ANNOTATION" => $cert->annotation]; |
|
525 | - } |
|
526 | - $adminApi->returnSuccess($certDetails); |
|
527 | - break; |
|
528 | - case \web\lib\admin\API::ACTION_CERT_REVOKE: |
|
529 | - $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
530 | - if ($prof_id === FALSE) { |
|
531 | - exit(1); |
|
532 | - } |
|
533 | - $evaluation = commonSbProfileChecks($fed, $prof_id); |
|
534 | - if ($evaluation === FALSE) { |
|
535 | - exit(1); |
|
536 | - } |
|
537 | - list($idp, $profile) = $evaluation; |
|
538 | - // tear apart the serial |
|
539 | - $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL); |
|
540 | - if ($serialRaw === FALSE) { |
|
541 | - exit(1); |
|
542 | - } |
|
543 | - $serial = explode(":", $serialRaw); |
|
544 | - $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]); |
|
545 | - if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) { |
|
546 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found."); |
|
547 | - } |
|
548 | - if ($cert->profileId != $profile->identifier) { |
|
549 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile."); |
|
550 | - } |
|
551 | - $cert->revokeCertificate(); |
|
552 | - $adminApi->returnSuccess([]); |
|
489 | + } |
|
553 | 490 | break; |
554 | - case \web\lib\admin\API::ACTION_CERT_ANNOTATE: |
|
555 | - $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
556 | - if ($prof_id === FALSE) { |
|
557 | - exit(1); |
|
558 | - } |
|
559 | - $evaluation = commonSbProfileChecks($fed, $prof_id); |
|
560 | - if ($evaluation === FALSE) { |
|
561 | - exit(1); |
|
562 | - } |
|
563 | - list($idp, $profile) = $evaluation; |
|
564 | - // tear apart the serial |
|
565 | - $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL); |
|
566 | - if ($serialRaw === FALSE) { |
|
567 | - exit(1); |
|
568 | - } |
|
569 | - $serial = explode(":", $serialRaw); |
|
570 | - $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]); |
|
571 | - if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) { |
|
572 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found."); |
|
573 | - } |
|
574 | - if ($cert->profileId != $profile->identifier) { |
|
575 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile."); |
|
576 | - } |
|
577 | - $annotationRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTANNOTATION); |
|
578 | - if ($annotationRaw === FALSE) { |
|
579 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Unable to extract annotation."); |
|
491 | + case \web\lib\admin\API::ACTION_TOKEN_REVOKE: |
|
492 | + $tokenRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_TOKEN); |
|
493 | + if ($tokenRaw === FALSE) { |
|
494 | + exit(1); |
|
495 | + } |
|
496 | + $token = new core\SilverbulletInvitation($tokenRaw); |
|
497 | + if ($token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_VALID && $token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_PARTIALLY_REDEEMED) { |
|
498 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "This is not a currently valid token."); |
|
499 | + exit(1); |
|
500 | + } |
|
501 | + $token->revokeInvitation(); |
|
502 | + $adminApi->returnSuccess([]); |
|
580 | 503 | break; |
581 | - } |
|
582 | - $annotation = json_decode($annotationRaw, TRUE); |
|
583 | - $cert->annotate($annotation); |
|
584 | - $adminApi->returnSuccess([]); |
|
504 | + case \web\lib\admin\API::ACTION_CERT_LIST: |
|
505 | + $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
506 | + $user_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID); |
|
507 | + if ($prof_id === FALSE || !is_int($user_id)) { |
|
508 | + exit(1); |
|
509 | + } |
|
510 | + $evaluation = commonSbProfileChecks($fed, $prof_id); |
|
511 | + if ($evaluation === FALSE) { |
|
512 | + exit(1); |
|
513 | + } |
|
514 | + list($idp, $profile) = $evaluation; |
|
515 | + $invitations = $profile->userStatus($user_id); |
|
516 | + // now pull out cert information from the object |
|
517 | + $certs = []; |
|
518 | + foreach ($invitations as $oneInvitation) { |
|
519 | + $certs = array_merge($certs, $oneInvitation->associatedCertificates); |
|
520 | + } |
|
521 | + // extract relevant subset of information from cert objects |
|
522 | + $certDetails = []; |
|
523 | + foreach ($certs as $cert) { |
|
524 | + $certDetails[$cert->ca_type . ":" . $cert->serial] = ["ISSUED" => $cert->issued, "EXPIRY" => $cert->expiry, "STATUS" => $cert->status, "DEVICE" => $cert->device, "CN" => $cert->username, "ANNOTATION" => $cert->annotation]; |
|
525 | + } |
|
526 | + $adminApi->returnSuccess($certDetails); |
|
527 | + break; |
|
528 | + case \web\lib\admin\API::ACTION_CERT_REVOKE: |
|
529 | + $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
530 | + if ($prof_id === FALSE) { |
|
531 | + exit(1); |
|
532 | + } |
|
533 | + $evaluation = commonSbProfileChecks($fed, $prof_id); |
|
534 | + if ($evaluation === FALSE) { |
|
535 | + exit(1); |
|
536 | + } |
|
537 | + list($idp, $profile) = $evaluation; |
|
538 | + // tear apart the serial |
|
539 | + $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL); |
|
540 | + if ($serialRaw === FALSE) { |
|
541 | + exit(1); |
|
542 | + } |
|
543 | + $serial = explode(":", $serialRaw); |
|
544 | + $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]); |
|
545 | + if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) { |
|
546 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found."); |
|
547 | + } |
|
548 | + if ($cert->profileId != $profile->identifier) { |
|
549 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile."); |
|
550 | + } |
|
551 | + $cert->revokeCertificate(); |
|
552 | + $adminApi->returnSuccess([]); |
|
553 | + break; |
|
554 | + case \web\lib\admin\API::ACTION_CERT_ANNOTATE: |
|
555 | + $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
556 | + if ($prof_id === FALSE) { |
|
557 | + exit(1); |
|
558 | + } |
|
559 | + $evaluation = commonSbProfileChecks($fed, $prof_id); |
|
560 | + if ($evaluation === FALSE) { |
|
561 | + exit(1); |
|
562 | + } |
|
563 | + list($idp, $profile) = $evaluation; |
|
564 | + // tear apart the serial |
|
565 | + $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL); |
|
566 | + if ($serialRaw === FALSE) { |
|
567 | + exit(1); |
|
568 | + } |
|
569 | + $serial = explode(":", $serialRaw); |
|
570 | + $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]); |
|
571 | + if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) { |
|
572 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found."); |
|
573 | + } |
|
574 | + if ($cert->profileId != $profile->identifier) { |
|
575 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile."); |
|
576 | + } |
|
577 | + $annotationRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTANNOTATION); |
|
578 | + if ($annotationRaw === FALSE) { |
|
579 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Unable to extract annotation."); |
|
580 | + break; |
|
581 | + } |
|
582 | + $annotation = json_decode($annotationRaw, TRUE); |
|
583 | + $cert->annotate($annotation); |
|
584 | + $adminApi->returnSuccess([]); |
|
585 | 585 | |
586 | - break; |
|
586 | + break; |
|
587 | 587 | |
588 | - default: |
|
589 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_ACTION, "Not implemented yet."); |
|
588 | + default: |
|
589 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_ACTION, "Not implemented yet."); |
|
590 | 590 | } |
591 | 591 | \ No newline at end of file |