Passed
Push — release_2_1 ( 156650...595abe )
by Stefan
11:50
created
web/admin/API.php 2 patches
Switch Indentation   +384 added lines, -384 removed lines patch added patch discarded remove patch
@@ -84,230 +84,230 @@  discard block
 block discarded – undo
84 84
 }
85 85
 
86 86
 switch ($inputDecoded['ACTION']) {
87
-    case web\lib\admin\API::ACTION_NEWINST:
88
-        // create the inst, no admin, no attributes
89
-        $typeRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_INSTTYPE);
90
-        if ($typeRaw === FALSE) {
91
-            throw new Exception("We did not receive a valid participant type!");
92
-        }
93
-        $type = $validator->partType($typeRaw);
94
-        $idp = new \core\IdP($fed->newIdP($type, "PENDING", "API"));
95
-        // now add all submitted attributes
96
-        $inputs = $adminApi->uglify($scrubbedParameters);
97
-        $optionParser->processSubmittedFields($idp, $inputs["POST"], $inputs["FILES"]);
98
-        $adminApi->returnSuccess([web\lib\admin\API::AUXATTRIB_CAT_INST_ID => $idp->identifier]);
99
-        break;
100
-    case web\lib\admin\API::ACTION_DELINST:
101
-        try {
102
-            $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID), NULL, $fed);
103
-        } catch (Exception $e) {
104
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
105
-            exit(1);
106
-        }
107
-        $idp->destroy();
108
-        $adminApi->returnSuccess([]);
109
-        break;
110
-    case web\lib\admin\API::ACTION_ADMIN_LIST:
111
-        try {
112
-            $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID), NULL, $fed);
113
-        } catch (Exception $e) {
114
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
115
-            exit(1);
116
-        }
117
-        $adminApi->returnSuccess($idp->listOwners());
118
-        break;
119
-    case web\lib\admin\API::ACTION_ADMIN_ADD:
120
-        // IdP in question
121
-        try {
122
-            $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID), NULL, $fed);
123
-        } catch (Exception $e) {
124
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
125
-            exit(1);
126
-        }
127
-        // here is the token
128
-        $mgmt = new core\UserManagement();
129
-        // we know we have an admin ID but scrutinizer wants this checked more explicitly
130
-        $admin = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_ADMINID);
131
-        if ($admin === FALSE) {
132
-            throw new Exception("A required parameter is missing, and this wasn't caught earlier?!");
133
-        }
134
-        $newtokens = $mgmt->createTokens(true, [$admin], $idp);
135
-        $URL = "https://" . $_SERVER['SERVER_NAME'] . dirname($_SERVER['SCRIPT_NAME']) . "/action_enrollment.php?token=" . array_keys($newtokens)[0];
136
-        $success = ["TOKEN URL" => $URL, "TOKEN" => array_keys($newtokens)[0]];
137
-        // done with the essentials - display in response. But if we also have an email address, send it there
138
-        $email = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_TARGETMAIL);
139
-        if ($email !== FALSE) {
140
-            $sent = \core\common\OutsideComm::adminInvitationMail($email, "EXISTING-FED", array_keys($newtokens)[0], $idp->name, $fed, $idp->type);
141
-            $success["EMAIL SENT"] = $sent["SENT"];
142
-            if ($sent["SENT"] === TRUE) {
143
-                $success["EMAIL TRANSPORT SECURE"] = $sent["TRANSPORT"];
87
+        case web\lib\admin\API::ACTION_NEWINST:
88
+            // create the inst, no admin, no attributes
89
+            $typeRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_INSTTYPE);
90
+            if ($typeRaw === FALSE) {
91
+                throw new Exception("We did not receive a valid participant type!");
144 92
             }
145
-        }
146
-        $adminApi->returnSuccess($success);
147
-        break;
148
-    case web\lib\admin\API::ACTION_ADMIN_DEL:
149
-        // IdP in question
150
-        try {
151
-            $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID), NULL, $fed);
152
-        } catch (Exception $e) {
153
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
154
-            exit(1);
155
-        }
156
-        $currentAdmins = $idp->listOwners();
157
-        $toBeDeleted = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_ADMINID);
158
-        if ($toBeDeleted === FALSE) {
159
-            throw new Exception("A required parameter is missing, and this wasn't caught earlier?!");
160
-        }
161
-        $found = FALSE;
162
-        foreach ($currentAdmins as $oneAdmin) {
163
-            if ($oneAdmin['MAIL'] == $toBeDeleted) {
164
-                $found = TRUE;
165
-                $mgmt = new core\UserManagement();
166
-                $mgmt->removeAdminFromIdP($idp, $oneAdmin['ID']);
93
+            $type = $validator->partType($typeRaw);
94
+            $idp = new \core\IdP($fed->newIdP($type, "PENDING", "API"));
95
+            // now add all submitted attributes
96
+            $inputs = $adminApi->uglify($scrubbedParameters);
97
+            $optionParser->processSubmittedFields($idp, $inputs["POST"], $inputs["FILES"]);
98
+            $adminApi->returnSuccess([web\lib\admin\API::AUXATTRIB_CAT_INST_ID => $idp->identifier]);
99
+            break;
100
+        case web\lib\admin\API::ACTION_DELINST:
101
+            try {
102
+                $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID), NULL, $fed);
103
+            } catch (Exception $e) {
104
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
105
+                exit(1);
167 106
             }
