From 563c55c388e50f65db8c2eb09887dbc804b60470 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 21:01:28 +0000 Subject: [PATCH] Adding santity check module to simplesamlphp. It checks things and reports if things are not working :) also supports using the cron hook git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@993 44740490-163a-0410-bde0-09ae8108e29a --- .../config-templates/config-sanitycheck.php | 18 +++++++ modules/sanitycheck/default-enable | 0 modules/sanitycheck/hooks/hook_cron.php | 35 +++++++++++++ modules/sanitycheck/hooks/hook_frontpage.php | 17 +++++++ .../sanitycheck/hooks/hook_sanitycheck.php | 17 +++++++ .../templates/default/check-tpl.php | 49 +++++++++++++++++++ modules/sanitycheck/www/index.php | 25 ++++++++++ 7 files changed, 161 insertions(+) create mode 100644 modules/sanitycheck/config-templates/config-sanitycheck.php create mode 100644 modules/sanitycheck/default-enable create mode 100644 modules/sanitycheck/hooks/hook_cron.php create mode 100644 modules/sanitycheck/hooks/hook_frontpage.php create mode 100644 modules/sanitycheck/hooks/hook_sanitycheck.php create mode 100644 modules/sanitycheck/templates/default/check-tpl.php create mode 100644 modules/sanitycheck/www/index.php diff --git a/modules/sanitycheck/config-templates/config-sanitycheck.php b/modules/sanitycheck/config-templates/config-sanitycheck.php new file mode 100644 index 000000000..ad607479f --- /dev/null +++ b/modules/sanitycheck/config-templates/config-sanitycheck.php @@ -0,0 +1,18 @@ +<?php +/* + * The configuration of simpleSAMLphp sanitycheck package + */ + +$config = array ( + + /* + * Do you want to generate statistics using the cron module? If so, specify which cron tag to use. + * Examples: daily, weekly + * To not run statistics in cron, set value to + * 'cron_tag' => NULL, + */ + 'cron_tag' => 'hourly', + +); + +?> \ No newline at end of file diff --git a/modules/sanitycheck/default-enable b/modules/sanitycheck/default-enable new file mode 100644 index 000000000..e69de29bb diff --git a/modules/sanitycheck/hooks/hook_cron.php b/modules/sanitycheck/hooks/hook_cron.php new file mode 100644 index 000000000..bcd5d93c9 --- /dev/null +++ b/modules/sanitycheck/hooks/hook_cron.php @@ -0,0 +1,35 @@ +<?php +/** + * Hook to run a cron job. + * + * @param array &$croninfo Output + */ +function sanitycheck_hook_cron(&$croninfo) { + assert('is_array($croninfo)'); + assert('array_key_exists("summary", $croninfo)'); + assert('array_key_exists("tag", $croninfo)'); + + $config = SimpleSAML_Configuration::getInstance(); + $sconfig = $config->copyFromBase('sconfig', 'config-sanitycheck.php'); + + if (is_null($sconfig->getValue('cron_tag', NULL))) return; + if ($sconfig->getValue('cron_tag', NULL) !== $croninfo['tag']) return; + + + $info = array(); + $errors = array(); + $hookinfo = array( + 'info' => &$info, + 'errors' => &$errors, + ); + + SimpleSAML_Module::callHooks('sanitycheck', $hookinfo); + + if (count($errors) > 0) { + foreach ($errors AS $err) { + $croninfo['summary'][] = 'Sanitycheck error: ' . $err; + } + } + +} +?> \ No newline at end of file diff --git a/modules/sanitycheck/hooks/hook_frontpage.php b/modules/sanitycheck/hooks/hook_frontpage.php new file mode 100644 index 000000000..8245ae24b --- /dev/null +++ b/modules/sanitycheck/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 sanitycheck_hook_frontpage(&$links) { + assert('is_array($links)'); + assert('array_key_exists("links", $links)'); + + $links['links'][] = array( + 'href' => SimpleSAML_Module::getModuleURL('sanitycheck/index.php'), + 'text' => array('en' => 'Sanity check of your simpleSAMLphp setup'), + ); + +} +?> \ No newline at end of file diff --git a/modules/sanitycheck/hooks/hook_sanitycheck.php b/modules/sanitycheck/hooks/hook_sanitycheck.php new file mode 100644 index 000000000..834977766 --- /dev/null +++ b/modules/sanitycheck/hooks/hook_sanitycheck.php @@ -0,0 +1,17 @@ +<?php +/** + * Hook to add the modinfo module to the frontpage. + * + * @param array &$hookinfo hookinfo + */ +function sanitycheck_hook_sanitycheck(&$hookinfo) { + assert('is_array($hookinfo)'); + assert('array_key_exists("errors", $hookinfo)'); + assert('array_key_exists("info", $hookinfo)'); + + $hookinfo['info'][] = '[sanitycheck] At least the sanity check it self is working :)'; + + $hookinfo['errors'][] = '[sanitycheck] At least the sanity check it self is working (NOT) :)'; + +} +?> \ No newline at end of file diff --git a/modules/sanitycheck/templates/default/check-tpl.php b/modules/sanitycheck/templates/default/check-tpl.php new file mode 100644 index 000000000..f167b4787 --- /dev/null +++ b/modules/sanitycheck/templates/default/check-tpl.php @@ -0,0 +1,49 @@ +<?php +$this->data['header'] = 'Sanity check'; +$this->includeAtTemplateBase('includes/header.php'); + +?> +<div id="content"> + +<h2><?php echo($this->data['header']); ?></h2> + +<?php +if (count($this->data['errors']) > 0) { +?> +<div style="border: 1px solid #800; background: #caa; margin: 1em; padding: .5em"> +<p><?php echo '<img src="/' . $this->data['baseurlpath'] . 'resources/icons/delete.png" alt="Failed" />'; ?> +These checks failed:</p> +<?php + + echo '<ul>'; + foreach ($this->data['errors'] AS $err) { + echo '<li>' . $err . '</li>'; + } + echo '</ul>'; + +echo '</div>'; +} +?> + +<?php +if (count($this->data['info']) > 0) { +?> +<div style="border: 1px solid #ccc; background: #eee; margin: 1em; padding: .5em"> +<p><?php echo '<img src="/' . $this->data['baseurlpath'] . 'resources/icons/accept.png" alt="OK" />'; ?> +These checks succeeded:</p> +<?php + echo '<ul>'; + foreach ($this->data['info'] AS $i) { + echo '<li>' . $i . '</li>'; + } + echo '</ul>'; + + +echo '</div>'; +} +?> + + +</div> + +<?php $this->includeAtTemplateBase('includes/footer.php'); ?> \ No newline at end of file diff --git a/modules/sanitycheck/www/index.php b/modules/sanitycheck/www/index.php new file mode 100644 index 000000000..7d86a2dab --- /dev/null +++ b/modules/sanitycheck/www/index.php @@ -0,0 +1,25 @@ +<?php + + +$config = SimpleSAML_Configuration::getInstance(); +$sconfig = $config->copyFromBase('sconfig', 'config-sanitycheck.php'); + + + + +$info = array(); +$errors = array(); +$hookinfo = array( + 'info' => &$info, + 'errors' => &$errors, +); +SimpleSAML_Module::callHooks('sanitycheck', $hookinfo); + + +$config = SimpleSAML_Configuration::getInstance(); +$t = new SimpleSAML_XHTML_Template($config, 'sanitycheck:check-tpl.php'); +$t->data['errors'] = $errors; +$t->data['info'] = $info; +$t->show(); + +?> \ No newline at end of file -- GitLab