Passed
Push — master ( 0c48ee...bcc3a3 )
by Stefan
07:00 queued 11s
created
web/admin/action_enrollment.php 1 patch
Switch Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -53,14 +53,14 @@
 block discarded – undo
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) {
Please login to merge, or discard this patch.
web/admin/inc/sendinvite.inc.php 1 patch
Switch Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -100,88 +100,88 @@
 block discarded – undo
100 100
 }
101 101
 
102 102
 switch ($operationMode) {
103
-    case OPERATION_MODE_EDIT:
104
-        $idp = $validator->existingIdP($_GET['inst_id']);
105
-        // editing IdPs is done from within the popup. When we're done, send the 
106
-        // user back to the popup (append the result of the operation later)
107
-        $redirect_destination = "manageAdmins.inc.php?inst_id=" . $idp->identifier . "&";
108
-        $mailaddress = abortOnBogusMail($newmailaddress, $redirect_destination);
109
-        // is the user primary admin of this IdP?
110
-        $is_owner = $idp->isPrimaryOwner($_SESSION['user']);
111
-        // check if he is (also) federation admin for the federation this IdP is in. His invitations have more blessing then.
112
-        $fedadmin = $userObject->isFederationAdmin($idp->federation);
113
-        // check if he is either one, if not, complain
114
-        if (!$is_owner && !$fedadmin) {
115
-            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>";
116
-            exit(1);
117
-        }
103
+        case OPERATION_MODE_EDIT:
104
+            $idp = $validator->existingIdP($_GET['inst_id']);
105
+            // editing IdPs is done from within the popup. When we're done, send the 
106
+            // user back to the popup (append the result of the operation later)
107
+            $redirect_destination = "manageAdmins.inc.php?inst_id=" . $idp->identifier . "&";
108
+            $mailaddress = abortOnBogusMail($newmailaddress, $redirect_destination);
109
+            // is the user primary admin of this IdP?
110
+            $is_owner = $idp->isPrimaryOwner($_SESSION['user']);
111
+            // check if he is (also) federation admin for the federation this IdP is in. His invitations have more blessing then.
112
+            $fedadmin = $userObject->isFederationAdmin($idp->federation);
113
+            // check if he is either one, if not, complain
114
+            if (!$is_owner && !$fedadmin) {
115
+                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>";
116
+                exit(1);
117
+            }
118 118
 
119
-        $prettyprintname = $idp->name;
120
-        $newtokens = $mgmt->createTokens($fedadmin, $mailaddress, $idp);
121
-        $loggerInstance->writeAudit($_SESSION['user'], "NEW", "IdP " . $idp->identifier . " - Token created for " . implode(",", $mailaddress));
122
-        $introtext = "CO-ADMIN";
123
-        $participant_type = $idp->type;
124
-        break;
125
-    case OPERATION_MODE_NEWUNLINKED:
126
-        $redirect_destination = "../overview_federation.php?";
127
-        $mailaddress = abortOnBogusMail($newmailaddress, $redirect_destination);
128
-        // run an input check and conversion of the raw inputs... just in case
129
-        $newinstname = $validator->string($_POST['name']);
130
-        $newcountry = $validator->string($_POST['country']);
131
-        $participant_type = $validator->partType($_POST['participant_type']);
132
-        $new_idp_authorized_fedadmin = $userObject->isFederationAdmin($newcountry);
133
-        if ($new_idp_authorized_fedadmin !== TRUE) {
134
-            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!");
135
-        }
136
-        $federation = $validator->existingFederation($newcountry);
137
-        $prettyprintname = $newinstname;
138
-        $introtext = "NEW-FED";
139
-        // send the user back to his federation overview page, append the result of the operation later
140
-        // do the token creation magic
141
-        $newtokens = $mgmt->createTokens(TRUE, $mailaddress, $newinstname, 0, $newcountry, $participant_type);
142
-        $loggerInstance->writeAudit($_SESSION['user'], "NEW", "ORG FUTURE  - Token created for $participant_type " . implode(",", $mailaddress));
143
-        break;
144
-    case OPERATION_MODE_NEWFROMDB:
145
-        $redirect_destination = "../overview_federation.php?";
146
-        $mailaddress = abortOnBogusMail($newmailaddress, $redirect_destination);
147
-        // a real external DB entry was submitted and all the required parameters are there
148
-        $newexternalid = $validator->string($_POST['externals']);
149
-        $extinfo = $catInstance->getExternalDBEntityDetails($newexternalid);
150
-        $new_idp_authorized_fedadmin = $userObject->isFederationAdmin($extinfo['country']);
151
-        if ($new_idp_authorized_fedadmin !== TRUE) {
152
-            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!");
153
-        }
154
-        $federation = $validator->existingFederation($extinfo['country']);
155
-        $newcountry = $extinfo['country'];
156
-        // 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
157
-        $prettyprintname = "";
158
-        foreach ($extinfo['names'] as $lang => $name) {
159
-            if ($lang == $languageInstance->getLang()) {
160
-                $prettyprintname = $name;
119
+            $prettyprintname = $idp->name;
120
+            $newtokens = $mgmt->createTokens($fedadmin, $mailaddress, $idp);
121
+            $loggerInstance->writeAudit($_SESSION['user'], "NEW", "IdP " . $idp->identifier . " - Token created for " . implode(",", $mailaddress));
122
+            $introtext = "CO-ADMIN";
123
+            $participant_type = $idp->type;
124
+            break;
125
+        case OPERATION_MODE_NEWUNLINKED:
126
+            $redirect_destination = "../overview_federation.php?";
127
+            $mailaddress = abortOnBogusMail($newmailaddress, $redirect_destination);
128
+            // run an input check and conversion of the raw inputs... just in case
129
+            $newinstname = $validator->string($_POST['name']);
130
+            $newcountry = $validator->string($_POST['country']);
131
+            $participant_type = $validator->partType($_POST['participant_type']);
132
+            $new_idp_authorized_fedadmin = $userObject->isFederationAdmin($newcountry);
133
+            if ($new_idp_authorized_fedadmin !== TRUE) {
134
+                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!");
161 135
             }
162
-        }
163
-        if ($prettyprintname == "" && isset($extinfo['names']['en'])) {
164
-            $prettyprintname = $extinfo['names']['en'];
165
-        }
166
-        if ($prettyprintname == "") {
167
-            foreach ($extinfo['names'] as $name) {
168
-                $prettyprintname = $name;
136
+            $federation = $validator->existingFederation($newcountry);
137
+            $prettyprintname = $newinstname;
138
+            $introtext = "NEW-FED";
139
+            // send the user back to his federation overview page, append the result of the operation later
140
+            // do the token creation magic
141
+            $newtokens = $mgmt->createTokens(TRUE, $mailaddress, $newinstname, 0, $newcountry, $participant_type);
142
+            $loggerInstance->writeAudit($_SESSION['user'], "NEW", "ORG FUTURE  - Token created for $participant_type " . implode(",", $mailaddress));
143
+            break;
144
+        case OPERATION_MODE_NEWFROMDB:
145
+            $redirect_destination = "../overview_federation.php?";
146
+            $mailaddress = abortOnBogusMail($newmailaddress, $redirect_destination);
147
+            // a real external DB entry was submitted and all the required parameters are there
148
+            $newexternalid = $validator->string($_POST['externals']);
149
+            $extinfo = $catInstance->getExternalDBEntityDetails($newexternalid);
150
+            $new_idp_authorized_fedadmin = $userObject->isFederationAdmin($extinfo['country']);
151
+            if ($new_idp_authorized_fedadmin !== TRUE) {
152
+                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!");
169 153
             }
170
-        }
171
-        // TODO when we have access to the data
172
-        $participant_type = "IdPSP";
173
-        // fill the rest of the text
174
-        $introtext = "EXISTING-FED";
175
-        // do the token creation magic
176
-        $newtokens = $mgmt->createTokens(TRUE, $mailaddress, $prettyprintname, $newexternalid);
177
-        $loggerInstance->writeAudit($_SESSION['user'], "NEW", "IdP FUTURE  - Token created for " . implode(",", $mailaddress));
178
-        break;
179
-    default: // includes OPERATION_MODE_INVALID
180
-        $wrongcontent = print_r($_POST, TRUE);
181
-        echo "<pre>Wrong parameters in POST:
154
+            $federation = $validator->existingFederation($extinfo['country']);
155
+            $newcountry = $extinfo['country'];
156
+            // 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
157
+            $prettyprintname = "";
158
+            foreach ($extinfo['names'] as $lang => $name) {
159
+                if ($lang == $languageInstance->getLang()) {
160
+                    $prettyprintname = $name;
161
+                }
162
+            }
163
+            if ($prettyprintname == "" && isset($extinfo['names']['en'])) {
164
+                $prettyprintname = $extinfo['names']['en'];
165
+            }
166
+            if ($prettyprintname == "") {
167
+                foreach ($extinfo['names'] as $name) {
168
+                    $prettyprintname = $name;
169
+                }
170
+            }
171
+            // TODO when we have access to the data
172
+            $participant_type = "IdPSP";
173
+            // fill the rest of the text
174
+            $introtext = "EXISTING-FED";
175
+            // do the token creation magic
176
+            $newtokens = $mgmt->createTokens(TRUE, $mailaddress, $prettyprintname, $newexternalid);
177
+            $loggerInstance->writeAudit($_SESSION['user'], "NEW", "IdP FUTURE  - Token created for " . implode(",", $mailaddress));
178
+            break;
179
+        default: // includes OPERATION_MODE_INVALID
180
+            $wrongcontent = print_r($_POST, TRUE);
181
+            echo "<pre>Wrong parameters in POST:
182 182
 " . htmlspecialchars($wrongcontent) . "
183 183
 </pre>";
184
-        exit(1);
184
+            exit(1);
185 185
 }
186 186
 
187 187
 // send, and invalidate the token immediately if the mail could not be sent!
Please login to merge, or discard this patch.
web/admin/API.php 1 patch
Switch Indentation   +356 added lines, -356 removed lines patch added patch discarded remove patch
@@ -115,217 +115,217 @@  discard block
 block discarded – undo
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
-        $typeRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_INSTTYPE);
121
-        if ($typeRaw === FALSE) {
122
-            throw new Exception("We did not receive a valid participant type!");
123
-        }
124
-        $type = $validator->partType($typeRaw);
125
-        $idp = new \core\IdP($fed->newIdP($type, "PENDING", "API"));
126
-        // now add all submitted attributes
127
-        $inputs = $adminApi->uglify($scrubbedParameters);
128
-        $optionParser->processSubmittedFields($idp, $inputs["POST"], $inputs["FILES"]);
129
-        $adminApi->returnSuccess([web\lib\admin\API::AUXATTRIB_CAT_INST_ID => $idp->identifier]);
130
-        break;
131
-    case web\lib\admin\API::ACTION_DELINST:
132
-        try {
133
-            $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID));
134
-        } catch (Exception $e) {
135
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
136
-            exit(1);
137
-        }
138
-        $idp->destroy();
139
-        $adminApi->returnSuccess([]);
140
-        break;
141
-    case web\lib\admin\API::ACTION_ADMIN_LIST:
142
-        try {
143
-            $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID));
144
-        } catch (Exception $e) {
145
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
146
-            exit(1);
147
-        }
148
-        $adminApi->returnSuccess($idp->listOwners());
149
-        break;
150
-    case web\lib\admin\API::ACTION_ADMIN_ADD:
151
-        // IdP in question
152
-        try {
153
-            $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID));
154
-        } catch (Exception $e) {
155
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
156
-            exit(1);
157
-        }
158
-        // here is the token
159
-        $mgmt = new core\UserManagement();
160
-        // we know we have an admin ID but scrutinizer wants this checked more explicitly
161
-        $admin = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_ADMINID);
162
-        if ($admin === FALSE) {
163
-            throw new Exception("A required parameter is missing, and this wasn't caught earlier?!");
164
-        }
165
-        $newtokens = $mgmt->createTokens(true, [$admin], $idp);
166
-        $URL = "https://" . $_SERVER['SERVER_NAME'] . dirname($_SERVER['SCRIPT_NAME']) . "/action_enrollment.php?token=" . array_keys($newtokens)[0];
167
-        $success = ["TOKEN URL" => $URL, "TOKEN" => array_keys($newtokens)[0]];
168
-        // done with the essentials - display in response. But if we also have an email address, send it there
169
-        $email = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_TARGETMAIL);
170
-        if ($email !== FALSE) {
171
-            $sent = \core\common\OutsideComm::adminInvitationMail($email, "EXISTING-FED", array_keys($newtokens)[0], $idp->name, $fed, $idp->type);
172
-            $success["EMAIL SENT"] = $sent["SENT"];
173
-            if ($sent["SENT"] === TRUE) {
174
-                $success["EMAIL TRANSPORT SECURE"] = $sent["TRANSPORT"];
118
+        case web\lib\admin\API::ACTION_NEWINST:
119
+            // create the inst, no admin, no attributes
120
+            $typeRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_INSTTYPE);
121
+            if ($typeRaw === FALSE) {
122
+                throw new Exception("We did not receive a valid participant type!");
175 123
             }
176
-        }
177
-        $adminApi->returnSuccess($success);
178
-        break;
179
-    case web\lib\admin\API::ACTION_ADMIN_DEL:
180
-        // IdP in question
181
-        try {
182
-            $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID));
183
-        } catch (Exception $e) {
184
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
185
-            exit(1);
186
-        }
187
-        $currentAdmins = $idp->listOwners();
188
-        $toBeDeleted = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_ADMINID);
189
-        if ($toBeDeleted === FALSE) {
190
-            throw new Exception("A required parameter is missing, and this wasn't caught earlier?!");
191
-        }
192
-        $found = FALSE;
193
-        foreach ($currentAdmins as $oneAdmin) {
194
-            if ($oneAdmin['MAIL'] == $toBeDeleted) {
195
-                $found = TRUE;
196
-                $mgmt = new core\UserManagement();
197
-                $mgmt->removeAdminFromIdP($idp, $oneAdmin['ID']);
124
+            $type = $validator->partType($typeRaw);
125
+            $idp = new \core\IdP($fed->newIdP($type, "PENDING", "API"));
126
+            // now add all submitted attributes
127
+            $inputs = $adminApi->uglify($scrubbedParameters);
128
+            $optionParser->processSubmittedFields($idp, $inputs["POST"], $inputs["FILES"]);
129
+            $adminApi->returnSuccess([web\lib\admin\API::AUXATTRIB_CAT_INST_ID => $idp->identifier]);
130
+            break;
131
+        case web\lib\admin\API::ACTION_DELINST:
132
+            try {
133
+                $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID));
134
+            } catch (Exception $e) {
135
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
136
+                exit(1);
198 137
             }