168
-        }
169
-        if ($found) {
107
+            $idp->destroy();
170 108
             $adminApi->returnSuccess([]);
171
-        }
172
-        $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "The admin with ID $toBeDeleted is not associated to IdP " . $idp->identifier);
173
-        break;
174
-    case web\lib\admin\API::ACTION_STATISTICS_FED:
175
-        $adminApi->returnSuccess($fed->downloadStats("array"));
176
-        break;
177
-    case \web\lib\admin\API::ACTION_FEDERATION_LISTIDP:
178
-        $retArray = [];
179
-        $idpIdentifier = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID);
180
-        if ($idpIdentifier === FALSE) {
181
-            $allIdPs = $fed->listIdentityProviders(0);
182
-            foreach ($allIdPs as $instanceId => $oneIdP) {
183
-                $theIdP = $oneIdP["instance"];
184
-                $retArray[$instanceId] = $theIdP->getAttributes();
185
-            }
186
-        } else {
109
+            break;
110
+        case web\lib\admin\API::ACTION_ADMIN_LIST:
187 111
             try {
188
-                $thisIdP = $validator->existingIdP($idpIdentifier, NULL, $fed);
112
+                $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID), NULL, $fed);
189 113
             } catch (Exception $e) {
190 114
                 $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
191 115
                 exit(1);
192 116
             }
193
-            $retArray[$idpIdentifier] = $thisIdP->getAttributes();
194
-            foreach ($thisIdP->listProfiles() as $oneProfile) {
195
-                $retArray[$idpIdentifier]["PROFILES"][$oneProfile->identifier] = $oneProfile->getAttributes();
117
+            $adminApi->returnSuccess($idp->listOwners());
118
+            break;
119
+        case web\lib\admin\API::ACTION_ADMIN_ADD:
120
+            // IdP in question
121
+            try {
122
+                $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID), NULL, $fed);
123
+            } catch (Exception $e) {
124
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
125
+                exit(1);
196 126
             }
197
-        }
198
-        foreach ($retArray as $instNumber => $oneInstData) {
199
-            foreach ($oneInstData as $attribNumber => $oneAttrib) {
200
-                if ($oneAttrib['name'] == "general:logo_file") {
201
-                    // JSON doesn't cope well with raw binary data, so b64 it
202
-                    $retArray[$instNumber][$attribNumber]['value'] = base64_encode($oneAttrib['value']);
203
-                    if ($attribNumber == "PROFILES") {
204
-                        // scan for included fed:logo_file and b64 escape it, t2oo
205
-                        foreach ($oneAttrib as $profileNumber => $profileContent) {
206
-                                foreach ($profileContent as $oneProfileIterator => $oneProfileContent) {
207
-                                        if ($oneProfileContent['name'] == "fed:logo_file")
208
-                                                $retArray[$instNumber]["PROFILES"][$profileNumber][$oneProfileIterator]['value'] = base64_encode($oneProfileContent['value']);
209
-                                        }
210
-                                }
211
-                        }
127
+            // here is the token
128
+            $mgmt = new core\UserManagement();
129
+            // we know we have an admin ID but scrutinizer wants this checked more explicitly
130
+            $admin = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_ADMINID);
131
+            if ($admin === FALSE) {
132
+                throw new Exception("A required parameter is missing, and this wasn't caught earlier?!");
133
+            }
134
+            $newtokens = $mgmt->createTokens(true, [$admin], $idp);
135
+            $URL = "https://" . $_SERVER['SERVER_NAME'] . dirname($_SERVER['SCRIPT_NAME']) . "/action_enrollment.php?token=" . array_keys($newtokens)[0];
136
+            $success = ["TOKEN URL" => $URL, "TOKEN" => array_keys($newtokens)[0]];
137
+            // done with the essentials - display in response. But if we also have an email address, send it there
138
+            $email = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_TARGETMAIL);
139
+            if ($email !== FALSE) {
140
+                $sent = \core\common\OutsideComm::adminInvitationMail($email, "EXISTING-FED", array_keys($newtokens)[0], $idp->name, $fed, $idp->type);
141
+                $success["EMAIL SENT"] = $sent["SENT"];
142
+                if ($sent["SENT"] === TRUE) {
143
+                    $success["EMAIL TRANSPORT SECURE"] = $sent["TRANSPORT"];
212 144
                 }
213 145
             }
214
-        }
215
-        $adminApi->returnSuccess($retArray);
216
-        break;
217
-    case \web\lib\admin\API::ACTION_NEWPROF_RADIUS:
218
-    // fall-through intended: both get mostly identical treatment
219
-    case web\lib\admin\API::ACTION_NEWPROF_SB:
220
-        try {
221
-            $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID), NULL, $fed);
222
-        } catch (Exception $e) {
223
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
224
-            exit(1);
225
-        }
226
-        if ($inputDecoded['ACTION'] == web\lib\admin\API::ACTION_NEWPROF_RADIUS) {
227
-            $type = "RADIUS";
228
-        } else {
229
-            $type = "SILVERBULLET";
230
-        }
231
-        $profile = $idp->newProfile($type);
232
-        if ($profile === NULL) {
233
-            $adminApi->returnError(\web\lib\admin\API::ERROR_INTERNAL_ERROR, "Unable to create a new Profile, for no apparent reason. Please contact support.");
234
-            exit(1);
235
-        }
236
-        $inputs = $adminApi->uglify($scrubbedParameters);
237
-        $optionParser->processSubmittedFields($profile, $inputs["POST"], $inputs["FILES"]);
238
-        if ($inputDecoded['ACTION'] == web\lib\admin\API::ACTION_NEWPROF_SB) {
239
-            // auto-accept ToU?
240
-            if ($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_TOU) !== FALSE) {
241
-                $profile->addAttribute("hiddenprofile:tou_accepted", NULL, 1);
242
-            }
243
-            // we're done at this point
244
-            $adminApi->returnSuccess([\web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID => $profile->identifier]);
146
+            $adminApi->returnSuccess($success);
245 147
             break;
