Issues (2963)

includes/html/table/eventlog.inc.php (1 issue)

1
<?php
2
/*
3
 * This program is free software: you can redistribute it and/or modify it
4
 * under the terms of the GNU General Public License as published by the
5
 * Free Software Foundation, either version 3 of the License, or (at your
6
 * option) any later version.  Please see LICENSE.txt at the top level of
7
 * the source code distribution for details.
8
 *
9
 * @package    LibreNMS
10
 * @subpackage webui
11
 * @link       https://www.librenms.org
12
 * @copyright  2018 LibreNMS
13
 * @author     LibreNMS Contributors
14
*/
15
16
$where = '1';
17
18
if (is_numeric($vars['device'])) {
19
    $where .= ' AND E.device_id = ?';
20
    $param[] = (int) $vars['device'];
21
}
22
23
if (! empty($vars['eventtype'])) {
24
    $where .= ' AND `E`.`type` = ?';
25
    $param[] = $vars['eventtype'];
26
}
27
28
if ($vars['string']) {
29
    $where .= ' AND E.message LIKE ?';
30
    $param[] = '%' . $vars['string'] . '%';
31
}
32
33
if (Auth::user()->hasGlobalRead()) {
34
    $sql = " FROM `eventlog` AS E LEFT JOIN `devices` AS `D` ON `E`.`device_id`=`D`.`device_id` WHERE $where";
35
} else {
36
    $sql = " FROM `eventlog` AS E, devices_perms AS P WHERE $where AND E.device_id = P.device_id AND P.user_id = ?";
37
    $param[] = Auth::id();
38
}
39
40
if (isset($searchPhrase) && ! empty($searchPhrase)) {
41
    $sql .= ' AND (`D`.`hostname` LIKE ? OR `D`.`sysName` LIKE ? OR `E`.`datetime` LIKE ? OR `E`.`message` LIKE ? OR `E`.`type` LIKE ? OR `E`.`username` LIKE ?)';
42
    $param[] = "%$searchPhrase%";
43
    $param[] = "%$searchPhrase%";
44
    $param[] = "%$searchPhrase%";
45
    $param[] = "%$searchPhrase%";
46
    $param[] = "%$searchPhrase%";
47
    $param[] = "%$searchPhrase%";
48
}
49
50
$count_sql = "SELECT COUNT(event_id) $sql";
51
$total = dbFetchCell($count_sql, $param);
52
if (empty($total)) {
53
    $total = 0;
54
}
55
56
if (! isset($sort) || empty($sort)) {
57
    $sort = 'datetime DESC';
58
}
59
60
$sql .= " ORDER BY $sort";
61
62
if (isset($current)) {
63
    $limit_low = (($current * $rowCount) - ($rowCount));
64
    $limit_high = $rowCount;
65
}
66
67
if ($rowCount != -1) {
68
    $sql .= " LIMIT $limit_low,$limit_high";
69
}
70
71
$sql = "SELECT `E`.*,DATE_FORMAT(datetime, '" . \LibreNMS\Config::get('dateformat.mysql.compact') . "') as humandate,severity $sql";
72
73
foreach (dbFetchRows($sql, $param) as $eventlog) {
74
    $dev = device_by_id_cache($eventlog['device_id']);
75
    if ($eventlog['type'] == 'interface') {
76
        $this_if = cleanPort(getifbyid($eventlog['reference']));
77
        $type = '<b>' . generate_port_link($this_if, makeshortif(strtolower($this_if['label']))) . '</b>';
0 ignored issues
show
Are you sure generate_port_link($this...er($this_if['label']))) of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

77
        $type = '<b>' . /** @scrutinizer ignore-type */ generate_port_link($this_if, makeshortif(strtolower($this_if['label']))) . '</b>';
Loading history...
78
    } else {
79
        $type = $eventlog['type'];
80
    }
81
    $severity_colour = $eventlog['severity'];
82
83
    if ($eventlog['username'] == '') {
84
        $eventlog['username'] = 'System';
85
    }
86
87
    $response[] = [
88
        'datetime' => "<span class='alert-status " . eventlog_severity($severity_colour) . " eventlog-status'></span><span style='display:inline;'>" . $eventlog['humandate'] . '</span>',
89
        'hostname' => generate_device_link($dev, shorthost($dev['hostname'])),
90
        'type' => $type,
91
        'message' => htmlspecialchars($eventlog['message']),
92
        'username' => $eventlog['username'],
93
    ];
94
}
95
96
$output = [
97
    'current' => $current,
98
    'rowCount' => $rowCount,
99
    'rows' => $response,
100
    'total' => $total,
101
];
102
echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
103