199
-        }
200
-        if ($found) {
138
+            $idp->destroy();
201 139
             $adminApi->returnSuccess([]);
202
-        }
203
-        $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "The admin with ID $toBeDeleted is not associated to IdP " . $idp->identifier);
204
-        break;
205
-    case web\lib\admin\API::ACTION_STATISTICS_FED:
206
-        $adminApi->returnSuccess($fed->downloadStats("array"));
207
-        break;
208
-    case \web\lib\admin\API::ACTION_NEWPROF_RADIUS:
209
-    // fall-through intended: both get mostly identical treatment
210
-    case web\lib\admin\API::ACTION_NEWPROF_SB:
211
-        try {
212
-            $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID));
213
-        } catch (Exception $e) {
214
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
215
-            exit(1);
216
-        }
217
-        if ($inputDecoded['ACTION'] == web\lib\admin\API::ACTION_NEWPROF_RADIUS) {
218
-            $type = "RADIUS";
219
-        } else {
220
-            $type = "SILVERBULLET";
221
-        }
222
-        $profile = $idp->newProfile($type);
223
-        if ($profile === NULL) {
224
-            $adminApi->returnError(\web\lib\admin\API::ERROR_INTERNAL_ERROR, "Unable to create a new Profile, for no apparent reason. Please contact support.");
225
-            exit(1);
226
-        }
227
-        $inputs = $adminApi->uglify($scrubbedParameters);
228
-        $optionParser->processSubmittedFields($profile, $inputs["POST"], $inputs["FILES"]);
229
-        if ($inputDecoded['ACTION'] == web\lib\admin\API::ACTION_NEWPROF_SB) {
230
-            // auto-accept ToU?
231
-            if ($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_TOU) !== FALSE) {
232
-                $profile->addAttribute("hiddenprofile:tou_accepted", NULL, 1);
233
-            }
234
-            // we're done at this point
235
-            $adminApi->returnSuccess([\web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID => $profile->identifier]);
236 140
             break;
