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

Adding cron module...

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@988 44740490-163a-0410-bde0-09ae8108e29a
parent 13cffefc
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 cron_hook_cron(&$croninfo) {
assert('is_array($croninfo)');
assert('array_key_exists("summary", $croninfo)');
assert('array_key_exists("tag", $croninfo)');
$config = SimpleSAML_Configuration::getInstance();
$cronconfig = $config->copyFromBase('cron', 'module_cron.php');
if ($cronconfig->getValue('debug_message', TRUE)) {
$croninfo['summary'][] = 'Cron did run tag [' . $croninfo['tag'] . '] at ' . date(DATE_RFC822);
}
}
?>
\ No newline at end of file
<?php
$config = SimpleSAML_Configuration::getInstance();
$cronconfig = $config->copyFromBase('cron', 'module_cron.php');
if (!is_null($cronconfig->getValue('key'))) {
if ($_REQUEST['key'] !== $cronconfig->getValue('key')) {
SimpleSAML_Logger::error('Cron - Wrong key provided. Cron will not run.');
exit;
}
}
#print_r($_REQUEST['tag']) ; exit;
if (!is_null($cronconfig->getValue('allowed_tags'))) {
if (!in_array($_REQUEST['tag'], $cronconfig->getValue('allowed_tags'))) {
SimpleSAML_Logger::error('Cron - Illegal tag [' . $_REQUEST['tag'] . '].');
exit;
}
}
$summary = array();
$croninfo = array(
'summary' => &$summary,
'tag' => $_REQUEST['tag'],
);
SimpleSAML_Module::callHooks('cron', $croninfo);
foreach ($summary AS $s) {
SimpleSAML_Logger::debug('Cron - Summary: ' . $s);
}
if ($cronconfig->getValue('sendemail', TRUE) && count($summary) > 0) {
$statustext = '<ul><li>' . join('</li><li>', $summary) . '</li></ul>';
$message = '<h1>Cron report</h1><p>Cron ran at ' . date(DATE_RFC822) . '</p>' .
'<p>Tag: ' . $_REQUEST['tag'] . "</p>\n\n" . $statustext;
$toaddress = $config->getValue('technicalcontact_email', 'na@example.org');
if($toaddress == 'na@example.org') {
SimpleSAML_Logger::error('Cron - Could not send email. [technicalcontact_email] not set in config.');
} else {
$email = new SimpleSAML_XHTML_EMail($toaddress, 'simpleSAMLphp cron report', 'no-reply@simplesamlphp.com');
$email->setBody($message);
$email->send();
}
}
#$t = new SimpleSAML_XHTML_Template($config, 'modinfo:modlist.php');
#$t->data['modules'] = $modinfo;
#$t->show();
?>
\ No newline at end of file
......@@ -46,7 +46,9 @@ function parse23($str) {
$results = array();
# Sat, 16 Feb 08 00:55:11 (23 chars)
foreach ($logfile AS $logline) {
$datenumbers = 15;
$datenumbers = 19;
if (!preg_match('/^[0-9]{4}/', $logline)) continue;
$datestr = substr($logline,0,$datenumbers);
#$datestr = substr($logline,0,23);
......@@ -55,14 +57,23 @@ foreach ($logfile AS $logline) {
$restcols = split(' ', $restofline);
$action = $restcols[5];
# print_r($restcols); exit;
// print_r($timestamp);
// print_r($restcols); if ($i++ > 5) exit;
foreach ($statrules AS $rulename => $rule) {
$timeslot = floor($timestamp/$rule['slot']);
$fileslot = floor($timestamp/$rule['fileslot']);
if ($action !== $rule['action']) continue;
if (isset($rule['action'])) {
if ($action !== $rule['action']) continue;
}
$difcol = $restcols[$rule['col']];
$difcolsp = split('@', $difcol);
$difcol = $difcolsp[1];
// print(' foo: ' . $difcol . ' : ' . $rule['col']); exit;
$results[$rulename][$fileslot][$timeslot]['_']++;
$results[$rulename][$fileslot][$timeslot][$difcol]++;
}
......@@ -72,7 +83,7 @@ foreach ($logfile AS $logline) {
echo "Results:\n";
print_r($results);
#print_r($results);
......
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