Subversion Repositories logviewer

Rev

Rev 3 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 daniel-mar 1
<?php
2
 
3
require_once __DIR__.'/config.inc.php';
4
 
5
$hostname = trim(file_get_contents('/etc/hostname'));
6
 
7
if (file_exists(__DIR__."/db_$hostname.inc.php")) {
8
        require_once __DIR__."/db_$hostname.inc.php";
9
} else {
10
        require_once __DIR__.'/db.inc.php';
11
}
12
 
13
if (file_exists(__DIR__."/auth_$hostname.inc.php")) {
14
        require_once __DIR__."/auth_$hostname.inc.php";
15
} else {
16
        require_once __DIR__.'/auth.inc.php';
17
}
18
 
19
try {
20
        logviewer_check_access();
21
} catch (Exception $e) {
22
        die('<h1>ViaThinkSoft LogViewer - Error</h1><p>'.$e->getMessage().'</p>');
23
}
24
 
25
# Please keep this code synchronized with ajax_cmd.php
26
$add_filters = logviewer_additional_filter();
27
$hardcoded_filters = empty($add_filters) ? '' : "and ($add_filters)";
28
$hardcoded_filters .= " and (letzter >= DATE_SUB(NOW(),INTERVAL ".MAXYEARS." YEAR))";
29
# Please keep this code synchronized with ajax_cmd.php
30
 
31
if (isset($_REQUEST['solveall']) && logviewer_allow_solvemark()) {
32
        mysql_query("update vts_fehlerlog set anzahlsolved = anzahl where text like '%".mysql_real_escape_string($_REQUEST['solveall'])."%'");
33
        header('location:?sort='.urlencode($sort)); // avoid F5
34
        die();
35
}
36
 
37
$filter = isset($_REQUEST['filter']) ? '%'.mysql_real_escape_string($filter).'%' : '';
38
$filter_add = $filter ? "and text like '%".mysql_real_escape_string($filter)."%'" : '';
39
 
40
$sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : '';
41
if ($sort == '') $sort = 'anzahl';
42
if (($sort != 'anzahl') && ($sort != 'letzter') && ($sort != 'random')) die('Sort falsch');
43
 
44
?>
45
<html>
46
 
47
<head>
48
        <title>ViaThinkSoft LogViewer</title>
49
        <script src="ajax.js"></script>
50
        <link href="style<?php if (file_exists("style_$hostname.css")) echo "_$hostname"; ?>.css" rel="stylesheet" type="text/css">
51
</head>
52
 
53
<body>
54
 
55
<h1>ViaThinkSoft LogViewer</h1>
56
 
57
<form method="GET" action="index.php">
58
<input type="hidden" name="sort" value="<?php echo htmlentities($sort); ?>">
59
<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
60
if (isset($_REQUEST['filter'])) {
61
        echo ' <a href="?sort='.htmlentities($sort).'">Clear filter</a>';
62
        if (logviewer_allow_solvemark()) {
63
                echo ' | <a href="?sort='.htmlentities($sort).'&solveall='.urlencode($_REQUEST['filter']).'" onclick="return confirm(\'Are you sure?\');">Solve all</a>';
64
        }
65
}
66
?></p>
67
</form>
68
 
69
<?php
70
if (!empty($add_filters)) {
71
        echo '<span class="filter_hint">Showing max. '.COUNT.' results of max. '.MAXYEARS.' years; Hardcoded filter: '.htmlentities($add_filters).'</span>';
72
} else {
73
        echo '<span class="filter_hint">Showing max. '.COUNT.' results of max. '.MAXYEARS.' years</span>';
74
}
75
?>
76
 
77
<div id="sort">Sort by: <?php
78
 
79
if ($sort == 'anzahl') {
80
        echo '<span class="selected_menu">Occurrences</span>';
81
} else {
82
        echo '<a href="?sort=anzahl'.((isset($_REQUEST['filter'])) ? '&filter='.urlencode($_REQUEST['filter']) : '').'">Occurrences</a>';
83
}
84
 
85
?> | <?php
86
 
87
if ($sort == 'letzter') {
88
        echo '<span class="selected_menu">Last occurrence</span>';
89
} else {
90
        echo '<a href="?sort=letzter'.((isset($_REQUEST['filter'])) ? '&filter='.urlencode($_REQUEST['filter']) : '').'">Last occurrence</a>';
91
}
92
 