237
-        }
238
-        if (!$profile instanceof core\ProfileRADIUS) {
239
-            throw new Exception("Can't be. This is only here to convince Scrutinizer that we're really talking RADIUS.");
240
-        }
241
-        /* const AUXATTRIB_PROFILE_REALM = 'ATTRIB-PROFILE-REALM';
242
-          const AUXATTRIB_PROFILE_OUTERVALUE = 'ATTRIB-PROFILE-OUTERVALUE'; */
243
-        $realm = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_REALM);
244
-        $outer = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_OUTERVALUE);
245
-        if ($realm !== FALSE) {
246
-            if ($outer === FALSE) {
247
-                $outer = "";
248
-                $profile->setAnonymousIDSupport(FALSE);
141
+        case web\lib\admin\API::ACTION_ADMIN_LIST:
142
+            try {
143
+                $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID));
144
+            } catch (Exception $e) {
145
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
146
+                exit(1);
147
+            }
148
+            $adminApi->returnSuccess($idp->listOwners());
149
+            break;
150
+        case web\lib\admin\API::ACTION_ADMIN_ADD:
151
+            // IdP in question
152
+            try {
153
+                $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID));
154
+            } catch (Exception $e) {
155
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
156
+                exit(1);
157
+            }
158
+            // here is the token
159
+            $mgmt = new core\UserManagement();
160
+            // we know we have an admin ID but scrutinizer wants this checked more explicitly
161
+            $admin = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_ADMINID);
162
+            if ($admin === FALSE) {
163
+                throw new Exception("A required parameter is missing, and this wasn't caught earlier?!");
164
+            }
165
+            $newtokens = $mgmt->createTokens(true, [$admin], $idp);
166
+            $URL = "https://" . $_SERVER['SERVER_NAME'] . dirname($_SERVER['SCRIPT_NAME']) . "/action_enrollment.php?token=" . array_keys($newtokens)[0];
167
+            $success = ["TOKEN URL" => $URL, "TOKEN" => array_keys($newtokens)[0]];
168
+            // done with the essentials - display in response. But if we also have an email address, send it there
169
+            $email = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_TARGETMAIL);
170
+            if ($email !== FALSE) {
171
+                $sent = \core\common\OutsideComm::adminInvitationMail($email, "EXISTING-FED", array_keys($newtokens)[0], $idp->name, $fed, $idp->type);
172
+                $success["EMAIL SENT"] = $sent["SENT"];
173
+                if ($sent["SENT"] === TRUE) {
174
+                    $success["EMAIL TRANSPORT SECURE"] = $sent["TRANSPORT"];
175
+                }
176
+            }
177
+            $adminApi->returnSuccess($success);
178
+            break;
179
+        case web\lib\admin\API::ACTION_ADMIN_DEL:
180
+            // IdP in question
181
+            try {
182
+                $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID));
183
+            } catch (Exception $e) {
184
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
185
+                exit(1);
186
+            }
187
+            $currentAdmins = $idp->listOwners();
188
+            $toBeDeleted = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_ADMINID);
189
+            if ($toBeDeleted === FALSE) {
190
+                throw new Exception("A required parameter is missing, and this wasn't caught earlier?!");
191
+            }
192
+            $found = FALSE;
193
+            foreach ($currentAdmins as $oneAdmin) {
194
+                if ($oneAdmin['MAIL'] == $toBeDeleted) {
195
+                    $found = TRUE;
196
+                    $mgmt = new core\UserManagement();
197
+                    $mgmt->removeAdminFromIdP($idp, $oneAdmin['ID']);
198
+                }
199
+            }
200
+            if ($found) {
201
+                $adminApi->returnSuccess([]);
202
+            }
203
+            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "The admin with ID $toBeDeleted is not associated to IdP " . $idp->identifier);
204
+            break;
205
+        case web\lib\admin\API::ACTION_STATISTICS_FED:
206
+            $adminApi->returnSuccess($fed->downloadStats("array"));
207
+            break;
208
+        case \web\lib\admin\API::ACTION_NEWPROF_RADIUS:
209
+        // fall-through intended: both get mostly identical treatment
210
+        case web\lib\admin\API::ACTION_NEWPROF_SB:
211
+            try {
212
+                $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID));
213
+            } catch (Exception $e) {
214
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
215
+                exit(1);
216
+            }
217
+            if ($inputDecoded['ACTION'] == web\lib\admin\API::ACTION_NEWPROF_RADIUS) {
218
+                $type = "RADIUS";
249 219
             } else {
250
-                $outer = $outer . "@";
251
-                $profile->setAnonymousIDSupport(TRUE);
220
+                $type = "SILVERBULLET";
252 221
             }