246
-        }
247
-        if (!$profile instanceof core\ProfileRADIUS) {
248
-            throw new Exception("Can't be. This is only here to convince Scrutinizer that we're really talking RADIUS.");
249
-        }
250
-        /* const AUXATTRIB_PROFILE_REALM = 'ATTRIB-PROFILE-REALM';
251
-          const AUXATTRIB_PROFILE_OUTERVALUE = 'ATTRIB-PROFILE-OUTERVALUE'; */
252
-        $realm = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_REALM);
253
-        $outer = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_OUTERVALUE);
254
-        if ($realm !== FALSE) {
255
-            if ($outer === FALSE) {
256
-                $outer = "";
257
-                $profile->setAnonymousIDSupport(FALSE);
148
+        case web\lib\admin\API::ACTION_ADMIN_DEL:
149
+            // IdP in question
150
+            try {
151
+                $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID), NULL, $fed);
152
+            } catch (Exception $e) {
153
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
154
+                exit(1);
155
+            }
156
+            $currentAdmins = $idp->listOwners();
157
+            $toBeDeleted = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_ADMINID);
158
+            if ($toBeDeleted === FALSE) {
159
+                throw new Exception("A required parameter is missing, and this wasn't caught earlier?!");
160
+            }
161
+            $found = FALSE;
162
+            foreach ($currentAdmins as $oneAdmin) {
163
+                if ($oneAdmin['MAIL'] == $toBeDeleted) {
164
+                    $found = TRUE;
165
+                    $mgmt = new core\UserManagement();
166
+                    $mgmt->removeAdminFromIdP($idp, $oneAdmin['ID']);
167
+                }
168
+            }
169
+            if ($found) {
170
+                $adminApi->returnSuccess([]);
171
+            }
172
+            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "The admin with ID $toBeDeleted is not associated to IdP " . $idp->identifier);
173
+            break;
174
+        case web\lib\admin\API::ACTION_STATISTICS_FED:
175
+            $adminApi->returnSuccess($fed->downloadStats("array"));
176
+            break;
177
+        case \web\lib\admin\API::ACTION_FEDERATION_LISTIDP:
178
+            $retArray = [];
179
+            $idpIdentifier = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID);
180
+            if ($idpIdentifier === FALSE) {
181
+                $allIdPs = $fed->listIdentityProviders(0);
182
+                foreach ($allIdPs as $instanceId => $oneIdP) {
183
+                    $theIdP = $oneIdP["instance"];
184
+                    $retArray[$instanceId] = $theIdP->getAttributes();
185
+                }
258 186
             } else {
259
-                $outer = $outer . "@";
260
-                $profile->setAnonymousIDSupport(TRUE);
187
+                try {
188
+                    $thisIdP = $validator->existingIdP($idpIdentifier, NULL, $fed);
189
+                } catch (Exception $e) {
190
+                    $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
191
+                    exit(1);
192
+                }
193
+                $retArray[$idpIdentifier] = $thisIdP->getAttributes();
194
+                foreach ($thisIdP->listProfiles() as $oneProfile) {
195
+                    $retArray[$idpIdentifier]["PROFILES"][$oneProfile->identifier] = $oneProfile->getAttributes();
196
+                }
261 197
             }
