Passed
Push — release_2_0 ( f474b2...fbceb4 )
by Stefan
07:29
created
web/admin/API.php 1 patch
Switch Indentation   +368 added lines, -368 removed lines patch added patch discarded remove patch
@@ -115,213 +115,213 @@  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
-        $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;
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
                     $profile->setUserExpiryDate($user, $expiry);
330 330
                     $retval = 1; // function doesn't have any failure vectors not raising an Exception and doesn't return a value
331 331
                     break;
332
-            }
332
+                }
333 333
         } catch (Exception $e) {
334 334
             $adminApi->returnError(web\lib\admin\API::ERROR_INTERNAL_ERROR, "The operation failed. Maybe a duplicate username, or malformed expiry date?");
335 335
             exit(1);
@@ -340,25 +340,25 @@  discard block
 block discarded – undo
340 340
         }
341 341
         $adminApi->returnSuccess([web\lib\admin\API::AUXATTRIB_SB_USERNAME => $user, \web\lib\admin\API::AUXATTRIB_SB_USERID => $retval]);
342 342
         break;
343
-    case \web\lib\admin\API::ACTION_ENDUSER_DEACTIVATE:
344
-    // fall-through intended: both actions are very similar
345
-    case \web\lib\admin\API::ACTION_TOKEN_NEW:
346
-        $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
347
-        if ($profile_id === FALSE) {
348
-            exit(1);
349
-        }
350
-        $evaluation = commonSbProfileChecks($fed, $profile_id);
351
-        if ($evaluation === FALSE) {
352
-            exit(1);
353
-        }
354
-        list($idp, $profile) = $evaluation;
355
-        $userId = $validator->integer($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID));
356
-        if ($userId === FALSE) {
357
-            $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "User ID is not an integer.");
358
-            exit(1);
359
-        }
360
-        $additionalInfo = [];
361
-        switch ($inputDecoded['ACTION']) { // this is where the two differ
343
+        case \web\lib\admin\API::ACTION_ENDUSER_DEACTIVATE:
344
+        // fall-through intended: both actions are very similar
345
+        case \web\lib\admin\API::ACTION_TOKEN_NEW:
346
+            $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
347
+            if ($profile_id === FALSE) {
348
+                exit(1);
349
+            }
350
+            $evaluation = commonSbProfileChecks($fed, $profile_id);
351
+            if ($evaluation === FALSE) {
352
+                exit(1);
353
+            }
354
+            list($idp, $profile) = $evaluation;
355
+            $userId = $validator->integer($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID));
356
+            if ($userId === FALSE) {
357
+                $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "User ID is not an integer.");
358
+                exit(1);
359
+            }
360
+            $additionalInfo = [];
361
+            switch ($inputDecoded['ACTION']) { // this is where the two differ
362 362
             case \web\lib\admin\API::ACTION_ENDUSER_DEACTIVATE:
363 363
                 $result = $profile->deactivateUser($userId);
364 364
                 break;
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
                     }
392 392
                 }
393 393
                 break;
394
-        }
394
+            }
395 395
 
396 396
         if ($result !== TRUE) {
397 397
             $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "These parameters did not lead to an existing, active user.");
@@ -399,70 +399,70 @@  discard block
 block discarded – undo
399 399
         }
400 400
         $adminApi->returnSuccess($additionalInfo);
401 401
         break;