253
-            $profile->setRealm($outer . $realm);
254
-        }
255
-        /* const AUXATTRIB_PROFILE_TESTUSER = 'ATTRIB-PROFILE-TESTUSER'; */
256
-        $testuser = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_TESTUSER);
257
-        if ($testuser !== FALSE) {
258
-            $profile->setRealmCheckUser(TRUE, $testuser);
259
-        }
260
-        /* const AUXATTRIB_PROFILE_INPUT_HINT = 'ATTRIB-PROFILE-HINTREALM';
222
+            $profile = $idp->newProfile($type);
223
+            if ($profile === NULL) {
224
+                $adminApi->returnError(\web\lib\admin\API::ERROR_INTERNAL_ERROR, "Unable to create a new Profile, for no apparent reason. Please contact support.");
225
+                exit(1);
226
+            }
227
+            $inputs = $adminApi->uglify($scrubbedParameters);
228
+            $optionParser->processSubmittedFields($profile, $inputs["POST"], $inputs["FILES"]);
229
+            if ($inputDecoded['ACTION'] == web\lib\admin\API::ACTION_NEWPROF_SB) {
230
+                // auto-accept ToU?
231
+                if ($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_TOU) !== FALSE) {
232
+                    $profile->addAttribute("hiddenprofile:tou_accepted", NULL, 1);
233
+                }
234
+                // we're done at this point
235
+                $adminApi->returnSuccess([\web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID => $profile->identifier]);
236
+                break;
237
+            }
238
+            if (!$profile instanceof core\ProfileRADIUS) {
239
+                throw new Exception("Can't be. This is only here to convince Scrutinizer that we're really talking RADIUS.");
240
+            }
241
+            /* const AUXATTRIB_PROFILE_REALM = 'ATTRIB-PROFILE-REALM';
242
+          const AUXATTRIB_PROFILE_OUTERVALUE = 'ATTRIB-PROFILE-OUTERVALUE'; */
243
+            $realm = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_REALM);
244
+            $outer = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_OUTERVALUE);
245
+            if ($realm !== FALSE) {
246
+                if ($outer === FALSE) {
247
+                    $outer = "";
248
+                    $profile->setAnonymousIDSupport(FALSE);
249
+                } else {
250
+                    $outer = $outer . "@";
251
+                    $profile->setAnonymousIDSupport(TRUE);
252
+                }
253
+                $profile->setRealm($outer . $realm);
254
+            }
255
+            /* const AUXATTRIB_PROFILE_TESTUSER = 'ATTRIB-PROFILE-TESTUSER'; */
256
+            $testuser = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_TESTUSER);
257
+            if ($testuser !== FALSE) {
258
+                $profile->setRealmCheckUser(TRUE, $testuser);
259
+            }
260
+            /* const AUXATTRIB_PROFILE_INPUT_HINT = 'ATTRIB-PROFILE-HINTREALM';
261 261
           const AUXATTRIB_PROFILE_INPUT_VERIFY = 'ATTRIB-PROFILE-VERIFYREALM'; */
