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

Commit e1ad062

Browse files
committed
feat: Added metadata expiration page
1 parent 12759e7 commit e1ad062

File tree

2 files changed

+74
-0
lines changed

2 files changed

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

www/metadata_expiration.php

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

0 commit comments

Comments
 (0)