402
-    case \web\lib\admin\API::ACTION_ENDUSER_IDENTIFY:
403
-        $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
404
-        if ($profile_id === FALSE) {
405
-            exit(1);
406
-        }
407
-        $evaluation = commonSbProfileChecks($fed, $profile_id);
408
-        if ($evaluation === FALSE) {
409
-            exit(1);
410
-        }
411
-        list($idp, $profile) = $evaluation;
412
-        $userId = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID);
413
-        $userName = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERNAME);
414
-        $certSerial = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL);
415
-        if ($userId === FALSE && $userName === FALSE && $certSerial === FALSE) {
416
-            // we need at least one of those
417
-            $adminApi->returnError(\web\lib\admin\API::ERROR_MISSING_PARAMETER, "At least one of User ID, Username, or certificate serial is required.");
418
-        }
419
-        $userlist = $profile->listAllUsers();
420
-        if ($userName === FALSE && $certSerial === FALSE) { // we got a user ID
421
-            if (!isset($userlist[$userId])) {
422
-                $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "This user ID does not exist in this profile.");
402
+        case \web\lib\admin\API::ACTION_ENDUSER_IDENTIFY:
403
+            $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
404
+            if ($profile_id === FALSE) {
405
+                exit(1);
406
+            }
407
+            $evaluation = commonSbProfileChecks($fed, $profile_id);
408
+            if ($evaluation === FALSE) {
409
+                exit(1);
410
+            }
411
+            list($idp, $profile) = $evaluation;
412
+            $userId = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID);
413
+            $userName = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERNAME);
414
+            $certSerial = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL);
415
+            if ($userId === FALSE && $userName === FALSE && $certSerial === FALSE) {
416
+                // we need at least one of those
417
+                $adminApi->returnError(\web\lib\admin\API::ERROR_MISSING_PARAMETER, "At least one of User ID, Username, or certificate serial is required.");
418
+            }
419
+            $userlist = $profile->listAllUsers();
420
+            if ($userName === FALSE && $certSerial === FALSE) { // we got a user ID
421
+                if (!isset($userlist[$userId])) {
422
+                    $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "This user ID does not exist in this profile.");
423
+                    break;
424
+                }
425
+                $adminApi->returnSuccess([$userId => $userlist[$userId]]);
423 426
                 break;
424 427
             }
425
-            $adminApi->returnSuccess([$userId => $userlist[$userId]]);
426
-            break;
427
-        }
428
-        if ($userId === FALSE && $certSerial === FALSE) { // we got a username
429
-            $key = array_search($userName, $userlist);
430
-            if ($key === FALSE) {
431
-                $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "This username does not exist in this profile.");
428
+            if ($userId === FALSE && $certSerial === FALSE) { // we got a username
429
+                $key = array_search($userName, $userlist);
430
+                if ($key === FALSE) {
431
+                    $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "This username does not exist in this profile.");
432
+                    break;
433
+                }
434
+                $adminApi->returnSuccess([$key => $userlist[$key]]);
435
+                break;
436
+            }
437
+            if ($userId === FALSE && $userName === FALSE) { // we got a cert serial
438
+                $serial = explode(":", $certSerial);
439
+                $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]);
440
+                if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) {
441
+                    $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found.");
442
+                }
443
+                if ($cert->profileId != $profile->identifier) {
444
+                    $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile.");
445
+                }
446
+                $adminApi->returnSuccess([$cert->userId => $userlist[$cert->userId]]);
432 447
                 break;
433 448
             }
434
-            $adminApi->returnSuccess([$key => $userlist[$key]]);
449
+            $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "Only exactly one of User ID, username or cert serial can be specified.");
435 450
             break;