262
-        $hint = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_INPUT_HINT);
263
-        $enforce = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_INPUT_VERIFY);
264
-        if ($enforce !== FALSE) {
265
-            $profile->setInputVerificationPreference($enforce, $hint);
266
-        }
267
-        /* const AUXATTRIB_PROFILE_EAPTYPE */
268
-        $iterator = 1;
269
-        foreach ($scrubbedParameters as $oneParam) {
270
-            if ($oneParam['NAME'] == web\lib\admin\API::AUXATTRIB_PROFILE_EAPTYPE && is_int($oneParam["VALUE"])) {
271
-                $type = new \core\common\EAP($oneParam["VALUE"]);
272
-                $profile->addSupportedEapMethod($type, $iterator);
273
-                $iterator = $iterator + 1;
262
+            $hint = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_INPUT_HINT);
263
+            $enforce = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_INPUT_VERIFY);
264
+            if ($enforce !== FALSE) {
265
+                $profile->setInputVerificationPreference($enforce, $hint);
274 266
             }
275
-        }
276
-        // reinstantiate $profile freshly from DB - it was updated in the process
277
-        $profileFresh = new core\ProfileRADIUS($profile->identifier);
278
-        $profileFresh->prepShowtime();
279
-        $adminApi->returnSuccess([\web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID => $profileFresh->identifier]);
280
-        break;
281
-    case web\lib\admin\API::ACTION_ENDUSER_NEW:
282
-        $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
283
-        if ($prof_id === FALSE) {
284
-            exit(1);
285
-        }
286
-        $evaluation = commonSbProfileChecks($fed, $prof_id);
287
-        if ($evaluation === FALSE) {
288
-            exit(1);
289
-        }
290
-        list($idp, $profile) = $evaluation;
291
-        $user = $validator->string($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERNAME));
292
-        $expiryRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_EXPIRY);
293
-        if ($expiryRaw === FALSE) {
294
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "The expiry date wasn't found in the request.");
295
-            exit(1);
296
-        }
297
-        $expiry = new DateTime($expiryRaw);
298
-        try {
299
-            $retval = $profile->addUser($user, $expiry);
300
-        } catch (Exception $e) {
301
-            $adminApi->returnError(web\lib\admin\API::ERROR_INTERNAL_ERROR, "The operation failed. Maybe a duplicate username, or malformed expiry date?");
302
-            exit(1);
303
-        }
304
-        if ($retval == 0) {// that didn't work, it seems
305
-            $adminApi->returnError(web\lib\admin\API::ERROR_INTERNAL_ERROR, "The operation failed subtly. Contact the administrators.");
306
-            exit(1);
307
-        }
308
-        $adminApi->returnSuccess([web\lib\admin\API::AUXATTRIB_SB_USERNAME => $user, \web\lib\admin\API::AUXATTRIB_SB_USERID => $retval]);
309
-        break;
310
-    case \web\lib\admin\API::ACTION_ENDUSER_DEACTIVATE:
311
-    // fall-through intended: both actions are very similar
312
-    case \web\lib\admin\API::ACTION_TOKEN_NEW:
313
-        $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
314
-        if ($profile_id === FALSE) {
315
-            exit(1);
316
-        }
317
-        $evaluation = commonSbProfileChecks($fed, $profile_id);
318
-        if ($evaluation === FALSE) {
319
-            exit(1);
320
-        }
321
-        list($idp, $profile) = $evaluation;
322
-        $userId = $validator->integer($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID));
323
-        if ($userId === FALSE) {
324
-            $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "User ID is not an integer.");
325
-            exit(1);
326
-        }
327
-        $additionalInfo = [];
328
-        switch ($inputDecoded['ACTION']) { // this is where the two differ
267
+            /* const AUXATTRIB_PROFILE_EAPTYPE */
268
+            $iterator = 1;
269
+            foreach ($scrubbedParameters as $oneParam) {
270
+                if ($oneParam['NAME'] == web\lib\admin\API::AUXATTRIB_PROFILE_EAPTYPE && is_int($oneParam["VALUE"])) {
271
+                    $type = new \core\common\EAP($oneParam["VALUE"]);
272
+                    $profile->addSupportedEapMethod($type, $iterator);
273
+                    $iterator = $iterator + 1;
274
+                }
275
+            }
276
+            // reinstantiate $profile freshly from DB - it was updated in the process
277
+            $profileFresh = new core\ProfileRADIUS($profile->identifier);
278
+            $profileFresh->prepShowtime();
279
+            $adminApi->returnSuccess([\web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID => $profileFresh->identifier]);
280
+            break;
281
+        case web\lib\admin\API::ACTION_ENDUSER_NEW:
282
+            $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
283
+            if ($prof_id === FALSE) {
284
+                exit(1);
285
+            }
286
+            $evaluation = commonSbProfileChecks($fed, $prof_id);
287
+            if ($evaluation === FALSE) {
288
+                exit(1);
289
+            }
290
+            list($idp, $profile) = $evaluation;
291
+            $user = $validator->string($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERNAME));
292
+            $expiryRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_EXPIRY);
293
+            if ($expiryRaw === FALSE) {
294
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "The expiry date wasn't found in the request.");
295
+                exit(1);
296
+            }
297
+            $expiry = new DateTime($expiryRaw);
298
+            try {
299
+                $retval = $profile->addUser($user, $expiry);
300
+            } catch (Exception $e) {
301
+                $adminApi->returnError(web\lib\admin\API::ERROR_INTERNAL_ERROR, "The operation failed. Maybe a duplicate username, or malformed expiry date?");
302
+                exit(1);
303
+            }
304
+            if ($retval == 0) {// that didn't work, it seems
305
+                $adminApi->returnError(web\lib\admin\API::ERROR_INTERNAL_ERROR, "The operation failed subtly. Contact the administrators.");
306
+                exit(1);
307
+            }
308
+            $adminApi->returnSuccess([web\lib\admin\API::AUXATTRIB_SB_USERNAME => $user, \web\lib\admin\API::AUXATTRIB_SB_USERID => $retval]);
309
+            break;
310
+        case \web\lib\admin\API::ACTION_ENDUSER_DEACTIVATE:
311
+        // fall-through intended: both actions are very similar
312
+        case \web\lib\admin\API::ACTION_TOKEN_NEW:
313
+            $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
314
+            if ($profile_id === FALSE) {
315
+                exit(1);
316
+            }
317
+            $evaluation = commonSbProfileChecks($fed, $profile_id);
318
+            if ($evaluation === FALSE) {
319
+                exit(1);
320
+            }
321
+            list($idp, $profile) = $evaluation;
322
+            $userId = $validator->integer($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID));
323
+            if ($userId === FALSE) {
324
+                $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "User ID is not an integer.");
325
+                exit(1);
326
+            }
327
+            $additionalInfo = [];
328
+            switch ($inputDecoded['ACTION']) { // this is where the two differ
329 329
             case \web\lib\admin\API::ACTION_ENDUSER_DEACTIVATE:
330 330
                 $result = $profile->deactivateUser($userId);
331 331
                 break;
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
                     }
