Subversion Repositories logviewer

Rev

Rev 6 | Rev 9 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6 Rev 8
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * ViaThinkSoft LogViewer
4
 * ViaThinkSoft LogViewer
5
 * Copyright 2018-2019 Daniel Marschall, ViaThinkSoft
5
 * Copyright 2018-2019 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
require_once __DIR__.'/config.inc.php';
-
 
21
 
-
 
22
$hostname = trim(file_get_contents('/etc/hostname'));
20
$hostname = trim(file_get_contents('/etc/hostname'));
23
 
21
 
-
 
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
 
24
if (file_exists(__DIR__."/db_$hostname.inc.php")) {
28
if (file_exists(__DIR__."/db_$hostname.inc.php")) {
25
        require_once __DIR__."/db_$hostname.inc.php";
29
        require_once __DIR__."/db_$hostname.inc.php";
26
} else {
30
} else {
27
        require_once __DIR__.'/db.inc.php';
31
        require_once __DIR__.'/db.inc.php';
28
}
32
}
29
 
33
 
30
if (file_exists(__DIR__."/auth_$hostname.inc.php")) {
34
if (file_exists(__DIR__."/auth_$hostname.inc.php")) {
31
        require_once __DIR__."/auth_$hostname.inc.php";
35
        require_once __DIR__."/auth_$hostname.inc.php";
32
} else {
36
} else {
33
        require_once __DIR__.'/auth.inc.php';
37
        require_once __DIR__.'/auth.inc.php';
34
}
38
}
35
 
39
 
36
try {
40
try {
37
        logviewer_check_access();
41
        logviewer_check_access();
38
} catch (Exception $e) {
42
} catch (Exception $e) {
39
        die('<h1>ViaThinkSoft LogViewer - Error</h1><p>'.$e->getMessage().'</p>');
43
        die('<h1>ViaThinkSoft LogViewer - Error</h1><p>'.$e->getMessage().'</p>');
40
}
44
}
41
 
45
 
42
$sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : '';
46
$sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : '';
43
if ($sort == '') $sort = 'anzahl';
47
if ($sort == '') $sort = 'anzahl';
44
if (($sort != 'anzahl') && ($sort != 'letzter') && ($sort != 'random')) die('Sort falsch');
48
if (($sort != 'anzahl') && ($sort != 'letzter') && ($sort != 'random')) die('Sort falsch');
45
 
49
 
46
# Please keep this code synchronized with ajax_cmd.php
50
# Please keep this code synchronized with ajax_cmd.php
47
$add_filters = logviewer_additional_filter();
51
$add_filters = logviewer_additional_filter();
48
$hardcoded_filters = empty($add_filters) ? '' : "and ($add_filters)";
52
$hardcoded_filters = empty($add_filters) ? '' : "and ($add_filters)";
49
$hardcoded_filters .= " and (letzter >= DATE_SUB(NOW(),INTERVAL ".MAXYEARS." YEAR))";
53
$hardcoded_filters .= " and (letzter >= DATE_SUB(NOW(),INTERVAL ".MAXYEARS." YEAR))";
50
# Please keep this code synchronized with ajax_cmd.php
54
# Please keep this code synchronized with ajax_cmd.php
51
 
55
 
52
if (isset($_REQUEST['solveall']) && logviewer_allow_solvemark()) {
56
if (isset($_REQUEST['solveall']) && logviewer_allow_solvemark()) {
53
        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'])."%'");
54
        header('location:?sort='.urlencode($sort)); // avoid F5
58
        header('location:?sort='.urlencode($sort)); // avoid F5
55
        die();
59
        die();
56
}
60
}
57
 
61
 
