Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit 6e5bf43

Browse files
author
Dominik František Bučík
authored
Merge pull request #179 from BaranekD/metadata_expiration
feat: Added metadata expiration page
2 parents 487511c + a264738 commit 6e5bf43

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This template just shows a time to metadata expiration.
7+
*
8+
* It can be used to check whether the meta refresh works without problems.
9+
*/
10+
11+
echo $this->data['closestExpiration'];

www/metadata_expiration.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This script loads all the metadata and finds the one which is closest to expiration. Then it sends the time to
7+
* expiration to the template.
8+
*
9+
* This can be used to check whether the meta refresh works without problems.
10+
*/
11+
12+
$config = SimpleSAML_Configuration::getInstance();
13+
$session = SimpleSAML_Session::getSessionFromRequest();
14+
15+
$metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
16+
17+
$metaentries = [
18+
'hosted' => [],
19+
'remote' => [],
20+
];
21+
$metaentries['remote']['saml20-idp-remote'] = $metadata->getList('saml20-idp-remote');
22+
$metaentries['remote']['shib13-idp-remote'] = $metadata->getList('shib13-idp-remote');
23+
24+
if ($config->getBoolean('enable.saml20-idp', false) === true) {
25+
try {
26+
$metaentries['remote']['saml20-sp-remote'] = $metadata->getList('saml20-sp-remote');
27+
} catch (Exception $e) {
28+
SimpleSAML\Logger::error('Federation: Error loading saml20-idp: ' . $e->getMessage());
29+
}
30+
}
31+
32+
if ($config->getBoolean('enable.shib13-idp', false) === true) {
33+
try {
34+
$metaentries['remote']['shib13-sp-remote'] = $metadata->getList('shib13-sp-remote');
35+
} catch (Exception $e) {
36+
SimpleSAML\Logger::error('Federation: Error loading shib13-idp: ' . $e->getMessage());
37+
}
38+
}
39+
40+
if ($config->getBoolean('enable.adfs-idp', false) === true) {
41+
try {
42+
$metaentries['remote']['adfs-sp-remote'] = $metadata->getList('adfs-sp-remote');
43+
} catch (Exception $e) {
44+
SimpleSAML\Logger::error('Federation: Error loading adfs-idp: ' . $e->getMessage());
45+
}
46+
}
47+
48+
foreach ($metaentries['remote'] as $key => $value) {
49+
if (empty($value)) {
50+
unset($metaentries['remote'][$key]);
51+
}
52+
}
53+
54+
$now = time();
55+
$closestExpiration = null;
56+
57+
foreach ($metaentries['remote'] as $setkey => $set) {
58+
foreach ($set as $entry) {
59+
if (array_key_exists('expire', $entry)) {
60+
$expires = number_format(($entry['expire'] - $now) / 3600, 1);
61+
$closestExpiration === null ?
62+
$closestExpiration = $expires : $closestExpiration = min($closestExpiration, $expires);
63+
}
64+
}
65+
}
66+
67+
$t = new SimpleSAML_XHTML_Template($config, 'perun:metadata_expiration-tpl.php');
68+
$t->data['closestExpiration'] = $closestExpiration;
69+
$t->show();

0 commit comments

Comments
 (0)