359 359
                 }
360 360
                 break;
361
-        }
361
+            }
362 362
 
363 363
         if ($result !== TRUE) {
364 364
             $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "These parameters did not lead to an existing, active user.");
@@ -366,65 +366,65 @@  discard block
 block discarded – undo
366 366
         }
367 367
         $adminApi->returnSuccess($additionalInfo);
368 368
         break;
369
-    case \web\lib\admin\API::ACTION_ENDUSER_IDENTIFY:
370
-        $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
371
-        if ($profile_id === FALSE) {
372
-            exit(1);
373
-        }
374
-        $evaluation = commonSbProfileChecks($fed, $profile_id);
375
-        if ($evaluation === FALSE) {
376
-            exit(1);
377
-        }
378
-        list($idp, $profile) = $evaluation;
379
-        $userId = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID);
380
-        $userName = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERNAME);
381
-        $certSerial = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL);
382
-        if ($userId === FALSE && $userName === FALSE && $certSerial === FALSE) {
383
-            // we need at least one of those
384
-            $adminApi->returnError(\web\lib\admin\API::ERROR_MISSING_PARAMETER, "At least one of User ID, Username, or certificate serial is required.");
385
-        }
386
-        $userlist = $profile->listAllUsers();
387
-        if ($userName === FALSE && $certSerial === FALSE) { // we got a user ID
388
-            if (!isset($userlist[$userId])) {
389
-                return $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "This user ID does not exist in this profile.");
369
+        case \web\lib\admin\API::ACTION_ENDUSER_IDENTIFY:
370
+            $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
371
+            if ($profile_id === FALSE) {
372
+                exit(1);
390 373
             }
391
-            $adminApi->returnSuccess([$userId => $userlist[$userId]]);
392
-        }
393
-        if ($userId === FALSE && $certSerial === FALSE) { // we got a username
394
-            $key = array_search($userName, $userlist);
395
-            if ($key === FALSE) {
396
-                return $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "This username does not exist in this profile.");
374
+            $evaluation = commonSbProfileChecks($fed, $profile_id);
375
+            if ($evaluation === FALSE) {
376
+                exit(1);
397 377
             }
398
-            $adminApi->returnSuccess([$key => $userlist[$key]]);
399
-        }
400
-        if ($userId === FALSE && $userName === FALSE) { // we got a cert serial
401
-            $serial = explode(":", $certSerial);
402
-            $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]);
403
-            if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) {
404
-                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found.");
378
+            list($idp, $profile) = $evaluation;
379
+            $userId = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID);
380
+            $userName = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERNAME);
381
+            $certSerial = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL);
382
+            if ($userId === FALSE && $userName === FALSE && $certSerial === FALSE) {
383
+                // we need at least one of those
384
+                $adminApi->returnError(\web\lib\admin\API::ERROR_MISSING_PARAMETER, "At least one of User ID, Username, or certificate serial is required.");
405 385
             }
