Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | daniel-mar | 1 | #!/usr/bin/php |
2 | <?php |
||
3 | |||
4 | if (php_sapi_name() !== 'cli') { |
||
5 | die("Error: This script can only be called from command line.\n"); |
||
6 | } |
||
7 | |||
8 | require_once __DIR__.'/../config.inc.php'; |
||
9 | |||
10 | $hostname = trim(file_get_contents('/etc/hostname')); |
||
11 | |||
12 | if (file_exists(__DIR__."/../db_$hostname.inc.php")) { |
||
13 | require_once __DIR__."/../db_$hostname.inc.php"; |
||
14 | } else { |
||
15 | require_once __DIR__.'/../db.inc.php'; |
||
16 | } |
||
17 | |||
18 | $files = array(); |
||
19 | foreach (apache_log_locations as $tpl) $files = array_merge($files, glob($tpl)); |
||
20 | usort($files, create_function('$a,$b', 'return filemtime($a) - filemtime($b);')); |
||
21 | |||
22 | $phpfiles = array(); |
||
23 | foreach (php_log_locations as $tpl) $phpfiles = array_merge($phpfiles, glob($tpl)); |
||
24 | usort($phpfiles, create_function('$a,$b', 'return filemtime($a) - filemtime($b);')); |
||
25 | |||
26 | $file_nr = 0; |
||
27 | $file_max = count($files) + count($phpfiles); |
||
28 | foreach ($files as $file) { |
||
29 | $file_nr++; |
||
30 | $lines = file($file); |
||
31 | $line_nr = 0; |
||
32 | $line_max = count($lines); |
||
33 | $logfile = removeLogrotateSuffix($file); |
||
34 | foreach ($lines as $line) { |
||
35 | $line_nr++; |
||
36 | #[Sun Aug 13 15:54:16.054530 2017] [fcgid:warn] [pid 28401] [client 104.236.113.44:52188] mod_fcgid: stderr: PHP Notice: Undefined offset: 11 in /home/d |
||
37 | if (!preg_match('@^\[(.*)\] \[(.*)\] \[(.*)\] \[(.*)\] (.*)$@ismU', $line, $m)) continue; |
||
38 | $time = $m[1]; |
||
39 | $modul = $m[2]; |
||
40 | $text = $m[5]; |
||
41 | |||
42 | $time = trim(substr($time, 4, 6)).' '.substr($time, -4).' '.substr($time, 11, 8); |
||
43 | $time_mysql = date('Y-m-d H:i:s', strtotime($time)); |
||
44 | |||
45 | $res = mysql_query("select * from vts_fehlerlog where modul = '".mysql_real_escape_string($modul)."' and logfile = '".mysql_real_escape_string($logfile)."' and text = '".mysql_real_escape_string($text)."';"); |
||
46 | #echo mysql_error(); |
||
47 | if (mysql_num_rows($res) > 0) { |
||
48 | mysql_query("update vts_fehlerlog set anzahl = anzahl + 1, letzter = '$time_mysql' " . |
||
49 | "where modul = '".mysql_real_escape_string($modul)."' and logfile = '".mysql_real_escape_string($logfile)."' and text = '".mysql_real_escape_string($text)."' and letzter < '".$time_mysql."';"); |
||
50 | #echo mysql_error(); |
||
51 | |||
52 | } else { |
||
53 | mysql_query("insert into vts_fehlerlog (modul, text, anzahl, letzter, logfile) " . |
||
54 | "values ('".mysql_real_escape_string($modul)."', '".mysql_real_escape_string($text)."', 1, '".$time_mysql."', '".mysql_real_escape_string($logfile)."');"); |
||
55 | #echo mysql_error(); |
||
56 | } |
||
57 | echo "file $file_nr/$file_max (line $line_nr/$line_max) \r"; |
||
58 | } |
||
59 | } |
||
60 | foreach ($phpfiles as $file) { |
||
61 | $file_nr++; |
||
62 | |||
63 | $cont = file_get_contents($file); |
||
64 | $cont = str_replace("\r", "", $cont); |
||
65 | $cont = str_replace("\n ", " ", $cont); |
||
66 | $lines = explode("\n", $cont); |
||
67 | |||
68 | $line_nr = 0; |
||
69 | $line_max = count($lines); |
||
70 | $logfile = removeLogrotateSuffix($file); |
||
71 | foreach ($lines as $line) { |
||
72 | $line_nr++; |
||
73 | # [19-Aug-2017 23:00:54 europe/berlin] PHP Notice: Undefined variable: ssl in /home/viathinksoft/public_html/serverinfo/index.php on line 364 |
||
74 | if (!preg_match('@^\[(.*)\] ((.*)(\n ){0,1})$@ismU', $line, $m)) continue; |
||
75 | $time = $m[1]; |
||
76 | $modul = ''; |
||
77 | $text = $m[2]; |
||
78 | |||
79 | $time = trim(substr($time, 0, 20)); |
||
80 | $time_mysql = date('Y-m-d H:i:s', strtotime($time)); |
||
81 | |||
82 | $res = mysql_query("select * from vts_fehlerlog where modul = '".mysql_real_escape_string($modul)."' and logfile = '".mysql_real_escape_string($logfile)."' and text = '".mysql_real_escape_string($text)."';"); |
||
83 | #echo mysql_error(); |
||
84 | if (mysql_num_rows($res) > 0) { |
||
85 | mysql_query("update vts_fehlerlog set anzahl = anzahl + 1, letzter = '$time_mysql' " . |
||
86 | "where modul = '".mysql_real_escape_string($modul)."' and logfile = '".mysql_real_escape_string($logfile)."' and text = '".mysql_real_escape_string($text)."' and letzter < '".$time_mysql."';"); |
||
87 | #echo mysql_error(); |
||
88 | |||
89 | } else { |
||
90 | mysql_query("insert into vts_fehlerlog (modul, text, anzahl, letzter, logfile) " . |
||
91 | "values ('".mysql_real_escape_string($modul)."', '".mysql_real_escape_string($text)."', 1, '".$time_mysql."', '".mysql_real_escape_string($logfile)."');"); |
||
92 | #echo mysql_error(); |
||
93 | } |
||
94 | echo "file $file_nr/$file_max (line $line_nr/$line_max) \r"; |
||
95 | } |
||
96 | } |
||
97 | echo "\n"; |
||
98 | |||
99 | # --- |
||
100 | |||
101 | function removeLogrotateSuffix($filename) { |
||
102 | $filename = preg_replace('@\\.(\\d+)(\\.gz){0,1}$@ismU', '', $filename); |
||
103 | return $filename; |
||
104 | } |
||
105 |