262
-            $profile->setRealm($outer . $realm);
263
-        }
264
-        /* const AUXATTRIB_PROFILE_TESTUSER = 'ATTRIB-PROFILE-TESTUSER'; */
265
-        $testuser = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_TESTUSER);
266
-        if ($testuser !== FALSE) {
267
-            $profile->setRealmCheckUser(TRUE, $testuser);
268
-        }
269
-        /* const AUXATTRIB_PROFILE_INPUT_HINT = 'ATTRIB-PROFILE-HINTREALM';
198
+            foreach ($retArray as $instNumber => $oneInstData) {
199
+                foreach ($oneInstData as $attribNumber => $oneAttrib) {
200
+                    if ($oneAttrib['name'] == "general:logo_file") {
201
+                        // JSON doesn't cope well with raw binary data, so b64 it
202
+                        $retArray[$instNumber][$attribNumber]['value'] = base64_encode($oneAttrib['value']);
203
+                        if ($attribNumber == "PROFILES") {
204
+                            // scan for included fed:logo_file and b64 escape it, t2oo
205
+                            foreach ($oneAttrib as $profileNumber => $profileContent) {
206
+                                    foreach ($profileContent as $oneProfileIterator => $oneProfileContent) {
207
+                                            if ($oneProfileContent['name'] == "fed:logo_file")
208
+                                                    $retArray[$instNumber]["PROFILES"][$profileNumber][$oneProfileIterator]['value'] = base64_encode($oneProfileContent['value']);
209
+                                            }
210
+                                    }
211
+                            }
212
+                    }
213
+                }
214
+            }
215
+            $adminApi->returnSuccess($retArray);
216
+            break;
217
+        case \web\lib\admin\API::ACTION_NEWPROF_RADIUS:
218
+        // fall-through intended: both get mostly identical treatment
219
+        case web\lib\admin\API::ACTION_NEWPROF_SB:
220
+            try {
221
+                $idp = $validator->existingIdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID), NULL, $fed);
222
+            } catch (Exception $e) {
223
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!");
224
+                exit(1);
225
+            }
226
+            if ($inputDecoded['ACTION'] == web\lib\admin\API::ACTION_NEWPROF_RADIUS) {
227
+                $type = "RADIUS";
228
+            } else {
229
+                $type = "SILVERBULLET";
230
+            }
231
+            $profile = $idp->newProfile($type);
232
+            if ($profile === NULL) {
233
+                $adminApi->returnError(\web\lib\admin\API::ERROR_INTERNAL_ERROR, "Unable to create a new Profile, for no apparent reason. Please contact support.");
234
+                exit(1);
235
+            }
236
+            $inputs = $adminApi->uglify($scrubbedParameters);
237
+            $optionParser->processSubmittedFields($profile, $inputs["POST"], $inputs["FILES"]);
238
+            if ($inputDecoded['ACTION'] == web\lib\admin\API::ACTION_NEWPROF_SB) {
239
+                // auto-accept ToU?
240
+                if ($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_TOU) !== FALSE) {
241
+                    $profile->addAttribute("hiddenprofile:tou_accepted", NULL, 1);
242
+                }
243
+                // we're done at this point
244
+                $adminApi->returnSuccess([\web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID => $profile->identifier]);
245
+                break;
246
+            }
247
+            if (!$profile instanceof core\ProfileRADIUS) {
248
+                throw new Exception("Can't be. This is only here to convince Scrutinizer that we're really talking RADIUS.");
249
+            }
250
+            /* const AUXATTRIB_PROFILE_REALM = 'ATTRIB-PROFILE-REALM';
251
+          const AUXATTRIB_PROFILE_OUTERVALUE = 'ATTRIB-PROFILE-OUTERVALUE'; */
252
+            $realm = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_REALM);
253
+            $outer = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_OUTERVALUE);
254
+            if ($realm !== FALSE) {
255
+                if ($outer === FALSE) {
256
+                    $outer = "";
257
+                    $profile->setAnonymousIDSupport(FALSE);
258
+                } else {
259
+                    $outer = $outer . "@";
260
+                    $profile->setAnonymousIDSupport(TRUE);
261
+                }
262
+                $profile->setRealm($outer . $realm);
263
+            }
264
+            /* const AUXATTRIB_PROFILE_TESTUSER = 'ATTRIB-PROFILE-TESTUSER'; */
265
+            $testuser = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_TESTUSER);
266
+            if ($testuser !== FALSE) {
267
+                $profile->setRealmCheckUser(TRUE, $testuser);
268
+            }
269
+            /* const AUXATTRIB_PROFILE_INPUT_HINT = 'ATTRIB-PROFILE-HINTREALM';
270 270
           const AUXATTRIB_PROFILE_INPUT_VERIFY = 'ATTRIB-PROFILE-VERIFYREALM'; */
271
-        $hint = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_INPUT_HINT);
272
-        $enforce = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_INPUT_VERIFY);
273
-        if ($enforce !== FALSE) {
274
-            $profile->setInputVerificationPreference($enforce, $hint);
275
-        }
276
-        /* const AUXATTRIB_PROFILE_EAPTYPE */
277
-        $iterator = 1;
278
-        foreach ($scrubbedParameters as $oneParam) {
279
-            if ($oneParam['NAME'] == web\lib\admin\API::AUXATTRIB_PROFILE_EAPTYPE && is_int($oneParam["VALUE"])) {
280
-                $type = new \core\common\EAP($oneParam["VALUE"]);
281
-                $profile->addSupportedEapMethod($type, $iterator);
282
-                $iterator = $iterator + 1;
271
+            $hint = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_INPUT_HINT);
272
+            $enforce = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_INPUT_VERIFY);
273
+            if ($enforce !== FALSE) {
274
+                $profile->setInputVerificationPreference($enforce, $hint);
283 275
             }
