From ea9c87b9ef52576a585e2d1e06b29faec6479ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no> Date: Fri, 14 Nov 2008 20:00:09 +0000 Subject: [PATCH] Adding link to cron information page at frontpage. Cron infomration page requires admin login. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@991 44740490-163a-0410-bde0-09ae8108e29a --- modules/cron/hooks/hook_frontpage.php | 17 +++++++ .../cron/templates/default/croninfo-tpl.php | 39 +++++++++++++++ modules/cron/www/croninfo.php | 48 +++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 modules/cron/hooks/hook_frontpage.php create mode 100644 modules/cron/templates/default/croninfo-tpl.php create mode 100644 modules/cron/www/croninfo.php diff --git a/modules/cron/hooks/hook_frontpage.php b/modules/cron/hooks/hook_frontpage.php new file mode 100644 index 000000000..869019f70 --- /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 000000000..e243363d7 --- /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 000000000..54122dc95 --- /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 -- GitLab