Rev 9 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | daniel-mar | 1 | <?php |
2 | |||
4 | daniel-mar | 3 | /* |
4 | * ViaThinkSoft LogViewer |
||
12 | daniel-mar | 5 | * Copyright 2018-2023 Daniel Marschall, ViaThinkSoft |
4 | daniel-mar | 6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
2 | daniel-mar | 20 | $hostname = trim(file_get_contents('/etc/hostname')); |
21 | |||
8 | daniel-mar | 22 | if (file_exists(__DIR__."/config_$hostname.inc.php")) { |
23 | require_once __DIR__."/config_$hostname.inc.php"; |
||
24 | } else { |
||
25 | require_once __DIR__.'/config.inc.php'; |
||
26 | } |
||
27 | |||
2 | daniel-mar | 28 | if (file_exists(__DIR__."/db_$hostname.inc.php")) { |
29 | require_once __DIR__."/db_$hostname.inc.php"; |
||
30 | } else { |
||
31 | require_once __DIR__.'/db.inc.php'; |
||
32 | } |
||
33 | |||
34 | if (file_exists(__DIR__."/auth_$hostname.inc.php")) { |
||
35 | require_once __DIR__."/auth_$hostname.inc.php"; |
||
36 | } else { |
||
37 | require_once __DIR__.'/auth.inc.php'; |
||
38 | } |
||
39 | |||
40 | try { |
||
41 | logviewer_check_access(); |
||
42 | } catch (Exception $e) { |
||
43 | die('<h1>ViaThinkSoft LogViewer - Error</h1><p>'.$e->getMessage().'</p>'); |
||
44 | } |
||
45 | |||
6 | daniel-mar | 46 | $sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : ''; |
47 | if ($sort == '') $sort = 'anzahl'; |
||
48 | if (($sort != 'anzahl') && ($sort != 'letzter') && ($sort != 'random')) die('Sort falsch'); |
||
49 | |||
2 | daniel-mar | 50 | # Please keep this code synchronized with ajax_cmd.php |
51 | $add_filters = logviewer_additional_filter(); |
||
12 | daniel-mar | 52 | $hardcoded_filters = empty($add_filters) ? '' : " and ($add_filters)"; |
2 | daniel-mar | 53 | $hardcoded_filters .= " and (letzter >= DATE_SUB(NOW(),INTERVAL ".MAXYEARS." YEAR))"; |
54 | # Please keep this code synchronized with ajax_cmd.php |
||
55 | |||
3 | daniel-mar | 56 | $filter_add = ''; |
57 | if (isset($_REQUEST['filter'])) { |
||
58 | $ary = explode(' ', $_REQUEST['filter']); |
||
59 | foreach ($ary as $a) { |
||
60 | $a = trim($a); |
||
61 | if ($a == '') continue; |
||
2 | daniel-mar | 62 | |
3 | daniel-mar | 63 | if (substr($a,0,1) == '-') { |
64 | $negate = "NOT "; |
||
65 | $a = substr($a, 1); // remove "-" |
||
66 | } else { |
||
67 | $negate = " "; |
||
68 | } |
||
69 | |||
6 | daniel-mar | 70 | $filter_add .= " and text $negate like '".db_real_escape_string('%'.$a.'%')."' "; |
3 | daniel-mar | 71 | } |
72 | } |
||
73 | |||
12 | daniel-mar | 74 | $where = "(anzahl > anzahlsolved) ".$filter_add." ".$hardcoded_filters; |
75 | |||
76 | if (isset($_REQUEST['solveall']) && logviewer_allow_solvemark()) { |
||
77 | db_query("update vts_fehlerlog set anzahlsolved = anzahl where $where"); |
||
78 | header('location:?sort='.urlencode($sort)); // avoid F5 |
||
79 | die(); |
||
80 | } |
||
81 | |||
2 | daniel-mar | 82 | ?> |
83 | <html> |
||
84 | |||
85 | <head> |
||
86 | <title>ViaThinkSoft LogViewer</title> |
||
87 | <script src="ajax.js"></script> |
||
88 | <link href="style<?php if (file_exists("style_$hostname.css")) echo "_$hostname"; ?>.css" rel="stylesheet" type="text/css"> |
||
89 | </head> |
||
90 | |||
91 | <body> |
||
92 | |||
93 | <h1>ViaThinkSoft LogViewer</h1> |
||
94 | |||
95 | <form method="GET" action="index.php"> |
||
96 | <input type="hidden" name="sort" value="<?php echo htmlentities($sort); ?>"> |
||
97 | <p>Filter: <input style="width:300px" type="text" name="filter" value="<?php echo htmlentities(isset($_REQUEST['filter']) ? $_REQUEST['filter'] : ''); ?>"> <input type="submit" value="Filter"><?php |
||
98 | if (isset($_REQUEST['filter'])) { |
||
99 | echo ' <a href="?sort='.htmlentities($sort).'">Clear filter</a>'; |
||
100 | if (logviewer_allow_solvemark()) { |
||
12 | daniel-mar | 101 | echo ' | <a href="?sort='.htmlentities($sort).'&solveall=1&filter='.urlencode($_REQUEST['filter']).'" onclick="return confirm(\'Are you sure?\');">Solve all</a>'; |
2 | daniel-mar | 102 | } |
103 | } |
||
104 | ?></p> |
||
3 | daniel-mar | 105 | <p><font size="-3">Search terms divided with whitespace. Prepend hyphen to exclude a search term. Only field "Message" will be searched.</font></p> |
2 | daniel-mar | 106 | </form> |
107 | |||
108 | <?php |
||
109 | if (!empty($add_filters)) { |
||
110 | echo '<span class="filter_hint">Showing max. '.COUNT.' results of max. '.MAXYEARS.' years; Hardcoded filter: '.htmlentities($add_filters).'</span>'; |
||
111 | } else { |
||
112 | echo '<span class="filter_hint">Showing max. '.COUNT.' results of max. '.MAXYEARS.' years</span>'; |
||
113 | } |
||
114 | ?> |
||
115 | |||
116 | <div id="sort">Sort by: <?php |
||
117 | |||
118 | if ($sort == 'anzahl') { |
||
119 | echo '<span class="selected_menu">Occurrences</span>'; |
||
120 | } else { |
||
121 | echo '<a href="?sort=anzahl'.((isset($_REQUEST['filter'])) ? '&filter='.urlencode($_REQUEST['filter']) : '').'">Occurrences</a>'; |
||
122 | } |
||
123 | |||
124 | ?> | <?php |
||
125 | |||
126 | if ($sort == 'letzter') { |
||
127 | echo '<span class="selected_menu">Last occurrence</span>'; |
||
128 | } else { |
||
129 | echo '<a href="?sort=letzter'.((isset($_REQUEST['filter'])) ? '&filter='.urlencode($_REQUEST['filter']) : '').'">Last occurrence</a>'; |
||
130 | } |
||
131 | |||
132 | ?> | <?php |
||
133 | |||
134 | if ($sort == 'random') { |
||
135 | echo '<span class="selected_menu">Random order</span>'; |
||
136 | } else { |
||
137 | echo '<a href="?sort=random'.((isset($_REQUEST['filter'])) ? '&filter='.urlencode($_REQUEST['filter']) : '').'">Random order</a>'; |
||
138 | } |
||
139 | |||
140 | ?> (<span id="count"><?php |
||
141 | |||
12 | daniel-mar | 142 | $res = db_query("select count(*) as cnt from vts_fehlerlog where $where;"); |
6 | daniel-mar | 143 | $row = db_fetch_object($res); |
144 | echo $row->cnt; |
||
2 | daniel-mar | 145 | |
146 | ?></span>)</div> |
||
147 | |||
148 | <table border="1" width="100%"> |
||
149 | <thead> |
||
150 | <tr> |
||
151 | <?php |
||
152 | if (SOURCE_STYLE == 0) { |
||
153 | // nothing |
||
154 | } else if (SOURCE_STYLE == 1) { |
||
155 | ?> |
||
156 | <td>Source</td> |
||
157 | <td>Module</td> |
||
158 | <?php |
||
159 | } else if (SOURCE_STYLE == 2) { |
||
160 | ?> |
||
161 | <td>User</td> |
||
162 | <?php |
||
163 | } |
||
164 | ?> |
||
165 | <?php if (logviewer_allow_solvemark()) { ?><td>Mark as...</td><?php } ?> |
||
166 | <td>Count</td> |
||
167 | <td>Last occurrence</td> |
||
168 | <td>Message</td> |
||
169 | </tr> |
||
170 | </thead> |
||
171 | <tbody> |
||
172 | <tr> |
||
173 | <?php |
||
174 | |||
175 | $odd = true; |
||
176 | |||
177 | if ($sort == 'letzter') { |
||
12 | daniel-mar | 178 | $res = db_query("select * from vts_fehlerlog where $where order by letzter desc, anzahl desc, id asc limit ".COUNT); |
2 | daniel-mar | 179 | } else if ($sort == 'anzahl') { |
12 | daniel-mar | 180 | $res = db_query("select * from vts_fehlerlog where $where order by anzahl desc, letzter desc, id asc limit ".COUNT); |
2 | daniel-mar | 181 | } else if ($sort == 'random') { |
12 | daniel-mar | 182 | $res = db_query("select * from vts_fehlerlog where $where order by RAND() limit ".COUNT); |
2 | daniel-mar | 183 | } |
6 | daniel-mar | 184 | while ($row = db_fetch_object($res)) { |
185 | $text = htmlentities($row->text); |
||
2 | daniel-mar | 186 | $text = preg_replace('@ ([^ ]{2,}) on line@ismU', ' <a href="?sort='.urlencode($sort).'&filter=\1">\1</a> on line', $text); // TODO: urlencode \1 |
187 | $text = preg_replace('@(at|in) ([^ ]{2,}):(\d+)@ismU', '\1 <a href="?sort='.urlencode($sort).'&filter=\2">\2</a>:\3', $text); // TODO: urlencode \2 |
||
188 | |||
6 | daniel-mar | 189 | $anzahl = htmlentities($row->anzahl); |
190 | if ($row->anzahlsolved != 0) $anzahl .= '<br>('.$row->anzahlsolved.')'; |
||
2 | daniel-mar | 191 | |
192 | $class = $odd ? 'tr_odd' : 'tr_even'; |
||
193 | $odd = !$odd; |
||
194 | |||
6 | daniel-mar | 195 | echo '<tr id="line'.$row->id.'" class="'.$class.'">'; |
2 | daniel-mar | 196 | if (SOURCE_STYLE == 0) { |
197 | // nothing |
||
198 | } else if (SOURCE_STYLE == 1) { |
||
6 | daniel-mar | 199 | echo '<td>'.htmlentities($row->logfile).'</td>'; |
200 | echo '<td>'.htmlentities($row->modul).'</td>'; |
||
2 | daniel-mar | 201 | } else { |
6 | daniel-mar | 202 | $user = preg_match('@/home/(.+)/@sU', $row->logfile, $m) ? $m[1] : ((strpos($row->logfile, '/root/') === 0) ? 'root' : ''); |
2 | daniel-mar | 203 | echo '<td>'.htmlentities($user).'</td>'; |
204 | } |
||
6 | daniel-mar | 205 | if (logviewer_allow_solvemark()) echo '<td><a href="javascript:_solve('.$row->id.')">Solved</a></td>'; |
2 | daniel-mar | 206 | echo '<td>'.$anzahl.'</td>'; |
6 | daniel-mar | 207 | echo '<td>'.htmlentities($row->letzter).'</td>'; |
2 | daniel-mar | 208 | echo '<td>'.$text.'</td>'; |
209 | echo '</tr>'; |
||
210 | flush(); |
||
211 | } |
||
212 | ?> |
||
213 | </tr> |
||
214 | </tbody> |
||
215 | </table> |
||
216 | |||
217 | </body> |
||
218 | |||
219 | </html> |