2011-09-27 13:22:38 +00:00
<? php
2015-07-13 20:10:26 +02:00
if ( $vars [ 'view' ] == 'graphs' || $vars [ 'view' ] == 'minigraphs' ) {
if ( isset ( $vars [ 'graph' ])) {
$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-09-27 13:22:38 +00:00
}
2011-10-08 23:49:24 +00:00
2015-07-13 20:10:26 +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
}
2011-09-27 13:22:38 +00:00
2015-07-13 20:10:26 +02:00
$link_array = array (
'page' => 'device' ,
'device' => $device [ 'device_id' ],
'tab' => 'ports' ,
);
2011-09-27 13:22:38 +00:00
print_optionbar_start ();
$menu_options [ 'basic' ] = 'Basic' ;
$menu_options [ 'details' ] = 'Details' ;
$menu_options [ 'arp' ] = 'ARP Table' ;
2017-06-26 07:58:17 -05:00
$menu_options [ 'fdb' ] = 'FDB Table' ;
2011-09-27 13:22:38 +00:00
2015-07-13 20:10:26 +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" )) {
$menu_options [ 'neighbours' ] = 'Neighbours' ;
2011-09-27 13:22:38 +00:00
}
2015-07-13 20:10:26 +02:00
if ( dbFetchCell ( "SELECT COUNT(*) FROM `ports` WHERE `ifType` = 'adsl'" )) {
$menu_options [ 'adsl' ] = 'ADSL' ;
2011-09-27 13:22:38 +00:00
}
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'>" ;
}
echo generate_link ( $text , $link_array , array ( 'view' => $option ));
if ( $vars [ 'view' ] == $option ) {
echo '</span>' ;
}
$sep = ' | ' ;
2011-09-27 13:22:38 +00:00
}
unset ( $sep );
2015-07-13 20:10:26 +02:00
echo ' | Graphs: ' ;
2011-09-27 13:22:38 +00:00
2015-07-13 20:10:26 +02:00
$graph_types = array (
'bits' => 'Bits' ,
'upkts' => 'Unicast Packets' ,
'nupkts' => 'Non-Unicast Packets' ,
'errors' => 'Errors' ,
);
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'>" ;
}
echo generate_link ( $descr , $link_array , array ( 'view' => 'graphs' , 'graph' => $type ));
if ( $vars [ 'graph' ] == $type && $vars [ 'view' ] == 'graphs' ) {
echo '</span>' ;
}
echo ' (' ;
if ( $vars [ 'graph' ] == $type && $vars [ 'view' ] == 'minigraphs' ) {
echo "<span class='pagemenu-selected'>" ;
}
2011-09-27 13:22:38 +00:00
2015-07-13 20:10:26 +02:00
echo generate_link ( 'Mini' , $link_array , array ( 'view' => 'minigraphs' , 'graph' => $type ));
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' ) {
$timeperiods = array (
'-1day' ,
'-1week' ,
'-1month' ,
'-1year' ,
);
$from = '-1day' ;
echo "<div style='display: block; clear: both; margin: auto; min-height: 500px;'>" ;
unset ( $seperator );
// FIXME - FIX THIS. UGLY.
2019-02-07 13:24:20 -06:00
foreach ( dbFetchRows ( 'select * from ports WHERE device_id = ? AND `disabled` = 0 ORDER BY ifIndex' , array ( $device [ 'device_id' ])) as $port ) {
2017-04-04 08:08:23 +01:00
$port = cleanPort ( $port , $device );
2019-06-22 05:44:47 +02:00
echo "<div class='minigraph-div'><div style='font-weight: bold;'>" . makeshortif ( $port [ 'ifDescr' ]) . "</div>
2019-09-24 18:03:24 +02:00
<a href= \" " . generate_port_url ( $port ) . " \" onmouseover= \" return overlib('<div class=\'overlib-content\'>\
2019-06-22 05:44:47 +02:00
<div class=\'overlib-text\'>" . $device [ 'hostname' ] . " - " . $port [ 'ifDescr' ] . "</div>\
<span class=\'overlib-title\'>" . $port [ 'ifAlias' ] . "</span>\
2019-06-23 00:29:12 -05:00
<img src=\'graph.php?type=" . $graph_type . '&id=' . $port [ 'port_id' ] . '&from=' . $from . '&to=' . \LibreNMS\Config :: get ( 'time.now' ) . "&width=450&height=150\'>\
2015-11-27 08:31:08 -08:00
</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 . '&id=' . $port [ 'port_id' ] . '&from=' . $from . '&to=' . \LibreNMS\Config :: get ( 'time.now' ) . "&width=180&height=45&legend=no'>
2015-07-13 20:10:26 +02:00
</a>
2017-04-04 08:08:23 +01: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' ) {
2015-07-13 20:10:26 +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-04-03 08:41:24 -05:00
?>
2015-11-26 17:56:14 +08:00
<div style='margin: 0px;'><table class='table'>
<tr>
2015-11-26 20:05:58 +08:00
<th width="350"><A href="<?php echo generate_url($vars, array('sort' => "port")); ?>">Port</a></th>
2015-11-26 17:56:14 +08:00
<th width="100"></th>
<th width="120"><a href="<?php echo generate_url($vars, array('sort' => "traffic")); ?>">Traffic</a></th>
<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;
2018-08-17 19:24:11 +02:00
$ports = dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = '0' AND `disabled` = 0 ORDER BY `ifIndex` ASC", array($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;
$ports[$key]["ifOctets_rate"] = $port["ifInOctets_rate"] + $port["ifOutOctets_rate"];
}
2015-07-13 20:10:26 +02:00
2020-04-03 08:41:24 -05:00
switch ($vars["sort"]) {
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++;
}
2011-09-27 13:22:38 +00:00
2015-07-13 20:10:26 +02:00
echo '</table></div>';
}//end if
2011-10-18 14:27:21 +00:00
2015-07-13 20:10:26 +02:00
$pagetitle[] = 'Ports';