Skip to content

Commit 563c55c

Browse files
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
1 parent 461736b commit 563c55c

7 files changed

Lines changed: 161 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/*
3+
* The configuration of simpleSAMLphp sanitycheck package
4+
*/
5+
6+
$config = array (
7+
8+
/*
9+
* Do you want to generate statistics using the cron module? If so, specify which cron tag to use.
10+
* Examples: daily, weekly
11+
* To not run statistics in cron, set value to
12+
* 'cron_tag' => NULL,
13+
*/
14+
'cron_tag' => 'hourly',
15+
16+
);
17+
18+
?>

modules/sanitycheck/default-enable

Whitespace-only changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Hook to run a cron job.
4+
*
5+
* @param array &$croninfo Output
6+
*/
7+
function sanitycheck_hook_cron(&$croninfo) {
8+
assert('is_array($croninfo)');
9+
assert('array_key_exists("summary", $croninfo)');
10+
assert('array_key_exists("tag", $croninfo)');
11+
12+
$config = SimpleSAML_Configuration::getInstance();
13+
$sconfig = $config->copyFromBase('sconfig', 'config-sanitycheck.php');
14+
15+
if (is_null($sconfig->getValue('cron_tag', NULL))) return;
16+
if ($sconfig->getValue('cron_tag', NULL) !== $croninfo['tag']) return;
17+
18+
19+
$info = array();
20+
$errors = array();
21+
$hookinfo = array(
22+
'info' => &$info,
23+
'errors' => &$errors,
24+
);
25+
26+
SimpleSAML_Module::callHooks('sanitycheck', $hookinfo);
27+
28+
if (count($errors) > 0) {
29+
foreach ($errors AS $err) {
30+
$croninfo['summary'][] = 'Sanitycheck error: ' . $err;
31+
}
32+
}
33+
34+
}
35+
?>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Hook to add the modinfo module to the frontpage.
4+
*
5+
* @param array &$links The links on the frontpage, split into sections.
6+
*/
7+
function sanitycheck_hook_frontpage(&$links) {
8+
assert('is_array($links)');
9+
assert('array_key_exists("links", $links)');
10+
11+
$links['links'][] = array(
12+
'href' => SimpleSAML_Module::getModuleURL('sanitycheck/index.php'),
13+
'text' => array('en' => 'Sanity check of your simpleSAMLphp setup'),
14+
);
15+
16+
}
17+
?>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Hook to add the modinfo module to the frontpage.
4+
*
5+
* @param array &$hookinfo hookinfo
6+
*/
7+
function sanitycheck_hook_sanitycheck(&$hookinfo) {
8+
assert('is_array($hookinfo)');
9+
assert('array_key_exists("errors", $hookinfo)');
10+
assert('array_key_exists("info", $hookinfo)');
11+
12+
$hookinfo['info'][] = '[sanitycheck] At least the sanity check it self is working :)';
13+
14+
$hookinfo['errors'][] = '[sanitycheck] At least the sanity check it self is working (NOT) :)';
15+
16+
}
17+
?>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
$this->data['header'] = 'Sanity check';
3+
$this->includeAtTemplateBase('includes/header.php');
4+
5+
?>
6+
<div id="content">
7+
8+
<h2><?php echo($this->data['header']); ?></h2>
9+
10+
<?php
11+
if (count($this->data['errors']) > 0) {
12+
?>
13+
<div style="border: 1px solid #800; background: #caa; margin: 1em; padding: .5em">
14+
<p><?php echo '<img src="/' . $this->data['baseurlpath'] . 'resources/icons/delete.png" alt="Failed" />'; ?>
15+
These checks failed:</p>
16+
<?php
17+
18+
echo '<ul>';
19+
foreach ($this->data['errors'] AS $err) {
20+
echo '<li>' . $err . '</li>';
21+
}
22+
echo '</ul>';
23+
24+
echo '</div>';
25+
}
26+
?>
27+
28+
<?php
29+
if (count($this->data['info']) > 0) {
30+
?>
31+
<div style="border: 1px solid #ccc; background: #eee; margin: 1em; padding: .5em">
32+
<p><?php echo '<img src="/' . $this->data['baseurlpath'] . 'resources/icons/accept.png" alt="OK" />'; ?>
33+
These checks succeeded:</p>
34+
<?php
35+
echo '<ul>';
36+
foreach ($this->data['info'] AS $i) {
37+
echo '<li>' . $i . '</li>';
38+
}
39+
echo '</ul>';
40+
41+
42+
echo '</div>';
43+
}
44+
?>
45+
46+
47+
</div>
48+
49+
<?php $this->includeAtTemplateBase('includes/footer.php'); ?>

modules/sanitycheck/www/index.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
4+
$config = SimpleSAML_Configuration::getInstance();
5+
$sconfig = $config->copyFromBase('sconfig', 'config-sanitycheck.php');
6+
7+
8+
9+
10+
$info = array();
11+
$errors = array();
12+
$hookinfo = array(
13+
'info' => &$info,
14+
'errors' => &$errors,
15+
);
16+
SimpleSAML_Module::callHooks('sanitycheck', $hookinfo);
17+
18+
19+
$config = SimpleSAML_Configuration::getInstance();
20+
$t = new SimpleSAML_XHTML_Template($config, 'sanitycheck:check-tpl.php');
21+
$t->data['errors'] = $errors;
22+
$t->data['info'] = $info;
23+
$t->show();
24+
25+
?>

0 commit comments

Comments
 (0)