284
-        }
285
-        // reinstantiate $profile freshly from DB - it was updated in the process
286
-        $profileFresh = new core\ProfileRADIUS($profile->identifier);
287
-        $profileFresh->prepShowtime();
288
-        $adminApi->returnSuccess([\web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID => $profileFresh->identifier]);
289
-        break;
290
-    case web\lib\admin\API::ACTION_ENDUSER_NEW:
291
-    // fall-through intentional, those two actions are doing nearly identical things
292
-    case web\lib\admin\API::ACTION_ENDUSER_CHANGEEXPIRY:
293
-        $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
294
-        if ($prof_id === FALSE) {
295
-            exit(1);
296
-        }
297
-        $evaluation = $adminApi->commonSbProfileChecks($fed, $prof_id);
298
-        if ($evaluation === FALSE) {
299
-            exit(1);
300
-        }
301
-        list($idp, $profile) = $evaluation;
302
-        $user = $validator->string($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERNAME));
303
-        $expiryRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_EXPIRY);
304
-        if ($expiryRaw === FALSE) {
305
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "The expiry date wasn't found in the request.");
276
+            /* const AUXATTRIB_PROFILE_EAPTYPE */
277
+            $iterator = 1;
278
+            foreach ($scrubbedParameters as $oneParam) {
279
+                if ($oneParam['NAME'] == web\lib\admin\API::AUXATTRIB_PROFILE_EAPTYPE && is_int($oneParam["VALUE"])) {
280
+                    $type = new \core\common\EAP($oneParam["VALUE"]);
281
+                    $profile->addSupportedEapMethod($type, $iterator);
282
+                    $iterator = $iterator + 1;
283
+                }
284
+            }
285
+            // reinstantiate $profile freshly from DB - it was updated in the process
286
+            $profileFresh = new core\ProfileRADIUS($profile->identifier);
287
+            $profileFresh->prepShowtime();
288
+            $adminApi->returnSuccess([\web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID => $profileFresh->identifier]);
306 289
             break;
307
-        }
308
-        $expiry = new DateTime($expiryRaw);
309
-        try {
310
-            switch ($inputDecoded['ACTION']) {
290
+        case web\lib\admin\API::ACTION_ENDUSER_NEW:
291
+        // fall-through intentional, those two actions are doing nearly identical things
292
+        case web\lib\admin\API::ACTION_ENDUSER_CHANGEEXPIRY:
293
+            $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
294
+            if ($prof_id === FALSE) {
295
+                exit(1);
296
+            }
297
+            $evaluation = $adminApi->commonSbProfileChecks($fed, $prof_id);
298
+            if ($evaluation === FALSE) {
299
+                exit(1);
300
+            }
301
+            list($idp, $profile) = $evaluation;
302
+            $user = $validator->string($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERNAME));
303
+            $expiryRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_EXPIRY);
304
+            if ($expiryRaw === FALSE) {
305
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "The expiry date wasn't found in the request.");
306
+                break;
307
+            }
308
+            $expiry = new DateTime($expiryRaw);
309
+            try {
310
+                switch ($inputDecoded['ACTION']) {
311 311
                 case web\lib\admin\API::ACTION_ENDUSER_NEW:
312 312
                     $retval = $profile->addUser($user, $expiry);
313 313
                     break;
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
                         $retval = 1; // function doesn't have any failure vectors not raising an Exception and doesn't return a value
321 321
                     }
322 322
                     break;
323
-            }
323
+                }
324 324
         } catch (Exception $e) {
325 325
             $adminApi->returnError(web\lib\admin\API::ERROR_INTERNAL_ERROR, "The operation failed. Maybe a duplicate username, or malformed expiry date?");
326 326
             exit(1);
@@ -331,25 +331,25 @@  discard block
 block discarded – undo
331 331
         }
332 332
         $adminApi->returnSuccess([web\lib\admin\API::AUXATTRIB_SB_USERNAME => $user, \web\lib\admin\API::AUXATTRIB_SB_USERID => $retval]);
333 333
         break;
334
-    case \web\lib\admin\API::ACTION_ENDUSER_DEACTIVATE:
335
-    // fall-through intended: both actions are very similar
336
-    case \web\lib\admin\API::ACTION_TOKEN_NEW:
337
-        $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
338
-        if ($profile_id === FALSE) {
339
-            exit(1);
340
-        }
341
-        $evaluation = $adminApi->commonSbProfileChecks($fed, $profile_id);
342
-        if ($evaluation === FALSE) {
343
-            exit(1);
344
-        }
345
-        list($idp, $profile) = $evaluation;
346
-        $userId = $validator->integer($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID));
347
-        if ($userId === FALSE) {
348
-            $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "User ID is not an integer.");
349
-            exit(1);
350
-        }
351
-        $additionalInfo = [];
352
-        switch ($inputDecoded['ACTION']) { // this is where the two differ
334
+        case \web\lib\admin\API::ACTION_ENDUSER_DEACTIVATE:
335
+        // fall-through intended: both actions are very similar
336
+        case \web\lib\admin\API::ACTION_TOKEN_NEW:
337
+            $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
338
+            if ($profile_id === FALSE) {
339
+                exit(1);
340
+            }
341
+            $evaluation = $adminApi->commonSbProfileChecks($fed, $profile_id);
342
+            if ($evaluation === FALSE) {
343
+                exit(1);
344
+            }
345
+            list($idp, $profile) = $evaluation;
346
+            $userId = $validator->integer($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID));
347
+            if ($userId === FALSE) {
348
+                $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "User ID is not an integer.");
349
+                exit(1);
350
+            }
351
+            $additionalInfo = [];
352
+            switch ($inputDecoded['ACTION']) { // this is where the two differ
353 353
             case \web\lib\admin\API::ACTION_ENDUSER_DEACTIVATE:
354 354
                 $result = $profile->deactivateUser($userId);
355 355
                 break;
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
                     }
