| 
									
										
										
										
											2009-09-07 11:07:59 +00:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2008-03-22 23:09:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Discover interfaces
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   echo("Interfaces : "); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-13 21:45:39 +00:00
										 |  |  |   $interfaces = snmp_walk($device, "ifDescr", "-Onsq", "IF-MIB"); | 
					
						
							| 
									
										
										
										
											2010-02-08 03:36:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-22 23:09:35 +00:00
										 |  |  |   $interfaces = str_replace("\"", "", $interfaces); | 
					
						
							|  |  |  |   $interfaces = str_replace("ifDescr.", "", $interfaces); | 
					
						
							|  |  |  |   $interfaces = str_replace(" ", "||", $interfaces); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   $interface_ignored = 0; | 
					
						
							|  |  |  |   $interface_added   = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   foreach(explode("\n", $interfaces) as $entry){ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $entry = trim($entry); | 
					
						
							| 
									
										
										
										
											2009-04-28 10:28:58 +00:00
										 |  |  |     list($ifIndex, $ifDescr) = explode("||", $entry); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-22 23:09:35 +00:00
										 |  |  |     if(!strstr($entry, "irtual")) { | 
					
						
							| 
									
										
										
										
											2008-11-21 15:06:23 +00:00
										 |  |  |       $if = trim(strtolower($ifDescr)); | 
					
						
							| 
									
										
										
										
											2008-03-22 23:09:35 +00:00
										 |  |  |       $nullintf = 0; | 
					
						
							| 
									
										
										
										
											2009-10-05 12:47:16 +00:00
										 |  |  |       foreach($config['bad_if'] as $bi) { if (strstr($if, $bi)) { $nullintf = 1; } } | 
					
						
							| 
									
										
										
										
											2009-11-28 10:38:02 +00:00
										 |  |  |       if($device['os'] == "catos" && strstr($if, "vlan") ) { $nullintf = 1; }  | 
					
						
							| 
									
										
										
										
											2008-11-27 12:36:37 +00:00
										 |  |  |       $ifDescr = fixifName($ifDescr); | 
					
						
							| 
									
										
										
										
											2009-10-05 12:47:16 +00:00
										 |  |  |       if (preg_match('/serial[0-9]:/', $if)) { $nullintf = 1; } | 
					
						
							| 
									
										
										
										
											2010-01-16 23:56:33 +00:00
										 |  |  |       if(isset($config['allow_ng']) && !$config['allow_ng']) { | 
					
						
							| 
									
										
										
										
											2009-10-05 12:47:16 +00:00
										 |  |  |        if (preg_match('/ng[0-9]+$/', $if)) { $nullintf = 1; } | 
					
						
							| 
									
										
										
										
											2009-05-03 22:13:41 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2009-12-29 01:00:57 +00:00
										 |  |  |       if ($debug) echo("\n $if "); | 
					
						
							| 
									
										
										
										
											2008-03-22 23:09:35 +00:00
										 |  |  |       if ($nullintf == 0) { | 
					
						
							|  |  |  |         if(mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) == '0') { | 
					
						
							| 
									
										
										
										
											2008-11-19 12:12:54 +00:00
										 |  |  |           mysql_query("INSERT INTO `interfaces` (`device_id`,`ifIndex`,`ifDescr`) VALUES ('".$device['device_id']."','$ifIndex','$ifDescr')"); | 
					
						
							| 
									
										
										
										
											2008-03-27 10:59:10 +00:00
										 |  |  |           # Add Interface
 | 
					
						
							| 
									
										
										
										
											2008-03-27 11:03:16 +00:00
										 |  |  |            echo("+"); | 
					
						
							| 
									
										
										
										
											2008-04-03 21:52:59 +00:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2009-10-05 12:47:16 +00:00
										 |  |  |             mysql_query("UPDATE `interfaces` SET `deleted` = '0' WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'");  | 
					
						
							| 
									
										
										
										
											2008-04-03 21:52:59 +00:00
										 |  |  |             echo("."); | 
					
						
							| 
									
										
										
										
											2008-03-22 23:09:35 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2008-04-03 21:52:59 +00:00
										 |  |  |         $int_exists[] = "$ifIndex"; | 
					
						
							| 
									
										
										
										
											2008-03-22 23:09:35 +00:00
										 |  |  |       } else {  | 
					
						
							| 
									
										
										
										
											2008-11-19 12:12:54 +00:00
										 |  |  |         # Ignored Interface
 | 
					
						
							|  |  |  | 	if(mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0') { | 
					
						
							|  |  |  |           mysql_query("UPDATE `interfaces` SET `deleted` = '1' WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"); | 
					
						
							|  |  |  |           # Delete Interface
 | 
					
						
							|  |  |  |           echo("-"); ## Deleted Interface
 | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |           echo("X"); ## Ignored Interface
 | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2008-03-22 23:09:35 +00:00
										 |  |  |       } | 
					
						
							|  |  |  |     }  | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-03 21:52:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   $sql = "SELECT * FROM `interfaces` WHERE `device_id`  = '".$device['device_id']."' AND `deleted` = '0'"; | 
					
						
							|  |  |  |   $query = mysql_query($sql); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   while ($test_if = mysql_fetch_array($query)) { | 
					
						
							|  |  |  |         unset($exists); | 
					
						
							|  |  |  |         $i = 0; | 
					
						
							| 
									
										
										
										
											2010-01-16 23:56:33 +00:00
										 |  |  |         while ($i < count($int_exists) && !isset($exists)) { | 
					
						
							| 
									
										
										
										
											2008-04-03 21:52:59 +00:00
										 |  |  |             $this_if = $test_if['ifIndex']; | 
					
						
							|  |  |  |             if ($int_exists[$i] == $this_if) { $exists = 1; } | 
					
						
							|  |  |  |             $i++; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if(!$exists) { | 
					
						
							|  |  |  |           echo("-"); | 
					
						
							|  |  |  |           mysql_query("UPDATE `interfaces` SET `deleted` = '1' WHERE interface_id = '" . $test_if['interface_id'] . "'"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   unset($temp_exists); | 
					
						
							| 
									
										
										
										
											2008-03-22 23:09:35 +00:00
										 |  |  |   echo("\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ?>
 |