436
-        }
437
-        if ($userId === FALSE && $userName === FALSE) { // we got a cert serial
438
-            $serial = explode(":", $certSerial);
439
-            $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]);
440
-            if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) {
441
-                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found.");
451
+        case \web\lib\admin\API::ACTION_ENDUSER_LIST:
452
+        // fall-through: those two are similar
453
+        case \web\lib\admin\API::ACTION_TOKEN_LIST:
454
+            $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
455
+            if ($profile_id === FALSE) {
456
+                exit(1);
442 457
             }
443
-            if ($cert->profileId != $profile->identifier) {
444
-                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile.");
458
+            $evaluation = commonSbProfileChecks($fed, $profile_id);
459
+            if ($evaluation === FALSE) {
460
+                exit(1);
445 461
             }
446
-            $adminApi->returnSuccess([$cert->userId => $userlist[$cert->userId]]);
447
-            break;
448
-        }
449
-        $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "Only exactly one of User ID, username or cert serial can be specified.");
450
-        break;
451
-    case \web\lib\admin\API::ACTION_ENDUSER_LIST:
452
-    // fall-through: those two are similar
453
-    case \web\lib\admin\API::ACTION_TOKEN_LIST:
454
-        $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
455
-        if ($profile_id === FALSE) {
456
-            exit(1);
457
-        }
458
-        $evaluation = commonSbProfileChecks($fed, $profile_id);
459
-        if ($evaluation === FALSE) {
460
-            exit(1);
461
-        }
462
-        list($idp, $profile) = $evaluation;
463
-        $allUsers = $profile->listAllUsers();
464
-        // this is where they differ
465
-        switch ($inputDecoded['ACTION']) {
462
+            list($idp, $profile) = $evaluation;
463
+            $allUsers = $profile->listAllUsers();
464
+            // this is where they differ
465
+            switch ($inputDecoded['ACTION']) {
466 466
             case \web\lib\admin\API::ACTION_ENDUSER_LIST:
467 467
                 $adminApi->returnSuccess($allUsers);
468 468
                 break;
@@ -481,105 +481,105 @@  discard block
 block discarded – undo
481 481
                     $infoSet[$oneTokenObject->userId] = [\web\lib\admin\API::AUXATTRIB_TOKEN => $oneTokenObject->invitationTokenString, "STATUS" => $oneTokenObject->invitationTokenStatus];
482 482
                 }
483 483
                 $adminApi->returnSuccess($infoSet);
484
-        }
485
-        break;
486
-    case \web\lib\admin\API::ACTION_TOKEN_REVOKE:
487
-        $tokenRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_TOKEN);
488
-        if ($tokenRaw === FALSE) {
489
-            exit(1);
490
-        }
491
-        $token = new core\SilverbulletInvitation($tokenRaw);
492
-        if ($token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_VALID && $token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_PARTIALLY_REDEEMED) {
493
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "This is not a currently valid token.");
494
-            exit(1);
495
-        }
496
-        $token->revokeInvitation();
497
-        $adminApi->returnSuccess([]);
498
-        break;
499
-    case \web\lib\admin\API::ACTION_CERT_LIST:
500
-        $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
501
-        $user_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID);
502
-        if ($prof_id === FALSE || !is_int($user_id)) {
503
-            exit(1);
504
-        }
505
-        $evaluation = commonSbProfileChecks($fed, $prof_id);
506
-        if ($evaluation === FALSE) {
507
-            exit(1);
508
-        }
509
-        list($idp, $profile) = $evaluation;
510
-        $invitations = $profile->userStatus($user_id);
511
-        // now pull out cert information from the object
512
-        $certs = [];
513
-        foreach ($invitations as $oneInvitation) {
514
-            $certs = array_merge($certs, $oneInvitation->associatedCertificates);
515
-        }
516
-        // extract relevant subset of information from cert objects
517
-        $certDetails = [];
518
-        foreach ($certs as $cert) {
519
-            $certDetails[$cert->ca_type . ":" . $cert->serial] = ["ISSUED" => $cert->issued, "EXPIRY" => $cert->expiry, "STATUS" => $cert->status, "DEVICE" => $cert->device, "CN" => $cert->username, "ANNOTATION" => $cert->annotation];
520
-        }
521
-        $adminApi->returnSuccess($certDetails);
522
-        break;
523
-    case \web\lib\admin\API::ACTION_CERT_REVOKE:
524
-        $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
525
-        if ($prof_id === FALSE) {
526
-            exit(1);
527
-        }
528
-        $evaluation = commonSbProfileChecks($fed, $prof_id);
529
-        if ($evaluation === FALSE) {
530
-            exit(1);
531
-        }
532
-        list($idp, $profile) = $evaluation;
533
-        // tear apart the serial
534
-        $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL);
535
-        if ($serialRaw === FALSE) {
536
-            exit(1);
537
-        }
538
-        $serial = explode(":", $serialRaw);
539
-        $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]);
540
-        if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) {
541
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found.");
542
-        }
543
-        if ($cert->profileId != $profile->identifier) {
544
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile.");
545
-        }
546
-        $cert->revokeCertificate();
547
-        $adminApi->returnSuccess([]);
484
+            }
548 485
         break;
549
-    case \web\lib\admin\API::ACTION_CERT_ANNOTATE:
550
-        $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
551
-        if ($prof_id === FALSE) {
552
-            exit(1);
553
-        }
554
-        $evaluation = commonSbProfileChecks($fed, $prof_id);
555
-        if ($evaluation === FALSE) {
556
-            exit(1);
557
-        }
558
-        list($idp, $profile) = $evaluation;
559
-        // tear apart the serial
560
-        $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL);
561
-        if ($serialRaw === FALSE) {
562
-            exit(1);
563
-        }
564
-        $serial = explode(":", $serialRaw);
565
-        $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]);
566
-        if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) {
567
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found.");
568
-        }
569
-        if ($cert->profileId != $profile->identifier) {
570
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile.");
571
-        }
572
-        $annotationRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTANNOTATION);
573
-        if ($annotationRaw === FALSE) {
574
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Unable to extract annotation.");
486
+        case \web\lib\admin\API::ACTION_TOKEN_REVOKE:
487
+            $tokenRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_TOKEN);
488
+            if ($tokenRaw === FALSE) {
489
+                exit(1);
490
+            }
491
+            $token = new core\SilverbulletInvitation($tokenRaw);
492
+            if ($token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_VALID && $token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_PARTIALLY_REDEEMED) {
493
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "This is not a currently valid token.");
494
+                exit(1);
495
+            }
496
+            $token->revokeInvitation();
497
+            $adminApi->returnSuccess([]);
575 498
             break;
