2008-10-28 18:25:53 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								< ? php 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-03-24 15:24:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								if ( $config [ 'enable_pseudowires' ])  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-10-28 18:25:53 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								  unset (  $cpw_count  ); 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-19 12:12:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  unset ( $cpw_exists );   
							 
						 
					
						
							
								
									
										
										
										
											2008-10-28 18:25:53 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  echo ( " PW :  " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-04-24 15:04:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  $oids  =  shell_exec ( $config [ 'snmpwalk' ]  .  "  -m CISCO-IETF-PW-MIB -CI -Ln -Osqn - "  .  $device [ 'snmpver' ]  .  "  -c  "  .  $device [ 'community' ]  .  "   "  .  $device [ 'hostname' ] . " : " . $device [ 'port' ]  .  "  cpwVcID " ); 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-28 18:25:53 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  $oids  =  str_replace ( " .1.3.6.1.4.1.9.10.106.1.2.1.10. " ,  " " ,  $oids ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  $oids  =  trim ( $oids ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  foreach  (  explode ( " \n " ,  $oids )  as  $oid  )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								   if ( $oid )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    list ( $cpwOid ,  $cpwVcID )  =  explode ( "   " ,  $oid ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if ( $cpwOid )  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-04-24 15:04:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      list ( $cpw_remote_id )  =  split ( " : " ,  shell_exec ( $config [ 'snmpget' ]  .  "  -m CISCO-IETF-PW-MPLS-MIB -Ln -Osqnv - "  .  $device [ 'snmpver' ]  .  "  -c  "  .  $device [ 'community' ]  .  "   "  .  $device [ 'hostname' ] . " : " . $device [ 'port' ]  .  "  cpwVcMplsPeerLdpID. "  .  $cpwOid )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      $interface_descr  =  trim ( shell_exec ( $config [ 'snmpwalk' ]  .  "  -m CISCO-IETF-PW-MIB -Oqvn - "  .  $device [ 'snmpver' ]  .  "  -c  "  .  $device [ 'community' ]  .  "   "  .  $device [ 'hostname' ] . " : " . $device [ 'port' ]  .  "  cpwVcName. "  .  $cpwOid )); 
							 
						 
					
						
							
								
									
										
										
										
											2010-02-20 17:22:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      $cpw_remote_device  =  @ mysql_result ( mysql_query ( " SELECT device_id FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ' " . $cpw_remote_id . " ' AND A.interface_id = I.interface_id " ), 0 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      $if_id  =  @ mysql_result ( mysql_query ( " SELECT `interface_id` FROM `ports` WHERE `ifDescr` = ' $interface_descr ' AND `device_id` = ' " . $device [ 'device_id' ] . " ' " ), 0 ); 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-28 18:25:53 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								      if ( $cpw_remote_device  &&  $if_id )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $hostname  =  gethostbyid ( $cpw_remote_device ); 
							 
						 
					
						
							
								
									
										
										
										
											2009-04-24 15:04:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        #echo("\nOid: " . $cpwOid . " cpwVcID: " . $cpwVcID . " Remote Id: " . $cpw_remote_id . "($hostname(".$cpw_remote_device.") -> $interface_descr($if_id))");
 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-28 18:25:53 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								        if ( mysql_result ( mysql_query ( " SELECT count(*) FROM pseudowires WHERE `interface_id` = ' $if_id '
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                                     AND  `cpwVcID` = '".$cpwVcID."' " ),0))  { 
 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-19 12:12:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  	  echo ( " . " ); 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-28 18:25:53 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          $insert_query   =  " INSERT INTO `pseudowires` (`interface_id`,`peer_device_id`,`peer_ldp_id`,`cpwVcID`,`cpwOid`)  " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          $insert_query  .=  " VALUES (' $if_id ',' $cpw_remote_device ',' $cpw_remote_id ',' $cpwVcID ', ' $cpwOid ') " ;  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          mysql_query ( $insert_query ); 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-19 12:12:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								          echo ( " + " ); 
							 
						 
					
						
							
								
									
										
										
										
											2009-04-24 15:04:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								          #echo($device['device_id'] . " $cpwOid $cpw_remote_device $if_id $cpwVcID\n");
 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-28 18:25:53 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-19 12:12:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									$cpw_exists []  =  $device [ 'device_id' ]  .  "   $cpwOid   $cpw_remote_device   $if_id   $cpwVcID " ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-28 18:25:53 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-02-20 17:22:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								$sql  =  " SELECT * FROM pseudowires AS P, ports AS I, devices as D WHERE P.interface_id = I.interface_id AND I.device_id = D.device_id AND D.device_id = ' " . $device [ 'device_id' ] . " ' " ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-19 12:12:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								$query  =  mysql_query ( $sql ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								while  ( $cpw  =  mysql_fetch_array ( $query ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  unset ( $exists ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  $i  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  while  ( $i  <  count ( $cpw_exists )  &&  ! $exists )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $this_cpw  =  $cpw [ 'device_id' ]  .  "   "  .  $cpw [ 'cpwOid' ]  .  "   "  .  $cpw [ 'peer_device_id' ]  .  "   "  .  $cpw [ 'interface_id' ]  .  "   "  .  $cpw [ 'cpwVcID' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $cpw_exists [ $i ]  ==  $this_cpw )  {  $exists  =  1 ;  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#    echo($cpw_exists[$i]. " || $this_cpw \n");
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $i ++ ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  if ( ! $exists )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    echo ( " - " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#    echo($this_cpw . "\n");
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    mysql_query ( " DELETE FROM pseudowires WHERE pseudowire_id = ' "  .  $cpw [ 'pseudowire_id' ]  .  " ' " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-05-12 15:59:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								echo ( " \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-03-24 15:24:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-10-28 18:25:53 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								?>