383 383
                 }
384 384
                 break;
385
-        }
385
+            }
386 386
 
387 387
         if ($result !== TRUE) {
388 388
             $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "These parameters did not lead to an existing, active user.");
@@ -390,69 +390,69 @@  discard block
 block discarded – undo
390 390
         }
391 391
         $adminApi->returnSuccess($additionalInfo);
392 392
         break;
393
-    case \web\lib\admin\API::ACTION_ENDUSER_IDENTIFY:
394
-        $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
395
-        if ($profile_id === FALSE) {
396
-            exit(1);
397
-        }
398
-        $evaluation = $adminApi->commonSbProfileChecks($fed, $profile_id);
399
-        if ($evaluation === FALSE) {
400
-            exit(1);
401
-        }
402
-        list($idp, $profile) = $evaluation;
403
-        $userId = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID);
404
-        $userName = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERNAME);
405
-        $certSerial = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL);
406
-		$certCN = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTCN);
407
-        if ($userId === FALSE && $userName === FALSE && $certSerial === FALSE && $certCN === FALSE) {
408
-            // we need at least one of those
409
-            $adminApi->returnError(\web\lib\admin\API::ERROR_MISSING_PARAMETER, "At least one of User ID, Username, certificate serial, or certificate CN is required.");
410
-            break;
411
-        }
412
-        if ($certSerial !== FALSE) { // we got a cert serial
413
-            $serial = explode(":", $certSerial);
414
-            $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]);
393
+        case \web\lib\admin\API::ACTION_ENDUSER_IDENTIFY:
394
+            $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
395
+            if ($profile_id === FALSE) {
396
+                exit(1);
415 397
             }
416
-        if ($certCN !== FALSE) { // we got a cert CN
417
-            $cert = new \core\SilverbulletCertificate($certCN);
418
-        }
419
-        if ($cert !== NULL) { // we found a cert; verify it and extract userId
420
-            if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) {
421
-                return $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Certificate not found.");
398
+            $evaluation = $adminApi->commonSbProfileChecks($fed, $profile_id);
399
+            if ($evaluation === FALSE) {
400
+                exit(1);
422 401
             }
423
-            if ($cert->profileId != $profile->identifier) {
424
-                return $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Certificate does not belong to this profile.");
402
+            list($idp, $profile) = $evaluation;
403
+            $userId = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID);
404
+            $userName = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERNAME);
405
+            $certSerial = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL);
406
+		    $certCN = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTCN);
407
+            if ($userId === FALSE && $userName === FALSE && $certSerial === FALSE && $certCN === FALSE) {
408
+                // we need at least one of those
409
+                $adminApi->returnError(\web\lib\admin\API::ERROR_MISSING_PARAMETER, "At least one of User ID, Username, certificate serial, or certificate CN is required.");
410
+                break;
425 411
             }
426
-            $userId = $cert->userId;
427
-        }
428
-        if ($userId !== FALSE) {
429
-            $userList = $profile->getUserById($userId);
430
-        }
431
-        if ($userName !== FALSE) {
432
-            $userList = $profile->getUserByName($userName);
433
-        }
434
-        if (count($userList) === 1) {
435
-            foreach ($userList as $oneUserId => $oneUserName) {
436
-                return $adminApi->returnSuccess([web\lib\admin\API::AUXATTRIB_SB_USERNAME => $oneUserName, \web\lib\admin\API::AUXATTRIB_SB_USERID => $oneUserId]);
412
+            if ($certSerial !== FALSE) { // we got a cert serial
413
+                $serial = explode(":", $certSerial);
414
+                $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]);
415
+                }
416
+            if ($certCN !== FALSE) { // we got a cert CN
417
+                $cert = new \core\SilverbulletCertificate($certCN);
437 418
             }
