Skip to content
Snippets Groups Projects
Commit c754cda5 authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg
Browse files

Implementing cron hook in metarefresh module...

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1032 44740490-163a-0410-bde0-09ae8108e29a
parent 4114af1f
No related branches found
No related tags found
No related merge requests found
<?php
/**
* Hook to run a cron job.
*
* @param array &$croninfo Output
*/
function metarefresh_hook_cron(&$croninfo) {
assert('is_array($croninfo)');
assert('array_key_exists("summary", $croninfo)');
assert('array_key_exists("tag", $croninfo)');
SimpleSAML_Logger::info('cron [metarefresh]: Running cron in cron tag [' . $croninfo['tag'] . '] ');
try {
$config = SimpleSAML_Configuration::getInstance();
$mconfig = $config->copyFromBase('mconfig', 'config-metarefresh.php');
$sets = $mconfig->getValue('sets');
if (count($sets) < 1) return;
foreach ($sets AS $setkey => $set) {
// Only process sets where cron matches the current cron tag.
if (!in_array($croninfo['tag'], $set['cron'])) continue;
SimpleSAML_Logger::info('cron [metarefresh]: Executing set [' . $setkey . ']');
$maxcache = NULL; if (array_key_exists('maxcache', $set)) $maxcache = $set['maxcache'];
$maxduration = NULL; if (array_key_exists('maxduration', $set)) $maxcache = $set['maxduration'];
$metaloader = new sspmod_metarefresh_MetaLoader($maxcache, $maxduration);
foreach($set['sources'] AS $source) {
SimpleSAML_Logger::debug('cron [metarefresh]: In set [' . $setkey . '] loading source [' . $source['src'] . ']');
$metaloader->loadSource($source);
}
$metaloader->writeMetadataFiles($config->resolvePath($set['outputDir']));
}
} catch (Exception $e) {
$croninfo['summary'][] = 'Error during metarefresh: ' . $e->getMessage();
}
}
?>
\ No newline at end of file
...@@ -30,21 +30,21 @@ class sspmod_metarefresh_MetaLoader { ...@@ -30,21 +30,21 @@ class sspmod_metarefresh_MetaLoader {
* *
* @param $src Filename of the metadata file. * @param $src Filename of the metadata file.
*/ */
public function loadSource($src, $validateFingerprint = NULL, $template = NULL) { public function loadSource($source, $validateFingerprint = NULL, $template = NULL) {
$entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsFile($src); $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsFile($source['src']);
foreach($entities as $entity) { foreach($entities as $entity) {
if($validateFingerprint !== NULL) { if($validateFingerprint !== NULL) {
if(!$entity->validateFingerprint($validateFingerprint)) { if(!$entity->validateFingerprint($validateFingerprint)) {
echo('Skipping "' . $entity->getEntityId() . '" - could not verify signature.' . "\n"); SimpleSAML_Logger::info('Skipping "' . $entity->getEntityId() . '" - could not verify signature.' . "\n");
continue; continue;
} }
} }
if($ca !== NULL) { if($ca !== NULL) {
if(!$entity->validateCA($ca)) { if(!$entity->validateCA($ca)) {
echo('Skipping "' . $entity->getEntityId() . '" - could not verify certificate.' . "\n"); SimpleSAML_Logger::info('Skipping "' . $entity->getEntityId() . '" - could not verify certificate.' . "\n");
continue; continue;
} }
} }
...@@ -122,7 +122,7 @@ class sspmod_metarefresh_MetaLoader { ...@@ -122,7 +122,7 @@ class sspmod_metarefresh_MetaLoader {
} }
if(!file_exists($outputDir)) { if(!file_exists($outputDir)) {
echo('Creating directory: ' . $outputDir . "\n"); SimpleSAML_Logger::info('Creating directory: ' . $outputDir . "\n");
mkdir($outputDir, 0777, TRUE); mkdir($outputDir, 0777, TRUE);
} }
...@@ -130,11 +130,11 @@ class sspmod_metarefresh_MetaLoader { ...@@ -130,11 +130,11 @@ class sspmod_metarefresh_MetaLoader {
$filename = $outputDir . '/' . $category . '.php'; $filename = $outputDir . '/' . $category . '.php';
echo('Writing: ' . $filename . "\n"); SimpleSAML_Logger::debug('Writing: ' . $filename . "\n");
$fh = fopen($filename, 'w'); $fh = @fopen($filename, 'w');
if($fh === FALSE) { if($fh === FALSE) {
echo('Failed to open file for writing: ' . $filename . "\n"); throw new Exception('Failed to open file for writing: ' . $filename . "\n");
exit(1); exit(1);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment