@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | use Exception; |
| 31 | 31 | |
| 32 | -require_once dirname(dirname(dirname(dirname(__FILE__)))) . "/config/_config.php"; |
|
| 32 | +require_once dirname(dirname(dirname(dirname(__FILE__))))."/config/_config.php"; |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * This class defines the various actions doable with the admin API, the |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | const ACTIONS = [ |
| 245 | 245 | // Inst-level actions. |
| 246 | 246 | API::ACTION_NEWINST_BY_REF => [ |
| 247 | - "REQ" => [API::AUXATTRIB_EXTERNALID,], |
|
| 247 | + "REQ" => [API::AUXATTRIB_EXTERNALID, ], |
|
| 248 | 248 | "OPT" => [ |
| 249 | 249 | 'general:geo_coordinates', |
| 250 | 250 | 'general:logo_file', |
@@ -555,8 +555,8 @@ discard block |
||
| 555 | 555 | |
| 556 | 556 | case \core\Options::TYPECODE_COORDINATES: |
| 557 | 557 | $extension = \core\Options::TYPECODE_TEXT; |
| 558 | - $coercedInline["option"][$basename] = $oneAttrib['NAME'] . "#"; |
|
| 559 | - $coercedInline["value"][$basename . "-" . $extension] = $oneAttrib['VALUE']; |
|
| 558 | + $coercedInline["option"][$basename] = $oneAttrib['NAME']."#"; |
|
| 559 | + $coercedInline["value"][$basename."-".$extension] = $oneAttrib['VALUE']; |
|
| 560 | 560 | break; |
| 561 | 561 | case \core\Options::TYPECODE_TEXT: |
| 562 | 562 | // Fall-through: they all get the same treatment. |
@@ -566,18 +566,18 @@ discard block |
||
| 566 | 566 | // Fall-through: they all get the same treatment. |
| 567 | 567 | case \core\Options::TYPECODE_INTEGER: |
| 568 | 568 | $extension = $optionInfo['type']; |
| 569 | - $coercedInline["option"][$basename] = $oneAttrib['NAME'] . "#"; |
|
| 570 | - $coercedInline["value"][$basename . "-" . $extension] = $oneAttrib['VALUE']; |
|
| 569 | + $coercedInline["option"][$basename] = $oneAttrib['NAME']."#"; |
|
| 570 | + $coercedInline["value"][$basename."-".$extension] = $oneAttrib['VALUE']; |
|
| 571 | 571 | if ($optionInfo['flag'] == "ML") { |
| 572 | - $coercedInline["value"][$basename . "-lang"] = $oneAttrib['LANG']; |
|
| 572 | + $coercedInline["value"][$basename."-lang"] = $oneAttrib['LANG']; |
|
| 573 | 573 | } |
| 574 | 574 | break; |
| 575 | 575 | case \core\Options::TYPECODE_FILE: |
| 576 | 576 | // Binary data is expected in base64 encoding. This is true also for PEM files! |
| 577 | 577 | $extension = $optionInfo['type']; |
| 578 | - $coercedInline["option"][$basename] = $oneAttrib['NAME'] . "#"; |
|
| 579 | - file_put_contents($dir['dir'] . "/" . $basename . "-" . $extension, base64_decode($oneAttrib['VALUE'])); |
|
| 580 | - $coercedFile["value"]['tmp_name'][$basename . "-" . $extension] = $dir['dir'] . "/" . $basename . "-" . $extension; |
|
| 578 | + $coercedInline["option"][$basename] = $oneAttrib['NAME']."#"; |
|
| 579 | + file_put_contents($dir['dir']."/".$basename."-".$extension, base64_decode($oneAttrib['VALUE'])); |
|
| 580 | + $coercedFile["value"]['tmp_name'][$basename."-".$extension] = $dir['dir']."/".$basename."-".$extension; |
|
| 581 | 581 | break; |
| 582 | 582 | default: |
| 583 | 583 | throw new Exception("We don't seem to know this type code!"); |
@@ -606,7 +606,7 @@ discard block |
||
| 606 | 606 | public function returnSuccess($details) { |
| 607 | 607 | $output = json_encode(["result" => "SUCCESS", "details" => $details], JSON_PRETTY_PRINT); |
| 608 | 608 | if ($output === FALSE) { |
| 609 | - $this->returnError(API::ERROR_INTERNAL_ERROR, "Unable to JSON encode return data: ". json_last_error(). " - ". json_last_error_msg()); |
|
| 609 | + $this->returnError(API::ERROR_INTERNAL_ERROR, "Unable to JSON encode return data: ".json_last_error()." - ".json_last_error_msg()); |
|
| 610 | 610 | } |
| 611 | 611 | else { |
| 612 | 612 | echo $output; |
@@ -607,8 +607,7 @@ |
||
| 607 | 607 | $output = json_encode(["result" => "SUCCESS", "details" => $details], JSON_PRETTY_PRINT); |
| 608 | 608 | if ($output === FALSE) { |
| 609 | 609 | $this->returnError(API::ERROR_INTERNAL_ERROR, "Unable to JSON encode return data: ". json_last_error(). " - ". json_last_error_msg()); |
| 610 | - } |
|
| 611 | - else { |
|
| 610 | + } else { |
|
| 612 | 611 | echo $output; |
| 613 | 612 | } |
| 614 | 613 | } |
@@ -115,240 +115,240 @@ discard block |
||
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | switch ($inputDecoded['ACTION']) { |
| 118 | - case web\lib\admin\API::ACTION_NEWINST: |
|
| 119 | - // create the inst, no admin, no attributes |
|
| 120 | - $idp = new \core\IdP($fed->newIdP("PENDING", "API")); |
|
| 121 | - // now add all submitted attributes |
|
| 122 | - $inputs = $adminApi->uglify($scrubbedParameters); |
|
| 123 | - $optionParser->processSubmittedFields($idp, $inputs["POST"], $inputs["FILES"]); |
|
| 124 | - $adminApi->returnSuccess([web\lib\admin\API::AUXATTRIB_CAT_INST_ID => $idp->identifier]); |
|
| 125 | - break; |
|
| 126 | - case web\lib\admin\API::ACTION_DELINST: |
|
| 127 | - try { |
|
| 128 | - $idp = $validator->IdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID)); |
|
| 129 | - } catch (Exception $e) { |
|
| 130 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
|
| 131 | - exit(1); |
|
| 132 | - } |
|
| 133 | - $idp->destroy(); |
|
| 134 | - $adminApi->returnSuccess([]); |
|
| 135 | - break; |
|
| 136 | - case web\lib\admin\API::ACTION_ADMIN_LIST: |
|
| 137 | - try { |
|
| 138 | - $idp = $validator->IdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID)); |
|
| 139 | - } catch (Exception $e) { |
|
| 140 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
|
| 141 | - exit(1); |
|
| 142 | - } |
|
| 143 | - $adminApi->returnSuccess($idp->listOwners()); |
|
| 144 | - break; |
|
| 145 | - case web\lib\admin\API::ACTION_ADMIN_ADD: |
|
| 146 | - // IdP in question |
|
| 147 | - try { |
|
| 148 | - $idp = $validator->IdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID)); |
|
| 149 | - } catch (Exception $e) { |
|
| 150 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
|
| 151 | - exit(1); |
|
| 152 | - } |
|
| 153 | - // here is the token |
|
| 154 | - $mgmt = new core\UserManagement(); |
|
| 155 | - // we know we have an admin ID but scrutinizer wants this checked more explicitly |
|
| 156 | - $admin = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_ADMINID); |
|
| 157 | - if ($admin === FALSE) { |
|
| 158 | - throw new Exception("A required parameter is missing, and this wasn't caught earlier?!"); |
|
| 159 | - } |
|
| 160 | - $newtokens = $mgmt->createTokens(true, [$admin], $idp); |
|
| 161 | - $URL = "https://" . $_SERVER['SERVER_NAME'] . dirname($_SERVER['SCRIPT_NAME']) . "/action_enrollment.php?token=" . array_keys($newtokens)[0]; |
|
| 162 | - $success = ["TOKEN URL" => $URL, "TOKEN" => array_keys($newtokens)[0]]; |
|
| 163 | - // done with the essentials - display in response. But if we also have an email address, send it there |
|
| 164 | - $email = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_TARGETMAIL); |
|
| 165 | - if ($email !== FALSE) { |
|
| 166 | - $sent = \core\common\OutsideComm::adminInvitationMail($email, "EXISTING-FED", array_keys($newtokens)[0], $idp->name, $fed); |
|
| 167 | - $success["EMAIL SENT"] = $sent["SENT"]; |
|
| 168 | - if ($sent["SENT"] === TRUE) { |
|
| 169 | - $success["EMAIL TRANSPORT SECURE"] = $sent["TRANSPORT"]; |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - $adminApi->returnSuccess($success); |
|
| 173 | - break; |
|
| 174 | - case web\lib\admin\API::ACTION_ADMIN_DEL: |
|
| 175 | - // IdP in question |
|
| 176 | - try { |
|
| 177 | - $idp = $validator->IdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID)); |
|
| 178 | - } catch (Exception $e) { |
|
| 179 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
|
| 180 | - exit(1); |
|
| 181 | - } |
|
| 182 | - $currentAdmins = $idp->listOwners(); |
|
| 183 | - $toBeDeleted = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_ADMINID); |
|
| 184 | - if ($toBeDeleted === FALSE) { |
|
| 185 | - throw new Exception("A required parameter is missing, and this wasn't caught earlier?!"); |
|
| 186 | - } |
|
| 187 | - $found = FALSE; |
|
| 188 | - foreach ($currentAdmins as $oneAdmin) { |
|
| 189 | - if ($oneAdmin['MAIL'] == $toBeDeleted) { |
|
| 190 | - $found = TRUE; |
|
| 191 | - $mgmt = new core\UserManagement(); |
|
| 192 | - $mgmt->removeAdminFromIdP($idp, $oneAdmin['ID']); |
|
| 118 | + case web\lib\admin\API::ACTION_NEWINST: |
|
| 119 | + // create the inst, no admin, no attributes |
|
| 120 | + $idp = new \core\IdP($fed->newIdP("PENDING", "API")); |
|
| 121 | + // now add all submitted attributes |
|
| 122 | + $inputs = $adminApi->uglify($scrubbedParameters); |
|
| 123 | + $optionParser->processSubmittedFields($idp, $inputs["POST"], $inputs["FILES"]); |
|
| 124 | + $adminApi->returnSuccess([web\lib\admin\API::AUXATTRIB_CAT_INST_ID => $idp->identifier]); |
|
| 125 | + break; |
|
| 126 | + case web\lib\admin\API::ACTION_DELINST: |
|
| 127 | + try { |
|
| 128 | + $idp = $validator->IdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID)); |
|
| 129 | + } catch (Exception $e) { |
|
| 130 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
|
| 131 | + exit(1); |
|
| 193 | 132 | } |
| 194 | - } |
|
| 195 | - if ($found) { |
|
| 133 | + $idp->destroy(); |
|
| 196 | 134 | $adminApi->returnSuccess([]); |
| 197 | - } |
|
| 198 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "The admin with ID $toBeDeleted is not associated to IdP " . $idp->identifier); |
|
| 199 | - break; |
|
| 200 | - case web\lib\admin\API::ACTION_STATISTICS_FED: |
|
| 201 | - $adminApi->returnSuccess($fed->downloadStats("array")); |
|
| 202 | - break; |
|
| 203 | - case \web\lib\admin\API::ACTION_FEDERATION_LISTIDP: |
|
| 204 | - $retArray = []; |
|
| 205 | - $idpIdentifier = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID); |
|
| 206 | - if ($idpIdentifier === FALSE) { |
|
| 207 | - $allIdPs = $fed->listIdentityProviders(0); |
|
| 208 | - foreach ($allIdPs as $instanceId => $oneIdP) { |
|
| 209 | - $theIdP = $oneIdP["instance"]; |
|
| 210 | - $retArray[$instanceId] = $theIdP->getAttributes(); |
|
| 211 | - } |
|
| 212 | - } else { |
|
| 135 | + break; |
|
| 136 | + case web\lib\admin\API::ACTION_ADMIN_LIST: |
|
| 213 | 137 | try { |
| 214 | - $thisIdP = $validator->IdP($idpIdentifier); |
|
| 138 | + $idp = $validator->IdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID)); |
|
| 215 | 139 | } catch (Exception $e) { |
| 216 | 140 | $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
| 217 | 141 | exit(1); |
| 218 | 142 | } |
| 219 | - $retArray[$idpIdentifier] = $thisIdP->getAttributes(); |
|
| 220 | - } |
|
| 221 | - foreach ($retArray as $instNumber => $oneInstData) { |
|
| 222 | - foreach ($oneInstData as $attribNumber => $oneAttrib) { |
|
| 223 | - if ($oneAttrib['name'] == "general:logo_file") { |
|
| 224 | - // JSON doesn't cope well with raw binary data, so b64 it |
|
| 225 | - $retArray[$instNumber][$attribNumber]['value'] = base64_encode($oneAttrib['value']); |
|
| 143 | + $adminApi->returnSuccess($idp->listOwners()); |
|
| 144 | + break; |
|
| 145 | + case web\lib\admin\API::ACTION_ADMIN_ADD: |
|
| 146 | + // IdP in question |
|
| 147 | + try { |
|
| 148 | + $idp = $validator->IdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID)); |
|
| 149 | + } catch (Exception $e) { |
|
| 150 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
|
| 151 | + exit(1); |
|
| 152 | + } |
|
| 153 | + // here is the token |
|
| 154 | + $mgmt = new core\UserManagement(); |
|
| 155 | + // we know we have an admin ID but scrutinizer wants this checked more explicitly |
|
| 156 | + $admin = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_ADMINID); |
|
| 157 | + if ($admin === FALSE) { |
|
| 158 | + throw new Exception("A required parameter is missing, and this wasn't caught earlier?!"); |
|
| 159 | + } |
|
| 160 | + $newtokens = $mgmt->createTokens(true, [$admin], $idp); |
|
| 161 | + $URL = "https://" . $_SERVER['SERVER_NAME'] . dirname($_SERVER['SCRIPT_NAME']) . "/action_enrollment.php?token=" . array_keys($newtokens)[0]; |
|
| 162 | + $success = ["TOKEN URL" => $URL, "TOKEN" => array_keys($newtokens)[0]]; |
|
| 163 | + // done with the essentials - display in response. But if we also have an email address, send it there |
|
| 164 | + $email = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_TARGETMAIL); |
|
| 165 | + if ($email !== FALSE) { |
|
| 166 | + $sent = \core\common\OutsideComm::adminInvitationMail($email, "EXISTING-FED", array_keys($newtokens)[0], $idp->name, $fed); |
|
| 167 | + $success["EMAIL SENT"] = $sent["SENT"]; |
|
| 168 | + if ($sent["SENT"] === TRUE) { |
|
| 169 | + $success["EMAIL TRANSPORT SECURE"] = $sent["TRANSPORT"]; |
|
| 226 | 170 | } |
| 227 | 171 | } |
| 228 | - } |
|
| 229 | - $adminApi->returnSuccess($retArray); |
|
| 230 | - break; |
|
| 231 | - case \web\lib\admin\API::ACTION_NEWPROF_RADIUS: |
|
| 232 | - // fall-through intended: both get mostly identical treatment |
|
| 233 | - case web\lib\admin\API::ACTION_NEWPROF_SB: |
|
| 234 | - try { |
|
| 235 | - $idp = $validator->IdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID)); |
|
| 236 | - } catch (Exception $e) { |
|
| 237 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
|
| 238 | - exit(1); |
|
| 239 | - } |
|
| 240 | - if ($inputDecoded['ACTION'] == web\lib\admin\API::ACTION_NEWPROF_RADIUS) { |
|
| 241 | - $type = "RADIUS"; |
|
| 242 | - } else { |
|
| 243 | - $type = "SILVERBULLET"; |
|
| 244 | - } |
|
| 245 | - $profile = $idp->newProfile($type); |
|
| 246 | - if ($profile === NULL) { |
|
| 247 | - $adminApi->returnError(\web\lib\admin\API::ERROR_INTERNAL_ERROR, "Unable to create a new Profile, for no apparent reason. Please contact support."); |
|
| 248 | - exit(1); |
|
| 249 | - } |
|
| 250 | - $inputs = $adminApi->uglify($scrubbedParameters); |
|
| 251 | - $optionParser->processSubmittedFields($profile, $inputs["POST"], $inputs["FILES"]); |
|
| 252 | - if ($inputDecoded['ACTION'] == web\lib\admin\API::ACTION_NEWPROF_SB) { |
|
| 253 | - // auto-accept ToU? |
|
| 254 | - if ($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_TOU) !== FALSE) { |
|
| 255 | - $profile->addAttribute("hiddenprofile:tou_accepted", NULL, 1); |
|
| 256 | - } |
|
| 257 | - // we're done at this point |
|
| 258 | - $adminApi->returnSuccess([\web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID => $profile->identifier]); |
|
| 259 | - continue; |
|
| 260 | - } |
|
| 261 | - if (!$profile instanceof core\ProfileRADIUS) { |
|
| 262 | - throw new Exception("Can't be. This is only here to convince Scrutinizer that we're really talking RADIUS."); |
|
| 263 | - } |
|
| 264 | - /* const AUXATTRIB_PROFILE_REALM = 'ATTRIB-PROFILE-REALM'; |
|
| 265 | - const AUXATTRIB_PROFILE_OUTERVALUE = 'ATTRIB-PROFILE-OUTERVALUE'; */ |
|
| 266 | - $realm = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_REALM); |
|
| 267 | - $outer = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_PROFILE_OUTERVALUE); |
|
| 268 | - if ($realm !== FALSE) { |
|
| 269 | - if ($outer === FALSE) { |
|
| 270 | - $outer = ""; |
|
| 271 | - $profile->setAnonymousIDSupport(FALSE); |
|
| 172 | + $adminApi->returnSuccess($success); |
|
| 173 | + break; |
|
| 174 | + case web\lib\admin\API::ACTION_ADMIN_DEL: |
|
| 175 | + // IdP in question |
|
| 176 | + try { |
|
| 177 | + $idp = $validator->IdP($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID)); |
|
| 178 | + } catch (Exception $e) { |
|
| 179 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "IdP identifier does not exist!"); |
|
| 180 | + exit(1); |
|
| 181 | + } |
|
| 182 | + $currentAdmins = $idp->listOwners(); |
|
| 183 | + $toBeDeleted = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_ADMINID); |
|
| 184 | + if ($toBeDeleted === FALSE) { |
|
| 185 | + throw new Exception("A required parameter is missing, and this wasn't caught earlier?!"); |
|
| 186 | + } |
|
| 187 | + $found = FALSE; |
|
| 188 | + foreach ($currentAdmins as $oneAdmin) { |
|
| 189 | + if ($oneAdmin['MAIL'] == $toBeDeleted) { |
|
| 190 | + $found = TRUE; |
|
| 191 | + $mgmt = new core\UserManagement(); |
|
| 192 | + $mgmt->removeAdminFromIdP($idp, $oneAdmin['ID']); |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + if ($found) { |
|
| 196 | + $adminApi->returnSuccess([]); |
|
| 197 | + } |
|
| 198 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "The admin with ID $toBeDeleted is not associated to IdP " . $idp->identifier); |
|
| 199 | + break; |
|
| 200 | + case web\lib\admin\API::ACTION_STATISTICS_FED: |
|
| 201 | + $adminApi->returnSuccess($fed->downloadStats("array")); |
|
| 202 | + break; |
|
| 203 | + case \web\lib\admin\API::ACTION_FEDERATION_LISTIDP: |
|
| 204 | + $retArray = []; |
|
| 205 | + $idpIdentifier = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_INST_ID); |
|
| 206 | + if ($idpIdentifier === FALSE) { |
|
| 207 | + $allIdPs = $fed->listIdentityProviders(0); |
|
| 208 | + foreach ($allIdPs as $instanceId => $oneIdP) { |
|
| 209 | + $theIdP = $oneIdP["instance"]; |
|
| 210 | + $retArray[$instanceId] = $theIdP->getAttributes(); |
|
| 211 | + } |
|
| 212 | + } else { |
|
| 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(); |
|
| 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']); |
|
| 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"; |
|
| 272 | 242 | } else { |
| 273 | - $outer = $outer . "@"; |
|
| 274 | - $profile->setAnonymousIDSupport(TRUE); |
|
| 243 | + $type = "SILVERBULLET"; |
|
| 275 | 244 | } |
| 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'; |
|
| 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 | - $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
| 306 | - if ($prof_id === FALSE) { |
|
| 307 | - exit(1); |
|
| 308 | - } |
|
| 309 | - $evaluation = commonSbProfileChecks($fed, $prof_id); |
|
| 310 | - if ($evaluation === FALSE) { |
|
| 311 | - exit(1); |
|
| 312 | - } |
|
| 313 | - list($idp, $profile) = $evaluation; |
|
| 314 | - $user = $validator->string($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERNAME)); |
|
| 315 | - $expiryRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_EXPIRY); |
|
| 316 | - if ($expiryRaw === FALSE) { |
|
| 317 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "The expiry date wasn't found in the request."); |
|
| 318 | - exit(1); |
|
| 319 | - } |
|
| 320 | - $expiry = new DateTime($expiryRaw); |
|
| 321 | - try { |
|
| 322 | - $retval = $profile->addUser($user, $expiry); |
|
| 323 | - } catch (Exception $e) { |
|
| 324 | - $adminApi->returnError(web\lib\admin\API::ERROR_INTERNAL_ERROR, "The operation failed. Maybe a duplicate username, or malformed expiry date?"); |
|
| 325 | - exit(1); |
|
| 326 | - } |
|
| 327 | - if ($retval == 0) {// that didn't work, it seems |
|
| 328 | - $adminApi->returnError(web\lib\admin\API::ERROR_INTERNAL_ERROR, "The operation failed subtly. Contact the administrators."); |
|
| 329 | - exit(1); |
|
| 330 | - } |
|
| 331 | - $adminApi->returnSuccess([web\lib\admin\API::AUXATTRIB_SB_USERNAME => $user, \web\lib\admin\API::AUXATTRIB_SB_USERID => $retval]); |
|
| 332 | - break; |
|
| 333 | - case \web\lib\admin\API::ACTION_ENDUSER_DEACTIVATE: |
|
| 334 | - // fall-through intended: both actions are very similar |
|
| 335 | - case \web\lib\admin\API::ACTION_TOKEN_NEW: |
|
| 336 | - $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
| 337 | - if ($profile_id === FALSE) { |
|
| 338 | - exit(1); |
|
| 339 | - } |
|
| 340 | - $evaluation = commonSbProfileChecks($fed, $profile_id); |
|
| 341 | - if ($evaluation === FALSE) { |
|
| 342 | - exit(1); |
|
| 343 | - } |
|
| 344 | - list($idp, $profile) = $evaluation; |
|
| 345 | - $userId = $validator->integer($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID)); |
|
| 346 | - if ($userId === FALSE) { |
|
| 347 | - $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "User ID is not an integer."); |
|
| 348 | - exit(1); |
|
| 349 | - } |
|
| 350 | - $additionalInfo = []; |
|
| 351 | - switch ($inputDecoded['ACTION']) { // this is where the two differ |
|
| 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]); |
|
| 303 | + break; |
|
| 304 | + case web\lib\admin\API::ACTION_ENDUSER_NEW: |
|
| 305 | + $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
| 306 | + if ($prof_id === FALSE) { |
|
| 307 | + exit(1); |
|
| 308 | + } |
|
| 309 | + $evaluation = commonSbProfileChecks($fed, $prof_id); |
|
| 310 | + if ($evaluation === FALSE) { |
|
| 311 | + exit(1); |
|
| 312 | + } |
|
| 313 | + list($idp, $profile) = $evaluation; |
|
| 314 | + $user = $validator->string($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERNAME)); |
|
| 315 | + $expiryRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_EXPIRY); |
|
| 316 | + if ($expiryRaw === FALSE) { |
|
| 317 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "The expiry date wasn't found in the request."); |
|
| 318 | + exit(1); |
|
| 319 | + } |
|
| 320 | + $expiry = new DateTime($expiryRaw); |
|
| 321 | + try { |
|
| 322 | + $retval = $profile->addUser($user, $expiry); |
|
| 323 | + } catch (Exception $e) { |
|
| 324 | + $adminApi->returnError(web\lib\admin\API::ERROR_INTERNAL_ERROR, "The operation failed. Maybe a duplicate username, or malformed expiry date?"); |
|
| 325 | + exit(1); |
|
| 326 | + } |
|
| 327 | + if ($retval == 0) {// that didn't work, it seems |
|
| 328 | + $adminApi->returnError(web\lib\admin\API::ERROR_INTERNAL_ERROR, "The operation failed subtly. Contact the administrators."); |
|
| 329 | + exit(1); |
|
| 330 | + } |
|
| 331 | + $adminApi->returnSuccess([web\lib\admin\API::AUXATTRIB_SB_USERNAME => $user, \web\lib\admin\API::AUXATTRIB_SB_USERID => $retval]); |
|
| 332 | + break; |
|
| 333 | + case \web\lib\admin\API::ACTION_ENDUSER_DEACTIVATE: |
|
| 334 | + // fall-through intended: both actions are very similar |
|
| 335 | + case \web\lib\admin\API::ACTION_TOKEN_NEW: |
|
| 336 | + $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
| 337 | + if ($profile_id === FALSE) { |
|
| 338 | + exit(1); |
|
| 339 | + } |
|
| 340 | + $evaluation = commonSbProfileChecks($fed, $profile_id); |
|
| 341 | + if ($evaluation === FALSE) { |
|
| 342 | + exit(1); |
|
| 343 | + } |
|
| 344 | + list($idp, $profile) = $evaluation; |
|
| 345 | + $userId = $validator->integer($adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID)); |
|
| 346 | + if ($userId === FALSE) { |
|
| 347 | + $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "User ID is not an integer."); |
|
| 348 | + exit(1); |
|
| 349 | + } |
|
| 350 | + $additionalInfo = []; |
|
| 351 | + switch ($inputDecoded['ACTION']) { // this is where the two differ |
|
| 352 | 352 | case \web\lib\admin\API::ACTION_ENDUSER_DEACTIVATE: |
| 353 | 353 | $result = $profile->deactivateUser($userId); |
| 354 | 354 | break; |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | } |
| 382 | 382 | } |
| 383 | 383 | break; |
| 384 | - } |
|
| 384 | + } |
|
| 385 | 385 | |
| 386 | 386 | if ($result !== TRUE) { |
| 387 | 387 | $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "These parameters did not lead to an existing, active user."); |
@@ -389,65 +389,65 @@ discard block |
||
| 389 | 389 | } |
| 390 | 390 | $adminApi->returnSuccess($additionalInfo); |
| 391 | 391 | break; |
| 392 | - case \web\lib\admin\API::ACTION_ENDUSER_IDENTIFY: |
|
| 393 | - $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
| 394 | - if ($profile_id === FALSE) { |
|
| 395 | - exit(1); |
|
| 396 | - } |
|
| 397 | - $evaluation = commonSbProfileChecks($fed, $profile_id); |
|
| 398 | - if ($evaluation === FALSE) { |
|
| 399 | - exit(1); |
|
| 400 | - } |
|
| 401 | - list($idp, $profile) = $evaluation; |
|
| 402 | - $userId = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID); |
|
| 403 | - $userName = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERNAME); |
|
| 404 | - $certSerial = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL); |
|
| 405 | - if ($userId === FALSE && $userName === FALSE && $certSerial === FALSE) { |
|
| 406 | - // we need at least one of those |
|
| 407 | - $adminApi->returnError(\web\lib\admin\API::ERROR_MISSING_PARAMETER, "At least one of User ID, Username, or certificate serial is required."); |
|
| 408 | - } |
|
| 409 | - $userlist = $profile->listAllUsers(); |
|
| 410 | - if ($userName === FALSE && $certSerial === FALSE) { // we got a user ID |
|
| 411 | - if (!isset($userlist[$userId])) { |
|
| 412 | - return $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "This user ID does not exist in this profile."); |
|
| 392 | + case \web\lib\admin\API::ACTION_ENDUSER_IDENTIFY: |
|
| 393 | + $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
| 394 | + if ($profile_id === FALSE) { |
|
| 395 | + exit(1); |
|
| 413 | 396 | } |
| 414 | - $adminApi->returnSuccess([$userId => $userlist[$userId]]); |
|
| 415 | - } |
|
| 416 | - if ($userId === FALSE && $certSerial === FALSE) { // we got a username |
|
| 417 | - $key = array_search($userName, $userlist); |
|
| 418 | - if ($key === FALSE) { |
|
| 419 | - return $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "This username does not exist in this profile."); |
|
| 397 | + $evaluation = commonSbProfileChecks($fed, $profile_id); |
|
| 398 | + if ($evaluation === FALSE) { |
|
| 399 | + exit(1); |
|
| 420 | 400 | } |
| 421 | - $adminApi->returnSuccess([$key => $userlist[$key]]); |
|
| 422 | - } |
|
| 423 | - if ($userId === FALSE && $userName === FALSE) { // we got a cert serial |
|
| 424 | - $serial = explode(":", $certSerial); |
|
| 425 | - $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]); |
|
| 426 | - if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) { |
|
| 427 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found."); |
|
| 401 | + list($idp, $profile) = $evaluation; |
|
| 402 | + $userId = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID); |
|
| 403 | + $userName = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERNAME); |
|
| 404 | + $certSerial = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL); |
|
| 405 | + if ($userId === FALSE && $userName === FALSE && $certSerial === FALSE) { |
|
| 406 | + // we need at least one of those |
|
| 407 | + $adminApi->returnError(\web\lib\admin\API::ERROR_MISSING_PARAMETER, "At least one of User ID, Username, or certificate serial is required."); |
|
| 428 | 408 | } |
| 429 | - if ($cert->profileId != $profile->identifier) { |
|
| 430 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile."); |
|
| 409 | + $userlist = $profile->listAllUsers(); |
|
| 410 | + if ($userName === FALSE && $certSerial === FALSE) { // we got a user ID |
|
| 411 | + if (!isset($userlist[$userId])) { |
|
| 412 | + return $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "This user ID does not exist in this profile."); |
|
| 413 | + } |
|
| 414 | + $adminApi->returnSuccess([$userId => $userlist[$userId]]); |
|
| 431 | 415 | } |
| 432 | - $adminApi->returnSuccess([$cert->userId => $userlist[$cert->userId]]); |
|
| 433 | - } |
|
| 434 | - $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "Only exactly one of User ID, username or cert serial can be specified."); |
|
| 435 | - break; |
|
| 436 | - case \web\lib\admin\API::ACTION_ENDUSER_LIST: |
|
| 437 | - // fall-through: those two are similar |
|
| 438 | - case \web\lib\admin\API::ACTION_TOKEN_LIST: |
|
| 439 | - $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
| 440 | - if ($profile_id === FALSE) { |
|
| 441 | - exit(1); |
|
| 442 | - } |
|
| 443 | - $evaluation = commonSbProfileChecks($fed, $profile_id); |
|
| 444 | - if ($evaluation === FALSE) { |
|
| 445 | - exit(1); |
|
| 446 | - } |
|
| 447 | - list($idp, $profile) = $evaluation; |
|
| 448 | - $allUsers = $profile->listAllUsers(); |
|
| 449 | - // this is where they differ |
|
| 450 | - switch ($inputDecoded['ACTION']) { |
|
| 416 | + if ($userId === FALSE && $certSerial === FALSE) { // we got a username |
|
| 417 | + $key = array_search($userName, $userlist); |
|
| 418 | + if ($key === FALSE) { |
|
| 419 | + return $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "This username does not exist in this profile."); |
|
| 420 | + } |
|
| 421 | + $adminApi->returnSuccess([$key => $userlist[$key]]); |
|
| 422 | + } |
|
| 423 | + if ($userId === FALSE && $userName === FALSE) { // we got a cert serial |
|
| 424 | + $serial = explode(":", $certSerial); |
|
| 425 | + $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]); |
|
| 426 | + if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) { |
|
| 427 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found."); |
|
| 428 | + } |
|
| 429 | + if ($cert->profileId != $profile->identifier) { |
|
| 430 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile."); |
|
| 431 | + } |
|
| 432 | + $adminApi->returnSuccess([$cert->userId => $userlist[$cert->userId]]); |
|
| 433 | + } |
|
| 434 | + $adminApi->returnError(\web\lib\admin\API::ERROR_INVALID_PARAMETER, "Only exactly one of User ID, username or cert serial can be specified."); |
|
| 435 | + break; |
|
| 436 | + case \web\lib\admin\API::ACTION_ENDUSER_LIST: |
|
| 437 | + // fall-through: those two are similar |
|
| 438 | + case \web\lib\admin\API::ACTION_TOKEN_LIST: |
|
| 439 | + $profile_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
| 440 | + if ($profile_id === FALSE) { |
|
| 441 | + exit(1); |
|
| 442 | + } |
|
| 443 | + $evaluation = commonSbProfileChecks($fed, $profile_id); |
|
| 444 | + if ($evaluation === FALSE) { |
|
| 445 | + exit(1); |
|
| 446 | + } |
|
| 447 | + list($idp, $profile) = $evaluation; |
|
| 448 | + $allUsers = $profile->listAllUsers(); |
|
| 449 | + // this is where they differ |
|
| 450 | + switch ($inputDecoded['ACTION']) { |
|
| 451 | 451 | case \web\lib\admin\API::ACTION_ENDUSER_LIST: |
| 452 | 452 | $adminApi->returnSuccess($allUsers); |
| 453 | 453 | break; |
@@ -466,105 +466,105 @@ discard block |
||
| 466 | 466 | $infoSet[$oneTokenObject->userId] = [\web\lib\admin\API::AUXATTRIB_TOKEN => $oneTokenObject->invitationTokenString, "STATUS" => $oneTokenObject->invitationTokenStatus]; |
| 467 | 467 | } |
| 468 | 468 | $adminApi->returnSuccess($infoSet); |
| 469 | - } |
|
| 470 | - break; |
|
| 471 | - case \web\lib\admin\API::ACTION_TOKEN_REVOKE: |
|
| 472 | - $tokenRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_TOKEN); |
|
| 473 | - if ($tokenRaw === FALSE) { |
|
| 474 | - exit(1); |
|
| 475 | - } |
|
| 476 | - $token = new core\SilverbulletInvitation($tokenRaw); |
|
| 477 | - if ($token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_VALID && $token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_PARTIALLY_REDEEMED) { |
|
| 478 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "This is not a currently valid token."); |
|
| 479 | - exit(1); |
|
| 480 | - } |
|
| 481 | - $token->revokeInvitation(); |
|
| 482 | - $adminApi->returnSuccess([]); |
|
| 483 | - break; |
|
| 484 | - case \web\lib\admin\API::ACTION_CERT_LIST: |
|
| 485 | - $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
| 486 | - $user_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID); |
|
| 487 | - if ($prof_id === FALSE || !is_int($user_id)) { |
|
| 488 | - exit(1); |
|
| 489 | - } |
|
| 490 | - $evaluation = commonSbProfileChecks($fed, $prof_id); |
|
| 491 | - if ($evaluation === FALSE) { |
|
| 492 | - exit(1); |
|
| 493 | - } |
|
| 494 | - list($idp, $profile) = $evaluation; |
|
| 495 | - $invitations = $profile->userStatus($user_id); |
|
| 496 | - // now pull out cert information from the object |
|
| 497 | - $certs = []; |
|
| 498 | - foreach ($invitations as $oneInvitation) { |
|
| 499 | - $certs = array_merge($certs, $oneInvitation->associatedCertificates); |
|
| 500 | - } |
|
| 501 | - // extract relevant subset of information from cert objects |
|
| 502 | - $certDetails = []; |
|
| 503 | - foreach ($certs as $cert) { |
|
| 504 | - $certDetails[$cert->ca_type . ":" . $cert->serial] = ["ISSUED" => $cert->issued, "EXPIRY" => $cert->expiry, "STATUS" => $cert->status, "DEVICE" => $cert->device, "CN" => $cert->username, "ANNOTATION" => $cert->annotation]; |
|
| 505 | - } |
|
| 506 | - $adminApi->returnSuccess($certDetails); |
|
| 507 | - break; |
|
| 508 | - case \web\lib\admin\API::ACTION_CERT_REVOKE: |
|
| 509 | - $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
| 510 | - if ($prof_id === FALSE) { |
|
| 511 | - exit(1); |
|
| 512 | - } |
|
| 513 | - $evaluation = commonSbProfileChecks($fed, $prof_id); |
|
| 514 | - if ($evaluation === FALSE) { |
|
| 515 | - exit(1); |
|
| 516 | - } |
|
| 517 | - list($idp, $profile) = $evaluation; |
|
| 518 | - // tear apart the serial |
|
| 519 | - $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL); |
|
| 520 | - if ($serialRaw === FALSE) { |
|
| 521 | - exit(1); |
|
| 522 | - } |
|
| 523 | - $serial = explode(":", $serialRaw); |
|
| 524 | - $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]); |
|
| 525 | - if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) { |
|
| 526 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found."); |
|
| 527 | - } |
|
| 528 | - if ($cert->profileId != $profile->identifier) { |
|
| 529 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile."); |
|
| 530 | - } |
|
| 531 | - $cert->revokeCertificate(); |
|
| 532 | - $adminApi->returnSuccess([]); |
|
| 469 | + } |
|
| 533 | 470 | break; |
| 534 | - case \web\lib\admin\API::ACTION_CERT_ANNOTATE: |
|
| 535 | - $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
| 536 | - if ($prof_id === FALSE) { |
|
| 537 | - exit(1); |
|
| 538 | - } |
|
| 539 | - $evaluation = commonSbProfileChecks($fed, $prof_id); |
|
| 540 | - if ($evaluation === FALSE) { |
|
| 541 | - exit(1); |
|
| 542 | - } |
|
| 543 | - list($idp, $profile) = $evaluation; |
|
| 544 | - // tear apart the serial |
|
| 545 | - $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL); |
|
| 546 | - if ($serialRaw === FALSE) { |
|
| 547 | - exit(1); |
|
| 548 | - } |
|
| 549 | - $serial = explode(":", $serialRaw); |
|
| 550 | - $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]); |
|
| 551 | - if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) { |
|
| 552 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found."); |
|
| 553 | - } |
|
| 554 | - if ($cert->profileId != $profile->identifier) { |
|
| 555 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile."); |
|
| 556 | - } |
|
| 557 | - $annotationRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTANNOTATION); |
|
| 558 | - if ($annotationRaw === FALSE) { |
|
| 559 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Unable to extract annotation."); |
|
| 471 | + case \web\lib\admin\API::ACTION_TOKEN_REVOKE: |
|
| 472 | + $tokenRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_TOKEN); |
|
| 473 | + if ($tokenRaw === FALSE) { |
|
| 474 | + exit(1); |
|
| 475 | + } |
|
| 476 | + $token = new core\SilverbulletInvitation($tokenRaw); |
|
| 477 | + if ($token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_VALID && $token->invitationTokenStatus !== core\SilverbulletInvitation::SB_TOKENSTATUS_PARTIALLY_REDEEMED) { |
|
| 478 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "This is not a currently valid token."); |
|
| 479 | + exit(1); |
|
| 480 | + } |
|
| 481 | + $token->revokeInvitation(); |
|
| 482 | + $adminApi->returnSuccess([]); |
|
| 560 | 483 | break; |
| 561 | - } |
|
| 562 | - $annotation = json_decode($annotationRaw, TRUE); |
|
| 563 | - $cert->annotate($annotation); |
|
| 564 | - $adminApi->returnSuccess([]); |
|
| 484 | + case \web\lib\admin\API::ACTION_CERT_LIST: |
|
| 485 | + $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
| 486 | + $user_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_USERID); |
|
| 487 | + if ($prof_id === FALSE || !is_int($user_id)) { |
|
| 488 | + exit(1); |
|
| 489 | + } |
|
| 490 | + $evaluation = commonSbProfileChecks($fed, $prof_id); |
|
| 491 | + if ($evaluation === FALSE) { |
|
| 492 | + exit(1); |
|
| 493 | + } |
|
| 494 | + list($idp, $profile) = $evaluation; |
|
| 495 | + $invitations = $profile->userStatus($user_id); |
|
| 496 | + // now pull out cert information from the object |
|
| 497 | + $certs = []; |
|
| 498 | + foreach ($invitations as $oneInvitation) { |
|
| 499 | + $certs = array_merge($certs, $oneInvitation->associatedCertificates); |
|
| 500 | + } |
|
| 501 | + // extract relevant subset of information from cert objects |
|
| 502 | + $certDetails = []; |
|
| 503 | + foreach ($certs as $cert) { |
|
| 504 | + $certDetails[$cert->ca_type . ":" . $cert->serial] = ["ISSUED" => $cert->issued, "EXPIRY" => $cert->expiry, "STATUS" => $cert->status, "DEVICE" => $cert->device, "CN" => $cert->username, "ANNOTATION" => $cert->annotation]; |
|
| 505 | + } |
|
| 506 | + $adminApi->returnSuccess($certDetails); |
|
| 507 | + break; |
|
| 508 | + case \web\lib\admin\API::ACTION_CERT_REVOKE: |
|
| 509 | + $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
| 510 | + if ($prof_id === FALSE) { |
|
| 511 | + exit(1); |
|
| 512 | + } |
|
| 513 | + $evaluation = commonSbProfileChecks($fed, $prof_id); |
|
| 514 | + if ($evaluation === FALSE) { |
|
| 515 | + exit(1); |
|
| 516 | + } |
|
| 517 | + list($idp, $profile) = $evaluation; |
|
| 518 | + // tear apart the serial |
|
| 519 | + $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL); |
|
| 520 | + if ($serialRaw === FALSE) { |
|
| 521 | + exit(1); |
|
| 522 | + } |
|
| 523 | + $serial = explode(":", $serialRaw); |
|
| 524 | + $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]); |
|
| 525 | + if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) { |
|
| 526 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found."); |
|
| 527 | + } |
|
| 528 | + if ($cert->profileId != $profile->identifier) { |
|
| 529 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile."); |
|
| 530 | + } |
|
| 531 | + $cert->revokeCertificate(); |
|
| 532 | + $adminApi->returnSuccess([]); |
|
| 533 | + break; |
|
| 534 | + case \web\lib\admin\API::ACTION_CERT_ANNOTATE: |
|
| 535 | + $prof_id = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_CAT_PROFILE_ID); |
|
| 536 | + if ($prof_id === FALSE) { |
|
| 537 | + exit(1); |
|
| 538 | + } |
|
| 539 | + $evaluation = commonSbProfileChecks($fed, $prof_id); |
|
| 540 | + if ($evaluation === FALSE) { |
|
| 541 | + exit(1); |
|
| 542 | + } |
|
| 543 | + list($idp, $profile) = $evaluation; |
|
| 544 | + // tear apart the serial |
|
| 545 | + $serialRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTSERIAL); |
|
| 546 | + if ($serialRaw === FALSE) { |
|
| 547 | + exit(1); |
|
| 548 | + } |
|
| 549 | + $serial = explode(":", $serialRaw); |
|
| 550 | + $cert = new \core\SilverbulletCertificate($serial[1], $serial[0]); |
|
| 551 | + if ($cert->status == \core\SilverbulletCertificate::CERTSTATUS_INVALID) { |
|
| 552 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial not found."); |
|
| 553 | + } |
|
| 554 | + if ($cert->profileId != $profile->identifier) { |
|
| 555 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Serial does not belong to this profile."); |
|
| 556 | + } |
|
| 557 | + $annotationRaw = $adminApi->firstParameterInstance($scrubbedParameters, web\lib\admin\API::AUXATTRIB_SB_CERTANNOTATION); |
|
| 558 | + if ($annotationRaw === FALSE) { |
|
| 559 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_PARAMETER, "Unable to extract annotation."); |
|
| 560 | + break; |
|
| 561 | + } |
|
| 562 | + $annotation = json_decode($annotationRaw, TRUE); |
|
| 563 | + $cert->annotate($annotation); |
|
| 564 | + $adminApi->returnSuccess([]); |
|
| 565 | 565 | |
| 566 | - break; |
|
| 566 | + break; |
|
| 567 | 567 | |
| 568 | - default: |
|
| 569 | - $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_ACTION, "Not implemented yet."); |
|
| 568 | + default: |
|
| 569 | + $adminApi->returnError(web\lib\admin\API::ERROR_INVALID_ACTION, "Not implemented yet."); |
|
| 570 | 570 | } |
| 571 | 571 | \ No newline at end of file |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | * <base_url>/copyright.php after deploying the software |
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | -require_once dirname(dirname(__DIR__)) . '/config/_config.php'; |
|
| 22 | +require_once dirname(dirname(__DIR__)).'/config/_config.php'; |
|
| 23 | 23 | |
| 24 | 24 | $uiElements = new web\lib\admin\UIElements(); |
| 25 | 25 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | // filesystem cleanup |
| 76 | 76 | case web\lib\common\FormElements::BUTTON_DELETE: |
| 77 | 77 | $i = web\lib\admin\Maintenance::deleteObsoleteTempDirs(); |
| 78 | - echo "<div class='ca-summary'><table>" . $uiElements->boxRemark(sprintf("Deleted %d cache directories.", $i), "Cache deleted") . "</table></div>"; |
|
| 78 | + echo "<div class='ca-summary'><table>".$uiElements->boxRemark(sprintf("Deleted %d cache directories.", $i), "Cache deleted")."</table></div>"; |
|
| 79 | 79 | break; |
| 80 | 80 | default: |
| 81 | 81 | break; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $admin_query = $dbHandle->exec("SELECT SUM(downloads_admin) AS admin, SUM(downloads_user) AS user, SUM(downloads_silverbullet) as silverbullet FROM downloads WHERE device_id = '$index'"); |
| 142 | 142 | // SELECT -> mysqli_result, not boolean |
| 143 | 143 | while ($a = mysqli_fetch_object(/** @scrutinizer ignore-type */ $admin_query)) { |
| 144 | - echo "<td>" . $device_array['display'] . "</td><td>" . $a->admin . "</td><td>" . $a->user . "</td><td>" . $a->silverbullet . "</td><td>" . sprintf("%s", $a->user + $a->silverbullet) . "</td>"; |
|
| 144 | + echo "<td>".$device_array['display']."</td><td>".$a->admin."</td><td>".$a->user."</td><td>".$a->silverbullet."</td><td>".sprintf("%s", $a->user + $a->silverbullet)."</td>"; |
|
| 145 | 145 | $gross_admin = $gross_admin + $a->admin; |
| 146 | 146 | $gross_user = $gross_user + $a->user; |
| 147 | 147 | $gross_silverbullet = $gross_silverbullet + $a->silverbullet; |