1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
<?php
class Page_SysLog extends Page
{
protected function doPreprocess()
{
User::load();
if (!User::isLoggedIn()) {
Message::addError('no-permission');
Util::redirect('?do=Main');
}
}
protected function doRender()
{
Render::setTitle('Client Log');
Render::addScriptBottom('bootstrap-tagsinput.min');
if (isset($_GET['filter'])) {
$filter = $_GET['filter'];
$not = isset($_GET['not']) ? 'NOT' : '';
} elseif (isset($_POST['filter'])) {
$filter = $_POST['filter'];
$not = isset($_POST['not']) ? 'NOT' : '';
Session::set('log_filter', $filter);
Session::set('log_not', $not);
Session::save();
} else {
$filter = Session::get('log_filter');
$not = Session::get('log_not') ? 'NOT' : '';
}
if (!empty($filter)) {
$filterList = explode(',', $filter);
$whereClause = array();
foreach ($filterList as $filterItem) {
$filterItem = preg_replace('/[^a-z0-9_\-]/', '', trim($filterItem));
if (empty($filterItem) || in_array($filterItem, $whereClause)) continue;
$whereClause[] = "'$filterItem'";
}
if (!empty($whereClause)) $whereClause = ' WHERE logtypeid ' . $not . ' IN (' . implode(', ', $whereClause) . ')';
}
if (!isset($whereClause) || empty($whereClause)) $whereClause = '';
$today = date('d.m.Y');
$yesterday = date('d.m.Y', time() - 86400);
$lines = array();
$paginate = new Paginate("SELECT logid, dateline, logtypeid, clientip, description, extra FROM clientlog $whereClause ORDER BY logid DESC", 50);
$res = $paginate->exec();
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
$day = date('d.m.Y', $row['dateline']);
// TODO: No output strings in source files!
if ($day === $today) {
$day = 'Heute';
} elseif ($day === $yesterday) {
$day = 'Gestern';
}
$row['date'] = $day . date(' H:i', $row['dateline']);
$lines[] = $row;
}
$paginate->render('page-syslog', array(
'filter' => $filter,
'not' => $not,
'list' => $lines
));
}
}
|