@@ -108,13 +108,13 @@ discard block |
||
| 108 | 108 | try { |
| 109 | 109 | list($data, $responseHeaders) = \SimpleSAML\Utils\HTTP::fetch($source['src'], $context, true); |
| 110 | 110 | } catch (\Exception $e) { |
| 111 | - Logger::warning('metarefresh: ' . $e->getMessage()); |
|
| 111 | + Logger::warning('metarefresh: '.$e->getMessage()); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | // We have response headers, so the request succeeded |
| 115 | 115 | if (!isset($responseHeaders)) { |
| 116 | 116 | // No response headers, this means the request failed in some way, so re-use old data |
| 117 | - Logger::debug('No response from ' . $source['src'] . ' - attempting to re-use cached metadata'); |
|
| 117 | + Logger::debug('No response from '.$source['src'].' - attempting to re-use cached metadata'); |
|
| 118 | 118 | $this->addCachedMetadata($source); |
| 119 | 119 | return; |
| 120 | 120 | } elseif (preg_match('@^HTTP/1\.[01]\s304\s@', $responseHeaders[0])) { |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | return; |
| 125 | 125 | } elseif (!preg_match('@^HTTP/1\.[01]\s200\s@', $responseHeaders[0])) { |
| 126 | 126 | // Other error |
| 127 | - Logger::debug('Error from ' . $source['src'] . ' - attempting to re-use cached metadata'); |
|
| 127 | + Logger::debug('Error from '.$source['src'].' - attempting to re-use cached metadata'); |
|
| 128 | 128 | $this->addCachedMetadata($source); |
| 129 | 129 | return; |
| 130 | 130 | } |
@@ -143,8 +143,8 @@ discard block |
||
| 143 | 143 | try { |
| 144 | 144 | $entities = $this->loadXML($data, $source); |
| 145 | 145 | } catch (\Exception $e) { |
| 146 | - Logger::debug('XML parser error when parsing ' . $source['src'] . ' - attempting to re-use cached metadata'); |
|
| 147 | - Logger::debug('XML parser returned: ' . $e->getMessage()); |
|
| 146 | + Logger::debug('XML parser error when parsing '.$source['src'].' - attempting to re-use cached metadata'); |
|
| 147 | + Logger::debug('XML parser returned: '.$e->getMessage()); |
|
| 148 | 148 | $this->addCachedMetadata($source); |
| 149 | 149 | return; |
| 150 | 150 | } |
@@ -152,14 +152,14 @@ discard block |
||
| 152 | 152 | foreach ($entities as $entity) { |
| 153 | 153 | if (isset($source['blacklist'])) { |
| 154 | 154 | if (!empty($source['blacklist']) && in_array($entity->getEntityId(), $source['blacklist'], true)) { |
| 155 | - Logger::info('Skipping "' . $entity->getEntityId() . '" - blacklisted.' . "\n"); |
|
| 155 | + Logger::info('Skipping "'.$entity->getEntityId().'" - blacklisted.'."\n"); |
|
| 156 | 156 | continue; |
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | if (isset($source['whitelist'])) { |
| 161 | 161 | if (!empty($source['whitelist']) && !in_array($entity->getEntityId(), $source['whitelist'], true)) { |
| 162 | - Logger::info('Skipping "' . $entity->getEntityId() . '" - not in the whitelist.' . "\n"); |
|
| 162 | + Logger::info('Skipping "'.$entity->getEntityId().'" - not in the whitelist.'."\n"); |
|
| 163 | 163 | continue; |
| 164 | 164 | } |
| 165 | 165 | } |
@@ -171,22 +171,22 @@ discard block |
||
| 171 | 171 | continue; |
| 172 | 172 | |
| 173 | 173 | /* Do a recursive comparison for each whitelist of the attributewhitelist with the idpmetadata for this IdP. At least one of these whitelists should match */ |
| 174 | - $match=0; |
|
| 175 | - foreach ($source['attributewhitelist'] as $whitelist) { |
|
| 174 | + $match = 0; |
|
| 175 | + foreach ($source['attributewhitelist'] as $whitelist) { |
|
| 176 | 176 | if ($this->containsArray($whitelist, $idpmetadata)) { |
| 177 | - $match=1; |
|
| 177 | + $match = 1; |
|
| 178 | 178 | break; |
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | - if ($match==0) /* No match found -> next IdP */ |
|
| 181 | + if ($match == 0) /* No match found -> next IdP */ |
|
| 182 | 182 | continue; |
| 183 | - Logger::debug('Whitelisted entityID: '. $entity->getEntityID()); |
|
| 183 | + Logger::debug('Whitelisted entityID: '.$entity->getEntityID()); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | if (array_key_exists('certificates', $source) && ($source['certificates'] !== null)) { |
| 187 | 187 | if (!$entity->validateSignature($source['certificates'])) { |
| 188 | 188 | Logger::info( |
| 189 | - 'Skipping "' . $entity->getEntityId() . '" - could not verify signature using certificate.' . "\n" |
|
| 189 | + 'Skipping "'.$entity->getEntityId().'" - could not verify signature using certificate.'."\n" |
|
| 190 | 190 | ); |
| 191 | 191 | continue; |
| 192 | 192 | } |
@@ -226,14 +226,14 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | private function containsArray($src, $dst) { |
| 228 | 228 | if (is_array($src)) { |
| 229 | - if (!is_array($dst)) { |
|
| 229 | + if (!is_array($dst)) { |
|
| 230 | 230 | return false; |
| 231 | 231 | } |
| 232 | - $dstkeys=array_keys($dst); |
|
| 232 | + $dstkeys = array_keys($dst); |
|
| 233 | 233 | |
| 234 | 234 | /* Loop over all src keys */ |
| 235 | - foreach($src as $srckey => $srcval) { |
|
| 236 | - if (is_int($srckey)) { |
|
| 235 | + foreach ($src as $srckey => $srcval) { |
|
| 236 | + if (is_int($srckey)) { |
|
| 237 | 237 | /* key is number, check that the key appears as one |
| 238 | 238 | * of the destination keys: if not, then src has |
| 239 | 239 | * more keys than dst */ |
@@ -242,10 +242,10 @@ discard block |
||
| 242 | 242 | |
| 243 | 243 | /* loop over dest keys, to find value: we don't know |
| 244 | 244 | * whether they are in the same order */ |
| 245 | - $submatch=0; |
|
| 246 | - foreach ($dstkeys as $dstkey) { |
|
| 245 | + $submatch = 0; |
|
| 246 | + foreach ($dstkeys as $dstkey) { |
|
| 247 | 247 | if ($this->containsArray($srcval, $dst[$dstkey])) { |
| 248 | - $submatch=1; |
|
| 248 | + $submatch = 1; |
|
| 249 | 249 | break; |
| 250 | 250 | } |
| 251 | 251 | } |
@@ -253,19 +253,19 @@ discard block |
||
| 253 | 253 | return false; |
| 254 | 254 | } else { |
| 255 | 255 | /* key is regexp: find matching keys */ |
| 256 | - $matchingdstkeys=preg_grep($srckey, $dstkeys); |
|
| 256 | + $matchingdstkeys = preg_grep($srckey, $dstkeys); |
|
| 257 | 257 | if (!is_array($matchingdstkeys)) |
| 258 | 258 | return false; |
| 259 | 259 | |
| 260 | - $match=0; |
|
| 260 | + $match = 0; |
|
| 261 | 261 | foreach ($matchingdstkeys as $dstkey) { |
| 262 | 262 | if ($this->containsArray($srcval, $dst[$dstkey])) { |
| 263 | 263 | /* Found a match */ |
| 264 | - $match=1; |
|
| 264 | + $match = 1; |
|
| 265 | 265 | break; |
| 266 | 266 | } |
| 267 | 267 | } |
| 268 | - if ($match==0) /* none of the keys has a matching value */ |
|
| 268 | + if ($match == 0) /* none of the keys has a matching value */ |
|
| 269 | 269 | return false; |
| 270 | 270 | } |
| 271 | 271 | } |
@@ -296,11 +296,11 @@ discard block |
||
| 296 | 296 | $sourceState = $this->state[$source['src']]; |
| 297 | 297 | |
| 298 | 298 | if (isset($sourceState['last-modified'])) { |
| 299 | - $rawheader .= 'If-Modified-Since: ' . $sourceState['last-modified'] . "\r\n"; |
|
| 299 | + $rawheader .= 'If-Modified-Since: '.$sourceState['last-modified']."\r\n"; |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | if (isset($sourceState['etag'])) { |
| 303 | - $rawheader .= 'If-None-Match: ' . $sourceState['etag'] . "\r\n"; |
|
| 303 | + $rawheader .= 'If-None-Match: '.$sourceState['etag']."\r\n"; |
|
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | 306 | } |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | try { |
| 373 | 373 | $doc = \SAML2\DOMDocumentFactory::fromString($data); |
| 374 | 374 | } catch (\Exception $e) { |
| 375 | - throw new \Exception('Failed to read XML from ' . $source['src']); |
|
| 375 | + throw new \Exception('Failed to read XML from '.$source['src']); |
|
| 376 | 376 | } |
| 377 | 377 | return \SimpleSAML\Metadata\SAMLParser::parseDescriptorsElement($doc->documentElement); |
| 378 | 378 | } |
@@ -386,12 +386,12 @@ discard block |
||
| 386 | 386 | public function writeState(): void |
| 387 | 387 | { |
| 388 | 388 | if ($this->changed && !is_null($this->stateFile)) { |
| 389 | - Logger::debug('Writing: ' . $this->stateFile); |
|
| 389 | + Logger::debug('Writing: '.$this->stateFile); |
|
| 390 | 390 | \SimpleSAML\Utils\System::writeFile( |
| 391 | 391 | $this->stateFile, |
| 392 | - "<?php\n/* This file was generated by the metarefresh module at " . $this->getTime() . ".\n" . |
|
| 393 | - " Do not update it manually as it will get overwritten. */\n" . |
|
| 394 | - '$state = ' . var_export($this->state, true) . ";\n?>\n", |
|
| 392 | + "<?php\n/* This file was generated by the metarefresh module at ".$this->getTime().".\n". |
|
| 393 | + " Do not update it manually as it will get overwritten. */\n". |
|
| 394 | + '$state = '.var_export($this->state, true).";\n?>\n", |
|
| 395 | 395 | 0644 |
| 396 | 396 | ); |
| 397 | 397 | } |
@@ -406,19 +406,19 @@ discard block |
||
| 406 | 406 | public function dumpMetadataStdOut(): void |
| 407 | 407 | { |
| 408 | 408 | foreach ($this->metadata as $category => $elements) { |
| 409 | - echo '/* The following data should be added to metadata/' . $category . '.php. */' . "\n"; |
|
| 409 | + echo '/* The following data should be added to metadata/'.$category.'.php. */'."\n"; |
|
| 410 | 410 | |
| 411 | 411 | foreach ($elements as $m) { |
| 412 | 412 | $filename = $m['filename']; |
| 413 | 413 | $entityID = $m['metadata']['entityid']; |
| 414 | 414 | |
| 415 | 415 | echo "\n"; |
| 416 | - echo '/* The following metadata was generated from ' . $filename . ' on ' . $this->getTime() . '. */' . "\n"; |
|
| 417 | - echo '$metadata[\'' . addslashes($entityID) . '\'] = ' . var_export($m['metadata'], true) . ';' . "\n"; |
|
| 416 | + echo '/* The following metadata was generated from '.$filename.' on '.$this->getTime().'. */'."\n"; |
|
| 417 | + echo '$metadata[\''.addslashes($entityID).'\'] = '.var_export($m['metadata'], true).';'."\n"; |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | echo "\n"; |
| 421 | - echo '/* End of data which should be added to metadata/' . $category . '.php. */' . "\n"; |
|
| 421 | + echo '/* End of data which should be added to metadata/'.$category.'.php. */'."\n"; |
|
| 422 | 422 | echo "\n"; |
| 423 | 423 | } |
| 424 | 424 | } |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | |
| 498 | 498 | $arpxml = $arp->getXML(); |
| 499 | 499 | |
| 500 | - Logger::info('Writing ARP file: ' . $arpfile . "\n"); |
|
| 500 | + Logger::info('Writing ARP file: '.$arpfile."\n"); |
|
| 501 | 501 | file_put_contents($arpfile, $arpxml); |
| 502 | 502 | } |
| 503 | 503 | |
@@ -515,37 +515,37 @@ discard block |
||
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | if (!file_exists($outputDir)) { |
| 518 | - Logger::info('Creating directory: ' . $outputDir . "\n"); |
|
| 518 | + Logger::info('Creating directory: '.$outputDir."\n"); |
|
| 519 | 519 | $res = @mkdir($outputDir, 0777, true); |
| 520 | 520 | if ($res === false) { |
| 521 | - throw new \Exception('Error creating directory: ' . $outputDir); |
|
| 521 | + throw new \Exception('Error creating directory: '.$outputDir); |
|
| 522 | 522 | } |
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | foreach ($this->types as $type) { |
| 526 | - $filename = $outputDir . '/' . $type . '.php'; |
|
| 526 | + $filename = $outputDir.'/'.$type.'.php'; |
|
| 527 | 527 | |
| 528 | 528 | if (array_key_exists($type, $this->metadata)) { |
| 529 | 529 | $elements = $this->metadata[$type]; |
| 530 | - Logger::debug('Writing: ' . $filename); |
|
| 530 | + Logger::debug('Writing: '.$filename); |
|
| 531 | 531 | |
| 532 | - $content = '<?php' . "\n" . '/* This file was generated by the metarefresh module at '; |
|
| 533 | - $content .= $this->getTime() . "\nDo not update it manually as it will get overwritten\n" . '*/' . "\n"; |
|
| 532 | + $content = '<?php'."\n".'/* This file was generated by the metarefresh module at '; |
|
| 533 | + $content .= $this->getTime()."\nDo not update it manually as it will get overwritten\n".'*/'."\n"; |
|
| 534 | 534 | |
| 535 | 535 | foreach ($elements as $m) { |
| 536 | 536 | $entityID = $m['metadata']['entityid']; |
| 537 | - $content .= "\n" . '$metadata[\''; |
|
| 538 | - $content .= addslashes($entityID) . '\'] = ' . var_export($m['metadata'], true) . ';' . "\n"; |
|
| 537 | + $content .= "\n".'$metadata[\''; |
|
| 538 | + $content .= addslashes($entityID).'\'] = '.var_export($m['metadata'], true).';'."\n"; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | - $content .= "\n" . '?>'; |
|
| 541 | + $content .= "\n".'?>'; |
|
| 542 | 542 | |
| 543 | 543 | \SimpleSAML\Utils\System::writeFile($filename, $content, 0644); |
| 544 | 544 | } elseif (is_file($filename)) { |
| 545 | 545 | if (unlink($filename)) { |
| 546 | - Logger::debug('Deleting stale metadata file: ' . $filename); |
|
| 546 | + Logger::debug('Deleting stale metadata file: '.$filename); |
|
| 547 | 547 | } else { |
| 548 | - Logger::warning('Could not delete stale metadata file: ' . $filename); |
|
| 548 | + Logger::warning('Could not delete stale metadata file: '.$filename); |
|
| 549 | 549 | } |
| 550 | 550 | } |
| 551 | 551 | } |
@@ -568,8 +568,8 @@ discard block |
||
| 568 | 568 | $entityId = $m['metadata']['entityid']; |
| 569 | 569 | |
| 570 | 570 | Logger::debug( |
| 571 | - 'metarefresh: Add metadata entry ' . |
|
| 572 | - var_export($entityId, true) . ' in set ' . var_export($set, true) . '.' |
|
| 571 | + 'metarefresh: Add metadata entry '. |
|
| 572 | + var_export($entityId, true).' in set '.var_export($set, true).'.' |
|
| 573 | 573 | ); |
| 574 | 574 | $metaHandler->saveMetadata($entityId, $set, $m['metadata']); |
| 575 | 575 | } |
@@ -581,19 +581,19 @@ discard block |
||
| 581 | 581 | foreach ($metaHandler->getMetadataSet($set) as $entityId => $metadata) { |
| 582 | 582 | if (!array_key_exists('expire', $metadata)) { |
| 583 | 583 | Logger::warning( |
| 584 | - 'metarefresh: Metadata entry without expire timestamp: ' . var_export($entityId, true) . |
|
| 585 | - ' in set ' . var_export($set, true) . '.' |
|
| 584 | + 'metarefresh: Metadata entry without expire timestamp: '.var_export($entityId, true). |
|
| 585 | + ' in set '.var_export($set, true).'.' |
|
| 586 | 586 | ); |
| 587 | 587 | continue; |
| 588 | 588 | } |
| 589 | 589 | if ($metadata['expire'] > $ct) { |
| 590 | 590 | continue; |
| 591 | 591 | } |
| 592 | - Logger::debug('metarefresh: ' . $entityId . ' expired ' . date('l jS \of F Y h:i:s A', $metadata['expire'])); |
|
| 592 | + Logger::debug('metarefresh: '.$entityId.' expired '.date('l jS \of F Y h:i:s A', $metadata['expire'])); |
|
| 593 | 593 | Logger::debug( |
| 594 | - 'metarefresh: Delete expired metadata entry ' . |
|
| 595 | - var_export($entityId, true) . ' in set ' . var_export($set, true) . |
|
| 596 | - '. (' . ($ct - $metadata['expire']) . ' sec)' |
|
| 594 | + 'metarefresh: Delete expired metadata entry '. |
|
| 595 | + var_export($entityId, true).' in set '.var_export($set, true). |
|
| 596 | + '. ('.($ct - $metadata['expire']).' sec)' |
|
| 597 | 597 | ); |
| 598 | 598 | $metaHandler->deleteMetadata($entityId, $set); |
| 599 | 599 | } |
@@ -167,8 +167,10 @@ discard block |
||
| 167 | 167 | /* Do we have an attribute whitelist? */ |
| 168 | 168 | if (isset($source['attributewhitelist']) && !empty($source['attributewhitelist'])) { |
| 169 | 169 | $idpmetadata = $entity->getMetadata20IdP(); |
| 170 | - if (!isset($idpmetadata)) /* Skip non-IdPs */ |
|
| 170 | + if (!isset($idpmetadata)) { |
|
| 171 | + /* Skip non-IdPs */ |
|
| 171 | 172 | continue; |
| 173 | + } |
|
| 172 | 174 | |
| 173 | 175 | /* Do a recursive comparison for each whitelist of the attributewhitelist with the idpmetadata for this IdP. At least one of these whitelists should match */ |
| 174 | 176 | $match=0; |
@@ -178,8 +180,10 @@ discard block |
||
| 178 | 180 | break; |
| 179 | 181 | } |
| 180 | 182 | } |
| 181 | - if ($match==0) /* No match found -> next IdP */ |
|
| 183 | + if ($match==0) { |
|
| 184 | + /* No match found -> next IdP */ |
|
| 182 | 185 | continue; |
| 186 | + } |
|
| 183 | 187 | Logger::debug('Whitelisted entityID: '. $entity->getEntityID()); |
| 184 | 188 | } |
| 185 | 189 | |
@@ -237,8 +241,9 @@ discard block |
||
| 237 | 241 | /* key is number, check that the key appears as one |
| 238 | 242 | * of the destination keys: if not, then src has |
| 239 | 243 | * more keys than dst */ |
| 240 | - if (!array_key_exists($srckey, $dst)) |
|
| 241 | - return false; |
|
| 244 | + if (!array_key_exists($srckey, $dst)) { |
|
| 245 | + return false; |
|
| 246 | + } |
|
| 242 | 247 | |
| 243 | 248 | /* loop over dest keys, to find value: we don't know |
| 244 | 249 | * whether they are in the same order */ |
@@ -249,13 +254,15 @@ discard block |
||
| 249 | 254 | break; |
| 250 | 255 | } |
| 251 | 256 | } |
| 252 | - if ($submatch == 0) |
|
| 253 | - return false; |
|
| 257 | + if ($submatch == 0) { |
|
| 258 | + return false; |
|
| 259 | + } |
|
| 254 | 260 | } else { |
| 255 | 261 | /* key is regexp: find matching keys */ |
| 256 | 262 | $matchingdstkeys=preg_grep($srckey, $dstkeys); |
| 257 | - if (!is_array($matchingdstkeys)) |
|
| 258 | - return false; |
|
| 263 | + if (!is_array($matchingdstkeys)) { |
|
| 264 | + return false; |
|
| 265 | + } |
|
| 259 | 266 | |
| 260 | 267 | $match=0; |
| 261 | 268 | foreach ($matchingdstkeys as $dstkey) { |
@@ -265,8 +272,10 @@ discard block |
||
| 265 | 272 | break; |
| 266 | 273 | } |
| 267 | 274 | } |
| 268 | - if ($match==0) /* none of the keys has a matching value */ |
|
| 275 | + if ($match==0) { |
|
| 276 | + /* none of the keys has a matching value */ |
|
| 269 | 277 | return false; |
| 278 | + } |
|
| 270 | 279 | } |
| 271 | 280 | } |
| 272 | 281 | /* each src key/value matches */ |