58
$filter_add = '';
62
$filter_add = '';
59
if (isset($_REQUEST['filter'])) {
63
if (isset($_REQUEST['filter'])) {
60
        $ary = explode(' ', $_REQUEST['filter']);
64
        $ary = explode(' ', $_REQUEST['filter']);
61
        foreach ($ary as $a) {
65
        foreach ($ary as $a) {
62
                $a = trim($a);
66
                $a = trim($a);
63
                if ($a == '') continue;
67
                if ($a == '') continue;
64
 
68
 
65
                if (substr($a,0,1) == '-') {
69
                if (substr($a,0,1) == '-') {
66
                        $negate = "NOT ";
70
                        $negate = "NOT ";
67
                        $a = substr($a, 1); // remove "-"
71
                        $a = substr($a, 1); // remove "-"
68
                } else {
72
                } else {
69
                        $negate = " ";
73
                        $negate = " ";
70
                }
74
                }
71
 
75
 
72
                $filter_add .= " and text $negate like '".db_real_escape_string('%'.$a.'%')."' ";
76
                $filter_add .= " and text $negate like '".db_real_escape_string('%'.$a.'%')."' ";
73
        }
77
        }
74
}
78
}
75
 
79
 
76
?>
80
?>
77
<html>
81
<html>
78
 
82
 
79
<head>
83
<head>
80
        <title>ViaThinkSoft LogViewer</title>
84
        <title>ViaThinkSoft LogViewer</title>
81
        <script src="ajax.js"></script>
85
        <script src="ajax.js"></script>
82
        <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">
83
</head>
87
</head>
84
 
88
 
85
<body>
89
<body>
86
 
90
 
87
<h1>ViaThinkSoft LogViewer</h1>
91
<h1>ViaThinkSoft LogViewer</h1>
88
 
92
 
89
<form method="GET" action="index.php">
93
<form method="GET" action="index.php">
90
<input type="hidden" name="sort" value="<?php echo htmlentities($sort); ?>">
94
<input type="hidden" name="sort" value="<?php echo htmlentities($sort); ?>">
91
<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
92
if (isset($_REQUEST['filter'])) {
96
if (isset($_REQUEST['filter'])) {
93
        echo ' <a href="?sort='.htmlentities($sort).'">Clear filter</a>';
97
        echo ' <a href="?sort='.htmlentities($sort).'">Clear filter</a>';
94
        if (logviewer_allow_solvemark()) {
98
        if (logviewer_allow_solvemark()) {
95
                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>';
96
        }
100
        }
97
}
101
}
98
?></p>
102
?></p>
99
<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>
100
</form>
104
</form>
101
 
105
 
102
<?php
106
<?php
103
if (!empty($add_filters)) {
107
if (!empty($add_filters)) {
104
        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>';
105
} else {
109
} else {
106
        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>';
107
}
111
}
108
?>
112
?>
109
 
113
 
110
<div id="sort">Sort by: <?php
114
<div id="sort">Sort by: <?php
111
 
115
 
112
if ($sort == 'anzahl') {
116
if ($sort == 'anzahl') {
113
        echo '<span class="selected_menu">Occurrences</span>';
117
        echo '<span class="selected_menu">Occurrences</span>';
114
} else {
118
} else {
115
        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>';
116
}
120
}
117
 
121
 
118
?> | <?php
122
?> | <?php
119
 
123
 
120
if ($sort == 'letzter') {
124
if ($sort == 'letzter') {
121
        echo '<span class="selected_menu">Last occurrence</span>';
125
        echo '<span class="selected_menu">Last occurrence</span>';
122
} else {
126
} else {
123
        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>';
124
}
128
}
125
 
129
 
126
?> | <?php
130
?> | <?php
127
 
131
 
128
if ($sort == 'random') {
132
if ($sort == 'random') {
129
        echo '<span class="selected_menu">Random order</span>';
133
        echo '<span class="selected_menu">Random order</span>';
130
} else {
134
} else {
131
        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>';
132
}
136
}
133
 
137
 
134
?> (<span id="count"><?php
138
?> (<span id="count"><?php
135
 
139
 
136
$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.";");
137
$row = db_fetch_object($res);
141
$row = db_fetch_object($res);
138
echo $row->cnt;
142
echo $row->cnt;
139
 
143
 
140
?></span>)</div>
144
?></span>)</div>
141
 
145
 