406
-            if ($cert->profileId != $profile->identifier) {
407
-                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile.");
386
+            $userlist = $profile->listAllUsers();
387
+            if ($userName === FALSE && $certSerial === FALSE) { // we got a user ID
388
+                if (!isset($userlist[$userId])) {
389
+                    return $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "This user ID does not exist in this profile.");
390
+                }
391
+                $adminApi->returnSuccess([$userId => $userlist[$userId]]);
408 392
             }
409
-            $adminApi->returnSuccess([$cert->userId => $userlist[$cert->userId]]);
410
-        }
411
-        $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "Only exactly one of User ID, username or cert serial can be specified.");
412
-        break;
413
-    case \web\lib\admin\API::ACTION_ENDUSER_LIST:
414
-    // fall-through: those two are similar
415
-    case \web\lib\admin\API::ACTION_TOKEN_LIST:
416
-        $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
417
-        if ($profile_id === FALSE) {
418
-            exit(1);
419
-        }
420
-        $evaluation = commonSbProfileChecks($fed, $profile_id);
421
-        if ($evaluation === FALSE) {
422
-            exit(1);
423
-        }
424
-        list($idp, $profile) = $evaluation;
425
-        $allUsers = $profile->listAllUsers();
426
-        // this is where they differ
427
-        switch ($inputDecoded['ACTION']) {
393
+            if ($userId === FALSE && $certSerial === FALSE) { // we got a username
394
+                $key = array_search($userName, $userlist);
395
+                if ($key === FALSE) {
396
+                    return $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "This username does not exist in this profile.");
397
+                }
398
+                $adminApi->returnSuccess([$key => $userlist[$key]]);
399
+            }
400
+            if ($userId === FALSE && $userName === FALSE) { // we got a cert serial
401
+                $serial = explode(":", $certSerial);
402
+                $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]);
403
+                if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) {
404
+                    $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found.");
405
+                }
406
+                if ($cert->profileId != $profile->identifier) {
407
+                    $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile.");
408
+                }
409
+                $adminApi->returnSuccess([$cert->userId => $userlist[$cert->userId]]);
410
+            }
411
+            $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "Only exactly one of User ID, username or cert serial can be specified.");
412
+            break;
413
+        case \web\lib\admin\API::ACTION_ENDUSER_LIST:
414
+        // fall-through: those two are similar
415
+        case \web\lib\admin\API::ACTION_TOKEN_LIST:
416
+            $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
417
+            if ($profile_id === FALSE) {
418
+                exit(1);
419
+            }
420
+            $evaluation = commonSbProfileChecks($fed, $profile_id);
421
+            if ($evaluation === FALSE) {
422
+                exit(1);
423
+            }
424
+            list($idp, $profile) = $evaluation;
425
+            $allUsers = $profile->listAllUsers();
426
+            // this is where they differ
427
+            switch ($inputDecoded['ACTION']) {
428 428
             case \web\lib\admin\API::ACTION_ENDUSER_LIST:
429 429
                 $adminApi->returnSuccess($allUsers);
430 430
                 break;
@@ -443,105 +443,105 @@  discard block
 block discarded – undo
443 443
                     $infoSet[$oneTokenObject->userId] = [\web\lib\admin\API::AUXATTRIB_TOKEN => $oneTokenObject->invitationTokenString, "STATUS" => $oneTokenObject->invitationTokenStatus];
444 444
                 }
445 445
                 $adminApi->returnSuccess($infoSet);
446
-        }
447
-        break;
448
-    case \web\lib\admin\API::ACTION_TOKEN_REVOKE:
449
-        $tokenRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_TOKEN);
450
-        if ($tokenRaw === FALSE) {
451
-            exit(1);
452
-        }
453
-        $token = new core\SilverbulletInvitation($tokenRaw);
454
-        if ($token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_VALID && $token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_PARTIALLY_REDEEMED) {
455
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "This is not a currently valid token.");
456
-            exit(1);
457
-        }
458
-        $token->revokeInvitation();
459
-        $adminApi->returnSuccess([]);
460
-        break;
461
-    case \web\lib\admin\API::ACTION_CERT_LIST:
462
-        $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
463
-        $user_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID);
464
-        if ($prof_id === FALSE || !is_int($user_id)) {
465
-            exit(1);
466
-        }
467
-        $evaluation = commonSbProfileChecks($fed, $prof_id);
468
-        if ($evaluation === FALSE) {
469
-            exit(1);
470
-        }
471
-        list($idp, $profile) = $evaluation;
472
-        $invitations = $profile->userStatus($user_id);
473
-        // now pull out cert information from the object
474
-        $certs = [];
475
-        foreach ($invitations as $oneInvitation) {
476
-            $certs = array_merge($certs, $oneInvitation->associatedCertificates);
477
-        }
478
-        // extract relevant subset of information from cert objects
479
-        $certDetails = [];
480
-        foreach ($certs as $cert) {
481
-            $certDetails[$cert->ca_type . ":" . $cert->serial] = ["ISSUED" => $cert->issued, "EXPIRY" => $cert->expiry, "STATUS" => $cert->status, "DEVICE" => $cert->device, "CN" => $cert->username, "ANNOTATION" => $cert->annotation];
482
-        }
483
-        $adminApi->returnSuccess($certDetails);
484
-        break;
485
-    case \web\lib\admin\API::ACTION_CERT_REVOKE:
486
-        $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
487
-        if ($prof_id === FALSE) {
488
-            exit(1);
489
-        }
490
-        $evaluation = commonSbProfileChecks($fed, $prof_id);
491
-        if ($evaluation === FALSE) {
492
-            exit(1);
493
-        }
494
-        list($idp, $profile) = $evaluation;
495
-        // tear apart the serial
496
-        $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL);
497
-        if ($serialRaw === FALSE) {
498
-            exit(1);
499
-        }
500
-        $serial = explode(":", $serialRaw);
501
-        $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]);
502
-        if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) {
503
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found.");
504
-        }
505
-        if ($cert->profileId != $profile->identifier) {
506
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile.");
507
-        }
508
-        $cert->revokeCertificate();
509
-        $adminApi->returnSuccess([]);
446
+            }
510 447
         break;
