Files

170 lines
5.6 KiB
PHP
Raw Permalink Normal View History

<?php
2015-07-13 20:10:26 +02:00
if ($vars['view'] == 'graphs' || $vars['view'] == 'minigraphs') {
if (isset($vars['graph'])) {
2020-09-21 15:40:17 +02:00
$graph_type = 'port_' . $vars['graph'];
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
$graph_type = 'port_bits';
}
}
2011-10-08 23:49:24 +00:00
2020-09-21 15:40:17 +02:00
if (! $vars['view']) {
2019-06-23 00:29:12 -05:00
$vars['view'] = trim(\LibreNMS\Config::get('ports_page_default'), '/');
2015-07-13 20:10:26 +02:00
}
2020-09-21 15:40:17 +02:00
$link_array = [
2015-07-13 20:10:26 +02:00
'page' => 'device',
'device' => $device['device_id'],
'tab' => 'ports',
2020-09-21 15:40:17 +02:00
];
print_optionbar_start();
2020-09-21 15:40:17 +02:00
$menu_options['basic'] = 'Basic';
$menu_options['details'] = 'Details';
2020-09-21 15:40:17 +02:00
$menu_options['arp'] = 'ARP Table';
$menu_options['fdb'] = 'FDB Table';
2020-09-21 15:40:17 +02:00
if (dbFetchCell("SELECT * FROM links AS L, ports AS I WHERE I.device_id = '" . $device['device_id'] . "' AND I.port_id = L.local_port_id")) {
2015-07-13 20:10:26 +02:00
$menu_options['neighbours'] = 'Neighbours';
}
2015-07-13 20:10:26 +02:00
if (dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `ifType` = 'adsl'")) {
$menu_options['adsl'] = 'ADSL';
}
2015-07-13 20:10:26 +02:00
$sep = '';
foreach ($menu_options as $option => $text) {
echo $sep;
if ($vars['view'] == $option) {
echo "<span class='pagemenu-selected'>";
}
2020-09-21 15:40:17 +02:00
echo generate_link($text, $link_array, ['view' => $option]);
2015-07-13 20:10:26 +02:00
if ($vars['view'] == $option) {
echo '</span>';
}
$sep = ' | ';
}
unset($sep);
2015-07-13 20:10:26 +02:00
echo ' | Graphs: ';
2020-09-21 15:40:17 +02:00
$graph_types = [
2015-07-13 20:10:26 +02:00
'bits' => 'Bits',
'upkts' => 'Unicast Packets',
'nupkts' => 'Non-Unicast Packets',
'errors' => 'Errors',
2020-09-21 15:40:17 +02:00
];
2015-07-13 20:10:26 +02:00
2019-06-23 00:29:12 -05:00
if (\LibreNMS\Config::get('enable_ports_etherlike')) {
2016-07-08 22:58:36 -05:00
$graph_types['etherlike'] = 'Etherlike';
}
2015-07-13 20:10:26 +02:00
foreach ($graph_types as $type => $descr) {
echo "$type_sep";
if ($vars['graph'] == $type && $vars['view'] == 'graphs') {
echo "<span class='pagemenu-selected'>";
}
2020-09-21 15:40:17 +02:00
echo generate_link($descr, $link_array, ['view' => 'graphs', 'graph' => $type]);
2015-07-13 20:10:26 +02:00
if ($vars['graph'] == $type && $vars['view'] == 'graphs') {
echo '</span>';
}
echo ' (';
if ($vars['graph'] == $type && $vars['view'] == 'minigraphs') {
echo "<span class='pagemenu-selected'>";
}
2020-09-21 15:40:17 +02:00
echo generate_link('Mini', $link_array, ['view' => 'minigraphs', 'graph' => $type]);
2015-07-13 20:10:26 +02:00
if ($vars['graph'] == $type && $vars['view'] == 'minigraphs') {
echo '</span>';
2012-05-02 22:02:30 +00:00
}
2012-05-02 15:06:12 +00:00
2015-07-13 20:10:26 +02:00
echo ')';
$type_sep = ' | ';
}//end foreach
2012-05-02 22:02:30 +00:00
2015-07-13 20:10:26 +02:00
print_optionbar_end();
if ($vars['view'] == 'minigraphs') {
2020-09-21 15:40:17 +02:00
$timeperiods = [
2015-07-13 20:10:26 +02:00
'-1day',
'-1week',
'-1month',
'-1year',
2020-09-21 15:40:17 +02:00
];
$from = '-1day';
2015-07-13 20:10:26 +02:00
echo "<div style='display: block; clear: both; margin: auto; min-height: 500px;'>";
unset($seperator);
// FIXME - FIX THIS. UGLY.
2020-09-21 15:40:17 +02:00
foreach (dbFetchRows('select * from ports WHERE device_id = ? AND `disabled` = 0 ORDER BY ifIndex', [$device['device_id']]) as $port) {
$port = cleanPort($port, $device);
2020-09-21 15:59:34 +02:00
echo "<div class='minigraph-div'><div style='font-weight: bold;'>" . makeshortif($port['ifDescr']) . '</div>
<a href="' . generate_port_url($port) . "\" onmouseover=\"return overlib('<div class=\'overlib-content\'>\
<div class=\'overlib-text\'>" . $device['hostname'] . ' - ' . $port['ifDescr'] . "</div>\
2020-09-21 15:40:17 +02:00
<span class=\'overlib-title\'>" . $port['ifAlias'] . "</span>\
<img src=\'graph.php?type=" . $graph_type . '&amp;id=' . $port['port_id'] . '&amp;from=' . $from . '&amp;to=' . \LibreNMS\Config::get('time.now') . "&amp;width=450&amp;height=150\'>\
</div>\
2019-06-23 00:29:12 -05:00
', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >" . "<img src='graph.php?type=" . $graph_type . '&amp;id=' . $port['port_id'] . '&amp;from=' . $from . '&amp;to=' . \LibreNMS\Config::get('time.now') . "&amp;width=180&amp;height=45&amp;legend=no'>
2015-07-13 20:10:26 +02:00
</a>
2020-09-21 15:40:17 +02:00
<div style='font-size: 9px;'>" . substr(short_port_descr($port['ifAlias']), 0, 32) . '</div>
2015-07-13 20:10:26 +02:00
</div>';
}
echo '</div>';
2017-06-26 07:58:17 -05:00
} elseif ($vars['view'] == 'arp' || $vars['view'] == 'adsl' || $vars['view'] == 'neighbours' || $vars['view'] == 'fdb') {
2020-09-21 15:40:17 +02:00
include 'ports/' . $vars['view'] . '.inc.php';
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
if ($vars['view'] == 'details') {
$port_details = 1;
2020-09-21 15:40:17 +02:00
} ?>
2015-11-26 17:56:14 +08:00
<div style='margin: 0px;'><table class='table'>
<tr>
2020-09-21 15:59:34 +02:00
<th width="350"><A href="<?php echo generate_url($vars, ['sort' => 'port']); ?>">Port</a></th>
2015-11-26 17:56:14 +08:00
<th width="100"></th>
2020-09-21 15:59:34 +02:00
<th width="120"><a href="<?php echo generate_url($vars, ['sort' => 'traffic']); ?>">Traffic</a></th>
2015-11-26 17:56:14 +08:00
<th width="75">Speed</th>
<th width="100">Media</th>
<th width="100">Mac Address</th>
<th width="375"></th>
</tr>
2020-04-03 08:41:24 -05:00
<?php
2015-07-13 20:10:26 +02:00
$i = '1';
global $port_cache, $port_index_cache;
2020-09-21 15:40:17 +02:00
$ports = dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = '0' AND `disabled` = 0 ORDER BY `ifIndex` ASC", [$device['device_id']]);
2015-07-13 20:10:26 +02:00
// As we've dragged the whole database, lets pre-populate our caches :)
// FIXME - we should probably split the fetching of link/stack/etc into functions and cache them here too to cut down on single row queries.
2015-11-26 17:56:14 +08:00
2020-04-03 08:41:24 -05:00
foreach ($ports as $key => $port) {
$port_cache[$port['port_id']] = $port;
$port_index_cache[$port['device_id']][$port['ifIndex']] = $port;
2020-09-21 15:59:34 +02:00
$ports[$key]['ifOctets_rate'] = $port['ifInOctets_rate'] + $port['ifOutOctets_rate'];
2020-04-03 08:41:24 -05:00
}
2015-07-13 20:10:26 +02:00
2020-09-21 15:59:34 +02:00
switch ($vars['sort']) {
2020-04-03 08:41:24 -05:00
case 'traffic':
$ports = array_sort_by_column($ports, 'ifOctets_rate', SORT_DESC);
break;
default:
$ports = array_sort_by_column($ports, 'ifIndex', SORT_ASC);
break;
}
2015-07-13 20:10:26 +02:00
2020-04-03 08:41:24 -05:00
foreach ($ports as $port) {
include 'includes/html/print-interface.inc.php';
$i++;
}
2015-07-13 20:10:26 +02:00
echo '</table></div>';
}//end if
2015-07-13 20:10:26 +02:00
$pagetitle[] = 'Ports';