/** * Hook to run a cron job. * * @param array &$croninfo Output */ function statistics_hook_cron(&$croninfo) { assert('is_array($croninfo)'); assert('array_key_exists("summary", $croninfo)'); assert('array_key_exists("tag", $croninfo)'); $statconfig = SimpleSAML_Configuration::getConfig('module_statistics.php'); if (is_null($statconfig->getValue('cron_tag', NULL))) { return; } if ($statconfig->getValue('cron_tag', NULL) !== $croninfo['tag']) { return; } $maxtime = $statconfig->getInteger('time_limit', NULL); if ($maxtime) { set_time_limit($maxtime); } try { $aggregator = new sspmod_statistics_Aggregator(); $results = $aggregator->aggregate(); if (empty($results)) { SimpleSAML\Logger::notice('Output from statistics aggregator was empty.'); } else { $aggregator->store($results); } } catch (Exception $e) { $message = 'Loganalyzer threw exception: ' . $e->getMessage(); SimpleSAML\Logger::warning($message); $croninfo['summary'][] = $message; } }
case '--help': printHelp(); exit(0); case '--debug': $debug = TRUE; break; case '--dry-run': $dryrun = TRUE; break; default: echo 'Unknown option: ' . $a . "\n"; echo 'Please run `' . $progName . ' --help` for usage information.' . "\n"; exit(1); } } $aggregator = new sspmod_statistics_Aggregator(TRUE); $aggregator->dumpConfig(); $aggregator->debugInfo(); $results = $aggregator->aggregate($debug); $aggregator->debugInfo(); if (!$dryrun) { $aggregator->store($results); } foreach ($results as $slot => $val) { foreach ($val as $sp => $no) { echo $sp . " " . count($no) . " - "; } echo "\n"; } /** * This function prints the help output.
SimpleSAML_Logger::debug('Statistics auth - valid login with auth source [' . $authsource . ']'); // Retrieving attributes $attributes = $session->getAttributes(); // Check if userid exists if (!isset($attributes[$useridattr])) { throw new Exception('User ID is missing'); } // Check if userid is allowed access.. if (!in_array($attributes[$useridattr][0], $allowedusers)) { SimpleSAML_Logger::debug('Statistics auth - User denied access by user ID [' . $attributes[$useridattr][0] . ']'); throw new Exception('Access denied for this user.'); } SimpleSAML_Logger::debug('Statistics auth - User granted access by user ID [' . $attributes[$useridattr][0] . ']'); } elseif (isset($authsource)) { // If user is not logged in init login with authrouce if authsousrce is defined. SimpleSAML_Auth_Default::initLogin($authsource, SimpleSAML_Utilities::selfURL()); } else { // If authsource is not defined, init admin login. SimpleSAML_Utilities::requireAdmin(); } } $aggr = new sspmod_statistics_Aggregator(); $aggr->loadMetadata(); $metadata = $aggr->getMetadata(); // echo('<pre>'); print_r($metadata); /** * AUTHENTICATION and Authorization for access to the statistics. ------ */ $t = new SimpleSAML_XHTML_Template($config, 'statistics:statmeta-tpl.php'); $t->data['metadata'] = $metadata; $t->show();