438
-        }
439
-        $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "No matching user found in this profile.");
440
-        break;
441
-    case \web\lib\admin\API::ACTION_ENDUSER_LIST:
442
-    // fall-through: those two are similar
443
-    case \web\lib\admin\API::ACTION_TOKEN_LIST:
444
-        $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
445
-        if ($profile_id === FALSE) {
446
-            exit(1);
447
-        }
448
-        $evaluation = $adminApi->commonSbProfileChecks($fed, $profile_id);
449
-        if ($evaluation === FALSE) {
450
-            exit(1);
451
-        }
452
-        list($idp, $profile) = $evaluation;
453
-        $allUsers = $profile->listAllUsers();
454
-        // this is where they differ
455
-        switch ($inputDecoded['ACTION']) {
419
+            if ($cert !== NULL) { // we found a cert; verify it and extract userId
420
+                if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) {
421
+                    return $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Certificate not found.");
422
+                }
423
+                if ($cert->profileId != $profile->identifier) {
424
+                    return $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Certificate does not belong to this profile.");
425
+                }
426
+                $userId = $cert->userId;
427
+            }
428
+            if ($userId !== FALSE) {
429
+                $userList = $profile->getUserById($userId);
430
+            }
431
+            if ($userName !== FALSE) {
432
+                $userList = $profile->getUserByName($userName);
433
+            }
434
+            if (count($userList) === 1) {
435
+                foreach ($userList as $oneUserId => $oneUserName) {
436
+                    return $adminApi->returnSuccess([web\lib\admin\API::AUXATTRIB_SB_USERNAME => $oneUserName, \web\lib\admin\API::AUXATTRIB_SB_USERID => $oneUserId]);
437
+                }
438
+            }
439
+            $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "No matching user found in this profile.");
440
+            break;
441
+        case \web\lib\admin\API::ACTION_ENDUSER_LIST:
442
+        // fall-through: those two are similar
443
+        case \web\lib\admin\API::ACTION_TOKEN_LIST:
444
+            $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
445
+            if ($profile_id === FALSE) {
446
+                exit(1);
447
+            }
448
+            $evaluation = $adminApi->commonSbProfileChecks($fed, $profile_id);
449
+            if ($evaluation === FALSE) {
450
+                exit(1);
451
+            }
452
+            list($idp, $profile) = $evaluation;
453
+            $allUsers = $profile->listAllUsers();
454
+            // this is where they differ
455
+            switch ($inputDecoded['ACTION']) {
456 456
             case \web\lib\admin\API::ACTION_ENDUSER_LIST:
457 457
                 $adminApi->returnSuccess($allUsers);
458 458
                 break;
@@ -471,105 +471,105 @@  discard block
 block discarded – undo
471 471
                     $infoSet[$oneTokenObject->userId] = [\web\lib\admin\API::AUXATTRIB_TOKEN => $oneTokenObject->invitationTokenString, "STATUS" => $oneTokenObject->invitationTokenStatus];
472 472
                 }
473 473
                 $adminApi->returnSuccess($infoSet);
474
-        }
475
-        break;
476
-    case \web\lib\admin\API::ACTION_TOKEN_REVOKE:
477
-        $tokenRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_TOKEN);
478
-        if ($tokenRaw === FALSE) {
479
-            exit(1);
480
-        }
481
-        $token = new core\SilverbulletInvitation($tokenRaw);
482
-        if ($token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_VALID && $token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_PARTIALLY_REDEEMED) {
483
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "This is not a currently valid token.");
484
-            exit(1);
485
-        }
486
-        $token->revokeInvitation();
487
-        $adminApi->returnSuccess([]);
488
-        break;
489
-    case \web\lib\admin\API::ACTION_CERT_LIST:
490
-        $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
491
-        $user_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID);
492
-        if ($prof_id === FALSE || !is_int($user_id)) {
493
-            exit(1);
494
-        }
495
-        $evaluation = $adminApi->commonSbProfileChecks($fed, $prof_id);
496
-        if ($evaluation === FALSE) {
497
-            exit(1);
498
-        }
499
-        list($idp, $profile) = $evaluation;
500
-        $invitations = $profile->userStatus($user_id);
501
-        // now pull out cert information from the object
502
-        $certs = [];
503
-        foreach ($invitations as $oneInvitation) {
504
-            $certs = array_merge($certs, $oneInvitation->associatedCertificates);
505
-        }
506
-        // extract relevant subset of information from cert objects
507
-        $certDetails = [];
508
-        foreach ($certs as $cert) {
509
-            $certDetails[$cert->ca_type . ":" . $cert->serial] = ["ISSUED" => $cert->issued, "EXPIRY" => $cert->expiry, "STATUS" => $cert->status, "DEVICE" => $cert->device, "CN" => $cert->username, "ANNOTATION" => $cert->annotation];
510
-        }
511
-        $adminApi->returnSuccess($certDetails);
512
-        break;
513
-    case \web\lib\admin\API::ACTION_CERT_REVOKE:
514
-        $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
515
-        if ($prof_id === FALSE) {
516
-            exit(1);
517
-        }
518
-        $evaluation = $adminApi->commonSbProfileChecks($fed, $prof_id);
519
-        if ($evaluation === FALSE) {
520
-            exit(1);
521
-        }
522
-        list($idp, $profile) = $evaluation;
523
-        // tear apart the serial
524
-        $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL);
525
-        if ($serialRaw === FALSE) {
526
-            exit(1);
527
-        }
528
-        $serial = explode(":", $serialRaw);
529
-        $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]);
530
-        if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) {
531
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found.");
532
-        }
533
-        if ($cert->profileId != $profile->identifier) {
534
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile.");
535
-        }
536
-        $cert->revokeCertificate();
537
-        $adminApi->returnSuccess([]);
474
+            }
538 475
         break;
539
-    case \web\lib\admin\API::ACTION_CERT_ANNOTATE:
540
-        $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
541
-        if ($prof_id === FALSE) {
542
-            exit(1);
543
-        }
544
-        $evaluation = $adminApi->commonSbProfileChecks($fed, $prof_id);
545
-        if ($evaluation === FALSE) {
546
-            exit(1);
547
-        }
548
-        list($idp, $profile) = $evaluation;
549
-        // tear apart the serial
550
-        $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL);
551
-        if ($serialRaw === FALSE) {
552
-            exit(1);
553
-        }
554
-        $serial = explode(":", $serialRaw);
555
-        $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]);
556
-        if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) {
557
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found.");
558
-        }
559
-        if ($cert->profileId != $profile->identifier) {
560
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile.");
561
-        }
562
-        $annotationRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTANNOTATION);
563
-        if ($annotationRaw === FALSE) {
564
-            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Unable to extract annotation.");
476
+        case \web\lib\admin\API::ACTION_TOKEN_REVOKE:
477
+            $tokenRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_TOKEN);
478
+            if ($tokenRaw === FALSE) {
479
+                exit(1);
480
+            }
481
+            $token = new core\SilverbulletInvitation($tokenRaw);
482
+            if ($token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_VALID && $token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_PARTIALLY_REDEEMED) {
483
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "This is not a currently valid token.");
484
+                exit(1);
485
+            }
486
+            $token->revokeInvitation();
487
+            $adminApi->returnSuccess([]);
565 488
             break;
