2007-04-03 14:10:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								#!/usr/bin/php
  
						 
					
						
							
								
									
										
										
										
											2009-09-07 11:07:59 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< ? php  
						 
					
						
							
								
									
										
										
										
											2007-04-03 14:10:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								include ( " config.php " );  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								include ( " includes/functions.php " );  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-03-23 17:32:25 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								echo ( " digraph G  {  sep=0.6; size= \" 40,20 \" ; pack=10; bgcolor=transparent;splines=true;
  
						 
					
						
							
								
									
										
										
										
											2009-03-02 18:12:09 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     node  [  fontname = \ " helvetica \" , fontsize=38, fontstyle=bold, shape=box, style=bold]; 
 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-23 17:32:25 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     edge  [  labelfontsize = 10 ,  labelfontname = \ " helvetica \" , overlap=false, fontstyle=bold];
 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 11:37:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     graph  [ bgcolor = transparent ,  remincross = true ];  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								" );
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								$linkdone  =  array ();  
						 
					
						
							
								
									
										
										
										
											2007-04-03 14:10:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								$x  =  1 ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-03-02 18:12:09 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$loc_sql  =  " SELECT * FROM devices GROUP BY location " ;  
						 
					
						
							
								
									
										
										
										
											2007-11-23 11:37:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$loc_result  =  mysql_query ( $loc_sql );  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								while ( $loc_data  =  mysql_fetch_array ( $loc_result ))  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-09-08 10:10:49 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  echo ( " subgraph  \" " .  $loc_data [ 'location' ]   . " \"   { \n 
 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 11:37:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  label  =  \ " " .  $loc_data [ 'location' ]   . " \" ; 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  style = filled ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  color = lightgrey ; \n\n " );
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2009-11-28 10:38:02 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  $dev_sql  =  " SELECT * FROM devices WHERE location = ' "  .  $loc_data [ 'location' ]  .  " ' and (`os` LIKE '%ios%' OR `os` LIKE '%catos%') AND disabled = 0 " ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 11:37:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  $dev_result  =  mysql_query ( $dev_sql ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  while ( $dev_data  =  mysql_fetch_array ( $dev_result ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-02 18:12:09 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        $device_id  =  $dev_data [ 'device_id' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-02-15 23:56:30 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#    if(mysql_result(mysql_query("SELECT count(*) from links WHERE local_interface_id = '$device_id' OR remote_interface_id = '$device_id'"),0)) {
  
						 
					
						
							
								
									
										
										
										
											2007-04-03 14:10:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									$host  =  $dev_data [ 'hostname' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        unset ( $hostinfo ); 	
							 
						 
					
						
							
								
									
										
										
										
											2008-03-15 17:58:15 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if ( strpos ( $host ,  " cust. "  .  $config [ 'mydomain' ]))  {  $hostinfo  =  " shape=egg style=filled fillcolor=pink " ;  } 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-02 18:12:09 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if ( strpos ( $host ,  " bas " ))  {  $hostinfo  =  " shape=rectangle style=filled fillcolor=skyblue " ;  }  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if ( strpos ( $host ,  " crs " ))  {  $hostinfo  =  " shape=box3d style=filled fillcolor=skyblue " ;  } 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-23 17:32:25 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if ( strpos ( $host ,  " lcr " ))  {  $hostinfo  =  " shape=tripleoctagon style=filled fillcolor=darkolivegreen4 " ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if ( strpos ( $host ,  " ler " ))  {  $hostinfo  =  " shape=octagon style=filled fillcolor=darkolivegreen1 " ;  } 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-02 18:12:09 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if ( strpos ( $host ,  " pbr " ))  {  $hostinfo  =  " shape=ellipse style=filled fillcolor=orange " ;  } 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-23 17:32:25 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if ( strpos ( $host ,  " tbr " ))  {  $hostinfo  =  " shape=ellipse style=filled fillcolor=orange " ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if ( strstr ( $host ,  " gwr " ))  {  $hostinfo  =  " shape=ellipse style=filled fillcolor=orange " ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if ( strpos ( $host ,  " bgw " ))  {  $hostinfo  =  " shape=ellipse style=filled fillcolor=orange " ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if ( strpos ( $host ,  " vax " ))  {  $hostinfo  =  " shape=rect style=filled fillcolor=skyblue " ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if ( strpos ( $host ,  " vsx " ))  {  $hostinfo  =  " shape=box3d style=filled fillcolor=skyblue " ;  } 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-03 14:10:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-01-31 17:30:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        $host  =  $dev_data [ 'hostname' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-15 17:58:15 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									$host  =  str_replace ( " . "  .  $config [ 'mydomain' ], " " ,  $host ); 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-03 14:10:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									echo ( " \" $host\ "  [ $hostinfo ] 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-02 18:12:09 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        " );	
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 #   }
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 11:37:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								echo ( " \n } \n " );  
						 
					
						
							
								
									
										
										
										
											2007-04-03 14:10:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-02-20 17:22:22 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$links_sql  =  " SELECT *, X.ifDescr AS sif, I.ifDescr AS dif FROM links AS L, ports AS I, ports AS X, devices as D, devices as Y WHERE  I.device_id = D.device_id AND X.device_id = Y.device_id AND L.local_interface_id = I.interface_id AND X.interface_id = L.remote_interface_id " ;  
						 
					
						
							
								
									
										
										
										
											2009-03-02 18:12:09 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-04-03 14:10:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								$links_result  =  mysql_query ( $links_sql );  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								while ( $link_data  =  mysql_fetch_array ( $links_result ))  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-02-15 23:56:30 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									$local_interface_id  =  $link_data [ 'local_interface_id' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									$remote_interface_id  =  $link_data [ 'remote_interface_id' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-03 14:10:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-02-20 17:22:22 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        $sq  =  mysql_fetch_row ( mysql_query ( " SELECT `hostname`,`ifSpeed` FROM ports AS I, devices as D where I.device_id = D.device_id and I.interface_id = ' $local_interface_id ' " )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $dq  =  mysql_fetch_row ( mysql_query ( " SELECT `hostname`,`ifSpeed` FROM ports AS I, devices as D where I.device_id = D.device_id and I.interface_id = ' $remote_interface_id ' " )); 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-03 14:10:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $src  =  $sq [ 0 ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $dst  =  $dq [ 0 ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									$src_speed  =  $sq [ 1 ];  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									$dst_speed  =  $dq [ 1 ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-15 17:58:15 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									$src  =  str_replace ( " . "  .  $config [ 'mydomain' ],  " " ,  $src ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									$dst  =  str_replace ( " . "  .  $config [ 'mydomain' ],  " " ,  $dst ); 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-03 14:10:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									$info  =  " " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 11:37:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if ( $src_speed  >=  " 10000000000 " )  {  
							 
						 
					
						
							
								
									
										
										
										
											2009-03-02 18:12:09 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								           $info  .=  " color=lightred weight=10 style= \" setlinewidth(8) \" " ;  
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 11:37:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  elseif  ( $src_speed  >=  " 1000000000 " )  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-02 18:12:09 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								           $info  .=  " color=lightblue weight=5 style= \" setlinewidth(4) \" " ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 11:37:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  elseif  ( $src_speed  >=  " 100000000 " )  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-02 18:12:09 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								           $info  .=  " color=lightgrey weight=1 style= \" setlinewidth(2) \" " ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 11:37:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  elseif  ( $src_speed  >=  " 10000000 " )  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-02 18:12:09 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								           $info  .=  " style= \" setlinewidth(1) \"  weight=1 " ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 11:37:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-03 14:10:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									unset ( $die ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									$i  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									while  ( $i  <  count ( $linkdone ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2010-01-31 17:30:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									    $thislink  =  " $dst   " . $link_data [ 'dif' ] . "   $src   " . $link_data [ 'sif' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-03 14:10:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            if  ( $linkdone [ $i ]  ==  $thislink )  {  $die  =  " yes " ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									    $i ++ ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-01-31 17:30:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									$sif  =  makeshortif ( $link_data [ 'sif' ]); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									$dif  =  makeshortif ( $link_data [ 'dif' ]); 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-03 14:10:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if ( ! $die ){ 	
							 
						 
					
						
							
								
									
										
										
										
											2009-03-02 18:12:09 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									echo ( " \" $src\ "  ->  \ " $dst\ "  [ taillabel = \ " $dif\ "   headlabel = \ " $sif\ "  arrowhead = dot  arrowtail = dot  $info ]; \n " );
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-18 13:35:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#       echo("\"$src\" -> \"$dst\" [ arrowhead=none arrowtail=none $info];\n");
  
						 
					
						
							
								
									
										
										
										
											2010-01-31 17:30:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									$linkdone []  =  " $src   " . $link_data [ 'sif' ] . "   $dst   " . $link_data [ 'dif' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-03 14:10:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									$x ++ ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								echo ( " } " );  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								?>