2009-07-31 10:53:54 +00:00
<? php
2019-06-23 00:29:12 -05:00
use LibreNMS\Config ;
2012-05-25 12:24:34 +00:00
// FIXME - REWRITE!
2011-03-16 23:10:10 +00:00
$hostname = $device [ 'hostname' ];
2012-05-16 13:25:50 +00:00
$hostid = $device [ 'port_id' ];
2011-09-18 13:11:04 +00:00
$ifname = $port [ 'ifDescr' ];
2015-07-10 13:36:21 +02:00
$ifIndex = $port [ 'ifIndex' ];
$speed = humanspeed ( $port [ 'ifSpeed' ]);
2011-03-16 23:10:10 +00:00
2011-09-18 13:11:04 +00:00
$ifalias = $port [ 'name' ];
2011-03-16 23:10:10 +00:00
2015-07-10 13:36:21 +02:00
if ( $port [ 'ifPhysAddress' ]) {
$mac = $port [ 'ifPhysAddress' ];
}
$color = 'black' ;
if ( $port [ 'ifAdminStatus' ] == 'down' ) {
$status = "<span class='grey'>Disabled</span>" ;
}
2020-01-15 15:28:36 +01:00
if ( $port [ 'ifAdminStatus' ] == 'up' && $port [ 'ifOperStatus' ] != 'up' ) {
2015-07-10 13:36:21 +02:00
$status = "<span class='red'>Enabled / Disconnected</span>" ;
}
2011-03-16 23:10:10 +00:00
2015-07-10 13:36:21 +02:00
if ( $port [ 'ifAdminStatus' ] == 'up' && $port [ 'ifOperStatus' ] == 'up' ) {
$status = "<span class='green'>Enabled / Connected</span>" ;
}
2011-03-16 23:10:10 +00:00
2015-07-10 13:36:21 +02:00
$i = 1 ;
2011-03-16 23:10:10 +00:00
$inf = fixifName ( $ifname );
2015-07-10 13:36:21 +02:00
echo "<div style='clear: both;'>" ;
2011-03-16 23:10:10 +00:00
2015-07-10 13:36:21 +02:00
if ( $vars [ 'subview' ] == 'top10' ) {
if ( ! isset ( $vars [ 'sort' ])) {
$vars [ 'sort' ] = 'in' ;
}
if ( ! isset ( $vars [ 'period' ])) {
$vars [ 'period' ] = '1day' ;
}
2011-03-16 23:10:10 +00:00
2015-07-10 13:36:21 +02:00
$from = '-' . $vars [ 'period' ];
2011-03-16 23:10:10 +00:00
2015-07-10 13:36:21 +02:00
echo "<div style='margin: 0px 0px 0px 0px'>
2011-03-16 23:10:10 +00:00
<div style=' margin:0px; float: left;';>
<div style='margin: 0px 10px 5px 0px; padding:5px; background: #e5e5e5;'>
<span class=device-head>Day</span><br />
2011-09-18 13:11:04 +00:00
2019-05-21 03:56:19 +02:00
<a href='" . generate_url ( $link_array , array ( 'view' => 'macaccounting' , 'subview' => 'top10' , 'graph' => $vars [ 'graph' ], 'sort' => $vars [ 'sort' ], 'period' => '1d' )) . "'>
2011-09-18 13:11:04 +00:00
2019-06-23 00:29:12 -05:00
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=" . $port [ 'port_id' ] . '&stat=' . $vars [ 'graph' ] . '&type=port_mac_acc_total&sort=' . $vars [ 'sort' ] . '&from=' . Config :: get ( 'time.day' ) . '&to=' . Config :: get ( 'time.now' ) . "&width=150&height=50' />
2011-03-16 23:10:10 +00:00
</a>
</div>
<div style='margin: 0px 10px 5px 0px; padding:5px; background: #e5e5e5;'>
<span class=device-head>Two Day</span><br />
2019-05-21 03:56:19 +02:00
<a href='" . generate_url ( $link_array , array ( 'view' => 'macaccounting' , 'subview' => 'top10' , 'graph' => $vars [ 'graph' ], 'sort' => $vars [ 'sort' ], 'period' => '2d' )) . "/'>
2019-06-23 00:29:12 -05:00
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=" . $port [ 'port_id' ] . '&stat=' . $vars [ 'graph' ] . '&type=port_mac_acc_total&sort=' . $vars [ 'sort' ] . '&from=' . Config :: get ( 'time.twoday' ) . '&to=' . Config :: get ( 'time.now' ) . "&width=150&height=50' />
2011-03-16 23:10:10 +00:00
</a>
</div>
<div style='margin: 0px 10px 5px 0px; padding:5px; background: #e5e5e5;'>
<span class=device-head>Week</span><br />
2019-05-21 03:56:19 +02:00
<a href='" . generate_url ( $link_array , array ( 'view' => 'macaccounting' , 'subview' => 'top10' , 'graph' => $vars [ 'graph' ], 'sort' => $vars [ 'sort' ], 'period' => '1w' )) . "/'>
2019-06-23 00:29:12 -05:00
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=" . $port [ 'port_id' ] . '&type=port_mac_acc_total&sort=' . $vars [ 'sort' ] . '&stat=' . $vars [ 'graph' ] . '&from=' . Config :: get ( 'time.week' ) . '&to=' . Config :: get ( 'time.now' ) . "&width=150&height=50' />
2009-10-28 13:49:37 +00:00
</a>
</div>
<div style='margin: 0px 10px 5px 0px; padding:5px; background: #e5e5e5;'>
2011-03-16 23:10:10 +00:00
<span class=device-head>Month</span><br />
2019-05-21 03:56:19 +02:00
<a href='" . generate_url ( $link_array , array ( 'view' => 'macaccounting' , 'subview' => 'top10' , 'graph' => $vars [ 'graph' ], 'sort' => $vars [ 'sort' ], 'period' => '1m' )) . "/'>
2019-06-23 00:29:12 -05:00
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=" . $port [ 'port_id' ] . '&type=port_mac_acc_total&sort=' . $vars [ 'sort' ] . '&stat=' . $vars [ 'graph' ] . '&from=' . Config :: get ( 'time.month' ) . '&to=' . Config :: get ( 'time.now' ) . "&width=150&height=50' />
2009-09-24 14:38:17 +00:00
</a>
</div>
2011-03-16 23:10:10 +00:00
<div style='margin: 0px 10px 5px 0px; padding:5px; background: #e5e5e5;'>
<span class=device-head>Year</span><br />
2019-05-21 03:56:19 +02:00
<a href='" . generate_url ( $link_array , array ( 'view' => 'macaccounting' , 'subview' => 'top10' , 'graph' => $vars [ 'graph' ], 'sort' => $vars [ 'sort' ], 'period' => '1y' )) . "/'>
2019-06-23 00:29:12 -05:00
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=" . $port [ 'port_id' ] . '&type=port_mac_acc_total&sort=' . $vars [ 'sort' ] . '&stat=' . $vars [ 'graph' ] . '&from=' . Config :: get ( 'time.year' ) . '&to=' . Config :: get ( 'time.now' ) . "&width=150&height=50' />
2009-10-28 13:49:37 +00:00
</a>
</div>
2011-03-16 23:10:10 +00:00
</div>
<div style='float: left;'>
2019-06-23 00:29:12 -05:00
<img src='graph.php?id=" . $port [ 'port_id' ] . '&type=port_mac_acc_total&sort=' . $vars [ 'sort' ] . '&stat=' . $vars [ 'graph' ] . "&from= $from &to=" . Config :: get ( 'time.now' ) . "&width=745&height=300' />
2011-03-16 23:10:10 +00:00
</div>
<div style=' margin:0px; float: left;';>
2009-10-28 13:49:37 +00:00
<div style='margin: 0px 0px 5px 10px; padding:5px; background: #e5e5e5;'>
2011-03-16 23:10:10 +00:00
<span class=device-head>Traffic</span><br />
2018-07-13 17:08:00 -05:00
<a href='" . generate_url ( $link_array , array ( 'view' => 'macaccounting' , 'subview' => 'top10' , 'graph' => 'bits' , 'sort' => $vars [ 'sort' ], 'period' => $vars [ 'period' ])) . "'>
2019-06-23 00:29:12 -05:00
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=" . $port [ 'port_id' ] . '&stat=bits&type=port_mac_acc_total&sort=' . $vars [ 'sort' ] . "&from= $from &to=" . Config :: get ( 'time.now' ) . "&width=150&height=50' />
2011-03-16 23:10:10 +00:00
</a>
</div>
<div style='margin: 0px 0px 5px 10px; padding:5px; background: #e5e5e5;'>
<span class=device-head>Packets</span><br />
2018-07-13 17:08:00 -05:00
<a href='" . generate_url ( $link_array , array ( 'view' => 'macaccounting' , 'subview' => 'top10' , 'graph' => 'pkts' , 'sort' => $vars [ 'sort' ], 'period' => $vars [ 'period' ])) . "/'>
2019-06-23 00:29:12 -05:00
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=" . $port [ 'port_id' ] . '&stat=pkts&type=port_mac_acc_total&sort=' . $vars [ 'sort' ] . "&from= $from &to=" . Config :: get ( 'time.now' ) . "&width=150&height=50' />
2011-03-16 23:10:10 +00:00
</a>
</div>
<div style='margin: 0px 0px 5px 10px; padding:5px; background: #e5e5e5;'>
<span class=device-head>Top Input</span><br />
2018-07-13 17:08:00 -05:00
<a href='" . generate_url ( $link_array , array ( 'view' => 'macaccounting' , 'subview' => 'top10' , 'graph' => $vars [ 'graph' ], 'sort' => 'in' , 'period' => $vars [ 'period' ])) . "'>
2019-06-23 00:29:12 -05:00
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=" . $port [ 'port_id' ] . '&stat=' . $vars [ 'graph' ] . "&type=port_mac_acc_total&sort=in&from= $from &to=" . Config :: get ( 'time.now' ) . "&width=150&height=50' />
2011-03-16 23:10:10 +00:00
</a>
</div>
<div style='margin: 0px 0px 5px 10px; padding:5px; background: #e5e5e5;'>
<span class=device-head>Top Output</span><br />
2018-07-13 17:08:00 -05:00
<a href='" . generate_url ( $link_array , array ( 'view' => 'macaccounting' , 'subview' => 'top10' , 'graph' => $vars [ 'graph' ], 'sort' => 'out' , 'period' => $vars [ 'period' ])) . "'>
2019-06-23 00:29:12 -05:00
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=" . $port [ 'port_id' ] . '&stat=' . $vars [ 'graph' ] . "&type=port_mac_acc_total&sort=out&from= $from &to=" . Config :: get ( 'time.now' ) . "&width=150&height=50' />
2011-03-16 23:10:10 +00:00
</a>
</div>
<div style='margin: 0px 0px 5px 10px; padding:5px; background: #e5e5e5;'>
<span class=device-head>Top Aggregate</span><br />
2018-07-13 17:08:00 -05:00
<a href='" . generate_url ( $link_array , array ( 'view' => 'macaccounting' , 'subview' => 'top10' , 'graph' => $vars [ 'graph' ], 'sort' => 'both' , 'period' => $vars [ 'period' ])) . "'>
2019-06-23 00:29:12 -05:00
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=" . $port [ 'port_id' ] . '&stat=' . $vars [ 'graph' ] . "&type=port_mac_acc_total&sort=both&from= $from &to=" . Config :: get ( 'time.now' ) . "&width=150&height=50' />
2011-03-16 23:10:10 +00:00
</a>
</div>
</div>
</div>
2015-07-10 13:36:21 +02:00
" ;
unset ( $query );
2016-08-18 20:28:22 -05:00
} else {
2015-07-10 13:36:21 +02:00
$query = 'SELECT *, (M.cipMacHCSwitchedBytes_input_rate + M.cipMacHCSwitchedBytes_output_rate) as bps FROM `mac_accounting` AS M,
`ports` AS I, `devices` AS D WHERE M.port_id = ? AND I.port_id = M.port_id AND I.device_id = D.device_id ORDER BY bps DESC' ;
$param = array ( $port [ 'port_id' ]);
foreach ( dbFetchRows ( $query , $param ) as $acc ) {
if ( ! is_integer ( $i / 2 )) {
2019-06-23 00:29:12 -05:00
$row_colour = Config :: get ( 'list_colour.even' );
2016-08-18 20:28:22 -05:00
} else {
2019-06-23 00:29:12 -05:00
$row_colour = Config :: get ( 'list_colour.odd' );
2015-07-10 13:36:21 +02:00
}
$addy = dbFetchRow ( 'SELECT * FROM ipv4_mac where mac_address = ?' , array ( $acc [ 'mac' ]));
// $name = gethostbyaddr($addy['ipv4_address']); FIXME - Maybe some caching for this?
$arp_host = dbFetchRow ( 'SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id' , array ( $addy [ 'ipv4_address' ]));
2017-04-04 08:08:23 +01:00
$arp_host = cleanPort ( $arp_host );
2015-07-10 13:36:21 +02:00
if ( $arp_host ) {
$arp_name = generate_device_link ( $arp_host );
$arp_name .= ' ' . generate_port_link ( $arp_host );
2016-08-18 20:28:22 -05:00
} else {
2015-07-10 13:36:21 +02:00
unset ( $arp_if );
}
if ( $name == $addy [ 'ipv4_address' ]) {
unset ( $name );
}
if ( dbFetchCell ( 'SELECT count(*) FROM bgpPeers WHERE device_id = ? AND bgpPeerIdentifier = ?' , array ( $acc [ 'device_id' ], $addy [ 'ipv4_address' ]))) {
$peer_info = dbFetchRow ( 'SELECT * FROM bgpPeers WHERE device_id = ? AND bgpPeerIdentifier = ?' , array ( $acc [ 'device_id' ], $addy [ 'ipv4_address' ]));
2016-08-18 20:28:22 -05:00
} else {
2015-07-10 13:36:21 +02:00
unset ( $peer_info );
}
if ( $peer_info ) {
$asn = 'AS' . $peer_info [ 'bgpPeerRemoteAs' ];
$astext = $peer_info [ 'astext' ];
2016-08-18 20:28:22 -05:00
} else {
2015-07-10 13:36:21 +02:00
unset ( $as );
unset ( $astext );
unset ( $asn );
}
if ( $vars [ 'graph' ]) {
$graph_type = 'macaccounting_' . $vars [ 'graph' ];
2016-08-18 20:28:22 -05:00
} else {
2015-07-10 13:36:21 +02:00
$graph_type = 'macaccounting_bits' ;
}
if ( $vars [ 'subview' ] == 'minigraphs' ) {
if ( ! $asn ) {
$asn = 'No Session' ;
}
echo "<div style='display: block; padding: 3px; margin: 3px; min-width: 221px; max-width:221px; min-height:90px; max-height:90px; text-align: center; float: left; background-color: #e5e5e5;'>
" . $addy [ 'ipv4_address' ] . ' - ' . $asn . "
2011-03-16 23:10:10 +00:00
<a href='#' onmouseover= \" return overlib('\
2015-07-10 13:36:21 +02:00
<div style=\'font-size: 16px; padding:5px; font-weight: bold; color: #555555;\'>" . $name . ' - ' . $addy [ 'ipv4_address' ] . ' - ' . $asn . "</div>\
2019-06-23 00:29:12 -05:00
<img src=\'graph.php?id=" . $acc [ 'ma_id' ] . "&type= $graph_type &from=" . Config :: get ( 'time.twoday' ) . '&to=' . Config :: get ( 'time.now' ) . "&width=450&height=150\'>\
2011-03-16 23:10:10 +00:00
', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150); \" onmouseout= \" return nd(); \" >
2019-06-23 00:29:12 -05:00
<img src='graph.php?id=" . $acc [ 'ma_id' ] . "&type= $graph_type &from=" . Config :: get ( 'time.twoday' ) . '&to=' . Config :: get ( 'time.now' ) . "&width=213&height=45'></a>
2009-05-11 13:43:59 +00:00
2015-07-10 13:36:21 +02:00
<span style='font-size: 10px;'>" . $name . '</span>
</div>' ;
2016-08-18 20:28:22 -05:00
} else {
2015-07-10 13:36:21 +02:00
echo "<div style='background-color: $row_colour ; padding: 0px;'>" ;
2011-03-16 23:10:10 +00:00
2015-07-10 13:36:21 +02:00
echo ( '
2011-03-16 23:10:10 +00:00
<table>
<tr>
2015-07-10 13:36:21 +02:00
<td class=list-large width=200>' . mac_clean_to_readable ( $acc [ 'mac' ]) . '</td>
<td class=list-large width=200>' . $addy [ 'ipv4_address' ] . '</td>
<td class=list-large width=500>' . $name . ' ' . $arp_name . '</td>
<td class=list-large width=100>' . formatRates (( $acc [ 'cipMacHCSwitchedBytes_input_rate' ] / 8 )) . '</td>
<td class=list-large width=100>' . formatRates (( $acc [ 'cipMacHCSwitchedBytes_output_rate' ] / 8 )) . '</td>
2011-03-16 23:10:10 +00:00
</tr>
</table>
2015-07-10 13:36:21 +02:00
' );
2011-03-16 23:10:10 +00:00
2015-07-10 13:36:21 +02:00
$peer_info [ 'astext' ];
2012-04-06 13:56:23 +00:00
2015-07-10 13:36:21 +02:00
$graph_array [ 'type' ] = $graph_type ;
$graph_array [ 'id' ] = $acc [ 'ma_id' ];
$graph_array [ 'height' ] = '100' ;
$graph_array [ 'width' ] = '216' ;
2019-06-23 00:29:12 -05:00
$graph_array [ 'to' ] = Config :: get ( 'time.now' );
2015-07-10 13:36:21 +02:00
echo '<tr bgcolor="' . $bg_colour . '"' . ( $bg_image ? ' background="' . $bg_image . '"' : '' ) . '"><td colspan="7">' ;
2012-04-06 13:56:23 +00:00
2019-04-11 23:26:42 -05:00
include 'includes/html/print-graphrow.inc.php' ;
2011-04-30 10:43:27 +00:00
2015-07-10 13:36:21 +02:00
echo '</td></tr>' ;
2009-10-28 13:49:37 +00:00
2015-07-10 13:36:21 +02:00
$i ++ ;
} //end if
} //end foreach
} //end if