| 
									
										
										
										
											2009-09-07 11:07:59 +00:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2009-05-07 13:47:51 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ## Common Functions
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-28 13:49:37 +00:00
										 |  |  | function truncate($substring, $max = 50, $rep = '...'){ | 
					
						
							|  |  |  |   if(strlen($substring) < 1){ $string = $rep; } else { $string = $substring; } | 
					
						
							|  |  |  |   $leave = $max - strlen ($rep); | 
					
						
							|  |  |  |   if(strlen($string) > $max){ return substr_replace($string, $rep, $leave); } else { return $string; } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-19 10:43:02 +00:00
										 |  |  | function mres($string) { // short function wrapper because the real one is stupidly long and ugly. aestetics.
 | 
					
						
							|  |  |  |   return mysql_real_escape_string($string); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-11 13:43:59 +00:00
										 |  |  | function getifhost($id) { | 
					
						
							|  |  |  |      $sql = mysql_query("SELECT `device_id` from `interfaces` WHERE `interface_id` = '$id'"); | 
					
						
							|  |  |  |      $result = @mysql_result($sql, 0); | 
					
						
							|  |  |  |      return $result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-07 13:47:51 +00:00
										 |  |  | function gethostbyid($id) { | 
					
						
							|  |  |  |      $sql = mysql_query("SELECT `hostname` FROM `devices` WHERE `device_id` = '$id'"); | 
					
						
							|  |  |  |      $result = @mysql_result($sql, 0); | 
					
						
							|  |  |  |      return $result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function strgen ($length = 16) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     $entropy = array(0,1,2,3,4,5,6,7,8,9,'a','A','b','B','c','C','d','D','e', | 
					
						
							|  |  |  |     'E','f','F','g','G','h','H','i','I','j','J','k','K','l','L','m','M','n', | 
					
						
							|  |  |  |     'N','o','O','p','P','q','Q','r','R','s','S','t','T','u','U','v','V','w', | 
					
						
							|  |  |  |     'W','x','X','y','Y','z','Z'); | 
					
						
							|  |  |  |     $string = ""; | 
					
						
							|  |  |  |     for ($i=0; $i<$length; $i++) { | 
					
						
							|  |  |  |         $key = mt_rand(0,61); | 
					
						
							|  |  |  |         $string .= $entropy[$key]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return $string; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function getpeerhost($id) { | 
					
						
							|  |  |  |      $sql = mysql_query("SELECT `device_id` from `bgpPeers` WHERE `bgpPeer_id` = '$id'"); | 
					
						
							|  |  |  |      $result = @mysql_result($sql, 0); | 
					
						
							|  |  |  |      return $result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function getifindexbyid($id) { | 
					
						
							|  |  |  |      $sql = mysql_query("SELECT `ifIndex` FROM `interfaces` WHERE `interface_id` = '$id'"); | 
					
						
							|  |  |  |      $result = @mysql_result($sql, 0); | 
					
						
							|  |  |  |      return $result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function getifbyid($id) { | 
					
						
							|  |  |  |      $sql = mysql_query("SELECT `ifDescr` FROM `interfaces` WHERE `interface_id` = '$id'"); | 
					
						
							|  |  |  |      $result = @mysql_result($sql, 0); | 
					
						
							|  |  |  |      return $result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function getidbyname($domain){ | 
					
						
							|  |  |  |      $sql = mysql_query("SELECT `device_id` FROM `devices` WHERE `hostname` = '$domain'"); | 
					
						
							|  |  |  |      $result = @mysql_result($sql, 0); | 
					
						
							|  |  |  |      return $result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function gethostosbyid($id) { | 
					
						
							|  |  |  |      $sql = mysql_query("SELECT `os` FROM `devices` WHERE `device_id` = '$id'"); | 
					
						
							|  |  |  |      $result = @mysql_result($sql, 0); | 
					
						
							|  |  |  |      return $result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ?>
 |