511
-    case \web\lib\admin\API::ACTION_CERT_ANNOTATE:
512
-        $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
513
-        if ($prof_id === FALSE) {
514
-            exit(1);
515
-        }
516
-        $evaluation = commonSbProfileChecks($fed, $prof_id);
517
-        if ($evaluation === FALSE) {
518
-            exit(1);
519
-        }
520
-        list($idp, $profile) = $evaluation;
521
-        // tear apart the serial
522
-        $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL);
523
-        if ($serialRaw === FALSE) {
524
-            exit(1);
525
-        }
526
-        $serial = explode(":", $serialRaw);
527
-        $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]);
528
-        if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) {
529
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found.");
530
-        }
531
-        if ($cert->profileId != $profile->identifier) {
532
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile.");
533
-        }
534
-        $annotationRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTANNOTATION);
535
-        if ($annotationRaw === FALSE) {
536
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Unable to extract annotation.");
448
+        case \web\lib\admin\API::ACTION_TOKEN_REVOKE:
449
+            $tokenRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_TOKEN);
450
+            if ($tokenRaw === FALSE) {
451
+                exit(1);
452
+            }
453
+            $token = new core\SilverbulletInvitation($tokenRaw);
454
+            if ($token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_VALID && $token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_PARTIALLY_REDEEMED) {
455
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "This is not a currently valid token.");
456
+                exit(1);
457
+            }
458
+            $token->revokeInvitation();
459
+            $adminApi->returnSuccess([]);
537 460
             break;
538
-        }
539
-        $annotation = json_decode($annotationRaw, TRUE);
540
-        $cert->annotate($annotation);
541
-        $adminApi->returnSuccess([]);
461
+        case \web\lib\admin\API::ACTION_CERT_LIST:
462
+            $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
463
+            $user_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID);
464
+            if ($prof_id === FALSE || !is_int($user_id)) {
465
+                exit(1);
466
+            }
467
+            $evaluation = commonSbProfileChecks($fed, $prof_id);
468
+            if ($evaluation === FALSE) {
469
+                exit(1);
470
+            }
471
+            list($idp, $profile) = $evaluation;
472
+            $invitations = $profile->userStatus($user_id);
473
+            // now pull out cert information from the object
474
+            $certs = [];
475
+            foreach ($invitations as $oneInvitation) {
476
+                $certs = array_merge($certs, $oneInvitation->associatedCertificates);
477
+            }
478
+            // extract relevant subset of information from cert objects
479
+            $certDetails = [];
480
+            foreach ($certs as $cert) {
481
+                $certDetails[$cert->ca_type . ":" . $cert->serial] = ["ISSUED" => $cert->issued, "EXPIRY" => $cert->expiry, "STATUS" => $cert->status, "DEVICE" => $cert->device, "CN" => $cert->username, "ANNOTATION" => $cert->annotation];
482
+            }
483
+            $adminApi->returnSuccess($certDetails);
484
+            break;
485
+        case \web\lib\admin\API::ACTION_CERT_REVOKE:
486
+            $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
487
+            if ($prof_id === FALSE) {
488
+                exit(1);
489
+            }
490
+            $evaluation = commonSbProfileChecks($fed, $prof_id);
491
+            if ($evaluation === FALSE) {
492
+                exit(1);
493
+            }
494
+            list($idp, $profile) = $evaluation;
495
+            // tear apart the serial
496
+            $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL);
497
+            if ($serialRaw === FALSE) {
498
+                exit(1);
499
+            }
500
+            $serial = explode(":", $serialRaw);
501
+            $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]);
502
+            if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) {
503
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found.");
504
+            }
505
+            if ($cert->profileId != $profile->identifier) {
506
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile.");
507
+            }
508
+            $cert->revokeCertificate();
509
+            $adminApi->returnSuccess([]);
510
+            break;
511
+        case \web\lib\admin\API::ACTION_CERT_ANNOTATE:
512
+            $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
513
+            if ($prof_id === FALSE) {
514
+                exit(1);
515
+            }
516
+            $evaluation = commonSbProfileChecks($fed, $prof_id);
517
+            if ($evaluation === FALSE) {
518
+                exit(1);
519
+            }
520
+            list($idp, $profile) = $evaluation;
521
+            // tear apart the serial
522
+            $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL);
523
+            if ($serialRaw === FALSE) {
524
+                exit(1);
525
+            }
526
+            $serial = explode(":", $serialRaw);
527
+            $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]);
528
+            if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) {
529
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found.");
530
+            }
531
+            if ($cert->profileId != $profile->identifier) {
532
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile.");
533
+            }
534
+            $annotationRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTANNOTATION);
535
+            if ($annotationRaw === FALSE) {
536
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Unable to extract annotation.");
537
+                break;
538
+            }
539
+            $annotation = json_decode($annotationRaw, TRUE);
540
+            $cert->annotate($annotation);
541
+            $adminApi->returnSuccess([]);
542 542
         
543
-        break;
543
+            break;
544 544
         
545
-    default:
546
-        $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_ACTION, "Not implemented yet.");
545
+        default:
546
+            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_ACTION, "Not implemented yet.");
547 547
 }
548 548
\ No newline at end of file
Please login to merge, or discard this patch.