2010-11-25 15:32:47 +00:00
< ? php
2011-09-19 08:54:48 +00:00
2015-07-13 20:10:26 +02:00
$link_array = array (
'page' => 'device' ,
'device' => $device [ 'device_id' ],
'tab' => 'routing' ,
'proto' => 'bgp' ,
);
if ( ! isset ( $vars [ 'view' ])) {
$vars [ 'view' ] = 'basic' ;
}
2011-09-19 08:54:48 +00:00
2010-01-09 17:37:51 +00:00
print_optionbar_start ();
2010-11-25 15:32:47 +00:00
2015-07-13 20:10:26 +02:00
echo '<strong>Local AS : ' . $device [ 'bgpLocalAs' ] . '</strong> ' ;
echo " <span style='font-weight: bold;'>BGP</span> » " ;
if ( $vars [ 'view' ] == 'basic' ) {
echo " <span class='pagemenu-selected'> " ;
}
echo generate_link ( 'Basic' , $link_array , array ( 'view' => 'basic' ));
if ( $vars [ 'view' ] == 'basic' ) {
echo '</span>' ;
}
echo ' | ' ;
2015-06-02 16:32:39 +01:00
2015-07-13 20:10:26 +02:00
if ( $vars [ 'view' ] == 'updates' ) {
echo " <span class='pagemenu-selected'> " ;
}
echo generate_link ( 'Updates' , $link_array , array ( 'view' => 'updates' ));
if ( $vars [ 'view' ] == 'updates' ) {
echo '</span>' ;
}
echo ' | Prefixes: ' ;
if ( $vars [ 'view' ] == 'prefixes_ipv4unicast' ) {
echo " <span class='pagemenu-selected'> " ;
2017-03-11 23:16:49 +00:00
$extra_sql = " AND `bgpPeerIdentifier` NOT LIKE '%:%' " ;
2015-07-13 20:10:26 +02:00
}
echo generate_link ( 'IPv4' , $link_array , array ( 'view' => 'prefixes_ipv4unicast' ));
if ( $vars [ 'view' ] == 'prefixes_ipv4unicast' ) {
echo '</span>' ;
}
2011-03-16 23:10:10 +00:00
2015-07-13 20:10:26 +02:00
echo ' | ' ;
2010-11-25 15:32:47 +00:00
2015-07-13 20:10:26 +02:00
if ( $vars [ 'view' ] == 'prefixes_vpnv4unicast' ) {
echo " <span class='pagemenu-selected'> " ;
}
2011-04-17 16:14:44 +00:00
2015-07-13 20:10:26 +02:00
echo generate_link ( 'VPNv4' , $link_array , array ( 'view' => 'prefixes_vpnv4unicast' ));
if ( $vars [ 'view' ] == 'prefixes_vpnv4unicast' ) {
echo '</span>' ;
}
2011-04-17 16:14:44 +00:00
2015-07-13 20:10:26 +02:00
echo ' | ' ;
2011-04-17 16:14:44 +00:00
2015-07-13 20:10:26 +02:00
if ( $vars [ 'view' ] == 'prefixes_ipv6unicast' ) {
echo " <span class='pagemenu-selected'> " ;
2017-03-11 23:16:49 +00:00
$extra_sql = " AND `bgpPeerIdentifier` LIKE '%:%' " ;
2015-07-13 20:10:26 +02:00
}
2011-04-17 16:14:44 +00:00
2015-07-13 20:10:26 +02:00
echo generate_link ( 'IPv6' , $link_array , array ( 'view' => 'prefixes_ipv6unicast' ));
if ( $vars [ 'view' ] == 'prefixes_ipv6unicast' ) {
echo '</span>' ;
}
2011-04-17 16:14:44 +00:00
2015-07-13 20:10:26 +02:00
echo ' | Traffic: ' ;
2011-04-17 16:14:44 +00:00
2015-07-13 20:10:26 +02:00
if ( $vars [ 'view' ] == 'macaccounting_bits' ) {
echo " <span class='pagemenu-selected'> " ;
}
2011-04-17 16:14:44 +00:00
2015-07-13 20:10:26 +02:00
echo generate_link ( 'Bits' , $link_array , array ( 'view' => 'macaccounting_bits' ));
if ( $vars [ 'view' ] == 'macaccounting_bits' ) {
echo '</span>' ;
}
2011-04-17 16:14:44 +00:00
2015-07-13 20:10:26 +02:00
echo ' | ' ;
if ( $vars [ 'view' ] == 'macaccounting_pkts' ) {
echo " <span class='pagemenu-selected'> " ;
}
2011-04-29 17:11:07 +00:00
2015-07-13 20:10:26 +02:00
echo generate_link ( 'Packets' , $link_array , array ( 'view' => 'macaccounting_pkts' ));
if ( $vars [ 'view' ] == 'macaccounting_pkts' ) {
echo '</span>' ;
}
2010-11-25 15:32:47 +00:00
2010-01-09 17:37:51 +00:00
print_optionbar_end ();
2009-01-07 12:37:18 +00:00
2015-07-13 20:10:26 +02:00
echo '<table border="0" cellspacing="0" cellpadding="5" width="100%">' ;
2017-05-30 14:54:43 +02:00
echo '<tr style="height: 30px"><th>Peer address</th><th>Type</th><th>Family</th><th>Remote AS</th><th>State</th><th>Uptime</th></tr>' ;
2015-07-13 20:10:26 +02:00
$i = '1' ;
2016-08-02 23:38:08 +01:00
foreach ( dbFetchRows ( " SELECT * FROM `bgpPeers` WHERE `device_id` = ? $extra_sql ORDER BY `bgpPeerRemoteAs`, `bgpPeerIdentifier` " , array ( $device [ 'device_id' ])) as $peer ) {
2015-07-13 20:10:26 +02:00
$has_macaccounting = dbFetchCell ( 'SELECT COUNT(*) FROM `ipv4_mac` AS I, mac_accounting AS M WHERE I.ipv4_address = ? AND M.mac = I.mac_address' , array ( $peer [ 'bgpPeerIdentifier' ]));
unset ( $bg_image );
if ( ! is_integer ( $i / 2 )) {
$bg_colour = $list_colour_a ;
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
$bg_colour = $list_colour_b ;
}
unset ( $alert , $bg_image );
unset ( $peerhost , $peername );
if ( ! is_integer ( $i / 2 )) {
$bg_colour = $list_colour_b ;
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
$bg_colour = $list_colour_a ;
}
if ( $peer [ 'bgpPeerState' ] == 'established' ) {
$col = 'green' ;
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
$col = 'red' ;
$peer [ 'alert' ] = 1 ;
}
if ( $peer [ 'bgpPeerAdminStatus' ] == 'start' || $peer [ 'bgpPeerAdminStatus' ] == 'running' ) {
$admin_col = 'green' ;
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
$admin_col = 'gray' ;
}
if ( $peer [ 'bgpPeerAdminStatus' ] == 'stop' ) {
$peer [ 'alert' ] = 0 ;
$peer [ 'disabled' ] = 1 ;
}
if ( $peer [ 'bgpPeerRemoteAs' ] == $device [ 'bgpLocalAs' ]) {
$peer_type = " <span style='color: #00f;'>iBGP</span> " ;
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
$peer_type = " <span style='color: #0a0;'>eBGP</span> " ;
}
$query = 'SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE ' ;
$query .= '(A.ipv4_address = ? AND I.port_id = A.port_id)' ;
$query .= ' AND D.device_id = I.device_id' ;
$ipv4_host = dbFetchRow ( $query , array ( $peer [ 'bgpPeerIdentifier' ]));
$query = 'SELECT * FROM ipv6_addresses AS A, ports AS I, devices AS D WHERE ' ;
$query .= '(A.ipv6_address = ? AND I.port_id = A.port_id)' ;
$query .= ' AND D.device_id = I.device_id' ;
$ipv6_host = dbFetchRow ( $query , array ( $peer [ 'bgpPeerIdentifier' ]));
if ( $ipv4_host ) {
$peerhost = $ipv4_host ;
2016-08-18 20:28:22 -05:00
} elseif ( $ipv6_host ) {
2015-07-13 20:10:26 +02:00
$peerhost = $ipv6_host ;
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
unset ( $peerhost );
}
2017-04-04 08:08:23 +01:00
$peerhost = cleanPort ( $peerhost );
2015-07-13 20:10:26 +02:00
if ( is_array ( $peerhost )) {
// $peername = generate_device_link($peerhost);
$peername = generate_device_link ( $peerhost ) . ' ' . generate_port_link ( $peerhost );
$peer_url = 'device/device=' . $peer [ 'device_id' ] . '/tab=routing/proto=bgp/view=updates/' ;
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
// FIXME
// $peername = gethostbyaddr($peer['bgpPeerIdentifier']); // FFffuuu DNS // Cache this in discovery?
// if ($peername == $peer['bgpPeerIdentifier'])
// {
// unset($peername);
// } else {
// $peername = "<i>".$peername."<i>";
// }
}
unset ( $peer_af );
unset ( $sep );
foreach ( dbFetchRows ( 'SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?' , array ( $device [ 'device_id' ], $peer [ 'bgpPeerIdentifier' ])) as $afisafi ) {
$afi = $afisafi [ 'afi' ];
$safi = $afisafi [ 'safi' ];
$this_afisafi = $afi . $safi ;
$peer [ 'afi' ] .= $sep . $afi . '.' . $safi ;
$sep = '<br />' ;
$peer [ 'afisafi' ][ $this_afisafi ] = 1 ;
// Build a list of valid AFI/SAFI for this peer
}
unset ( $sep );
if ( filter_var ( $peer [ 'bgpLocalAddr' ], FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 ) !== false ) {
$peer [ 'bgpPeerIdentifier' ] = Net_IPv6 :: compress ( $peer [ 'bgpPeerIdentifier' ]);
}
2016-02-03 06:41:20 +10:00
// display overlib graphs
$graph_array = array ();
$graph_array [ 'type' ] = 'bgp_updates' ;
$graph_array [ 'id' ] = $peer [ 'bgpPeer_id' ];
$graph_array [ 'to' ] = $config [ 'time' ][ 'now' ];
$graph_array [ 'from' ] = $config [ 'time' ][ 'day' ];
$graph_array [ 'height' ] = '110' ;
$graph_array [ 'width' ] = $width ;
// Peer Address
$graph_array_zoom = $graph_array ;
$graph_array_zoom [ 'height' ] = '150' ;
$graph_array_zoom [ 'width' ] = '500' ;
$overlib_link = " device/device= " . $peer [ 'device_id' ] . " /tab=routing/proto=bgp/ " ;
2017-03-05 19:42:39 +00:00
$link_array = $graph_array ;
$link_array [ 'page' ] = 'graphs' ;
unset ( $link_array [ 'height' ], $link_array [ 'width' ], $link_array [ 'legend' ]);
$link = generate_url ( $link_array );
$peeraddresslink = " <span class=list-large> " . overlib_link ( $link , $peer [ 'bgpPeerIdentifier' ], generate_graph_tag ( $graph_array_zoom ), null ) . " </span> " ;
2015-07-13 20:10:26 +02:00
echo '<tr bgcolor="' . $bg_colour . '"' . ( $peer [ 'alert' ] ? ' bordercolor="#cc0000"' : '' ) . ( $peer [ 'disabled' ] ? ' bordercolor="#cccccc"' : '' ) . ' >
' ;
2017-03-11 23:16:49 +00:00
echo '
2015-07-13 20:10:26 +02:00
< td > '.$peeraddresslink.' < br /> ' . $peername . " </td>
< td > $peer_type </ td >
< td style = 'font-size: 10px; font-weight: bold; line-height: 10px;' > " .(isset( $peer['afi'] ) ? $peer['afi'] : '').'</td>
< td >< strong > AS '.$peer[' bgpPeerRemoteAs '].' </ strong >< br /> '.$peer[' astext ' ] . " </td>
< td >< strong >< span style = 'color: $admin_col;' > " . $peer['bgpPeerAdminStatus'] . " < span >< br />< span style = 'color: $col;' > " . $peer['bgpPeerState'] .'</span></strong></td>
< td > '.formatUptime($peer[' bgpPeerFsmEstablishedTime ' ]) . " <br />
2017-02-15 17:16:03 -06:00
Updates < i class = 'fa fa-arrow-down icon-theme' aria - hidden = 'true' ></ i > " . $peer['bgpPeerInUpdates'] . "
< i class = 'fa fa-arrow-up icon-theme' aria - hidden = 'true' ></ i > " . $peer['bgpPeerOutUpdates'] .'</td>
2015-07-13 20:10:26 +02:00
</ tr >
< tr height = 5 ></ tr > ' ;
unset ( $invalid );
switch ( $vars [ 'view' ]) {
2016-08-18 20:28:22 -05:00
case 'prefixes_ipv4unicast' :
case 'prefixes_ipv4multicast' :
case 'prefixes_ipv4vpn' :
case 'prefixes_ipv6unicast' :
case 'prefixes_ipv6multicast' :
list (, $afisafi ) = explode ( '_' , $vars [ 'view' ]);
if ( isset ( $peer [ 'afisafi' ][ $afisafi ])) {
$peer [ 'graph' ] = 1 ;
}
// FIXME no break??
case 'updates' :
$graph_array [ 'type' ] = 'bgp_' . $vars [ 'view' ];
$graph_array [ 'id' ] = $peer [ 'bgpPeer_id' ];
2015-07-13 20:10:26 +02:00
}
2011-04-19 21:54:43 +00:00
2015-07-13 20:10:26 +02:00
switch ( $vars [ 'view' ]) {
2016-08-18 20:28:22 -05:00
case 'macaccounting_bits' :
case 'macaccounting_pkts' :
$acc = dbFetchRow ( 'SELECT * FROM `ipv4_mac` AS I, `mac_accounting` AS M, `ports` AS P, `devices` AS D WHERE I.ipv4_address = ? AND M.mac = I.mac_address AND P.port_id = M.port_id AND D.device_id = P.device_id' , array ( $peer [ 'bgpPeerIdentifier' ]));
$database = rrd_name ( $device [ 'hostname' ], array ( 'cip' , $acc [ 'ifIndex' ], $acc [ 'mac' ]));
if ( is_array ( $acc ) && is_file ( $database )) {
$peer [ 'graph' ] = 1 ;
$graph_array [ 'id' ] = $acc [ 'ma_id' ];
$graph_array [ 'type' ] = $vars [ 'view' ];
}
2015-07-13 20:10:26 +02:00
}
if ( $vars [ 'view' ] == 'updates' ) {
$peer [ 'graph' ] = 1 ;
}
if ( $peer [ 'graph' ]) {
$graph_array [ 'height' ] = '100' ;
$graph_array [ 'width' ] = '216' ;
$graph_array [ 'to' ] = $config [ 'time' ][ 'now' ];
echo '<tr bgcolor="' . $bg_colour . '"' . ( $bg_image ? ' background="' . $bg_image . '"' : '' ) . '"><td colspan="7">' ;
include 'includes/print-graphrow.inc.php' ;
echo '</td></tr>' ;
}
$i ++ ;
unset ( $valid_afi_safi );
} //end foreach
2008-03-15 17:58:15 +00:00
?>
2010-11-25 15:32:47 +00:00
2011-04-19 21:54:43 +00:00
</ table >