576
-        }
577
-        $annotation = json_decode($annotationRaw, TRUE);
578
-        $cert->annotate($annotation);
579
-        $adminApi->returnSuccess([]);
499
+        case \web\lib\admin\API::ACTION_CERT_LIST:
500
+            $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
501
+            $user_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID);
502
+            if ($prof_id === FALSE || !is_int($user_id)) {
503
+                exit(1);
504
+            }
505
+            $evaluation = commonSbProfileChecks($fed, $prof_id);
506
+            if ($evaluation === FALSE) {
507
+                exit(1);
508
+            }
509
+            list($idp, $profile) = $evaluation;
510
+            $invitations = $profile->userStatus($user_id);
511
+            // now pull out cert information from the object
512
+            $certs = [];
513
+            foreach ($invitations as $oneInvitation) {
514
+                $certs = array_merge($certs, $oneInvitation->associatedCertificates);
515
+            }
516
+            // extract relevant subset of information from cert objects
517
+            $certDetails = [];
518
+            foreach ($certs as $cert) {
519
+                $certDetails[$cert->ca_type . ":" . $cert->serial] = ["ISSUED" => $cert->issued, "EXPIRY" => $cert->expiry, "STATUS" => $cert->status, "DEVICE" => $cert->device, "CN" => $cert->username, "ANNOTATION" => $cert->annotation];
520
+            }
521
+            $adminApi->returnSuccess($certDetails);
522
+            break;
523
+        case \web\lib\admin\API::ACTION_CERT_REVOKE:
524
+            $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
525
+            if ($prof_id === FALSE) {
526
+                exit(1);
527
+            }
528
+            $evaluation = commonSbProfileChecks($fed, $prof_id);
529
+            if ($evaluation === FALSE) {
530
+                exit(1);
531
+            }
532
+            list($idp, $profile) = $evaluation;
533
+            // tear apart the serial
534
+            $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL);
535
+            if ($serialRaw === FALSE) {
536
+                exit(1);
537
+            }
538
+            $serial = explode(":", $serialRaw);
539
+            $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]);
540
+            if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) {
541
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found.");
542
+            }
543
+            if ($cert->profileId != $profile->identifier) {
544
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile.");
545
+            }
546
+            $cert->revokeCertificate();
547
+            $adminApi->returnSuccess([]);
548
+            break;
549
+        case \web\lib\admin\API::ACTION_CERT_ANNOTATE:
550
+            $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
551
+            if ($prof_id === FALSE) {
552
+                exit(1);
553
+            }
554
+            $evaluation = commonSbProfileChecks($fed, $prof_id);
555
+            if ($evaluation === FALSE) {
556
+                exit(1);
557
+            }
558
+            list($idp, $profile) = $evaluation;
559
+            // tear apart the serial
560
+            $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL);
561
+            if ($serialRaw === FALSE) {
562
+                exit(1);
563
+            }
564
+            $serial = explode(":", $serialRaw);
565
+            $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]);
566
+            if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) {
567
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found.");
568
+            }
569
+            if ($cert->profileId != $profile->identifier) {
570
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile.");
571
+            }
572
+            $annotationRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTANNOTATION);
573
+            if ($annotationRaw === FALSE) {
574
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Unable to extract annotation.");
575
+                break;
576
+            }
577
+            $annotation = json_decode($annotationRaw, TRUE);
578
+            $cert->annotate($annotation);
579
+            $adminApi->returnSuccess([]);
580 580
 
581
-        break;
581
+            break;
582 582
 
583
-    default:
584
-        $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_ACTION, "Not implemented yet.");
583
+        default:
584
+            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_ACTION, "Not implemented yet.");
585 585
 }
586 586
\ No newline at end of file
Please login to merge, or discard this patch.