ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
logcleaner.php
Go to the documentation of this file.
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();
13 
14 $progName = array_shift($argv);
15 $debug = false;
16 $dryrun = false;
17 $output = '/tmp/simplesamlphp-new.log';
18 $infile = null;
19 
20 foreach ($argv as $a) {
21  if (strlen($a) === 0) {
22  continue;
23  }
24  if (strpos($a, '=') !== false) {
25  $p = strpos($a, '=');
26  $v = substr($a, $p + 1);
27  $a = substr($a, 0, $p);
28  } else {
29  $v = null;
30  }
31 
32  // Map short options to long options.
33  $shortOptMap = array('-d' => '--debug');
34  if (array_key_exists($a, $shortOptMap)) {
35  $a = $shortOptMap[$a];
36  }
37 
38  switch ($a) {
39  case '--help':
40  printHelp();
41  exit(0);
42  case '--debug':
43  $debug = true;
44  break;
45  case '--dry-run':
46  $dryrun = true;
47  break;
48  case '--infile':
49  $infile = $v;
50  break;
51  case '--outfile':
52  $output = $v;
53  break;
54  default:
55  echo('Unknown option: ' . $a . "\n");
56  echo('Please run `' . $progName . ' --help` for usage information.' . "\n");
57  exit(1);
58  }
59 }
60 
62 $cleaner->dumpConfig();
64 
65 echo "Cleaning these trackIDs: " . join(', ', $todelete) . "\n";
66 
67 if (!$dryrun) {
68  $cleaner->store($todelete, $output);
69 }
70 
75 function printHelp() {
76  global $progName;
77 
78  echo <<<END
79 Usage: $progName [options]
80 
81 This program cleans logs. This script is experimental. Do not run it unless you have talked to Andreas about it.
82 The script deletes log lines related to sessions that produce more than 200 lines.
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  --infile File input.
88  --outfile File to output the results.
89 
90 END;
91 }
92 
global $argv
Definition: svg-scanner.php:41
$debug
Definition: logcleaner.php:15
$dryrun
Definition: logcleaner.php:16
$baseDir
Definition: logcleaner.php:5
$todelete
Definition: logcleaner.php:63
run()
Runs the loop.
Definition: functions.php:130
static setConfigDir($path, $configSet='simplesaml')
Set the directory for configuration files for the given configuration set.
foreach($argv as $a) $cleaner
Definition: logcleaner.php:61
input
Definition: langcheck.php:166
$progName
Definition: logcleaner.php:14
$infile
Definition: logcleaner.php:18
if(! $dryrun) printHelp()
This function prints the help output.
Definition: logcleaner.php:75
$output
Definition: logcleaner.php:17
exit
Definition: backend.php:16
$configdir
Definition: logcleaner.php:11