566
-        }
567
-        $annotation = json_decode($annotationRaw, TRUE);
568
-        $cert->annotate($annotation);
569
-        $adminApi->returnSuccess([]);
489
+        case \web\lib\admin\API::ACTION_CERT_LIST:
490
+            $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
491
+            $user_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID);
492
+            if ($prof_id === FALSE || !is_int($user_id)) {
493
+                exit(1);
494
+            }
495
+            $evaluation = $adminApi->commonSbProfileChecks($fed, $prof_id);
496
+            if ($evaluation === FALSE) {
497
+                exit(1);
498
+            }
499
+            list($idp, $profile) = $evaluation;
500
+            $invitations = $profile->userStatus($user_id);
501
+            // now pull out cert information from the object
502
+            $certs = [];
503
+            foreach ($invitations as $oneInvitation) {
504
+                $certs = array_merge($certs, $oneInvitation->associatedCertificates);
505
+            }
506
+            // extract relevant subset of information from cert objects
507
+            $certDetails = [];
508
+            foreach ($certs as $cert) {
509
+                $certDetails[$cert->ca_type . ":" . $cert->serial] = ["ISSUED" => $cert->issued, "EXPIRY" => $cert->expiry, "STATUS" => $cert->status, "DEVICE" => $cert->device, "CN" => $cert->username, "ANNOTATION" => $cert->annotation];
510
+            }
511
+            $adminApi->returnSuccess($certDetails);
512
+            break;
513
+        case \web\lib\admin\API::ACTION_CERT_REVOKE:
514
+            $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
515
+            if ($prof_id === FALSE) {
516
+                exit(1);
517
+            }
518
+            $evaluation = $adminApi->commonSbProfileChecks($fed, $prof_id);
519
+            if ($evaluation === FALSE) {
520
+                exit(1);
521
+            }
522
+            list($idp, $profile) = $evaluation;
523
+            // tear apart the serial
524
+            $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL);
525
+            if ($serialRaw === FALSE) {
526
+                exit(1);
527
+            }
528
+            $serial = explode(":", $serialRaw);
529
+            $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]);
530
+            if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) {
531
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found.");
532
+            }
533
+            if ($cert->profileId != $profile->identifier) {
534
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile.");
535
+            }
536
+            $cert->revokeCertificate();
537
+            $adminApi->returnSuccess([]);
538
+            break;
539
+        case \web\lib\admin\API::ACTION_CERT_ANNOTATE:
540
+            $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID);
541
+            if ($prof_id === FALSE) {
542
+                exit(1);
543
+            }
544
+            $evaluation = $adminApi->commonSbProfileChecks($fed, $prof_id);
545
+            if ($evaluation === FALSE) {
546
+                exit(1);
547
+            }
548
+            list($idp, $profile) = $evaluation;
549
+            // tear apart the serial
550
+            $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL);
551
+            if ($serialRaw === FALSE) {
552
+                exit(1);
553
+            }
554
+            $serial = explode(":", $serialRaw);
555
+            $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]);
556
+            if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) {
557
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found.");
558
+            }
559
+            if ($cert->profileId != $profile->identifier) {
560
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile.");
561
+            }
562
+            $annotationRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTANNOTATION);
563
+            if ($annotationRaw === FALSE) {
564
+                $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Unable to extract annotation.");
565
+                break;
566
+            }
567
+            $annotation = json_decode($annotationRaw, TRUE);
568
+            $cert->annotate($annotation);
569
+            $adminApi->returnSuccess([]);
570 570
 
571
-        break;
571
+            break;
572 572
 
573
-    default:
574
-        $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_ACTION, "Not implemented yet.");
573
+        default:
574
+            $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_ACTION, "Not implemented yet.");
575 575
 }
576 576
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -204,8 +204,9 @@
 block discarded – undo
204 204
                         // scan for included fed:logo_file and b64 escape it, t2oo
205 205
                         foreach ($oneAttrib as $profileNumber => $profileContent) {
206 206
                                 foreach ($profileContent as $oneProfileIterator => $oneProfileContent) {
207
-                                        if ($oneProfileContent['name'] == "fed:logo_file")
208
-                                                $retArray[$instNumber]["PROFILES"][$profileNumber][$oneProfileIterator]['value'] = base64_encode($oneProfileContent['value']);
207
+                                        if ($oneProfileContent['name'] == "fed:logo_file") {
208
+                                                                                        $retArray[$instNumber]["PROFILES"][$profileNumber][$oneProfileIterator]['value'] = base64_encode($oneProfileContent['value']);
209
+                                        }
209 210
                                         }
210 211
                                 }
211 212
                         }
Please login to merge, or discard this patch.