New spider psbot/0.1
[infodrom.org/www.zeitungsliste.de] / lib / extern / apache-log-parser.php
1 <?php\r
2 /*\r
3 +----------------------------------------------+\r
4 |                                              |\r
5 |         PHP apache log parser class          |\r
6 |                                              |\r
7 +----------------------------------------------+\r
8 | Filename   : apache-log-parser.php           |\r
9 | Created    : 21-Sep-05 23:28 GMT             |\r
10 | Created By : Sam Clarke                      |\r
11 | Email      : admin@free-webmaster-help.com   |\r
12 | Version    : 1.0                             |\r
13 |                                              |\r
14 +----------------------------------------------+\r
15 \r
16 http://www.phpclasses.org/browse/download/1/file/10984/name/apache-log-parser.php\r
17 \r
18 LICENSE\r
19 \r
20 This program is free software; you can redistribute it and/or\r
21 modify it under the terms of the GNU General Public License (GPL)\r
22 as published by the Free Software Foundation; either version 2\r
23 of the License, or (at your option) any later version.\r
24 \r
25 This program is distributed in the hope that it will be useful,\r
26 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
28 GNU General Public License for more details.\r
29 \r
30 To read the license please visit http://www.gnu.org/copyleft/gpl.html\r
31 \r
32 */\r
33 \r
34 class apache_log_parser\r
35 {\r
36 \r
37   var $bad_rows; // Number of bad rows\r
38   var $fp; // File pointer\r
39 \r
40   function format_log_line($line)\r
41   {\r
42     preg_match("/^(\S+) (\S+) (\S+) \[([^:]+):(\d+:\d+:\d+) ([^\]]+)\] \"(\S+) (.*?) (\S+)\" (\S+) (\S+) (\".*?\") (\".*?\")$/", $line, $matches); // pattern to format the line\r
43     return $matches;\r
44   }\r
45 \r
46   function format_line($line)\r
47   {\r
48     $logs = $this->format_log_line($line); // format the line\r
49 \r
50     if (isset($logs[0])) // check that it formated OK\r
51     {\r
52       $formated_log = array(); // make an array to store the lin info in\r
53       $formated_log['ip'] = $logs[1];\r
54       $formated_log['identity'] = $logs[2];\r
55       $formated_log['user'] = $logs[2];\r
56       $formated_log['date'] = $logs[4];\r
57       $formated_log['time'] = $logs[5];\r
58       $formated_log['timezone'] = $logs[6];\r
59       $formated_log['method'] = $logs[7];\r
60       $formated_log['path'] = $logs[8];\r
61       $formated_log['protocal'] = $logs[9];\r
62       $formated_log['status'] = $logs[10];\r
63       $formated_log['bytes'] = $logs[11];\r
64       $formated_log['referer'] = $logs[12];\r
65       $formated_log['agent'] = $logs[13];\r
66       return $formated_log; // return the array of info\r
67     }\r
68     else\r
69     {\r
70       $this->badRows++; // if the row is not in the right format add it to the bad rows\r
71       return false;\r
72     }\r
73   }\r
74 \r
75   function open_log_file($file_name)\r
76   {\r
77     $this->fp = fopen($file_name, 'r'); // open the file\r
78     if (!$this->fp)\r
79     {\r
80       return false; // return false on fail\r
81     }\r
82     return true; // return true on sucsess\r
83   }\r
84 \r
85   function close_log_file()\r
86   {\r
87     return fclose($this->fp); // close the file\r
88   }\r
89 \r
90   // gets a line from the log file\r
91   function get_line()\r
92   {\r
93     if (feof($this->fp))\r
94     {\r
95        return false;\r
96     }\r
97     $line = fgets ($this->fp, 1024);\r
98     return $line;\r
99   }\r
100 \r
101 }\r
102 ?>\r