From 13eeb394d2980abf21e16cbb0ce08ca201407ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no> Date: Thu, 5 Nov 2009 13:13:03 +0000 Subject: [PATCH] Adding a separate page to load metadata, and verify output in logs... git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1971 44740490-163a-0410-bde0-09ae8108e29a --- modules/metarefresh/hooks/hook_frontpage.php | 17 +++++++ modules/metarefresh/templates/fetch.tpl.php | 23 +++++++++ modules/metarefresh/www/fetch.php | 50 ++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 modules/metarefresh/hooks/hook_frontpage.php create mode 100644 modules/metarefresh/templates/fetch.tpl.php create mode 100644 modules/metarefresh/www/fetch.php diff --git a/modules/metarefresh/hooks/hook_frontpage.php b/modules/metarefresh/hooks/hook_frontpage.php new file mode 100644 index 000000000..311cbc8d3 --- /dev/null +++ b/modules/metarefresh/hooks/hook_frontpage.php @@ -0,0 +1,17 @@ +<?php +/** + * Hook to add links to the frontpage. + * + * @param array &$links The links on the frontpage, split into sections. + */ +function metarefresh_hook_frontpage(&$links) { + assert('is_array($links)'); + assert('array_key_exists("links", $links)'); + + $links['federation'][] = array( + 'href' => SimpleSAML_Module::getModuleURL('metarefresh/fetch.php'), + 'text' => array('en' => 'Metarefresh: fetch metadata'), + ); + +} +?> \ No newline at end of file diff --git a/modules/metarefresh/templates/fetch.tpl.php b/modules/metarefresh/templates/fetch.tpl.php new file mode 100644 index 000000000..fe7b67687 --- /dev/null +++ b/modules/metarefresh/templates/fetch.tpl.php @@ -0,0 +1,23 @@ +<?php +$this->data['header'] = $this->t('{aggregator:dict:aggregator_header}'); +$this->includeAtTemplateBase('includes/header.php'); + +echo('<h1>Metarefresh fetch</h1>'); + + +if (!empty($this->data['logentries'])) { + + echo '<pre style="border: 1px solid #aaa; padding: .5em; overflow: scroll">'; + foreach($this->data['logentries'] AS $l) { + echo $l . "\n"; + } + echo '</pre>'; + +} else { + echo 'No output from metarefresh.'; +} + + + +$this->includeAtTemplateBase('includes/footer.php'); +?> \ No newline at end of file diff --git a/modules/metarefresh/www/fetch.php b/modules/metarefresh/www/fetch.php new file mode 100644 index 000000000..246bf74af --- /dev/null +++ b/modules/metarefresh/www/fetch.php @@ -0,0 +1,50 @@ +<?php + +$config = SimpleSAML_Configuration::getInstance(); +$mconfig = SimpleSAML_Configuration::getConfig('config-metarefresh.php'); + +SimpleSAML_Utilities::requireAdmin(); + +SimpleSAML_Logger::setCaptureLog(TRUE); + + +$sets = $mconfig->getConfigList('sets'); + +foreach ($sets AS $setkey => $set) { + + SimpleSAML_Logger::info('[metarefresh]: Executing set [' . $setkey . ']'); + + $expireAfter = $set->getInteger('expireAfter', NULL); + if ($expireAfter !== NULL) { + $expire = time() + $expireAfter; + } else { + $expire = NULL; + } + + $metaloader = new sspmod_metarefresh_MetaLoader($expire); + + foreach($set->getArray('sources') AS $source) { + SimpleSAML_Logger::debug('[metarefresh]: In set [' . $setkey . '] loading source [' . $source['src'] . ']'); + $metaloader->loadSource($source); + } + + $outputDir = $set->getString('outputDir'); + $outputDir = $config->resolvePath($outputDir); + + $outputFormat = $set->getValueValidate('outputFormat', array('flatfile', 'serialize'), 'flatfile'); + switch ($outputFormat) { + case 'flatfile': + $metaloader->writeMetadataFiles($outputDir); + break; + case 'serialize': + $metaloader->writeMetadataSerialize($outputDir); + break; + } + +} + +$logentries = SimpleSAML_Logger::getCapturedLog(); + +$t = new SimpleSAML_XHTML_Template($config, 'metarefresh:fetch.tpl.php'); +$t->data['logentries'] = $logentries; +$t->show(); \ No newline at end of file -- GitLab