mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Use Laravel for authentication Support legacy auth methods Always create DB entry for users (segregate by auth method) Port api auth to Laravel restrict poller errors to devices the user has access to Run checks on every page load. But set a 5 minute (configurable) timer. Only run some checks if the user is an admin Move toastr down a few pixels so it isn't as annoying. Fix menu not loaded on laravel pages when twofactor is enabled for the system, but disabled for the user. Add two missing menu entries in the laravel menu Rewrite 2FA code Simplify some and verify code before applying Get http-auth working Handle legacy $_SESSION differently. Allows Auth::once(), etc to work. * Fix tests and mysqli extension check * remove duplicate Toastr messages * Fix new items * Rename 266.sql to 267.sql
63 lines
2.2 KiB
PHP
63 lines
2.2 KiB
PHP
<?php
|
|
/*
|
|
* LibreNMS front page top devices graph
|
|
* - Find most utilised devices that have been polled in the last N minutes
|
|
*
|
|
* Author: Paul Gear
|
|
* Copyright (c) 2013 Gear Consulting Pty Ltd <http://libertysys.com.au/>
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
use LibreNMS\Authentication\LegacyAuth;
|
|
|
|
$minutes = 15;
|
|
$seconds = ($minutes * 60);
|
|
$top = $config['front_page_settings']['top']['devices'];
|
|
if (LegacyAuth::user()->hasGlobalRead()) {
|
|
$query = "
|
|
SELECT *, sum(p.ifInOctets_rate + p.ifOutOctets_rate) as total
|
|
FROM ports as p, devices as d
|
|
WHERE d.device_id = p.device_id
|
|
AND unix_timestamp() - p.poll_time < $seconds
|
|
AND ( p.ifInOctets_rate > 0
|
|
OR p.ifOutOctets_rate > 0 )
|
|
GROUP BY d.device_id
|
|
ORDER BY total desc
|
|
LIMIT $top
|
|
";
|
|
} else {
|
|
$query = "
|
|
SELECT *, sum(p.ifInOctets_rate + p.ifOutOctets_rate) as total
|
|
FROM ports as p, devices as d, `devices_perms` AS `P`
|
|
WHERE `P`.`user_id` = ? AND `P`.`device_id` = `d`.`device_id` AND
|
|
d.device_id = p.device_id
|
|
AND unix_timestamp() - p.poll_time < $seconds
|
|
AND ( p.ifInOctets_rate > 0
|
|
OR p.ifOutOctets_rate > 0 )
|
|
GROUP BY d.device_id
|
|
ORDER BY total desc
|
|
LIMIT $top
|
|
";
|
|
$param[] = array(LegacyAuth::id());
|
|
}//end if
|
|
|
|
echo "<strong>Top $top devices (last $minutes minutes)</strong>\n";
|
|
echo "<table class='simple'>\n";
|
|
foreach (dbFetchRows($query, $param) as $result) {
|
|
echo '<tr class=top10>'.'<td class=top10>'.generate_device_link($result, shorthost($result['hostname'])).'</td>'.'<td class=top10>'.generate_device_link(
|
|
$result,
|
|
generate_minigraph_image($result, $config['time']['day'], $config['time']['now'], 'device_bits', 'no', 150, 21, '&', 'top10'),
|
|
array(),
|
|
0,
|
|
0,
|
|
0
|
|
).'</td>'."</tr>\n";
|
|
}
|
|
|
|
echo "</table>\n";
|