2016-01-20 15:13:53 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< ? php  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*  Copyright  ( C )  2014  Nicolas  Armando  < nicearma @ yahoo . com >  and  Mathieu  Millet  < htam - net @ github . net >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  This  program  is  free  software :  you  can  redistribute  it  and / or  modify  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  it  under  the  terms  of  the  GNU  General  Public  License  as  published  by  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  the  Free  Software  Foundation ,  either  version  3  of  the  License ,  or  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  ( at  your  option )  any  later  version .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  This  program  is  distributed  in  the  hope  that  it  will  be  useful ,  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  but  WITHOUT  ANY  WARRANTY ;  without  even  the  implied  warranty  of  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  MERCHANTABILITY  or  FITNESS  FOR  A  PARTICULAR  PURPOSE . See  the  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  GNU  General  Public  License  for  more  details .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  You  should  have  received  a  copy  of  the  GNU  General  Public  License  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  along  with  this  program .  If  not ,  see  < http :// www . gnu . org / licenses />.  */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								global  $debug ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// This one only will work with the CISCO-CONTEXT-MAPPING-MIB V2 of cisco
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( $config [ 'enable_vrf_lite_cisco' ])  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $ids  =  array (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // For the moment only will be cisco and the version 3
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( $device [ 'os_group' ]  ==  " cisco "  &&  $device [ 'snmpver' ]  ==  'v3' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $mib  =  " SNMP-COMMUNITY-MIB " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $mib  =  " CISCO-CONTEXT-MAPPING-MIB " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //-Osq because if i put the n the oid from the first command is not the same of this one
 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        $listVrf  =  snmp_walk ( $device ,  " cContextMappingVrfName " ,  " -Osq -Ln " ,  $mib ,  null ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-20 15:13:53 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        $listVrf  =  str_replace ( " cContextMappingVrfName. " ,  " " ,  $listVrf ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $listVrf  =  str_replace ( '"' ,  " " ,  $listVrf ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $listVrf  =  trim ( $listVrf ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-01-25 11:17:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        d_echo ( " \n [DEBUG] \n Using  $mib\n[/DEBUG] \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        d_echo ( " \n [DEBUG List Vrf only name] \n $listVrf\n[/DEBUG] \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-20 15:13:53 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $tableVrf ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        foreach  ( explode ( " \n " ,  $listVrf )  as  $lineVrf )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $tmpVrf  =  explode ( "   " ,  $lineVrf ,  2 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            //the $tmpVrf[0] will be the context
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( count ( $tmpVrf )  ==  2  &&  ! empty ( $tmpVrf [ 1 ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                $tableVrf [ $tmpVrf [ 0 ]][ 'vrf_name' ]  =  $tmpVrf [ 1 ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        unset ( $listVrf ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-25 11:17:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        $listIntance  =  snmp_walk ( $device ,  " cContextMappingProtoInstName " ,  " -Osq -Ln " ,  $mib ,  null ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-20 15:13:53 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        $listIntance  =  str_replace ( " cContextMappingProtoInstName. " ,  " " ,  $listIntance ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $listIntance  =  str_replace ( '"' ,  " " ,  $listIntance ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $listIntance  =  trim ( $listIntance ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-25 11:17:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        d_echo ( " \n [DEBUG] \n Using  $mib\n[/DEBUG] \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        d_echo ( " \n [DEBUG] \n  List Intance only names \n $listIntance\n[/DEBUG] \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-25 11:17:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        
							 
						 
					
						
							
								
									
										
										
										
											2016-01-20 15:13:53 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        foreach  ( explode ( " \n " ,  $listIntance )  as  $lineIntance )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $tmpIntance  =  explode ( "   " ,  $lineIntance ,  2 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            //the $tmpIntance[0] will be the context and $tmpIntance[1] the intance
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( count ( $tmpIntance )  ==  2  &&  ! empty ( $tmpIntance [ 1 ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                $tableVrf [ $tmpIntance [ 0 ]][ 'intance_name' ]  =  $tmpIntance [ 1 ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        unset ( $listIntance ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        foreach  ( $tableVrf  as  $context  =>  $vrf )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( $debug )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                echo  ( " \n [DEBUG] \n Relation:t "  .  $context  .  " t "  .  $vrf [ 'intance' ]  .  " t "  .  $vrf [ 'vrf' ]  .  " \n [/DEBUG] \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $tmpVrf  =  dbFetchRow ( " SELECT * FROM vrf_lite_cisco WHERE device_id = ? and context_name=? " ,  array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                $device  [ 'device_id' ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                $context 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( ! empty ( $tmpVrf ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                $ids [ $tmpVrf [ 'vrf_lite_cisco_id' ]]  =  $tmpVrf [ 'vrf_lite_cisco_id' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                $vrfUpdate = array (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                foreach  ( $vrfUpdate  as  $key  =>  $value )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    if  ( $vrf [ $key ] != $value )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-20 15:13:53 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                        $vrfUpdate [ $key ] = $value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( ! empty ( $vrfUpdate ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    dbUpdate ( $vrfUpdate ,  'vrf_lite_cisco' ,  'vrf_lite_cisco_id=?' ,  array ( 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-20 15:13:53 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                        $tmp [ 'vrf_lite_cisco_id' ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                $id  =  dbInsert ( array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    'device_id'  =>  $device  [ 'device_id' ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    'context_name'  =>  $context , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    'intance_name'  =>  $vrf [ 'intance_name' ], 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    'vrf_name'  =>  $vrf [ 'vrf_name' ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        ),  'vrf_lite_cisco' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                $ids [ $id ]  =  $id ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        unset ( $tableVrf ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    //get all vrf_lite_cisco, this will used where the value depend of the context, be careful with the order that you call this module, if the module is disabled the context search will not work
 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-20 15:13:53 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    $tmpVrfC  =  dbFetchRows ( " SELECT * FROM vrf_lite_cisco WHERE device_id = ?  " ,  array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $device  [ 'device_id' ])); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $device [ 'vrf_lite_cisco' ]  =  $tmpVrfC ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    //Delete all vrf that chaged
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    foreach  ( $tmpVrfC  as  $vrfC )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        unset ( $ids [ $vrfC [ 'vrf_lite_cisco_id' ]]); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( ! empty ( $ids ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        foreach  ( $ids  as  $id )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-25 11:17:06 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            dbDelete ( 'vrf_lite_cisco' ,  'vrf_lite_cisco_id = ? ' ,  array ( $id )); 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-20 15:13:53 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    unset ( $ids ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    unset ( $tmpVrfC ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  // enable_vrf_lite_cisco