142
<table border="1" width="100%">
146
<table border="1" width="100%">
143
<thead>
147
<thead>
144
<tr>
148
<tr>
145
<?php
149
<?php
146
if (SOURCE_STYLE == 0) {
150
if (SOURCE_STYLE == 0) {
147
        // nothing
151
        // nothing
148
} else if (SOURCE_STYLE == 1) {
152
} else if (SOURCE_STYLE == 1) {
149
?>
153
?>
150
        <td>Source</td>
154
        <td>Source</td>
151
        <td>Module</td>
155
        <td>Module</td>
152
<?php
156
<?php
153
} else if (SOURCE_STYLE == 2) {
157
} else if (SOURCE_STYLE == 2) {
154
?>
158
?>
155
        <td>User</td>
159
        <td>User</td>
156
<?php
160
<?php
157
}
161
}
158
?>
162
?>
159
        <?php if (logviewer_allow_solvemark()) { ?><td>Mark&nbsp;as...</td><?php } ?>
163
        <?php if (logviewer_allow_solvemark()) { ?><td>Mark&nbsp;as...</td><?php } ?>
160
        <td>Count</td>
164
        <td>Count</td>
161
        <td>Last&nbsp;occurrence</td>
165
        <td>Last&nbsp;occurrence</td>
162
        <td>Message</td>
166
        <td>Message</td>
163
</tr>
167
</tr>
164
</thead>
168
</thead>
165
<tbody>
169
<tbody>
166
<tr>
170
<tr>
167
<?php
171
<?php
168
 
172
 
169
$odd = true;
173
$odd = true;
170
 
174
 
171
if ($sort == 'letzter') {
175
if ($sort == 'letzter') {
172
        $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);
173
} else if ($sort == 'anzahl') {
177
} else if ($sort == 'anzahl') {
174
        $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);
175
} else if ($sort == 'random') {
179
} else if ($sort == 'random') {
176
        $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);
177
}
181
}
178
while ($row = db_fetch_object($res)) {
182
while ($row = db_fetch_object($res)) {
179
        $text = htmlentities($row->text);
183
        $text = htmlentities($row->text);
180
        $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
181
        $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
182
 
186
 
183
        $anzahl = htmlentities($row->anzahl);
187
        $anzahl = htmlentities($row->anzahl);
184
        if ($row->anzahlsolved != 0) $anzahl .= '<br>('.$row->anzahlsolved.')';
188
        if ($row->anzahlsolved != 0) $anzahl .= '<br>('.$row->anzahlsolved.')';
185
 
189
 
186
        $class = $odd ? 'tr_odd' : 'tr_even';
190
        $class = $odd ? 'tr_odd' : 'tr_even';
187
        $odd = !$odd;
191
        $odd = !$odd;
188
 
192
 
189
        echo '<tr id="line'.$row->id.'" class="'.$class.'">';
193
        echo '<tr id="line'.$row->id.'" class="'.$class.'">';
190
        if (SOURCE_STYLE == 0) {
194
        if (SOURCE_STYLE == 0) {
191
                // nothing
195
                // nothing
192
        } else if (SOURCE_STYLE == 1) {
196
        } else if (SOURCE_STYLE == 1) {
193
                echo '<td>'.htmlentities($row->logfile).'</td>';
197
                echo '<td>'.htmlentities($row->logfile).'</td>';
194
                echo '<td>'.htmlentities($row->modul).'</td>';
198
                echo '<td>'.htmlentities($row->modul).'</td>';
195
        } else {
199
        } else {
196
                $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' : '');
197
                echo '<td>'.htmlentities($user).'</td>';
201
                echo '<td>'.htmlentities($user).'</td>';
198
        }
202
        }
199
        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>';
200
        echo '<td>'.$anzahl.'</td>';
204
        echo '<td>'.$anzahl.'</td>';
201
        echo '<td>'.htmlentities($row->letzter).'</td>';
205
        echo '<td>'.htmlentities($row->letzter).'</td>';
202
        echo '<td>'.$text.'</td>';
206
        echo '<td>'.$text.'</td>';
203
        echo '</tr>';
207
        echo '</tr>';
204
        flush();
208
        flush();
205
}
209
}
206
?>
210
?>
207
</tr>
211
</tr>
208
</tbody>
212
</tbody>
209
</table>
213
</table>
210
 
214
 
211
</body>
215
</body>
212
 
216
 
213
</html>
217
</html>
214
 
218