-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogreader.php
More file actions
121 lines (104 loc) · 2.49 KB
/
logreader.php
File metadata and controls
121 lines (104 loc) · 2.49 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
class apachelogparser
{
/**
* PHP5 Constructor method
*
* @param void
* @return void
* @access public
*/
function __construct()
{
}
/**
* PHP4 Constructor method
*
* @return logparser
*/
function logparser()
{
$this->__construct();
}
/**
* Method to convert a logfile to an array to manipulate
*
* @param string filename $file
* @return array
* @access public
*/
function log2arr($file)
{
$file = file($file);
return $file;
}
/**
* Get the statistics from the file manager
*
* @param string $file
* @return array
*/
public function logfileStats($file)
{
$fname = basename($file);
$fsize = filesize($file);
$fpath = pathinfo($file);
return array('filesize' => $fsize, 'filename' => $fname, 'filepath' => $fpath);
}
/**
* Method to parse and glean info from an apache2 logfile entry
*
* @param string $line
* @return array
* @access public
*/
public function parselogEntry($line)
{
$stuff = explode('"',$line);
//unset the blanks
unset($stuff[4]);
unset($stuff[6]);
//split the first line into ip and date
$comps = explode(" ", $stuff[0]);
$ip = $comps[0];
$date = $comps[3].$comps[4];
//fix up the date to be more readable
$date = str_replace("[","",$date);
$date = str_replace("]","",$date);
$date = $this->fixDates($date);
$ts = strtotime($date);
$request = $stuff[1];
$servercode = $stuff[2];
$requrl = $stuff[3];
$useragent = $stuff[5];
$requestarr = array('fullrecord' => $line, 'ip' => $ip, 'date' => $date, 'ts' => $ts, 'request' => $request, 'servercode' => $servercode, 'requrl' => $requrl, 'useragent' => $useragent);
return $requestarr;
}
/**
* Method to fix the dates that appear in std format in the logfiles
*
* @param string $datetime
* @return ISO formatted date
* @access private
*/
private function fixDates($datetime)
{
$datetime = explode("/", $datetime);
$day = $datetime[0];
$month = $datetime[1];
$yearandtime = $datetime[2];
$yndarr = explode(":", $yearandtime);
$year = $yndarr[0];
$hours = $yndarr[1];
$minutes = $yndarr[2];
$secsandtz = $yndarr[3];
$sarr = explode("+",$secsandtz);
$seconds = $sarr[0];
$tz = $sarr[1];
$datestring = $day . " " . $month . " " . $year . " " . $hours . ":" . $minutes . ":" . $seconds . " " . "+" . $tz;
$date = strtotime($datestring);
$ref = date('r', $date);
return $ref;
}
}
?>