librenms-librenms/html/includes/table/stp-ports.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

58 lines
2.2 KiB
PHP

<?php
$device_id = mres($vars['device_id']);
$param[] = $device_id;
$sql = " FROM `ports_stp` `ps` JOIN `ports` `p` ON `ps`.`port_id`=`p`.`port_id` WHERE `ps`.`device_id` = ?";
$count_sql = "SELECT COUNT(*) $sql";
$total = dbFetchCell($count_sql, $param);
if (empty($total)) {
$total = 0;
}
if (!isset($sort) || empty($sort)) {
$sort = 'port_id DESC';
}
$sql .= " ORDER BY ps.$sort";
if (isset($current)) {
$limit_low = (($current * $rowCount) - ($rowCount));
$limit_high = $rowCount;
}
if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
$sql = "SELECT `ps`.*, `p`.* $sql";
foreach (dbFetchRows($sql, array($device_id)) as $stp_ports_db) {
$stp_ports_db = cleanPort($stp_ports_db);
$bridge_device = dbFetchRow("SELECT `devices`.*, `stp`.`device_id`, `stp`.`bridgeAddress` FROM `devices` JOIN `stp` ON `devices`.`device_id`=`stp`.`device_id` WHERE `stp`.`bridgeAddress` = ?", array($stp_ports_db['designatedBridge']));
$root_device = dbFetchRow("SELECT `devices`.*, `stp`.`device_id`, `stp`.`bridgeAddress` FROM `devices` JOIN `stp` ON `devices`.`device_id`=`stp`.`device_id` WHERE `stp`.`bridgeAddress` = ?", array($stp_ports_db['designatedRoot']));
$response[] = array (
'port_id' => generate_port_link($stp_ports_db, $stp_ports_db['ifName'])."<br>".$stp_ports_db['ifAlias'],
'priority' => $stp_ports_db['priority'],
'state' => $stp_ports_db['state'],
'enable' => $stp_ports_db['enable'],
'pathCost' => $stp_ports_db['pathCost'],
'designatedRoot' => generate_device_link($root_device, $root_device['hostname'])."<br>".$stp_ports_db['designatedRoot'],
'designatedCost' => $stp_ports_db['designatedCost'],
'designatedBridge' => generate_device_link($bridge_device, $bridge_device['hostname'])."<br>".$stp_ports_db['designatedBridge'],
'designatedPort' => $stp_ports_db['designatedPort'],
'forwardTransitions' => $stp_ports_db['forwardTransitions']
);
}
$output = array(
'current' => $current,
'rowCount' => $rowCount,
'rows' => $response,
'total' => $total,
);
echo _json_encode($output);