93
?> | <?php
94
 
95
if ($sort == 'random') {
96
        echo '<span class="selected_menu">Random order</span>';
97
} else {
98
        echo '<a href="?sort=random'.((isset($_REQUEST['filter'])) ? '&filter='.urlencode($_REQUEST['filter']) : '').'">Random order</a>';
99
}
100
 
101
?> (<span id="count"><?php
102
 
103
$res = mysql_query("select count(*) as cnt from vts_fehlerlog where (anzahl > anzahlsolved) ".$filter_add." ".$hardcoded_filters.";");
104
$row = mysql_fetch_array($res);
105
echo $row['cnt'];
106
 
107
?></span>)</div>
108
 
109
<table border="1" width="100%">
110
<thead>
111
<tr>
112
<?php
113
if (SOURCE_STYLE == 0) {
114
        // nothing
115
} else if (SOURCE_STYLE == 1) {
116
?>
117
        <td>Source</td>
118
        <td>Module</td>
119
<?php
120
} else if (SOURCE_STYLE == 2) {
121
?>
122
        <td>User</td>
123
<?php
124
}
125
?>
126
        <?php if (logviewer_allow_solvemark()) { ?><td>Mark&nbsp;as...</td><?php } ?>
127
        <td>Count</td>
128
        <td>Last&nbsp;occurrence</td>
129
        <td>Message</td>
130
</tr>
131
</thead>
132
<tbody>
133
<tr>
134
<?php
135
 
136
$odd = true;
137
 
138
if ($sort == 'letzter') {
139
        $res = mysql_query("select * from vts_fehlerlog where (anzahl > anzahlsolved) ".$filter_add." ".$hardcoded_filters." order by letzter desc, anzahl desc, id asc limit ".COUNT);
140
} else if ($sort == 'anzahl') {
141
        $res = mysql_query("select * from vts_fehlerlog where (anzahl > anzahlsolved) ".$filter_add." ".$hardcoded_filters." order by anzahl desc, letzter desc, id asc limit ".COUNT);
142
} else if ($sort == 'random') {
143
        $res = mysql_query("select * from vts_fehlerlog where (anzahl > anzahlsolved) ".$filter_add." ".$hardcoded_filters." order by RAND() limit ".COUNT);
144
}
145
while ($row = mysql_fetch_array($res)) {
146
        $text = htmlentities($row['text']);
147
        $text = preg_replace('@ ([^ ]{2,}) on line@ismU', ' <a href="?sort='.urlencode($sort).'&filter=\1">\1</a> on line', $text); // TODO: urlencode \1
148
        $text = preg_replace('@(at|in) ([^ ]{2,}):(\d+)@ismU', '\1 <a href="?sort='.urlencode($sort).'&filter=\2">\2</a>:\3', $text); // TODO: urlencode \2
149
 
150
        $anzahl = htmlentities($row['anzahl']);
151
        if ($row['anzahlsolved'] != 0) $anzahl .= '<br>('.$row['anzahlsolved'].')';
152
 
153
        $class = $odd ? 'tr_odd' : 'tr_even';
154
        $odd = !$odd;
155
 
156
        echo '<tr id="line'.$row['id'].'" class="'.$class.'">';
157
        if (SOURCE_STYLE == 0) {
158
                // nothing
159
        } else if (SOURCE_STYLE == 1) {
160
                echo '<td>'.htmlentities($row['logfile']).'</td>';
161
                echo '<td>'.htmlentities($row['modul']).'</td>';
162
        } else {
163
                $user = preg_match('@/home/(.+)/@sU', $row['logfile'], $m) ? $m[1] : ((strpos($row['logfile'], '/root/') === 0) ? 'root' : '');
164
                echo '<td>'.htmlentities($user).'</td>';
165
        }
166
        if (logviewer_allow_solvemark()) echo '<td><a href="javascript:_solve('.$row['id'].')">Solved</a></td>';
167
        echo '<td>'.$anzahl.'</td>';
168
        echo '<td>'.htmlentities($row['letzter']).'</td>';
169
        echo '<td>'.$text.'</td>';
170
        echo '</tr>';
171
        flush();
172
}
173
?>
174
</tr>
175
</tbody>
176
</table>
177
 
178
</body>
179
 
180
</html>