|
| 1 | +#!/usr/bin/env php |
| 2 | +<?php |
| 3 | + |
| 4 | +// This is the base directory of the SimpleSAMLphp installation |
| 5 | +$baseDir = dirname(dirname(dirname(dirname(__FILE__)))); |
| 6 | + |
| 7 | +// Add library autoloader. |
| 8 | +require_once($baseDir.'/lib/_autoload.php'); |
| 9 | + |
| 10 | +// Initialize the configuration. |
| 11 | +$configdir = \SimpleSAML\Utils\Config::getConfigDir(); |
| 12 | +\SimpleSAML\Configuration::setConfigDir($configdir); |
| 13 | +\SimpleSAML\Utils\Time::initTimezone(); |
| 14 | + |
| 15 | +$progName = array_shift($argv); |
| 16 | +$debug = false; |
| 17 | +$dryrun = false; |
| 18 | + |
| 19 | +foreach ($argv as $a) { |
| 20 | + if (strlen($a) === 0) { |
| 21 | + continue; |
| 22 | + } |
| 23 | + if (strpos($a, '=') !== false) { |
| 24 | + $p = strpos($a, '='); |
| 25 | + $v = substr($a, $p + 1); |
| 26 | + $a = substr($a, 0, $p); |
| 27 | + } else { |
| 28 | + $v = null; |
| 29 | + } |
| 30 | + |
| 31 | + // Map short options to long options. |
| 32 | + $shortOptMap = ['-d' => '--debug']; |
| 33 | + if (array_key_exists($a, $shortOptMap)) { |
| 34 | + $a = $shortOptMap[$a]; |
| 35 | + } |
| 36 | + switch ($a) { |
| 37 | + case '--help': |
| 38 | + printHelp(); |
| 39 | + exit(0); |
| 40 | + case '--debug': |
| 41 | + $debug = true; |
| 42 | + break; |
| 43 | + case '--dry-run': |
| 44 | + $dryrun = true; |
| 45 | + break; |
| 46 | + default: |
| 47 | + echo 'Unknown option: '.$a."\n"; |
| 48 | + echo 'Please run `'.$progName.' --help` for usage information.'."\n"; |
| 49 | + exit(1); |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +$aggregator = new \SimpleSAML\Module\statistics\Aggregator(true); |
| 54 | +$aggregator->dumpConfig(); |
| 55 | +$aggregator->debugInfo(); |
| 56 | +$results = $aggregator->aggregate($debug); |
| 57 | +$aggregator->debugInfo(); |
| 58 | + |
| 59 | +if (!$dryrun) { |
| 60 | + $aggregator->store($results); |
| 61 | +} |
| 62 | + |
| 63 | +foreach ($results as $slot => $val) { |
| 64 | + foreach ($val as $sp => $no) { |
| 65 | + echo $sp." ".count($no)." - "; |
| 66 | + } |
| 67 | + echo "\n"; |
| 68 | +} |
| 69 | + |
| 70 | + |
| 71 | +/** |
| 72 | + * This function prints the help output. |
| 73 | + * @return void |
| 74 | + */ |
| 75 | +function printHelp() |
| 76 | +{ |
| 77 | + global $progName; |
| 78 | + |
| 79 | + echo <<<END |
| 80 | +Usage: $progName [options] |
| 81 | +
|
| 82 | +This program parses and aggregates SimpleSAMLphp log files. |
| 83 | +
|
| 84 | +Options: |
| 85 | + -d, --debug Used when configuring the log file syntax. See doc. |
| 86 | + --dry-run Aggregate but do not store the results. |
| 87 | +END; |
| 88 | +} |
0 commit comments