Skip to content

Commit

Permalink
added reporting script
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Schmid committed Nov 4, 2016
1 parent 068fec4 commit 356f119
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
log
63 changes: 63 additions & 0 deletions report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
function clean($txt) {
$txt = str_replace(';', ',', $txt);
$ret = '';
for ($i=0; $i<strlen($txt); $i++) {
$c = substr($txt, $i, 1);
if (ord($c)<32) {
continue;
}
if (ord($c)>127) {
$c = '_';
}
$ret .= $c;
}
return $ret;
}

$step = clean($_REQUEST['step']);
if (!$step) {
exit;
}
$succss = (int)$_REQUEST['succss'];
$pin = max(0, min(10000, (int)$_REQUEST['pin']));
$run = max(0, min(1000000, (int)$_REQUEST['run']));
$note = clean($_REQUEST['note']);
$txt = clean($_REQUEST['txt']);
$line = "$step;$succss;$note;$txt\n";

$logdir = 'log';
$logext = '.report';
$file = $logdir.'/'.$pin.'-'.$run.'-'.sha1($_SERVER['REMOTE_ADDR'].'#'.$_SERVER['HTTP_USER_AGENT']).$logext;

if (is_file($file)) {
$fp = @fopen($file, 'a');
} else {
$fp = @fopen($file, 'w');
fputs($fp, ';'.$_SERVER['REMOTE_ADDR'].';'.$_SERVER['HTTP_USER_AGENT']."\n");
}

if ($fp) {
fputs($fp, $line);
fclose($fp);
}

# expire old log files
$expired = time()-7*24*3600;
$delfiles = array();
$fp = @opendir($logdir);
while (false!==($file=@readdir($fp))) {
if (strlen($file)<10 || substr($file, -strlen($logext))!==$logext) {
continue;
}
$file = $logdir.'/'.$file;
$tim = @filemtime($file);
if ($tim && $tim<$expired && is_file($file)) {
$delfiles[] = $file;
}
}
@closedir($fp);
foreach ($delfiles as $file) {
@unlink($file);
}

0 comments on commit 356f119

Please sign in to comment.