diff --git a/modules/cron/hooks/hook_frontpage.php b/modules/cron/hooks/hook_frontpage.php new file mode 100644 index 0000000000000000000000000000000000000000..869019f70ceef180d78e5823b76c587b2500e80d --- /dev/null +++ b/modules/cron/hooks/hook_frontpage.php @@ -0,0 +1,17 @@ +<?php +/** + * Hook to add the modinfo module to the frontpage. + * + * @param array &$links The links on the frontpage, split into sections. + */ +function cron_hook_frontpage(&$links) { + assert('is_array($links)'); + assert('array_key_exists("links", $links)'); + + $links['links'][] = array( + 'href' => SimpleSAML_Module::getModuleURL('cron/croninfo.php'), + 'text' => array('en' => 'Cron module information page'), + ); + +} +?> \ No newline at end of file diff --git a/modules/cron/templates/default/croninfo-tpl.php b/modules/cron/templates/default/croninfo-tpl.php new file mode 100644 index 0000000000000000000000000000000000000000..e243363d71294eec4bcedb135060815f7ca2479f --- /dev/null +++ b/modules/cron/templates/default/croninfo-tpl.php @@ -0,0 +1,39 @@ +<?php + +$this->data['header'] = 'Cron information page'; +$this->includeAtTemplateBase('includes/header.php'); + +?> +<div id="content"> + + <p>Cron is a way to run things regularly on unix systems.</p> + + <p>Here is a suggestion for a crontab file:</p> + <pre style="font-size: x-small; color: #444; padding: 1em; border: 1px solid #eee; margin: .4em "><code><?php + + foreach ($this->data['urls'] AS $url ) { + echo "# " . $url['title'] . "\n"; + echo "" . $url['int'] . " /usr/bin/lynx -source " . $url['href'] . "\n"; + } + + ?> + </code></pre> + + <p>Click here to run the cron jobs: + <ul> + <?php + + foreach ($this->data['urls'] AS $url ) { + echo '<li><a href="' . $url['href'] . '">' . $url['title'] . '</a></li>'; + } + + ?> + + </ul> + + +</div> + +<?php +$this->includeAtTemplateBase('includes/footer.php'); +?> \ No newline at end of file diff --git a/modules/cron/www/croninfo.php b/modules/cron/www/croninfo.php new file mode 100644 index 0000000000000000000000000000000000000000..54122dc95184dcaafbd021470171c82e9dfcaf88 --- /dev/null +++ b/modules/cron/www/croninfo.php @@ -0,0 +1,48 @@ +<?php + +/** + * The _include script registers a autoloader for the simpleSAMLphp libraries. It also + * initializes the simpleSAMLphp config class with the correct path. + */ +require_once('_include.php'); + + +/* Load simpleSAMLphp, configuration and metadata */ +$config = SimpleSAML_Configuration::getInstance(); +$session = SimpleSAML_Session::getInstance(); + +if (!isset($session) || !$session->isValid('login-admin') ) { + SimpleSAML_Utilities::redirect('/' . $config->getBaseURL() . 'auth/login-admin.php', + array('RelayState' => SimpleSAML_Utilities::selfURL()) + ); +} + +$cronconfig = $config->copyFromBase('cron', 'module_cron.php'); + +$key = $cronconfig->getValue('key', ''); +$tags = $cronconfig->getValue('allowed_tags'); + +$def = array( + 'weekly' => "22 0 * * 0", + 'daily' => "02 0 * * *", + 'hourly' => "01 * * * *", + 'default' => "XXXXXXXXXX", +); + +$urls = array(); +foreach ($tags AS $tag) { + $urls[] = array( + 'href' => SimpleSAML_Module::getModuleURL('cron/cron.php?key=' . $key . '&tag=' . $tag), + 'title' => 'Run cron [' . $tag . ']', + 'int' => (array_key_exists($tag, $def) ? $def[$tag] : $def['default']), + ); +} + + + +$t = new SimpleSAML_XHTML_Template($config, 'cron:croninfo-tpl.php'); +$t->data['urls'] = $urls; +$t->show(); + + +?> \ No newline at end of file