librenms-librenms/html/includes/table/tnmsneinfo.inc.php
Maurice den Braber 9f5b42b028 webui: Allow full search on devices page (#8364)
* Update devices.inc.php

* Update devices.inc.php

* Replace $_POST with $vars

Better protection for SQL injection attempts; Need to verify other files for same issue.

* Fixed whitespace.

*sigh*

* More search options & sql injection fixes.

+Allow full search on devices page;
+Allow sysName search on alertlog page;
+Allow sysName search on alerts page;
+Allow sysName search on eventlog page;
+Allow sysName search on poll-log page;
+Allow sysName search on ports page;

*Replaced all occurrences of $_POST with $vars in librenms/html/includes/table. ($vars are sanity-checked).

* Whitespace fix

* Fixed $where & $param

* Add files via upload

* Whitespaces....

Sometimes you want'em, sometimes you hate'em.
2018-03-25 21:50:09 +01:00

111 lines
4.0 KiB
PHP

<?php
/*
* LibreNMS device MIB association browser
*
* Copyright (c) 2015 Gear Consulting Pty Ltd <github@libertysys.com.au>
*
* by Paul Gear
* based on code by Søren Friis Rosiak <sorenrosiak@gmail.com>
* in commit 054bf3ae209f34a2c3bc8968300722004903df1b
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
$columns = array(
'neName',
'neLocation',
'neType',
'neOpMode',
'neAlarm',
'neOpState',
);
if (isset($vars['device_id'])) {
$params = array(
$vars['device_id'],
);
$sql = 'SELECT `neName`,`neLocation`,`neType`,`neOpMode`,`neAlarm`,`neOpState` FROM `tnmsneinfo`';
$wheresql = ' WHERE `device_id` = ?';
$sortcolumns = 3;
$count_sql = "SELECT COUNT(id) FROM `tnmsneinfo`".$wheresql;
// all columns are searchable - search across them
if (isset($searchPhrase) && !empty($searchPhrase)) {
$searchsql = implode(' OR ', array_map("search_phrase_column", array_map("mres", $columns)));
$wheresql .= " AND ( $searchsql )";
}
$sql .= $wheresql;
// get total
$total = dbFetchCell($count_sql, $params);
if (empty($total)) {
$total = 0;
}
// set up default sort
if (!isset($sort) || empty($sort)) {
$sort = implode(', ', array_map("mres", array_slice($columns, 0, $sortcolumns)));
}
$sql .= " ORDER BY $sort";
// select only the required rows
if (isset($current)) {
$limit_low = (($current * $rowCount) - ($rowCount));
$limit_high = $rowCount;
}
if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
// load data from database into response array
$response = array();
foreach (dbFetchRows($sql, $params) as $tnmsne) {
if ($tnmsne['neOpMode'] == 'operation') {
$neop = '<span style="min-width:40px; display:inlink-block;" class="label label-success">operation</span>';
} else {
$neop = '<span style="min-width:40px; display:inlink-block;" class="label label-danger">' . $tnmsne['neOpMode'] . '</span>';
}
switch ($tnmsne['neAlarm']) {
case "cleared":
$alarm = '<span style="min-width:40px; display:inline-block;" class="label label-success">cleared</span>';
break;
case "warning":
$alarm = '<span style="min-width:40px; display:inline-block;" class="label label-warning">warning</span>';
break;
case "minor":
case "major":
case "critical":
case "indeterminate":
$alarm = '<span style="min-width:40px; display:inline-block;" class="label label-danger">' . $tnmsne['neAlarm'] . '</span>';
break;
default:
$alarm = '<span style="min-width:40px; display:inline-block;" class="label label-default">' . $tnmsne['neAlarm'] . '</span>';
}
if ($tnmsne['neOpState'] == 'enabled') {
$opstate = '<td class="list"><span style="min-width:40px; display:inline-block;" class="label label-success">enabled</span></td>';
} else {
$opstate = '<td class="list"><span style="min-width:40px; display:inline-block;" class="label label-danger">'.$tnmsne['neOpState'].'</span></td>';
}
$response[] = array(
'neName' => $tnmsne['neName'],
'neLocation' => $tnmsne['neLocation'],
'neType' => $tnmsne['neType'],
'neOpMode' => $neop,
'neAlarm' => $alarm,
'neOpState' => $opstate,
);
}
$output = array(
'current' => $current,
'rowCount' => $rowCount,
'rows' => $response,
'total' => $total,
);
echo _json_encode($output);
}