2011-04-28 14:20:17 +00:00
< ? php
2018-04-07 15:55:28 -05:00
use LibreNMS\Authentication\Auth ;
if ( Auth :: user () -> hasGlobalRead ()) {
2016-02-17 13:59:58 +00:00
if ( ! isset ( $_GET [ 'optb' ])) {
$_GET [ 'optb' ] = 'all' ;
2015-07-10 13:36:21 +02:00
}
2016-02-17 13:59:58 +00:00
if ( ! isset ( $_GET [ 'optc' ])) {
$_GET [ 'optc' ] = 'basic' ;
2015-07-10 13:36:21 +02:00
}
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
2015-07-10 13:36:21 +02:00
echo '<span style="font-weight: bold;">VRF</span> » ' ;
2016-02-17 13:59:58 +00:00
if ( $_GET [ 'opta' ] == 'vrf' && $_GET [ 'optb' ] == 'all' ) {
2015-07-10 13:36:21 +02:00
echo " <span class='pagemenu-selected'> " ;
}
2016-02-17 13:59:58 +00:00
echo '<a href="routing/vrf/all/' . $_GET [ 'optc' ] . '/">All</a>' ;
if ( $_GET [ 'opta' ] == 'vrf' && $_GET [ 'optb' ] == 'all' ) {
2015-07-10 13:36:21 +02:00
echo '</span>' ;
}
2011-04-28 14:20:17 +00:00
2015-07-10 13:36:21 +02:00
echo ' | ' ;
2016-02-17 13:59:58 +00:00
if ( $_GET [ 'opta' ] == 'vrf' && $_GET [ 'optc' ] == 'basic' ) {
2015-07-10 13:36:21 +02:00
echo " <span class='pagemenu-selected'> " ;
}
2016-02-17 13:59:58 +00:00
echo '<a href="routing/vrf/' . $_GET [ 'optb' ] . '/basic/">Basic</a>' ;
if ( $_GET [ 'opta' ] == 'vrf' && $_GET [ 'optc' ] == 'basic' ) {
2015-07-10 13:36:21 +02:00
echo '</span>' ;
}
echo ' | ' ;
2016-02-17 13:59:58 +00:00
if ( $_GET [ 'opta' ] == 'vrf' && $_GET [ 'optc' ] == 'details' ) {
2015-07-10 13:36:21 +02:00
echo " <span class='pagemenu-selected'> " ;
}
2011-04-28 14:20:17 +00:00
2016-02-17 13:59:58 +00:00
echo '<a href="routing/vrf/' . $_GET [ 'optb' ] . '/details/">Details</a>' ;
if ( $_GET [ 'opta' ] == 'vrf' && $_GET [ 'optc' ] == 'details' ) {
2015-07-10 13:36:21 +02:00
echo '</span>' ;
}
2011-04-28 14:20:17 +00:00
2015-07-10 13:36:21 +02:00
echo ' | Graphs: ( ' ;
2016-02-17 13:59:58 +00:00
if ( $_GET [ 'opta' ] == 'vrf' && $_GET [ 'optc' ] == 'bits' ) {
2015-07-10 13:36:21 +02:00
echo " <span class='pagemenu-selected'> " ;
}
2011-04-28 14:20:17 +00:00
2016-02-17 13:59:58 +00:00
echo '<a href="routing/vrf/' . $_GET [ 'optb' ] . '/bits/">Bits</a>' ;
if ( $_GET [ 'opta' ] == 'vrf' && $_GET [ 'optc' ] == 'bits' ) {
2015-07-10 13:36:21 +02:00
echo '</span>' ;
}
echo ' | ' ;
2016-02-17 13:59:58 +00:00
if ( $_GET [ 'opta' ] == 'vrf' && $_GET [ 'optc' ] == 'upkts' ) {
2015-07-10 13:36:21 +02:00
echo " <span class='pagemenu-selected'> " ;
}
2016-02-17 13:59:58 +00:00
echo '<a href="routing/vrf/' . $_GET [ 'optb' ] . '/upkts/">Packets</a>' ;
if ( $_GET [ 'opta' ] == 'vrf' && $_GET [ 'optc' ] == 'upkts' ) {
2015-07-10 13:36:21 +02:00
echo '</span>' ;
}
echo ' | ' ;
2016-02-17 13:59:58 +00:00
if ( $_GET [ 'opta' ] == 'vrf' && $_GET [ 'optc' ] == 'nupkts' ) {
2015-07-10 13:36:21 +02:00
echo " <span class='pagemenu-selected'> " ;
}
2016-02-17 13:59:58 +00:00
echo '<a href="routing/vrf/' . $_GET [ 'optb' ] . '/nupkts/">NU Packets</a>' ;
if ( $_GET [ 'opta' ] == 'vrf' && $_GET [ 'optc' ] == 'nupkts' ) {
2015-07-10 13:36:21 +02:00
echo '</span>' ;
}
echo ' | ' ;
2016-02-17 13:59:58 +00:00
if ( $_GET [ 'opta' ] == 'vrf' && $_GET [ 'optc' ] == 'errors' ) {
2015-07-10 13:36:21 +02:00
echo " <span class='pagemenu-selected'> " ;
}
2016-02-17 13:59:58 +00:00
echo '<a href="routing/vrf/' . $_GET [ 'optb' ] . '/errors/">Errors</a>' ;
if ( $_GET [ 'opta' ] == 'vrf' && $_GET [ 'optc' ] == 'errors' ) {
2015-07-10 13:36:21 +02:00
echo '</span>' ;
}
echo ' )' ;
print_optionbar_end ();
2016-02-17 13:59:58 +00:00
if ( $_GET [ 'optb' ] == 'all' ) {
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' ;
$dev_fields = 'D.device_id as device_id, hostname, os, hardware, version, features, location, status, `ignore`, disabled' ;
$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-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-13 15:28:12 -06:00
foreach ( dbFetchRows ( 'SELECT * FROM `vrfs` GROUP BY `mplsVpnVrfRouteDistinguisher`,`vrf_name`' ) as $vrf ) {
2015-07-10 13:36:21 +02:00
if (( $i % 2 )) {
2018-02-12 03:15:44 -06:00
$bg_colour = $config [ 'list_colour' ][ 'even' ];
2016-08-18 20:28:22 -05:00
} else {
2018-02-12 03:15:44 -06:00
$bg_colour = $config [ 'list_colour' ][ 'odd' ];
2015-07-10 13:36:21 +02:00
}
echo " <tr valign=top bgcolor=' $bg_colour '> " ;
2016-02-17 13:59:58 +00:00
echo " <td width=240><a class=list-large href='routing/vrf/ " . $vrf [ 'mplsVpnVrfRouteDistinguisher' ] . '/' . $_GET [ 'optc' ] . " /'> " . $vrf [ 'vrf_name' ] . '</a><br /><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 width=200 class=box-desc>" . $vrf['mplsVpnVrfDescription'] . "</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 )) {
2018-02-12 03:15:44 -06:00
$dev_colour = $config [ 'list_colour' ][ 'even_alt' ];
2016-08-18 20:28:22 -05:00
} else {
2018-02-12 03:15:44 -06:00
$dev_colour = $config [ '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 )) {
2018-02-12 03:15:44 -06:00
$dev_colour = $config [ 'list_colour' ][ 'odd_alt2' ];
2016-08-18 20:28:22 -05:00
} else {
2018-02-12 03:15:44 -06:00
$dev_colour = $config [ 'list_colour' ][ 'odd_alt' ];
2015-07-10 13:36:21 +02:00
}
}
echo " <tr bgcolor=' $dev_colour '><td width=150> " . generate_device_link ( $device , shorthost ( $device [ 'hostname' ]));
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 );
2016-02-17 13:59:58 +00:00
switch ( $_GET [ 'optc' ]) {
2015-07-10 13:36:21 +02:00
case 'bits' :
case 'upkts' :
case 'nupkts' :
case 'errors' :
$port [ 'width' ] = '130' ;
$port [ 'height' ] = '30' ;
$port [ 'from' ] = $config [ 'time' ][ 'day' ];
$port [ 'to' ] = $config [ 'time' ][ 'now' ];
$port [ 'bg' ] = '#' . $bg ;
2016-02-17 13:59:58 +00:00
$port [ 'graph_type' ] = 'port_' . $_GET [ 'optc' ];
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;
2018-02-12 03:15:44 -06:00
text - align : center ; float : left ; background - color : " . $config['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>' ;
2016-08-18 20:28:22 -05:00
} else {
2018-02-12 03:15:44 -06:00
echo " <div style='background: { $config [ 'list_colour' ][ 'even' ] } ; padding: 10px;'><table border=0 cellspacing=0 cellpadding=5 width=100%> " ;
2016-02-17 13:59:58 +00:00
$vrf = dbFetchRow ( 'SELECT * FROM `vrfs` WHERE mplsVpnVrfRouteDistinguisher = ?' , array ( $_GET [ 'optb' ]));
2015-07-10 13:36:21 +02:00
echo " <tr valign=top bgcolor=' $bg_colour '> " ;
2016-02-17 13:59:58 +00:00
echo " <td width=200 class=list-large><a href='routing/vrf/ " . $vrf [ 'mplsVpnVrfRouteDistinguisher' ] . '/' . $_GET [ 'optc' ] . " /'> " . $vrf [ 'vrf_name' ] . '</a></td>' ;
2015-07-10 13:36:21 +02:00
echo '<td width=100 class=box-desc>' . $vrf [ 'mplsVpnVrfRouteDistinguisher' ] . '</td>' ;
echo '<td width=200 class=box-desc>' . $vrf [ 'mplsVpnVrfDescription' ] . '</td>' ;
echo '</table></div>' ;
$x = 0 ;
$devices = dbFetchRows ( 'SELECT * FROM `vrfs` AS V, `devices` AS D WHERE `mplsVpnVrfRouteDistinguisher` = ? AND D.device_id = V.device_id' , array ( $vrf [ 'mplsVpnVrfRouteDistinguisher' ]));
foreach ( $devices as $device ) {
$hostname = $device [ 'hostname' ];
2017-02-24 03:59:30 -06:00
echo '<div>' ;
2015-07-10 13:36:21 +02:00
include 'includes/device-header.inc.php' ;
2017-02-24 03:59:30 -06:00
echo '</div>' ;
2015-07-10 13:36:21 +02:00
unset ( $seperator );
echo '<div style="margin: 0 0 0 60px;"><table cellspacing=0 cellpadding=7>' ;
$i = 1 ;
foreach ( dbFetchRows ( 'SELECT * FROM `ports` WHERE `ifVrf` = ? AND `device_id` = ?' , array ( $device [ 'vrf_id' ], $device [ 'device_id' ])) as $interface ) {
if (( $x % 2 )) {
if (( $i % 2 ) === 0 ) {
2018-02-12 03:15:44 -06:00
$int_colour = $config [ 'list_colour' ][ 'even_alt2' ];
2016-08-18 20:28:22 -05:00
} else {
2018-02-12 03:15:44 -06:00
$int_colour = $config [ 'list_colour' ][ 'even_alt' ];
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 (( $i % 2 ) === 0 ) {
2018-02-12 03:15:44 -06:00
$int_colour = $config [ 'list_colour' ][ 'odd_alt' ];
2016-08-18 20:28:22 -05:00
} else {
2018-02-12 03:15:44 -06:00
$int_colour = $config [ 'list_colour' ][ 'odd_alt2' ];
2015-07-10 13:36:21 +02:00
}
}
include 'includes/print-interface.inc.php' ;
$i ++ ;
} //end foreach
$x ++ ;
echo '</table></div>' ;
echo " <div style='height: 10px;'></div> " ;
} //end foreach
} //end if
2016-08-18 20:28:22 -05:00
} else {
2015-07-10 13:36:21 +02:00
include 'includes/error-no-perm.inc.php' ;
} //end if