2009-09-07 11:07:59 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								< ? php 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-14 18:00:21 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  LibreNMS  -  Common  Functions 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Original  Observium  version  by :  Adam  Armstrong ,  Tom  Laermans 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Copyright  ( c )  2009 - 2012  Adam  Armstrong . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Additions  for  LibreNMS  by :  Neil  Lathwood ,  Paul  Gear ,  Tim  DuFrane 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Copyright  ( c )  2014 - 2015  Neil  Lathwood  < http :// www . lathwood . co . uk > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Copyright  ( c )  2014 - 2015  Gear  Consulting  Pty  Ltd  < http :// libertysys . com . au /> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  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 .   Please  see  LICENSE . txt  at  the  top  level  of 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  the  source  code  distribution  for  details . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-05-07 13:47:51 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-11 07:51:35 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								use  LibreNMS\Authentication\LegacyAuth ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-08 14:14:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								use  LibreNMS\Config ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								use  LibreNMS\Exceptions\InvalidIpException ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-08 21:42:56 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								use  LibreNMS\Util\Git ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-16 15:18:17 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								use  LibreNMS\Util\Html ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-08 14:14:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								use  LibreNMS\Util\IP ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-12 23:59:03 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								use  LibreNMS\Util\Laravel ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-08 14:14:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:57:54 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  generate_priority_label ( $priority ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-05 13:34:23 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $map  =  array ( 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:57:54 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        " emerg "      =>  " label-danger " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " alert "      =>  " label-danger " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " crit "       =>  " label-danger " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " err "        =>  " label-danger " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " warning "    =>  " label-warning " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " notice "     =>  " label-info " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " info "       =>  " label-info " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " debug "      =>  " label-default " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " "           =>  " label-info " , 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-05 13:34:23 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:57:54 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $barColor  =  isset ( $map [ $priority ])  ?  $map [ $priority ]  :  'label-info' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  '<span class="alert-status ' . $barColor  . '"> </span>' ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-06 13:39:53 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  generate_priority_status ( $priority ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $map  =  array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " emerg "      =>  2 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " alert "      =>  2 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " crit "       =>  2 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " err "        =>  2 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " warning "    =>  1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " notice "     =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " info "       =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " debug "      =>  3 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " "           =>  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  isset ( $map [ $priority ])  ?  $map [ $priority ]  :  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-05 13:34:23 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:59:16 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  graylog_severity_label ( $severity ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $map  =  array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " 0 "  =>  " label-danger " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " 1 "  =>  " label-danger " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " 2 "  =>  " label-danger " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " 3 "  =>  " label-danger " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " 4 "  =>  " label-warning " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " 5 "  =>  " label-info " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " 6 "  =>  " label-info " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " 7 "  =>  " label-default " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        " "   =>  " label-info " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $barColor  =  isset ( $map [ $severity ])  ?  $map [ $severity ]  :  'label-info' ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-09 22:47:33 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  '<span class="alert-status ' . $barColor  . '" style="margin-right:8px;float:left;"></span>' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-24 21:59:16 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-12-16 07:42:50 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Execute  and  snmp  command ,  filter  debug  output  unless  - v  is  specified 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  array  $command 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  null | string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  external_exec ( $command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-16 07:42:50 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    global  $debug ,  $vdebug ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $proc  =  new  \Symfony\Component\Process\Process ( $command ); 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-10 11:18:34 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $proc -> setTimeout ( Config :: get ( 'snmp.exec_timeout' ,  1200 )); 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-22 11:36:33 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $debug  &&  ! $vdebug )  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-16 07:42:50 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $patterns  =  [ 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-28 15:41:50 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            '/-c\' \'[\S]+\'/' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            '/-u\' \'[\S]+\'/' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            '/-U\' \'[\S]+\'/' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            '/-A\' \'[\S]+\'/' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            '/-X\' \'[\S]+\'/' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            '/-P\' \'[\S]+\'/' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            '/-H\' \'[\S]+\'/' , 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-16 07:42:50 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            '/(udp|udp6|tcp|tcp6):([^:]+):([\d]+)/' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $replacements  =  [ 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-28 15:41:50 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            '-c\' \'COMMUNITY\'' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            '-u\' \'USER\'' , 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-29 07:40:15 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            '-U\' \'USER\'' , 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-28 15:41:50 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            '-A\' \'PASSWORD\'' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            '-X\' \'PASSWORD\'' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            '-P\' \'PASSWORD\'' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            '-H\' \'HOSTNAME\'' , 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-16 07:42:50 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            '\1:HOSTNAME:\3' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $debug_command  =  preg_replace ( $patterns ,  $replacements ,  $proc -> getCommandLine ()); 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-22 11:36:33 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        c_echo ( 'SNMP[%c'  .  $debug_command  .  " %n] \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    }  elseif  ( $vdebug )  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-16 07:42:50 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        c_echo ( 'SNMP[%c' . $proc -> getCommandLine () . " %n] \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-17 14:39:17 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-12-16 07:42:50 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $proc -> run (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $output  =  $proc -> getOutput (); 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-17 14:39:17 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-22 11:36:33 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $debug  &&  ! $vdebug )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $ip_regex  =  '/(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $debug_output  =  preg_replace ( $ip_regex ,  '*' ,  $output ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        d_echo ( $debug_output  .  PHP_EOL ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    }  elseif  ( $vdebug )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        d_echo ( $output  .  PHP_EOL ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-17 14:39:17 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-16 07:42:50 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    d_echo ( $proc -> getErrorOutput ()); 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-22 18:28:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  $output ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-22 18:28:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  shorthost ( $hostname ,  $len  =  12 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // IP addresses should not be shortened
 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( filter_var ( $hostname ,  FILTER_VALIDATE_IP ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  $hostname ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-09 20:47:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $len  =  Config :: get ( 'shorthost_target_length' ,  $len ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $parts  =  explode ( " . " ,  $hostname ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $shorthost  =  $parts [ 0 ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $i  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    while  ( $i  <  count ( $parts )  &&  strlen ( $shorthost . '.' . $parts [ $i ])  <  $len )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $shorthost  =  $shorthost . '.' . $parts [ $i ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $i ++ ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  ( $shorthost ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  isCli () 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( php_sapi_name ()  ==  'cli'  &&  empty ( $_SERVER [ 'REMOTE_ADDR' ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-08 12:24:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  print_error ( $text ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( isCli ())  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-16 19:52:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        c_echo ( " %r " . $text . " %n \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-21 15:00:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        echo ( '<div class="alert alert-danger"><i class="fa fa-fw fa-exclamation-circle" aria-hidden="true"></i> ' . $text . '</div>' ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-08 12:24:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  print_message ( $text ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( isCli ())  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-16 19:52:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        c_echo ( " %g " . $text . " %n \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-22 08:09:31 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        echo ( '<div class="alert alert-success"><i class="fa fa-fw fa-check-circle" aria-hidden="true"></i> ' . $text . '</div>' ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-09-08 12:24:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  delete_port ( $int_id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $interface  =  dbFetchRow ( " SELECT * FROM `ports` AS P, `devices` AS D WHERE P.port_id = ? AND D.device_id = P.device_id " ,  array ( $int_id )); 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-13 15:05:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-16 02:42:56 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $interface_tables  =  array ( 'ipv4_addresses' ,  'ipv4_mac' ,  'ipv6_addresses' ,  'juniAtmVp' ,  'mac_accounting' ,  'ospf_nbrs' ,  'ospf_ports' ,  'ports' ,  'ports_adsl' ,  'ports_perms' ,  'ports_statistics' ,  'ports_stp' ,  'ports_vlans' ,  'pseudowires' ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-13 15:05:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    foreach  ( $interface_tables  as  $table )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        dbDelete ( $table ,  " `port_id` =  ? " ,  array ( $int_id )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-13 15:05:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-16 02:42:56 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    dbDelete ( 'links' ,  " `local_port_id` = ? OR `remote_port_id` = ? " ,  array ( $int_id ,  $int_id )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    dbDelete ( 'ports_stack' ,  " `port_id_low` = ? OR `port_id_high` = ? " ,  array ( $int_id ,  $int_id )); 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-13 15:05:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    unlink ( get_port_rrdfile_path ( $interface [ 'hostname' ],  $interface [ 'port_id' ])); 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-13 15:05:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-08 22:58:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_sensor_rrd ( $device ,  $sensor ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  rrd_name ( $device [ 'hostname' ],  get_sensor_rrd_name ( $device ,  $sensor )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_sensor_rrd_name ( $device ,  $sensor ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    # For IPMI, sensors tend to change order, and there is no index, so we prefer to use the description as key here.
 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( Config :: getOsSetting ( $device [ 'os' ],  'sensor_descr' )  ||  $sensor [ 'poller_type' ]  ==  " ipmi " )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-08 22:58:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  array ( 'sensor' ,  $sensor [ 'sensor_class' ],  $sensor [ 'sensor_type' ],  $sensor [ 'sensor_descr' ]); 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:33:43 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-08 22:58:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  array ( 'sensor' ,  $sensor [ 'sensor_class' ],  $sensor [ 'sensor_type' ],  $sensor [ 'sensor_index' ]); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:33:43 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  getPortRrdName ( $port_id ,  $suffix  =  '' ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:33:43 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( ! empty ( $suffix ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:33:43 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $suffix  =  '-'  .  $suffix ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-04-26 15:07:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:33:43 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  " port-id $port_id $suffix " ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-04-26 15:07:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_port_rrdfile_path ( $hostname ,  $port_id ,  $suffix  =  '' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:33:43 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  rrd_name ( $hostname ,  getPortRrdName ( $port_id ,  $suffix )); 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-26 13:49:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_port_by_index_cache ( $device_id ,  $ifIndex ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    global  $port_index_cache ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-19 10:02:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( isset ( $port_index_cache [ $device_id ][ $ifIndex ])  &&  is_array ( $port_index_cache [ $device_id ][ $ifIndex ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $port  =  $port_index_cache [ $device_id ][ $ifIndex ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $port  =  get_port_by_ifIndex ( $device_id ,  $ifIndex ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $port_index_cache [ $device_id ][ $ifIndex ]  =  $port ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-19 10:02:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  $port ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-19 10:02:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_port_by_ifIndex ( $device_id ,  $ifIndex ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  dbFetchRow ( " SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ? " ,  array ( $device_id ,  $ifIndex )); 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-19 10:02:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-25 11:43:45 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_all_devices () 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    global  $cache ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $devices  =  array (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // FIXME needs access control checks!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // FIXME respect $type (server, network, etc) -- needs an array fill in topnav.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( isset ( $cache [ 'devices' ][ 'hostname' ]))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-05 12:25:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $devices  =  array_keys ( $cache [ 'devices' ]); 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-07 16:20:59 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $devices  =  dbFetchRows ( " SELECT * FROM `devices` ORDER BY hostname " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $devices ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-07 13:52:46 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  table_from_entity_type ( $type ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // Fuck you, english pluralisation.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $type  ==  " storage " )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  $type ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  $type . " s " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-16 13:25:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-19 10:02:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_entity_by_id_cache ( $type ,  $id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    global  $entity_cache ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-16 13:25:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $table  =  table_from_entity_type ( $type ); 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-16 13:25:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( is_array ( $entity_cache [ $type ][ $id ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $entity  =  $entity_cache [ $type ][ $id ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $entity  =  dbFetchRow ( " SELECT * FROM ` " . $table . " ` WHERE ` " . $type . " _id` = ? " ,  array ( $id )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $entity_cache [ $type ][ $id ]  =  $entity ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $entity ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-16 13:25:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_port_by_id ( $port_id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( is_numeric ( $port_id ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $port  =  dbFetchRow ( " SELECT * FROM `ports` WHERE `port_id` = ? " ,  array ( $port_id )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( is_array ( $port ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  $port ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-19 10:02:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_application_by_id ( $application_id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( is_numeric ( $application_id ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $application  =  dbFetchRow ( " SELECT * FROM `applications` WHERE `app_id` = ? " ,  array ( $application_id )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( is_array ( $application ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  $application ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-22 19:28:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-01 14:17:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2010-07-28 19:43:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_sensor_by_id ( $sensor_id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( is_numeric ( $sensor_id ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $sensor  =  dbFetchRow ( " SELECT * FROM `sensors` WHERE `sensor_id` = ? " ,  array ( $sensor_id )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( is_array ( $sensor ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  $sensor ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-22 19:28:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-01 14:17:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_device_id_by_port_id ( $port_id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( is_numeric ( $port_id ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $device_id  =  dbFetchCell ( " SELECT `device_id` FROM `ports` WHERE `port_id` = ? " ,  array ( $port_id )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( is_numeric ( $device_id ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  $device_id ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-22 19:28:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-01 14:17:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_device_id_by_app_id ( $app_id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( is_numeric ( $app_id ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $device_id  =  dbFetchCell ( " SELECT `device_id` FROM `applications` WHERE `app_id` = ? " ,  array ( $app_id )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( is_numeric ( $device_id ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  $device_id ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-22 19:28:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2010-07-28 19:43:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  ifclass ( $ifOperStatus ,  $ifAdminStatus ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-07 16:24:53 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // fake a port model
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  \LibreNMS\Util\Url :: portLinkDisplayClass (( object )  [ 'ifOperStatus'  =>  $ifOperStatus ,  'ifAdminStatus'  =>  $ifAdminStatus ]); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  device_by_name ( $name ,  $refresh  =  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // FIXME - cache name > id too.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  device_by_id_cache ( getidbyname ( $name ),  $refresh ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-10-03 13:40:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2012-05-21 18:17:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  accesspoint_by_id ( $ap_id ,  $refresh  =  '0' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-21 18:17:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $ap  =  dbFetchRow ( " SELECT * FROM `access_points` WHERE `accesspoint_id` = ? " ,  array ( $ap_id )); 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-21 18:17:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  $ap ; 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-21 18:17:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-12-20 08:36:49 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  device_by_id_cache ( $device_id ,  $refresh  =  false ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    global  $cache ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-11 18:03:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( ! $refresh  &&  isset ( $cache [ 'devices' ][ 'id' ][ $device_id ])  &&  is_array ( $cache [ 'devices' ][ 'id' ][ $device_id ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $device  =  $cache [ 'devices' ][ 'id' ][ $device_id ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Refactored and update Location Geocoding (#9359)
- Fix location so it is a regular database relation (this allows multiple devices to be accurately linked to one location and saves api calls)
- Parse coordinates from the location more consistently
- Add settings to webui
- ~~Used [PHP Geocoder](http://geocoder-php.org/), which has lots of backends and is well tested. (also includes reverse and geoip)~~
- Google Maps, Bing, Mapquest, and OpenStreetMap supported initially.
- Default to OpenStreetMap, which doesn't require a key.  They will liberally hand out bans if you exceed 1 query per second though.
- All other Geocoding APIs require an API key. (Google requires a credit card on file, but seems to be the most accurate)
- Update all (I think) sql queries to handle the new structure
- Remove final vestiges of override_sysLocation as a device attribute
- Update existing device groups and rules in DB
- Tested all APIs with good/bad location, no/bad/good key, and no connection.
- Cannot fix advanced queries that use location
This blocks #8868
DO NOT DELETE THIS TEXT
#### Please note
> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.
- [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)
#### Testers
If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
After you are done testing, you can remove the changes with `./scripts/github-remove`.  If there are schema changes, you can ask on discord how to revert.
											 
										 
										
											2018-11-28 16:49:18 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $device  =  dbFetchRow ( " SELECT `devices`.*, `location`, `lat`, `lng` FROM `devices` LEFT JOIN locations ON `devices`.location_id=`locations`.`id` WHERE `device_id` = ? " ,  [ $device_id ]); 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-08 20:37:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $device [ 'attribs' ]  =  get_dev_attribs ( $device [ 'device_id' ]); 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-30 10:31:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        load_os ( $device ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-08 14:14:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        //order vrf_lite_cisco with context, this will help to get the vrf_name and instance_name all the time
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $vrfs_lite_cisco  =  dbFetchRows ( " SELECT * FROM `vrf_lite_cisco` WHERE `device_id` = ? " ,  array ( $device_id )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( ! empty ( $vrfs_lite_cisco ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $device [ 'vrf_lite_cisco' ]  =  array (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            foreach  ( $vrfs_lite_cisco  as  $vrf )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $device [ 'vrf_lite_cisco' ][ $vrf [ 'context_name' ]]  =  $vrf ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( ! empty ( $device [ 'ip' ]))  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-06 10:08:19 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $device [ 'ip' ]  =  inet6_ntop ( $device [ 'ip' ]); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $cache [ 'devices' ][ 'id' ][ $device_id ]  =  $device ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $device ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-04-20 15:46:17 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  truncate ( $substring ,  $max  =  50 ,  $rep  =  '...' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( strlen ( $substring )  <  1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $string  =  $rep ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $string  =  $substring ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $leave  =  $max  -  strlen ( $rep ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( strlen ( $string )  >  $max )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  substr_replace ( $string ,  $rep ,  $leave ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  $string ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2009-10-28 13:49:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  mres ( $string ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2018-08-17 15:29:20 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  $string ;  // FIXME bleh
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // short function wrapper because the real one is stupidly long and ugly. aesthetics.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-11 01:40:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    global  $database_link ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  mysqli_real_escape_string ( $database_link ,  $string ); 
							 
						 
					
						
							
								
									
										
										
										
											2009-06-19 10:43:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  getifhost ( $id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  dbFetchCell ( " SELECT `device_id` from `ports` WHERE `port_id` = ? " ,  array ( $id )); 
							 
						 
					
						
							
								
									
										
										
										
											2009-05-11 13:43:59 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  gethostbyid ( $id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    global  $cache ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-10-28 18:29:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( isset ( $cache [ 'devices' ][ 'id' ][ $id ][ 'hostname' ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $hostname  =  $cache [ 'devices' ][ 'id' ][ $id ][ 'hostname' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $hostname  =  dbFetchCell ( " SELECT `hostname` FROM `devices` WHERE `device_id` = ? " ,  array ( $id )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-10-28 18:29:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  $hostname ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-05-07 13:47:51 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  strgen ( $length  =  16 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $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  =  " " ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-11 18:03:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    for  ( $i = 0 ;  $i < $length ;  $i ++ )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $key  =  mt_rand ( 0 ,  61 ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $string  .=  $entropy [ $key ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-11 18:03:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  $string ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-05-07 13:47:51 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  getpeerhost ( $id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  dbFetchCell ( " SELECT `device_id` from `bgpPeers` WHERE `bgpPeer_id` = ? " ,  array ( $id )); 
							 
						 
					
						
							
								
									
										
										
										
											2009-05-07 13:47:51 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  getifindexbyid ( $id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  dbFetchCell ( " SELECT `ifIndex` FROM `ports` WHERE `port_id` = ? " ,  array ( $id )); 
							 
						 
					
						
							
								
									
										
										
										
											2009-05-07 13:47:51 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  getifbyid ( $id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  dbFetchRow ( " SELECT * FROM `ports` WHERE `port_id` = ? " ,  array ( $id )); 
							 
						 
					
						
							
								
									
										
										
										
											2010-01-08 23:09:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  getifdescrbyid ( $id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  dbFetchCell ( " SELECT `ifDescr` FROM `ports` WHERE `port_id` = ? " ,  array ( $id )); 
							 
						 
					
						
							
								
									
										
										
										
											2009-05-07 13:47:51 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  getidbyname ( $hostname ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    global  $cache ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-10-04 09:10:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( isset ( $cache [ 'devices' ][ 'hostname' ][ $hostname ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $id  =  $cache [ 'devices' ][ 'hostname' ][ $hostname ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $id  =  dbFetchCell ( " SELECT `device_id` FROM `devices` WHERE `hostname` = ? " ,  array ( $hostname )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-10-05 16:18:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  $id ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-05-07 13:47:51 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  gethostosbyid ( $id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    global  $cache ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-07 13:52:46 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( isset ( $cache [ 'devices' ][ 'id' ][ $id ][ 'os' ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $os  =  $cache [ 'devices' ][ 'id' ][ $id ][ 'os' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $os  =  dbFetchCell ( " SELECT `os` FROM `devices` WHERE `device_id` = ? " ,  array ( $id )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-10-04 09:10:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  $os ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-05-07 13:47:51 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  safename ( $name ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  preg_replace ( '/[^a-zA-Z0-9,._\-]/' ,  '_' ,  $name ); 
							 
						 
					
						
							
								
									
										
										
										
											2010-02-05 22:10:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2009-05-07 13:47:51 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-11-01 16:37:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Function  format  the  rrdtool  description  text  correctly . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  $descr 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  mixed 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-24 21:40:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  safedescr ( $descr ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-25 13:19:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  preg_replace ( '/[^a-zA-Z0-9,._\-\/\ ]/' ,  ' ' ,  $descr ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-24 21:40:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  zeropad ( $num ,  $length  =  2 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-08 14:14:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  str_pad ( $num ,  $length ,  '0' ,  STR_PAD_LEFT ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-28 20:29:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  set_dev_attrib ( $device ,  $attrib_type ,  $attrib_value ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( dbFetchCell ( " SELECT COUNT(*) FROM devices_attribs WHERE `device_id` = ? AND `attrib_type` = ? " ,  array ( $device [ 'device_id' ], $attrib_type )))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $return  =  dbUpdate ( array ( 'attrib_value'  =>  $attrib_value ),  'devices_attribs' ,  'device_id=? and attrib_type=?' ,  array ( $device [ 'device_id' ],  $attrib_type )); 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $return  =  dbInsert ( array ( 'device_id'  =>  $device [ 'device_id' ],  'attrib_type'  =>  $attrib_type ,  'attrib_value'  =>  $attrib_value ),  'devices_attribs' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $return ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-31 17:19:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_dev_attribs ( $device ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $attribs  =  array (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    foreach  ( dbFetchRows ( " SELECT * FROM devices_attribs WHERE `device_id` = ? " ,  array ( $device ))  as  $entry )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $attribs [ $entry [ 'attrib_type' ]]  =  $entry [ 'attrib_value' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $attribs ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-05-03 20:13:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_dev_entity_state ( $device ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $state  =  array (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    foreach  ( dbFetchRows ( " SELECT * FROM entPhysical_state WHERE `device_id` = ? " ,  array ( $device ))  as  $entity )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $state [ 'group' ][ $entity [ 'group' ]][ $entity [ 'entPhysicalIndex' ]][ $entity [ 'subindex' ]][ $entity [ 'key' ]]  =  $entity [ 'value' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $state [ 'index' ][ $entity [ 'entPhysicalIndex' ]][ $entity [ 'subindex' ]][ $entity [ 'group' ]][ $entity [ 'key' ]]  =  $entity [ 'value' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $state ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-11-14 18:28:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_dev_attrib ( $device ,  $attrib_type ,  $attrib_value  =  '' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-30 15:09:54 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $sql  =  '' ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-30 14:34:37 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $params  =  array ( $device [ 'device_id' ],  $attrib_type ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( ! empty ( $attrib_value ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $sql  =  "  AND `attrib_value`=? " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        array_push ( $params ,  $attrib_value ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $row  =  dbFetchRow ( " SELECT attrib_value FROM devices_attribs WHERE `device_id` = ? AND `attrib_type` = ?  $sql " ,  $params ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  $row [ 'attrib_value' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  null ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-31 17:19:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  is_dev_attrib_enabled ( $device ,  $attrib ,  $default  =  true ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-13 09:26:26 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $val  =  get_dev_attrib ( $device ,  $attrib ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-03 02:14:35 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $val  !=  null )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-13 09:26:26 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        // attribute is set
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  ( $val  !=  0 ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-13 09:26:26 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        // attribute not set
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  $default ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  del_dev_attrib ( $device ,  $attrib_type ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  dbDelete ( 'devices_attribs' ,  " `device_id` = ? AND `attrib_type` = ? " ,  array ( $device [ 'device_id' ],  $attrib_type )); 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-31 17:19:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-28 20:29:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  formatRates ( $value ,  $round  =  '2' ,  $sf  =  '3' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $value  =  format_si ( $value ,  $round ,  $sf )  .  " bps " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $value ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-04-05 13:29:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  formatStorage ( $value ,  $round  =  '2' ,  $sf  =  '3' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $value  =  format_bi ( $value ,  $round )  .  " B " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $value ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-04-05 13:29:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  format_si ( $value ,  $round  =  '2' ,  $sf  =  '3' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $neg  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $value  <  " 0 " )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $neg  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $value  =  $value  *  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-01 12:29:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $value  >=  " 0.1 " )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $sizes  =  array ( '' ,  'k' ,  'M' ,  'G' ,  'T' ,  'P' ,  'E' ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $ext  =  $sizes [ 0 ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        for  ( $i  =  1 ;  (( $i  <  count ( $sizes ))  &&  ( $value  >=  1000 ));  $i ++ )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $value  =  $value  /  1000 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $ext   =  $sizes [ $i ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-13 03:27:10 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $sizes  =  array ( '' ,  'm' ,  'u' ,  'n' ,  'p' ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $ext  =  $sizes [ 0 ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        for  ( $i  =  1 ;  (( $i  <  count ( $sizes ))  &&  ( $value  !=  0 )  &&  ( $value  <=  0.1 ));  $i ++ )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $value  =  $value  *  1000 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $ext   =  $sizes [ $i ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-04-05 13:29:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $neg  ==  1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $value  =  $value  *  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-01 12:29:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-12-21 02:50:36 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  ( number_format ( round ( $value ,  $round ),  $sf ,  '.' ,  '' ) + 0 ) . "   " . $ext ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-04-05 13:29:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  format_bi ( $value ,  $round  =  '2' ,  $sf  =  '3' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $value  <  " 0 " )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $neg  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $value  =  $value  *  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $sizes  =  array ( '' ,  'k' ,  'M' ,  'G' ,  'T' ,  'P' ,  'E' ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $ext  =  $sizes [ 0 ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    for  ( $i  =  1 ;  (( $i  <  count ( $sizes ))  &&  ( $value  >=  1024 ));  $i ++ )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $value  =  $value  /  1024 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $ext   =  $sizes [ $i ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-07 13:52:46 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $neg )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $value  =  $value  *  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-21 02:50:36 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  ( number_format ( round ( $value ,  $round ),  $sf ,  '.' ,  '' ) + 0 ) . "   " . $ext ; 
							 
						 
					
						
							
								
									
										
										
										
											2011-04-05 13:29:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  format_number ( $value ,  $base  =  '1000' ,  $round  =  2 ,  $sf  =  3 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $base  ==  '1000' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  format_si ( $value ,  $round ,  $sf ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  format_bi ( $value ,  $round ,  $sf ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2011-12-06 22:17:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  is_valid_hostname ( $hostname ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-25 15:30:58 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  \LibreNMS\Util\Validate :: hostname ( $hostname ); 
							 
						 
					
						
							
								
									
										
										
										
											2011-10-06 13:13:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-06-13 22:50:37 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  convenience  function  -  please  use  this  instead  of  'if ($debug) { echo ...; }' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-08 07:16:49 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								if  ( ! function_exists ( 'd_echo' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    //TODO remove this after installs have updated, leaving it for for transition
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    function  d_echo ( $text ,  $no_debug_text  =  null ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        global  $debug ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-03-12 23:59:03 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( Laravel :: isBooted ())  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-08 07:16:49 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            \Log :: debug ( is_string ( $text )  ?  rtrim ( $text )  :  $text ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        }  elseif  ( $debug )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            print_r ( $text ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2018-07-13 17:08:00 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-12-08 07:16:49 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( ! $debug  &&  $no_debug_text )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  " $no_debug_text " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-13 22:50:37 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-08 07:16:49 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-15 18:18:13 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-16 19:52:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Output  using  console  color  if  possible 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  https :// github . com / pear / Console_Color2 / blob / master / examples / documentation 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string  $string  the  string  to  print  with  console  color 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-17 16:00:43 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param  bool  $enabled  if  set  to  false ,  this  function  does  nothing 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-16 19:52:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-17 16:00:43 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  c_echo ( $string ,  $enabled  =  true ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-16 19:52:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( ! $enabled )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-17 16:00:43 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-16 19:52:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-17 13:02:28 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( isCli ())  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        global  $console_color ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $console_color )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  $console_color -> convert ( $string ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            // limited functionality for validate.php
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $search  =  array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                '/%n/' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                '/%g/' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                '/%R/' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                '/%Y/' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                '/%B/' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                '/%((%)|.)/'  // anything left over replace with empty string
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $replace  =  array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                " \ e[0m " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                " \ e[32m " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                " \ e[1;31m " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                " \ e[1;33m " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                " \ e[1;34m " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                " " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  preg_replace ( $search ,  $replace ,  $string ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-16 19:52:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        echo  preg_replace ( '/%((%)|.)/' ,  '' ,  $string ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-13 22:50:37 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  true  if  the  given  graph  type  is  a  dynamic  MIB  graph 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  is_mib_graph ( $type ,  $subtype ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-16 15:18:17 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  \LibreNMS\Util\Graph :: isMibGraph ( $type ,  $subtype ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-15 18:18:13 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}  // is_mib_graph
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-06-13 22:50:37 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  true  if  client  IP  address  is  authorized  to  access  graphs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  is_client_authorized ( $clientip ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-08 14:14:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( Config :: get ( 'allow_unauth_graphs' ,  false ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-13 22:50:37 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        d_echo ( " Unauthorized graphs allowed \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-08 14:14:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    foreach  ( Config :: get ( 'allow_unauth_graphs_cidr' ,  array ())  as  $range )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        try  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( IP :: parse ( $clientip ) -> inNetwork ( $range ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-13 22:50:37 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                d_echo ( " Unauthorized graphs allowed from  $range\n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-08 14:14:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  catch  ( InvalidIpException  $e )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            d_echo ( " Client IP ( $clientip ) is invalid. \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-13 22:50:37 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-15 18:18:13 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}  // is_client_authorized
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-06-13 22:50:37 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-06-13 22:55:18 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  an  array  of  all  graph  subtypes  for  the  given  type 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-17 15:00:15 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_graph_subtypes ( $type ,  $device  =  null ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-11 23:26:42 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $type  =  basename ( $type ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-13 22:55:18 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $types  =  array (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // find the subtypes defined in files
 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $handle  =  opendir ( Config :: get ( 'install_dir' )  .  " /includes/html/graphs/ $type / " ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-13 22:55:18 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        while  ( false  !==  ( $file  =  readdir ( $handle )))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( $file  !=  " . "  &&  $file  !=  " .. "  &&  $file  !=  " auth.inc.php "  &&  strstr ( $file ,  " .inc.php " ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $types []  =  str_replace ( " .inc.php " ,  " " ,  $file ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        closedir ( $handle ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-15 02:45:45 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $device  !=  null )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        // find the MIB subtypes
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $graphs  =  get_device_graphs ( $device ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        foreach  ( Config :: get ( 'graph_types' )  as  $type  =>  $unused1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            foreach  ( Config :: get ( " graph_types. $type " )  as  $subtype  =>  $unused2 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-22 05:03:21 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                if  ( is_mib_graph ( $type ,  $subtype )  &&  in_array ( $subtype ,  $graphs ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-15 02:45:45 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    $types []  =  $subtype ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-13 22:55:18 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    sort ( $types ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $types ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-15 18:18:13 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}  // get_graph_subtypes
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-15 02:45:45 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_device_graphs ( $device ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-17 15:00:15 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-15 02:45:45 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $query  =  'SELECT `graph` FROM `device_graphs` WHERE `device_id` = ?' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  dbFetchColumn ( $query ,  array ( $device [ 'device_id' ])); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-17 15:00:15 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_smokeping_files ( $device ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-16 16:01:51 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $smokeping_files  =  array (); 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( Config :: has ( 'smokeping.dir' ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-12 19:47:50 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $smokeping_dir  =  generate_smokeping_file ( $device ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-24 11:41:10 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( $handle  =  opendir ( $smokeping_dir ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            while  ( false  !==  ( $file  =  readdir ( $handle )))  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-16 16:01:51 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                if  ( $file  !=  '.'  &&  $file  !=  '..' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-24 01:05:14 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    if  ( stripos ( $file ,  '.rrd' )  !==  false )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        if  ( strpos ( $file ,  '~' )  !==  false )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-16 16:01:51 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                            list ( $target , $slave )  =  explode ( '~' ,  str_replace ( '.rrd' ,  '' ,  $file )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                            $target  =  str_replace ( '_' ,  '.' ,  $target ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-24 11:41:10 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                            $smokeping_files [ 'in' ][ $target ][ $slave ]  =  $file ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                            $smokeping_files [ 'out' ][ $slave ][ $target ]  =  $file ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-16 16:01:51 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                            $target  =  str_replace ( '.rrd' ,  '' ,  $file ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                            $target  =  str_replace ( '_' ,  '.' ,  $target ); 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                            $smokeping_files [ 'in' ][ $target ][ Config :: get ( 'own_hostname' )]  =  $file ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                            $smokeping_files [ 'out' ][ Config :: get ( 'own_hostname' )][ $target ]  =  $file ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-24 11:41:10 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $smokeping_files ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-23 17:51:24 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}  // end get_smokeping_files
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-10 16:10:35 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-15 18:18:13 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  generate_smokeping_file ( $device ,  $file  =  '' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( Config :: get ( 'smokeping.integration' )  ===  true )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  Config :: get ( 'smokeping.dir' )  .  '/'  .  $device [ 'type' ]  .  '/'  .  $file ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  Config :: get ( 'smokeping.dir' )  .  '/'  .  $file ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-10 16:10:35 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-15 18:18:13 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}  // generate_smokeping_file
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-10 16:10:35 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 17:08:09 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  rounded  value  to  10 th / 100 th / 1000 th  depending  on  input  ( valid :  10 ,  100 ,  1000 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  round_Nth ( $val ,  $round_to ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 17:08:09 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  (( $round_to  ==  " 10 " )  ||  ( $round_to  ==  " 100 " )  ||  ( $round_to  ==  " 1000 " ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $diff  =  $val  %  $round_to ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $diff  >=  ( $round_to  /  2 ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $ret  =  $val  +  ( $round_to - $diff ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $ret  =  $val  -  $diff ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  $ret ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}  // end round_Nth
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 17:08:09 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-15 18:18:13 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-01-07 09:38:32 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  true  if  this  device  should  be  polled  with  MIB - based  discovery 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  is_mib_poller_enabled ( $device ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-03 02:14:35 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $val  =  get_dev_attrib ( $device ,  'poll_mib' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $val  ==  null )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  Config :: get ( " poller_modules.mib " ,  false ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-07 09:38:32 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-03 02:14:35 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  $val ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-07 09:38:32 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}  // is_mib_poller_enabled
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-16 22:07:48 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  FIXME :  Dummy  implementation 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-01 08:14:23 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  count_mib_mempools ( $device ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-07 09:25:59 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( is_mib_poller_enabled ( $device )  &&  $device [ 'os' ]  ==  'ruckuswireless' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-01 08:14:23 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-15 18:18:13 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}  // count_mib_mempools
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-01 08:14:23 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-16 22:07:48 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  FIXME :  Dummy  implementation 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-01 08:14:23 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  count_mib_processors ( $device ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-07 09:25:59 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( is_mib_poller_enabled ( $device )  &&  $device [ 'os' ]  ==  'ruckuswireless' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-01 08:14:23 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-15 18:18:13 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}  // count_mib_processors
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-01 08:14:23 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  count_mib_health ( $device ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  count_mib_mempools ( $device )  +  count_mib_processors ( $device ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-15 18:18:13 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}  // count_mib_health
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-01 08:14:23 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-02 19:40:21 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_mibval ( $device ,  $oid ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $sql  =  'SELECT * FROM `device_oids` WHERE `device_id` = ? AND `oid` = ?' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  dbFetchRow ( $sql ,  array ( $device [ 'device_id' ],  $oid )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}  // get_mibval
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-01 08:14:23 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-02 19:40:21 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  FIXME :  Dummy  implementation  -  needs  an  abstraction  for  each  device 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  get_mib_mempools ( $device ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $mempools  =  array (); 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-07 09:25:59 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( is_mib_poller_enabled ( $device )  &&  $device [ 'os' ]  ==  'ruckuswireless' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-02 19:40:21 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $mempool  =  array (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $mibvals  =  get_mibval ( $device ,  '.1.3.6.1.4.1.25053.1.2.1.1.1.15.14.0' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $mempool [ 'mempool_descr' ]  =  $mibvals [ 'object_type' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $mempool [ 'mempool_id' ]  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $mempool [ 'mempool_total' ]  =  100 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $mempool [ 'mempool_used' ]  =  $mibvals [ 'numvalue' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $mempool [ 'mempool_free' ]  =  100  -  $mibvals [ 'numvalue' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $mempool [ 'percentage' ]  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $mempools []  =  $mempool ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $mempools ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}  // get_mib_mempools
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  FIXME :  Dummy  implementation  -  needs  an  abstraction  for  each  device 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  get_mib_processors ( $device ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $processors  =  array (); 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-07 09:25:59 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( is_mib_poller_enabled ( $device )  &&  $device [ 'os' ]  ==  'ruckuswireless' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-02 19:40:21 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $proc  =  array (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $mibvals  =  get_mibval ( $device ,  '.1.3.6.1.4.1.25053.1.2.1.1.1.15.13.0' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $proc [ 'processor_descr' ]  =  $mibvals [ 'object_type' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $proc [ 'processor_id' ]  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $proc [ 'processor_usage' ]  =  $mibvals [ 'numvalue' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $processors []  =  $proc ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $processors ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}  // get_mib_processors
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  FIXME :  Dummy  implementation  -  needs  an  abstraction  for  each  device 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-01 08:14:23 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ return  true  if  there  is  a  custom  graph  defined  for  this  type ,  subtype ,  and  device 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  is_custom_graph ( $type ,  $subtype ,  $device ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-07 09:25:59 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( is_mib_poller_enabled ( $device )  &&  $device [ 'os' ]  ==  'ruckuswireless'  &&  $type  ==  'device' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-01 08:14:23 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        switch  ( $subtype )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            case  'cpumem' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            case  'mempool' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            case  'processor' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-01 08:14:23 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-15 18:18:13 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}  // is_custom_graph
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-01 08:14:23 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-16 22:07:48 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  FIXME :  Dummy  implementation 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-01 08:14:23 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Set  section / graph  entries  in  $graph_enable  for  graphs  specific  to  $os . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  enable_os_graphs ( $os ,  & $graph_enable ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    /* 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    foreach  ( dbFetchRows ( " SELECT * FROM graph_conditions WHERE graph_type = 'device' AND condition_name = 'os' AND condition_value = ? " ,  array ( $os ))  as  $graph )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $graph_enable [ $graph [ 'graph_section' ]][ $graph [ 'graph_subtype' ]]  =  " device_ " . $graph [ 'graph_subtype' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    */ 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-15 18:18:13 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}  // enable_os_graphs
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-01 08:14:23 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  For  each  os - based  or  global  graph  relevant  to  $device ,  set  its  section / graph  entry  in  $graph_enable . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  enable_graphs ( $device ,  & $graph_enable ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-28 05:59:25 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // These are standard graphs we should have for (almost) all systems
 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-24 03:43:59 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $graph_enable [ 'poller' ][ 'poller_perf' ]          =  'device_poller_perf' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-28 05:59:25 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( ! $device [ 'snmp_disable' ])  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $graph_enable [ 'poller' ][ 'poller_modules_perf' ]  =  'device_poller_modules_perf' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( get_dev_attrib ( $device ,  " override_icmp_disable " )  !=  " true "  &&  can_ping_device ( $device )  ===  true )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-24 14:21:19 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $graph_enable [ 'poller' ][ 'ping_perf' ]  =  'device_ping_perf' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-01 08:14:23 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    enable_os_graphs ( $device [ 'os' ],  $graph_enable ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-15 18:18:13 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}  // enable_graphs
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-01 08:14:23 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-20 14:02:16 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								//
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// maintain a simple cache of objects
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								//
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  object_add_cache ( $section ,  $obj ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    global  $object_cache ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $object_cache [ $section ][ $obj ]  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-15 18:18:13 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}  // object_add_cache
 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-20 14:02:16 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  object_is_cached ( $section ,  $obj ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    global  $object_cache ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( array_key_exists ( $obj ,  $object_cache ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-06 18:07:51 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  $object_cache [ $section ][ $obj ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-20 14:02:16 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-15 18:18:13 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}  // object_is_cached
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-20 14:02:16 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-17 18:49:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Checks  if  config  allows  us  to  ping  this  device 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  $attribs  contains  an  array  of  all  of  this  devices 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  attributes 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  array  $attribs  Device  attributes 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  bool 
							 
						 
					
						
							
								
									
										
										
										
											2018-08-05 03:50:13 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 **/ 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  can_ping_device ( $attribs ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2018-07-17 02:16:13 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( Config :: get ( 'icmp_check' )  &&  ! ( isset ( $attribs [ 'override_icmp_disable' ])  &&  $attribs [ 'override_icmp_disable' ]  ==  " true " ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-17 18:49:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-17 18:49:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}  // end can_ping_device
 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 12:33:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-15 18:18:13 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-20 14:07:23 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  true  if  every  string  in  $arr  begins  with  $str 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  begins_with ( $str ,  $arr ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    foreach  ( $arr  as  $s )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $pos  =  strpos ( $s ,  $str ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $pos  ===  false  ||  $pos  >  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}  // begins_with
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-15 18:18:13 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-20 14:07:23 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  the  longest  starting  portion  of  $str  that  matches  everything  in  $arr 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  longest_matching_prefix ( $str ,  $arr ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $len  =  strlen ( $str ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    while  ( $len  >  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $prefix  =  substr ( $str ,  0 ,  $len ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( begins_with ( $prefix ,  $arr ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  $prefix ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $len  -=  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  '' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}  // longest_matching_prefix
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-15 18:18:13 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-06 18:07:51 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  search_phrase_column ( $c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    global  $searchPhrase ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  " $c  LIKE '% $searchPhrase %' " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}  // search_phrase_column
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  print_mib_poller_disabled () 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-07 09:25:59 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    echo  ' < h4 > MIB  polling  is  not  enabled </ h4 > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								< p > 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Set  \ ' poller_modules . mib\ '  in  your  config  or  enable  for  this  device  specifically  to  enable . 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-07 09:25:59 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								</ p > ' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}  // print_mib_poller_disabled
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 12:33:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Constructs  the  path  to  an  RRD  for  the  Ceph  application 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string  $gtype  The  type  of  rrd  we ' re  looking  for 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  string 
							 
						 
					
						
							
								
									
										
										
										
											2018-08-05 03:50:13 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 **/ 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  ceph_rrd ( $gtype ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 12:33:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    global  $device ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    global  $vars ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $gtype  ==  " osd " )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $var  =  $vars [ 'osd' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 12:33:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $var  =  $vars [ 'pool' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:33:43 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  rrd_name ( $device [ 'hostname' ],  array ( 'app' ,  'ceph' ,  $vars [ 'id' ],  $gtype ,  $var )); 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-15 18:18:13 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}  // ceph_rrd
 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-16 18:50:52 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Parse  location  field  for  coordinates 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string  location  The  location  field  to  look  for  coords  in . 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Refactored and update Location Geocoding (#9359)
- Fix location so it is a regular database relation (this allows multiple devices to be accurately linked to one location and saves api calls)
- Parse coordinates from the location more consistently
- Add settings to webui
- ~~Used [PHP Geocoder](http://geocoder-php.org/), which has lots of backends and is well tested. (also includes reverse and geoip)~~
- Google Maps, Bing, Mapquest, and OpenStreetMap supported initially.
- Default to OpenStreetMap, which doesn't require a key.  They will liberally hand out bans if you exceed 1 query per second though.
- All other Geocoding APIs require an API key. (Google requires a credit card on file, but seems to be the most accurate)
- Update all (I think) sql queries to handle the new structure
- Remove final vestiges of override_sysLocation as a device attribute
- Update existing device groups and rules in DB
- Tested all APIs with good/bad location, no/bad/good key, and no connection.
- Cannot fix advanced queries that use location
This blocks #8868
DO NOT DELETE THIS TEXT
#### Please note
> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.
- [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)
#### Testers
If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
After you are done testing, you can remove the changes with `./scripts/github-remove`.  If there are schema changes, you can ask on discord how to revert.
											 
										 
										
											2018-11-28 16:49:18 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ return  array | bool  Containing  the  lat  and  lng  coords 
							 
						 
					
						
							
								
									
										
										
										
											2018-08-05 03:50:13 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 **/ 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  parse_location ( $location ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Refactored and update Location Geocoding (#9359)
- Fix location so it is a regular database relation (this allows multiple devices to be accurately linked to one location and saves api calls)
- Parse coordinates from the location more consistently
- Add settings to webui
- ~~Used [PHP Geocoder](http://geocoder-php.org/), which has lots of backends and is well tested. (also includes reverse and geoip)~~
- Google Maps, Bing, Mapquest, and OpenStreetMap supported initially.
- Default to OpenStreetMap, which doesn't require a key.  They will liberally hand out bans if you exceed 1 query per second though.
- All other Geocoding APIs require an API key. (Google requires a credit card on file, but seems to be the most accurate)
- Update all (I think) sql queries to handle the new structure
- Remove final vestiges of override_sysLocation as a device attribute
- Update existing device groups and rules in DB
- Tested all APIs with good/bad location, no/bad/good key, and no connection.
- Cannot fix advanced queries that use location
This blocks #8868
DO NOT DELETE THIS TEXT
#### Please note
> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.
- [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)
#### Testers
If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
After you are done testing, you can remove the changes with `./scripts/github-remove`.  If there are schema changes, you can ask on discord how to revert.
											 
										 
										
											2018-11-28 16:49:18 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    preg_match ( '/\[(-?[0-9. ]+), *(-?[0-9. ]+)\]/' ,  $location ,  $tmp_loc ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( is_numeric ( $tmp_loc [ 1 ])  &&  is_numeric ( $tmp_loc [ 2 ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  [ 'lat'  =>  $tmp_loc [ 1 ],  'lng'  =>  $tmp_loc [ 2 ]]; 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-16 18:50:52 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Refactored and update Location Geocoding (#9359)
- Fix location so it is a regular database relation (this allows multiple devices to be accurately linked to one location and saves api calls)
- Parse coordinates from the location more consistently
- Add settings to webui
- ~~Used [PHP Geocoder](http://geocoder-php.org/), which has lots of backends and is well tested. (also includes reverse and geoip)~~
- Google Maps, Bing, Mapquest, and OpenStreetMap supported initially.
- Default to OpenStreetMap, which doesn't require a key.  They will liberally hand out bans if you exceed 1 query per second though.
- All other Geocoding APIs require an API key. (Google requires a credit card on file, but seems to be the most accurate)
- Update all (I think) sql queries to handle the new structure
- Remove final vestiges of override_sysLocation as a device attribute
- Update existing device groups and rules in DB
- Tested all APIs with good/bad location, no/bad/good key, and no connection.
- Cannot fix advanced queries that use location
This blocks #8868
DO NOT DELETE THIS TEXT
#### Please note
> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.
- [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)
#### Testers
If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
After you are done testing, you can remove the changes with `./scripts/github-remove`.  If there are schema changes, you can ask on discord how to revert.
											 
										 
										
											2018-11-28 16:49:18 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-16 18:50:52 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} //end parse_location()
 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-06 00:14:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Returns  version  info 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 01:56:09 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param  bool  $remote  fetch  remote  version  info  from  github 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-06 00:14:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ return  array 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 01:56:09 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  version_info ( $remote  =  false ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-22 06:47:07 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $version  =  \LibreNMS\Util\Version :: get (); 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-08 21:42:56 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $output  =  [ 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-22 06:47:07 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        'local_ver'  =>  $version -> local (), 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-08 21:42:56 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( Git :: repoPresent ()  &&  Git :: binaryExists ())  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( $remote  ===  true  &&  Config :: get ( 'update_channel' )  ==  'master' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 22:54:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $api  =  curl_init (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            set_curl_proxy ( $api ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            curl_setopt ( $api ,  CURLOPT_USERAGENT ,  'LibreNMS' ); 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            curl_setopt ( $api ,  CURLOPT_URL ,  Config :: get ( 'github_api' )  .  'commits/master' ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 22:54:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            curl_setopt ( $api ,  CURLOPT_RETURNTRANSFER ,  1 ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-03 14:12:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            curl_setopt ( $api ,  CURLOPT_TIMEOUT ,  5 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            curl_setopt ( $api ,  CURLOPT_TIMEOUT_MS ,  5000 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            curl_setopt ( $api ,  CURLOPT_CONNECTTIMEOUT ,  5 ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 22:54:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $output [ 'github' ]  =  json_decode ( curl_exec ( $api ),  true ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        list ( $local_sha ,  $local_date )  =  explode ( '|' ,  rtrim ( `git show --pretty='%H|%ct' -s HEAD` )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $output [ 'local_sha' ]     =  $local_sha ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $output [ 'local_date' ]    =  $local_date ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $output [ 'local_branch' ]  =  rtrim ( `git rev-parse --abbrev-ref HEAD` ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-22 06:47:07 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $output [ 'db_schema' ]    =  vsprintf ( '%s (%s)' ,  $version -> database ()); 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-06 00:14:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $output [ 'php_ver' ]      =  phpversion (); 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-17 13:02:28 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $output [ 'mysql_ver' ]    =  dbIsConnected ()  ?  dbFetchCell ( 'SELECT version()' )  :  '?' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $output [ 'rrdtool_ver' ]  =  str_replace ( '1.7.01.7.0' ,  '1.7.0' ,  implode ( ' ' ,  array_slice ( explode ( ' ' ,  shell_exec ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        Config :: get ( 'rrdtool' ,  'rrdtool' )  .  ' --version |head -n1' 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-17 13:02:28 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    )),  1 ,  1 ))); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $output [ 'netsnmp_ver' ]  =  str_replace ( 'version: ' ,  '' ,  rtrim ( shell_exec ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-02 16:52:55 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        Config :: get ( 'snmpget' ,  'snmpget' )  .  ' -V 2>&1' 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-17 13:02:28 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    ))); 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-06 00:14:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $output ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} //end version_info()
 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-17 23:59:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
									
										
										
										
											2018-08-05 03:50:13 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Convert  a  MySQL  binary  v4  ( 4 - byte )  or  v6  ( 16 - byte )  IP  address  to  a  printable  string . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string  $ip  A  binary  string  containing  an  IP  address ,  as  returned  from  MySQL ' s  INET6_ATON  function 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  string  Empty  if  not  valid . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-17 23:59:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// Fuction is from http://uk3.php.net/manual/en/function.inet-ntop.php
 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  inet6_ntop ( $ip ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-17 23:59:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $l  =  strlen ( $ip ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $l  ==  4  or  $l  ==  16 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  inet_ntop ( pack ( 'A'  .  $l ,  $ip )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  '' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-19 09:00:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-01-17 22:01:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-05 12:25:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  If  hostname  is  an  ip ,  use  return  sysName 
							 
						 
					
						
							
								
									
										
										
										
											2018-07-02 15:23:09 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param  array  $device  ( uses  hostname  and  sysName  fields ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-22 15:48:28 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param  string  $hostname 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-17 22:01:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ return  string 
							 
						 
					
						
							
								
									
										
										
										
											2018-07-02 15:23:09 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  format_hostname ( $device ,  $hostname  =  null ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-05 12:25:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( empty ( $hostname ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $hostname  =  $device [ 'hostname' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2018-07-02 15:23:09 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( Config :: get ( 'force_hostname_to_sysname' )  &&  ! empty ( $device [ 'sysName' ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( is_valid_hostname ( $hostname )  &&  ! IP :: isValid ( $hostname ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  $device [ 'sysName' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-17 22:01:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2018-07-02 15:23:09 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( Config :: get ( 'force_ip_to_sysname' )  &&  ! empty ( $device [ 'sysName' ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( IP :: isValid ( $hostname ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  $device [ 'sysName' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2018-06-23 22:59:09 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2018-07-02 15:23:09 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-05-05 12:25:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  $hostname ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-07-02 15:23:09 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-26 13:49:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Return  valid  port  association  modes 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  array 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-10 14:40:45 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_port_assoc_modes () 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2018-08-05 03:50:13 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        1  =>  'ifIndex' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        2  =>  'ifName' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        3  =>  'ifDescr' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        4  =>  'ifAlias' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-26 13:49:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Get  DB  id  of  given  port  association  mode  name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string  $port_assoc_mode 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-10 14:40:45 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ return  int 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-26 13:49:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-10 14:40:45 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_port_assoc_mode_id ( $port_assoc_mode ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2018-08-05 03:50:13 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $modes  =  array_flip ( get_port_assoc_modes ()); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  isset ( $modes [ $port_assoc_mode ])  ?  $modes [ $port_assoc_mode ]  :  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-26 13:49:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Get  name  of  given  port  association_mode  ID 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  int  $port_assoc_mode_id  Port  association  mode  ID 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-10 14:40:45 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_port_assoc_mode_name ( $port_assoc_mode_id ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2018-08-05 03:50:13 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $modes  =  get_port_assoc_modes (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  isset ( $modes [ $port_assoc_mode_id ])  ?  $modes [ $port_assoc_mode_id ]  :  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-26 13:49:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Query  all  ports  of  the  given  device  ( by  ID )  and  build  port  array  and 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  port  association  maps  for  ifIndex ,  ifName ,  ifDescr .  Query  port  stats 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  if  told  to  do  so ,  too . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  int  $device_id  ID  of  device  to  query  ports  for 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  bool  $with_statistics  Query  port  statistics ,  too .  ( optional ,  default  false ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  array 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_ports_mapped ( $device_id ,  $with_statistics  =  false ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-30 10:05:46 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $ports  =  array (); 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-30 10:10:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $maps  =  array ( 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-30 10:05:46 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        'ifIndex'  =>  array (), 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        'ifName'   =>  array (), 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        'ifDescr'  =>  array (), 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-26 13:49:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $with_statistics )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        /* ... including any related ports_statistics if requested */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $query  =  'SELECT *, `ports_statistics`.`port_id` AS `ports_statistics_port_id`, `ports`.`port_id` AS `port_id` FROM `ports` LEFT OUTER JOIN `ports_statistics` ON `ports`.`port_id` = `ports_statistics`.`port_id` WHERE `ports`.`device_id` = ? ORDER BY ports.port_id' ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-15 02:03:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        /* Query all information available for ports for this device ... */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $query  =  'SELECT * FROM `ports` WHERE `device_id` = ? ORDER BY port_id' ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-26 13:49:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // Query known ports in order of discovery to make sure the latest
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // discoverd/polled port is in the mapping tables.
 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    foreach  ( dbFetchRows ( $query ,  array  ( $device_id ))  as  $port )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-26 13:49:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        // Store port information by ports port_id from DB
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $ports [ $port [ 'port_id' ]]  =  $port ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        // Build maps from ifIndex, ifName, ifDescr to port_id
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $maps [ 'ifIndex' ][ $port [ 'ifIndex' ]]  =  $port [ 'port_id' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $maps [ 'ifName' ][ $port [ 'ifName' ]]    =  $port [ 'port_id' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $maps [ 'ifDescr' ][ $port [ 'ifDescr' ]]  =  $port [ 'port_id' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-01-30 10:05:46 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  array ( 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-26 13:49:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        'ports'  =>  $ports , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        'maps'   =>  $maps , 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-30 10:05:46 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-26 13:49:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Calculate  port_id  of  given  port  using  given  devices  port  information  and  port  association  mode 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  array  $ports_mapped  Port  information  of  device  queried  by  get_ports_mapped () 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  array  $port  Port  information  as  fetched  from  DB 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string  $port_association_mode  Port  association  mode  to  use  for  mapping 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  int  port_id  ( or  Null ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  get_port_id ( $ports_mapped ,  $port ,  $port_association_mode ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-26 13:49:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // Get port_id according to port_association_mode used for this device
 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $port_id  =  null ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-26 13:49:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    /* 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  Information  an  all  ports  is  available  through  $ports_mapped [ 'ports' ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  This  might  come  in  handy  sometime  in  the  future  to  add  you  nifty  new 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  port  mapping  schema : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  $ports  =  $ports_mapped [ 'ports' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $maps   =  $ports_mapped [ 'maps' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( in_array ( $port_association_mode ,  array  ( 'ifIndex' ,  'ifName' ,  'ifDescr' ,  'ifAlias' )))  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-26 13:49:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $port_id  =  $maps [ $port_association_mode ][ $port [ $port_association_mode ]]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $port_id ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-22 08:42:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Create  a  glue - chain 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  array  $tables  Initial  Tables  to  construct  glue - chain 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string  $target  Glue  to  find  ( usual  device_id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  int  $x  Recursion  Anchor 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  array  $hist  History  of  processed  tables 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  array  $last  Glues  on  the  fringe 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-02 17:03:36 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ return  array | false 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-22 08:42:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  ResolveGlues ( $tables ,  $target ,  $x  =  0 ,  $hist  =  array (),  $last  =  array ()) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( sizeof ( $tables )  ==  1  &&  $x  !=  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( dbFetchCell ( 'SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME = ?' ,  array ( $tables [ 0 ], $target ))  ==  1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  array_merge ( $last ,  array ( $tables [ 0 ] . '.' . $target )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-22 08:42:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-22 08:42:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $x ++ ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( $x  >  30 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-22 08:42:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            //Too much recursion. Abort.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        foreach  ( $tables  as  $table )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-02 17:03:36 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            if  ( $table  ==  'state_translations'  &&  ( $target  ==  'device_id'  ||  $target  ==  'sensor_id' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                // workaround for state_translations
 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-06 16:13:10 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                return  array_merge ( $last ,  array ( 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-02 17:03:36 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    'state_translations.state_index_id' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'sensors_to_state_indexes.sensor_id' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    " sensors. $target " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-06 16:13:10 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                )); 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Refactored and update Location Geocoding (#9359)
- Fix location so it is a regular database relation (this allows multiple devices to be accurately linked to one location and saves api calls)
- Parse coordinates from the location more consistently
- Add settings to webui
- ~~Used [PHP Geocoder](http://geocoder-php.org/), which has lots of backends and is well tested. (also includes reverse and geoip)~~
- Google Maps, Bing, Mapquest, and OpenStreetMap supported initially.
- Default to OpenStreetMap, which doesn't require a key.  They will liberally hand out bans if you exceed 1 query per second though.
- All other Geocoding APIs require an API key. (Google requires a credit card on file, but seems to be the most accurate)
- Update all (I think) sql queries to handle the new structure
- Remove final vestiges of override_sysLocation as a device attribute
- Update existing device groups and rules in DB
- Tested all APIs with good/bad location, no/bad/good key, and no connection.
- Cannot fix advanced queries that use location
This blocks #8868
DO NOT DELETE THIS TEXT
#### Please note
> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.
- [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)
#### Testers
If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
After you are done testing, you can remove the changes with `./scripts/github-remove`.  If there are schema changes, you can ask on discord how to revert.
											 
										 
										
											2018-11-28 16:49:18 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            }  elseif  ( $table  ==  'application_metrics'  &&  $target  ==  'device_id' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-06 16:13:10 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                return  array_merge ( $last ,  array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'application_metrics.app_id' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    " applications. $target " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                )); 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Refactored and update Location Geocoding (#9359)
- Fix location so it is a regular database relation (this allows multiple devices to be accurately linked to one location and saves api calls)
- Parse coordinates from the location more consistently
- Add settings to webui
- ~~Used [PHP Geocoder](http://geocoder-php.org/), which has lots of backends and is well tested. (also includes reverse and geoip)~~
- Google Maps, Bing, Mapquest, and OpenStreetMap supported initially.
- Default to OpenStreetMap, which doesn't require a key.  They will liberally hand out bans if you exceed 1 query per second though.
- All other Geocoding APIs require an API key. (Google requires a credit card on file, but seems to be the most accurate)
- Update all (I think) sql queries to handle the new structure
- Remove final vestiges of override_sysLocation as a device attribute
- Update existing device groups and rules in DB
- Tested all APIs with good/bad location, no/bad/good key, and no connection.
- Cannot fix advanced queries that use location
This blocks #8868
DO NOT DELETE THIS TEXT
#### Please note
> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.
- [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)
#### Testers
If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
After you are done testing, you can remove the changes with `./scripts/github-remove`.  If there are schema changes, you can ask on discord how to revert.
											 
										 
										
											2018-11-28 16:49:18 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            }  elseif  ( $table  ==  'locations'  &&  $target  ==  'device_id' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                return  array_merge ( $last ,  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'locations.id' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    'devices.device_id.location_id' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                ]); 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-02 17:03:36 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $glues  =  dbFetchRows ( 'SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME LIKE "%\_id"' ,  array ( $table )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( sizeof ( $glues )  ==  1  &&  $glues [ 0 ][ 'COLUMN_NAME' ]  !=  $target )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-22 08:42:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                //Search for new candidates to expand
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $ntables  =  array (); 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                list ( $tmp )  =  explode ( '_' ,  $glues [ 0 ][ 'COLUMN_NAME' ],  2 ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-22 08:42:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                $ntables []  =  $tmp ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $ntables []  =  $tmp . 's' ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                $tmp  =  dbFetchRows ( 'SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_NAME LIKE "' . substr ( $table ,  0 ,  - 1 ) . '_%" && TABLE_NAME != "' . $table . '"' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                foreach  ( $tmp  as  $expand )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-22 08:42:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    $ntables []  =  $expand [ 'TABLE_NAME' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                $tmp  =  ResolveGlues ( $ntables ,  $target ,  $x ++ ,  array_merge ( $tables ,  $ntables ),  array_merge ( $last ,  array ( $table . '.' . $glues [ 0 ][ 'COLUMN_NAME' ]))); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                if  ( is_array ( $tmp ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-22 08:42:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    return  $tmp ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                foreach  ( $glues  as  $glue )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    if  ( $glue [ 'COLUMN_NAME' ]  ==  $target )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        return  array_merge ( $last ,  array ( $table . '.' . $target )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        list ( $tmp )  =  explode ( '_' ,  $glue [ 'COLUMN_NAME' ]); 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-22 08:42:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        $tmp  .=  's' ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        if  ( ! in_array ( $tmp ,  $tables )  &&  ! in_array ( $tmp ,  $hist ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-22 08:42:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                            //Expand table
 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-28 12:32:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                            $tmp  =  ResolveGlues ( array ( $tmp ),  $target ,  $x ++ ,  array_merge ( $tables ,  array ( $tmp )),  array_merge ( $last ,  array ( $table . '.' . $glue [ 'COLUMN_NAME' ]))); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                            if  ( is_array ( $tmp ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-22 08:42:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                                return  $tmp ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    //You should never get here.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-29 15:58:21 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								if  ( ! function_exists ( 'str_contains' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    /** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  Determine  if  a  given  string  contains  a  given  substring . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  @ param   string  $haystack 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  @ param   string | array  $needles 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  @ return  bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    function  str_contains ( $haystack ,  $needles ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        foreach  (( array ) $needles  as  $needle )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-31 00:11:04 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            if  ( $needle  !=  ''  &&  strpos ( $haystack ,  $needle )  !==  false )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-19 14:57:08 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-29 15:58:21 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-19 14:57:08 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-29 15:58:21 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Determine  if  a  given  string  contains  a  given  substring . 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-19 14:57:08 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param   string  $haystack 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param   string | array  $needles 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-29 15:58:21 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  str_i_contains ( $haystack ,  $needles ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-19 14:57:08 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-29 15:58:21 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    foreach  (( array ) $needles  as  $needle )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $needle  !=  ''  &&  stripos ( $haystack ,  $needle )  !==  false )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-19 14:57:08 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-01-29 15:58:21 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								if  ( ! function_exists ( 'ends_with' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    /** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  Determine  if  a  given  string  ends  with  a  given  substring . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  @ param   string  $haystack 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  @ param   string | array  $needles 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  @ return  bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    function  ends_with ( $haystack ,  $needles ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-31 00:11:04 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        foreach  (( array ) $needles  as  $needle )  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-29 15:58:21 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            if  (( string ) $needle  ===  substr ( $haystack ,  - strlen ( $needle )))  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-31 00:11:04 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-29 15:58:21 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								if  ( ! function_exists ( 'starts_with' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    /** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  Determine  if  a  given  string  starts  with  a  given  substring . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  @ param   string  $haystack 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  @ param   string | array  $needles 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     *  @ return  bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    function  starts_with ( $haystack ,  $needles ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-31 00:11:04 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        foreach  (( array ) $needles  as  $needle )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            if  ( $needle  !=  ''  &&  strpos ( $haystack ,  $needle )  ===  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-19 14:57:08 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2018-01-29 15:58:21 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-19 14:57:08 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 22:45:51 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-11-23 11:41:13 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Print  a  list  of  items  up  to  a  max  amount 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  If  over  that  number ,  a  line  will  print  the  total  items 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  array  $list 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string  $format  format  as  consumed  by  printf () 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  int  $max  the  max  amount  of  items  to  print ,  default  10 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  print_list ( $list ,  $format ,  $max  =  10 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-02 08:04:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( is_array ( current ( $list )))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $list  =  array_map ( function  ( $item )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  implode ( ' ' ,  $item ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        },  $list ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-11-23 11:41:13 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    foreach  ( array_slice ( $list ,  0 ,  $max )  as  $item )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        printf ( $format ,  $item ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $extra  =  count ( $list )  -  $max ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $extra  >  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        printf ( $format ,  "  and  $extra  more... " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-15 20:45:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  $value 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-25 15:51:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param  bool  $strip_tags 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-15 20:45:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ return  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-25 15:51:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  clean ( $value ,  $strip_tags  =  true ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-15 20:45:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-25 15:51:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $strip_tags  ===  true )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  strip_tags ( mres ( $value )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  mres ( $value ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-15 20:45:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  $value 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-04 08:08:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param  array  $purifier_config  ( key ,  value  pair ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-15 20:45:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ return  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-16 15:18:17 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  display ( $value ,  $purifier_config  =  []) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-29 09:39:17 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  \LibreNMS\Util\Clean :: html ( $value ,  $purifier_config ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-15 20:45:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-23 17:53:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-09 02:16:09 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Load  the  os  definition  for  the  device  and  set  type  and  os_group 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  $device [ 'os' ]  must  be  set 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  array  $device 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-23 17:53:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-09 02:16:09 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  load_os ( & $device ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-23 17:53:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-09 02:16:09 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( ! isset ( $device [ 'os' ]))  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-28 10:37:41 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        d_echo ( " No OS to load \n " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( ! Config :: get ( " os. { $device [ 'os' ] } .definition_loaded " ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-30 14:53:43 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $tmp_os  =  Symfony\Component\Yaml\Yaml :: parse ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            file_get_contents ( Config :: get ( 'install_dir' )  .  '/includes/definitions/'  .  $device [ 'os' ]  .  '.yaml' ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-30 14:53:43 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-09 02:16:09 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        Config :: set ( " os. { $device [ 'os' ] } " ,  array_replace_recursive ( $tmp_os ,  Config :: get ( " os. { $device [ 'os' ] } " ,  []))); 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-17 22:26:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-09 02:16:09 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // Set type to a predefined type for the OS if it's not already set
 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $loaded_os_type  =  Config :: get ( " os. { $device [ 'os' ] } .type " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  (( ! isset ( $device [ 'attribs' ][ 'override_device_type' ])  &&  $device [ 'attribs' ][ 'override_device_type' ]  !=  1 )  &&  $loaded_os_type  !=  $device [ 'type' ])  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        log_event ( 'Device type changed '  .  $device [ 'type' ]  .  ' => '  .  $loaded_os_type ,  $device ,  'system' ,  3 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $device [ 'type' ]  =  $loaded_os_type ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        dbUpdate ([ 'type'  =>  $loaded_os_type ],  'devices' ,  'device_id=?' ,  [ $device [ 'device_id' ]]); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        d_echo ( " Device type changed to  $loaded_os_type ! \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-09 02:16:09 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $os_group  =  Config :: get ( " os. { $device [ 'os' ] } .group " ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $device [ 'os_group' ]  =  $os_group ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-22 15:48:28 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        unset ( $device [ 'os_group' ]); 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-23 17:53:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-28 10:37:41 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    Config :: set ( " os. { $device [ 'os' ] } .definition_loaded " ,  true ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-23 17:53:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-03 20:04:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 02:57:10 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Load  all  OS ,  optionally  load  just  the  OS  used  by  existing  devices 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Default  cache  time  is  1  day .  Controlled  by  os_def_cache_time . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  bool  $existing  Only  load  OS  that  have  existing  OS  in  the  database 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  bool  $cached  Load  os  definitions  from  the  cache  file 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-03 20:04:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 02:57:10 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  load_all_os ( $existing  =  false ,  $cached  =  true ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-23 17:53:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $install_dir  =  Config :: get ( 'install_dir' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $cache_file  =  $install_dir  .  '/cache/os_defs.cache' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 02:57:10 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $cached  &&  is_file ( $cache_file )  &&  ( time ()  -  filemtime ( $cache_file )  <  Config :: get ( 'os_def_cache_time' )))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 02:57:10 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        // Cached
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $os_defs  =  unserialize ( file_get_contents ( $cache_file )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $existing )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            // remove unneeded os
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $os_defs  =  array_diff_key ( $os_defs ,  dbFetchColumn ( 'SELECT DISTINCT(`os`) FROM `devices`' )); 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-03 09:52:53 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        Config :: set ( 'os' ,  array_replace_recursive ( $os_defs ,  Config :: get ( 'os' ))); 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 02:57:10 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        // load from yaml
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( $existing )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $os_list  =  array_map ( function  ( $os )  use  ( $install_dir )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                return  $install_dir  .  '/includes/definitions/'  .  $os  .  '.yaml' ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 02:57:10 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            },  dbFetchColumn ( 'SELECT DISTINCT(`os`) FROM `devices`' )); 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-17 22:26:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $os_list  =  glob ( $install_dir  .  '/includes/definitions/*.yaml' ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-17 22:26:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 02:57:10 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        foreach  ( $os_list  as  $file )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-06 14:24:39 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            if  ( is_readable ( $file ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $tmp  =  Symfony\Component\Yaml\Yaml :: parse ( file_get_contents ( $file )); 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 02:57:10 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                Config :: set ( " os. { $tmp [ 'os' ] } " ,  array_replace_recursive ( $tmp ,  Config :: get ( " os. { $tmp [ 'os' ] } " ,  []))); 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 02:57:10 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 19:58:10 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  *  Update  the  OS  cache  file  cache / os_defs . cache 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  bool  $force 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-03 16:10:24 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ return  bool  true  if  the  cache  was  updated 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 02:57:10 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 19:58:10 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  update_os_cache ( $force  =  false ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 02:57:10 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-27 15:03:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    $install_dir  =  Config :: get ( 'install_dir' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $cache_file  =  " $install_dir /cache/os_defs.cache " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $cache_keep_time  =  Config :: get ( 'os_def_cache_time' ,  86400 )  -  7200 ;  // 2hr buffer
 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 02:57:10 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 19:58:10 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( $force  ===  true  ||  ! is_file ( $cache_file )  ||  time ()  -  filemtime ( $cache_file )  >  $cache_keep_time )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 02:57:10 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        d_echo ( 'Updating os_def.cache... ' ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-27 15:03:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        // remove previously cached os settings and replace with user settings
 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $config  =  [ 'os'  =>  []];  // local $config variable, not global
 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-27 15:03:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        include  " $install_dir /config.php " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        Config :: set ( 'os' ,  $config [ 'os' ]); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        // load the os defs fresh from cache (merges with existing OS settings)
 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 02:57:10 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        load_all_os ( false ,  false ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-27 15:03:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        file_put_contents ( $cache_file ,  serialize ( Config :: get ( 'os' ))); 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 02:57:10 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        d_echo ( " Done \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-03 16:10:24 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-23 17:53:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-03 16:10:24 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-23 17:53:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-13 12:47:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-28 12:57:23 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Converts  fahrenheit  to  celsius  ( with  2  decimal  places ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  if  $scale  is  not  fahrenheit ,  it  assumes  celsius  and   returns  the  value 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  float  $value 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string  $scale  fahrenheit  or  celsius 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  string  ( containing  a  float ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-18 08:48:33 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-28 12:57:23 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  fahrenheit_to_celsius ( $value ,  $scale  =  'fahrenheit' ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-18 08:48:33 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $scale  ===  'fahrenheit' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $value  =  ( $value  -  32 )  /  1.8 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  sprintf ( '%.02f' ,  $value ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-19 20:22:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-19 17:00:11 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Converts  uW  to  dBm 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  $value  must  be  positive 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-19 16:42:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  uw_to_dbm ( $value ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  10  *  log10 ( $value  /  1000 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-19 17:00:11 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-18 08:48:33 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  $value 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  null  $default 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  int  $min 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  null 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-08 04:15:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								function  set_null ( $value ,  $default  =  null ,  $min  =  null ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-18 08:48:33 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2018-07-13 17:08:00 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( ! is_numeric ( $value ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-07 14:49:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  $default ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-07-13 17:08:00 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  elseif  ( is_nan ( $value ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-07 14:49:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  $default ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-07-13 17:08:00 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  elseif  ( is_infinite ( $value ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-08 04:15:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  $default ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    }  elseif  ( isset ( $min )  &&  $value  <  $min )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  $default ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-18 08:48:33 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-13 12:47:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param  $value 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  int  $default 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  set_numeric ( $value ,  $default  =  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2018-07-13 17:08:00 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( ! is_numeric ( $value )  || 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        is_nan ( $value )  || 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        is_infinite ( $value ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-07 14:49:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-13 12:47:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $value  =  $default ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-26 22:38:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  get_vm_parent_id ( $device ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( empty ( $device [ 'hostname' ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 00:29:12 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    return  dbFetchCell ( " SELECT `device_id` FROM `vminfo` WHERE `vmwVmDisplayName` = ? OR `vmwVmDisplayName` = ? " ,  [ $device [ 'hostname' ],  $device [ 'hostname' ]  .  '.'  .  Config :: get ( 'mydomain' )]); 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-26 22:38:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-05 03:25:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 16:18:00 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Fetch  a  user  preference  from  the  database 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Do  not  use  strict  comparison  as  results  could  be  strings 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string  $name  preference  name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  mixed  $default  value  to  return  if  the  preference  is  not  set 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  int  $user_id  for  this  user_id  otherwise ,  the  currently  logged  in  user 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  mixed  value  of  this  preference 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  get_user_pref ( $name ,  $default  =  null ,  $user_id  =  null ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    global  $user_prefs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 02:57:10 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( is_array ( $user_prefs )  &&  array_key_exists ( $name ,  $user_prefs ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 16:18:00 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return  $user_prefs [ $name ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( is_null ( $user_id ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-11 07:51:35 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $user_id  =  LegacyAuth :: id (); 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 16:18:00 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $pref  =  dbFetchCell ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        'SELECT `value` FROM `users_prefs` WHERE `user_id`=? AND `pref`=?' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        array ( $user_id ,  $name ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( ! is_null ( $pref ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $pref  =  json_decode ( $pref ,  true ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $user_prefs [ $name ]  =  $pref ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  $pref ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $default ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Set  a  user  preference  value 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string  $name  preference  name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  mixed  $value  value  of  this  preference 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  int  $user_id  for  this  user_id  otherwise ,  the  currently  logged  in  user 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  bool  whether  the  setting  was  changed  or  not 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  set_user_pref ( $name ,  $value ,  $user_id  =  null ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    global  $user_prefs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( is_null ( $user_id ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-11 07:51:35 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $user_id  =  LegacyAuth :: id (); 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-01 16:18:00 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $pref  =  array ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        'user_id'  =>  $user_id , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        'pref'  =>  $name , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        'value'  =>  json_encode ( $value ), 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( dbFetchCell ( 'SELECT count(*) FROM `users_prefs` WHERE `user_id`=? AND `pref`=?' ,  array ( $user_id ,  $name )))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $update  =  array ( 'value'  =>  json_encode ( $value )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $params  =  array ( $user_id ,  $name ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $result  =  dbUpdate ( $update ,  'users_prefs' ,  '`user_id`=? AND `pref`=?' ,  $params )  >  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $result  =  dbInsert ( $pref ,  'users_prefs' )  !==  null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( $result )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $user_prefs [ $name ]  =  $value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												feature: Wireless Sensors Overhaul  (#6471)
* feature: Wireless Sensors
Includes client counts for ios and unifi
Graphing could use some improvement.
Alerting and threshold ui not implemented
WIP: starting OO based wireless sensors.
Class based functionality working
remove old functional files
add schema file
discovery needs to be enabled, not polling
fix up schema
fix Unifi discovery not returning an array
Add some debug when discovering a sensor.
Fix style.
Add missing semicolin
Add a null object (Generic) for OS.
Fill out some phpdocs
Re-organized code
Each sensor type now has it's own discovery and polling interface
Custom polling tested with Unifi CCQ
Left to do:
Implement UI (Graphs and Custom thresholds)
Alerting
Testing
Fix event message text
Remove runDiscovery and runPolling from OS, they are unused and don't belong there.
Cleanups/docs
Missed this file.
Remove the requirement to fetch the current value to check validity.
Do that automatically if current is not specified
A few cleanups here and there
First pass at graphing.
device_ and wireless_ graphs added.
Add RouterOS support
Singleton OS instance isn't required right now.
Remove that to allow some memory to be freed.
Add wireless to the device list metrics.
Make all metrics clickable
Tweak graphs a bit
Implement limit configuration page.
Use sensors page as common code instead of duplicating.
Clean up some javascript interactions:  Allow enter on values to save. Cancel if update is not needed. Enable the clear custom button after setting a custom value.
Add some wireless alert rules to the library.
Add documentation.
Add unifi client counts by ssid in addition to radio.
Optimize Sensor polling a bit.
Add HP MSM clients support (for full controller)
Fix function accessibility
Formalize the discovery and poller interfaces.
Add Xirrus clients and noise floor
move module interfaces to a more appropriate place.
push caching code up to os, unsure about this do to the limitations
No point in selectively enabling wireless discovery.  We only discover if the device supports something.
Add RSSI, Power, and Rate.
Add these sensors for Ubnt Airos.
Clean up some copyrights.
Reduce the amount of files need to add new types.
Leave graph files for consistency and to allow customization.
Remove the old wifi clients graph completely.
ciscowlc should have improved counts (total and per-ssid)
Schema didn't get added.
Impelement the rest of the AirOS sensors
Reformat and re-organize the Airos.php class.
Add several UBNT AirFiber sensors
A few fixes add links to the section headers
Add HP MSM mibs.
* Schema file got dropped in rebase.
* Add wireless menu to view sensors across all devices.
Icons in the menu need help :/
* Add HeliOS, Mimosa, and Siklu support
Sensors added SNR + Noise
* Add power and utilization to Unifi
* Update polling to prefetch all sensor data in a few snmp requests as possible
* Add Extendair: tx+rx power, aggregate rate, frequency
* Add a check for duplicate sensors in discovery.  Just print an error for now.
* Add Bit Error Ratio (named error-ratio to allow for bit error rate to be added if needed)
Fix an incorrect link in the wireless sensors table
* Add error rate and change all bps and Hz to use si units
* Fixes to limits and frequency display
* Fix overview graph frequency display
A few decimal place tweaks
* Don't allow switching sensor and wireless-sensor graphs, it doesn't work.
Change individual distance graphs to use si units
* Go through the OS and make sure I got all the sensors I can (probably missed some still)
Because pollWirelessChannelAsFrequency() is generic and a little complex, so pull it up to OS.
Message to help developers adding supports that don't return an array from discover functions.
* Fix some issues
* Remove noise and signal for now at least
A couple more fixes
Add a notification
* Oopsie
* Bonus AirFiber sensors
											 
										 
										
											2017-05-01 23:49:11 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Generate  a  class  name  from  a  lowercase  string  containing  -  or  _ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Remove  -  and  _  and  camel  case  words 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string  $name  The  string  to  convert  to  a  class  name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string  $namespace  namespace  to  prepend  to  the  name  for  example :  LibreNMS\ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  string   Class  name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  str_to_class ( $name ,  $namespace  =  null ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $pre_format  =  str_replace ( array ( '-' ,  '_' ),  ' ' ,  $name ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $class  =  str_replace ( ' ' ,  '' ,  ucwords ( strtolower ( $pre_format ))); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  $namespace  .  $class ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-23 02:29:10 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Checks  file  permissions  against  a  minimum  permissions  mask . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  This  only  check  that  bits  are  enabled ,  not  disabled . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  The  mask  is  in  the  same  format  as  posix  permissions .  For  example ,  600  means  user  read  and  write . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string  $file  the  name  of  the  file  to  check 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  $mask 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  check_file_permissions ( $file ,  $mask ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $perms  =  fileperms ( $file ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    $mask  =  octdec ( $mask ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  ( $perms  &  $mask )  ===  $mask ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-01 01:53:26 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Index  an  array  by  a  column 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  array  $array 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  string | int  $column 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  array 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  array_by_column ( $array ,  $column ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  array_combine ( array_column ( $array ,  $column ),  $array ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}