-
Notifications
You must be signed in to change notification settings - Fork 56
/
report.php
99 lines (89 loc) · 2 KB
/
report.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
header('Access-Control-Allow-Origin: *');
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;
}
function getHbbTV($uagent) {
$idx = stripos($uagent, 'HbbTV/');
if ($idx===false) {
return null;
}
$uagent = substr($uagent, $idx);
$idx = strpos($uagent, ')');
if ($idx) {
$uagent = substr($uagent, 0, $idx+1);
}
return $uagent;
}
$now = time();
$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 = "$now;$step;$succss;$note;$txt\n";
$uagent = $_SERVER['HTTP_USER_AGENT'];
$hbbtv = getHbbTV($uagent);
$logdir = 'log';
$logext = '.report';
$file = $logdir.'/'.$pin.'-'.$run.'-'.sha1($_SERVER['REMOTE_ADDR'].'#'.$uagent).$logext;
if (is_file($file)) {
$fp = @fopen($file, 'a');
} else {
$fp = @fopen($file, 'w');
if ($fp) {
fputs($fp, ';'.$_SERVER['REMOTE_ADDR'].';'.$now.';'.$uagent."\n");
}
}
if (!$fp) {
exit;
}
fputs($fp, $line);
fclose($fp);
if ($hbbtv) {
$file = $logdir.'/bydev-'.sha1($hbbtv).$logext;
if (is_file($file)) {
$fp = @fopen($file, 'a');
} else {
$fp = @fopen($file, 'w');
fputs($fp, ';'.$_SERVER['REMOTE_ADDR'].';'.$now.';'.$uagent."\n");
}
if ($fp) {
fputs($fp, $line);
fclose($fp);
}
}
# expire old log files
$expired = time()-31*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);
}