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