2011-04-28 14:20:17 +00:00
< ? php
2019-06-23 00:29:12 -05:00
use LibreNMS\Config ;
2018-04-07 15:55:28 -05:00
2019-08-05 14:16:05 -05:00
if ( ! Auth :: user () -> hasGlobalRead ()) {
2019-04-11 23:26:42 -05:00
include 'includes/html/error-no-perm.inc.php' ;
2018-07-13 22:20:22 +02:00
} else {
$link_array = array (
'page' => 'routing' ,
'protocol' => 'vrf' ,
);
2011-04-28 14:20:17 +00:00
2015-07-10 13:36:21 +02:00
print_optionbar_start ();
2011-04-28 14:20:17 +00:00
2018-07-13 22:20:22 +02:00
echo " <span style='font-weight: bold;'>VRFs</span> » " ;
2011-04-28 14:20:17 +00:00
2018-07-13 22:20:22 +02:00
$menu_options = array ( 'basic' => 'Basic' ,
);
2015-07-10 13:36:21 +02:00
2018-07-13 22:20:22 +02:00
if ( ! $vars [ 'view' ]) {
$vars [ 'view' ] = 'basic' ;
2015-07-10 13:36:21 +02:00
}
2011-04-28 14:20:17 +00:00
2018-07-13 22:20:22 +02:00
$sep = '' ;
foreach ( $menu_options as $option => $text ) {
if ( $vars [ 'view' ] == $option ) {
echo " <span class='pagemenu-selected'> " ;
}
2015-07-10 13:36:21 +02:00
2018-07-13 22:20:22 +02:00
echo generate_link ( $text , $link_array , array ( 'view' => $option ));
if ( $vars [ 'view' ] == $option ) {
echo '</span>' ;
}
2015-07-10 13:36:21 +02:00
2018-07-13 22:20:22 +02:00
echo ' | ' ;
2015-07-10 13:36:21 +02:00
}
2018-07-13 22:20:22 +02:00
unset ( $sep );
2015-07-10 13:36:21 +02:00
2018-07-13 22:20:22 +02:00
echo ' Graphs: ' ;
2015-07-10 13:36:21 +02:00
2018-07-13 22:20:22 +02:00
$graph_types = array (
'bits' => 'Bits' ,
'upkts' => 'Unicast Packets' ,
'nupkts' => 'Non-Unicast Packets' ,
'errors' => 'Errors' ,
'etherlike' => 'Etherlike' ,
);
2015-07-10 13:36:21 +02:00
2018-07-13 22:20:22 +02:00
foreach ( $graph_types as $type => $descr ) {
echo " $type_sep " ;
if ( $vars [ 'graph' ] == $type ) {
echo " <span class='pagemenu-selected'> " ;
}
2018-09-11 07:51:35 -05:00
2018-07-13 22:20:22 +02:00
echo generate_link ( $descr , $link_array , array ( 'view' => 'graphs' , 'graph' => $type ));
if ( $vars [ 'graph' ] == $type ) {
echo '</span>' ;
}
2018-09-11 07:51:35 -05:00
2018-07-13 22:20:22 +02:00
$type_sep = ' | ' ;
2015-07-10 13:36:21 +02:00
}
print_optionbar_end ();
2018-07-13 22:20:22 +02:00
if ( $vars [ 'view' ] == 'basic' || $vars [ 'view' ] == 'graphs' ) {
2015-07-10 13:36:21 +02:00
// Pre-Cache in arrays
// That's heavier on RAM, but much faster on CPU (1:40)
// Specifying the fields reduces a lot the RAM used (1:4) .
$vrf_fields = 'vrf_id, mplsVpnVrfRouteDistinguisher, mplsVpnVrfDescription, vrf_name' ;
2019-01-19 18:44:32 +01:00
$dev_fields = 'D.device_id as device_id, hostname, os, hardware, version, features, location_id, status, `ignore`, disabled' ;
2015-07-10 13:36:21 +02:00
$port_fields = 'port_id, ifvrf, device_id, ifDescr, ifAlias, ifName' ;
foreach ( dbFetchRows ( " SELECT $vrf_fields , $dev_fields FROM `vrfs` AS V, `devices` AS D WHERE D.device_id = V.device_id " ) as $vrf_device ) {
2018-06-13 15:28:12 -06:00
if ( empty ( $vrf_devices [ $vrf_device [ 'vrf_name' ]][ $vrf_device [ 'mplsVpnVrfRouteDistinguisher' ]])) {
$vrf_devices [ $vrf_device [ 'vrf_name' ]][ $vrf_device [ 'mplsVpnVrfRouteDistinguisher' ]][ 0 ] = $vrf_device ;
2016-08-18 20:28:22 -05:00
} else {
2018-06-13 15:28:12 -06:00
array_push ( $vrf_devices [ $vrf_device [ 'vrf_name' ]][ $vrf_device [ 'mplsVpnVrfRouteDistinguisher' ]], $vrf_device );
2015-07-10 13:36:21 +02:00
}
}
2018-09-11 07:51:35 -05:00
2018-06-13 15:28:12 -06:00
unset ( $ports );
2015-07-10 13:36:21 +02:00
foreach ( dbFetchRows ( " SELECT $port_fields FROM `ports` WHERE ifVrf<>0 " ) as $port ) {
if ( empty ( $ports [ $port [ 'ifvrf' ]][ $port [ 'device_id' ]])) {
$ports [ $port [ 'ifvrf' ]][ $port [ 'device_id' ]][ 0 ] = $port ;
2016-08-18 20:28:22 -05:00
} else {
2015-07-10 13:36:21 +02:00
array_push ( $ports [ $port [ 'ifvrf' ]][ $port [ 'device_id' ]], $port );
}
}
echo " <div style='margin: 5px;'><table border=0 cellspacing=0 cellpadding=5 width=100%> " ;
$i = '1' ;
2018-06-16 05:51:32 -06:00
foreach ( dbFetchRows ( 'SELECT `vrf_name`, `mplsVpnVrfRouteDistinguisher`, `mplsVpnVrfDescription` FROM `vrfs` GROUP BY `mplsVpnVrfRouteDistinguisher`, `mplsVpnVrfDescription`,`vrf_name`' ) as $vrf ) {
2015-07-10 13:36:21 +02:00
if (( $i % 2 )) {
2019-06-23 00:29:12 -05:00
$bg_colour = Config :: get ( 'list_colour.even' );
2016-08-18 20:28:22 -05:00
} else {
2019-06-23 00:29:12 -05:00
$bg_colour = Config :: get ( 'list_colour.odd' );
2015-07-10 13:36:21 +02:00
}
echo " <tr valign=top bgcolor=' $bg_colour '> " ;
2018-07-13 22:20:22 +02:00
echo " <td width=240> " ;
echo " <a class=list-large href= " . generate_url ( $vars , array ( 'view' => 'detail' , 'vrf' => $vrf [ 'vrf_name' ] )) . " > " ;
echo $vrf [ 'vrf_name' ] . '</a><br />' ;
echo " <span class=box-desc> " . $vrf [ 'mplsVpnVrfDescription' ] . '</span></td>' ;
2015-07-10 13:36:21 +02:00
echo '<td width=100 class=box-desc>' . $vrf [ 'mplsVpnVrfRouteDistinguisher' ] . '</td>' ;
echo '<td><table border=0 cellspacing=0 cellpadding=5 width=100%>' ;
$x = 1 ;
2018-06-13 15:28:12 -06:00
foreach ( $vrf_devices [ $vrf [ 'vrf_name' ]][ $vrf [ 'mplsVpnVrfRouteDistinguisher' ]] as $device ) {
2015-07-10 13:36:21 +02:00
if (( $i % 2 )) {
if (( $x % 2 )) {
2019-06-23 00:29:12 -05:00
$dev_colour = Config :: get ( 'list_colour.even_alt' );
2016-08-18 20:28:22 -05:00
} else {
2019-06-23 00:29:12 -05:00
$dev_colour = Config :: get ( 'list_colour.even_alt2' );
2015-07-10 13:36:21 +02:00
}
2016-08-18 20:28:22 -05:00
} else {
2015-07-10 13:36:21 +02:00
if (( $x % 2 )) {
2019-06-23 00:29:12 -05:00
$dev_colour = Config :: get ( 'list_colour.odd_alt2' );
2016-08-18 20:28:22 -05:00
} else {
2019-06-23 00:29:12 -05:00
$dev_colour = Config :: get ( 'list_colour.odd_alt' );
2015-07-10 13:36:21 +02:00
}
}
2018-07-13 22:20:22 +02:00
echo " <tr bgcolor=' $dev_colour '><td width=150><a href=' " ;
echo generate_url (
array ( 'page' => 'device' ),
array ( 'tab' => 'routing' , 'view' => 'basic' , 'proto' => 'vrf' , 'device' => $device [ 'device_id' ])
);
echo " '> " . $device [ 'hostname' ] . " </a> " ;
2015-07-10 13:36:21 +02:00
if ( $device [ 'vrf_name' ] != $vrf [ 'vrf_name' ]) {
2017-01-25 19:42:26 +02:00
echo " <a href='#' onmouseover= \" return overlib('Expected Name : " . $vrf [ 'vrf_name' ] . '<br />Configured : ' . $device [ 'vrf_name' ] . " ', CAPTION, '<span class=list-large>VRF Inconsistency</span>' ,FGCOLOR,'#e5e5e5', BGCOLOR, '#c0c0c0', BORDER, 5, CELLPAD, 4, CAPCOLOR, '#050505'); \" onmouseout= \" return nd(); \" > <i class='fa fa-flag fa-lg' style='color:red' aria-hidden='true'></i></a> " ;
2015-07-10 13:36:21 +02:00
}
echo '</td><td>' ;
unset ( $seperator );
foreach ( $ports [ $device [ 'vrf_id' ]][ $device [ 'device_id' ]] as $port ) {
2017-04-04 08:08:23 +01:00
$port = cleanPort ( $port );
2015-07-10 13:36:21 +02:00
$port = array_merge ( $device , $port );
2018-07-13 22:20:22 +02:00
switch ( $vars [ 'graph' ]) {
2015-07-10 13:36:21 +02:00
case 'bits' :
case 'upkts' :
case 'nupkts' :
case 'errors' :
$port [ 'width' ] = '130' ;
$port [ 'height' ] = '30' ;
2019-06-23 00:29:12 -05:00
$port [ 'from' ] = Config :: get ( 'time.day' );
$port [ 'to' ] = Config :: get ( 'time.now' );
2015-07-10 13:36:21 +02:00
$port [ 'bg' ] = '#' . $bg ;
2018-07-13 22:20:22 +02:00
$port [ 'graph_type' ] = 'port_' . $vars [ 'graph' ];
2015-07-10 13:36:21 +02:00
echo " <div style='display: block; padding: 3px; margin: 3px; min-width: 135px; max-width:135px; min-height:75px; max-height:75px;
2019-06-23 00:29:12 -05:00
text - align : center ; float : left ; background - color : " . Config::get('list_colour.odd_alt2') . " ; ' >
2015-07-10 13:36:21 +02:00
< div style = 'font-weight: bold;' > " .makeshortif( $port['ifDescr'] ).'</div>';
print_port_thumbnail ( $port );
2017-04-04 08:08:23 +01:00
echo " <div style='font-size: 9px;'> " . substr ( short_port_descr ( $port [ 'ifAlias' ]), 0 , 22 ) . ' </ div >
2015-07-10 13:36:21 +02:00
</ div > ' ;
break ;
default :
echo $seperator . generate_port_link ( $port , makeshortif ( $port [ 'ifDescr' ]));
$seperator = ', ' ;
break ;
} //end switch
} //end foreach
echo '</td></tr>' ;
$x ++ ;
} //end foreach
echo '</table></td>' ;
$i ++ ;
} //end foreach
echo '</table></div>' ;
2018-07-13 22:20:22 +02:00
} elseif ( $vars [ 'view' ] == 'detail' ) {
echo " Not Implemented " ;
2015-07-10 13:36:21 +02:00
} //end if
} //end if