2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								#!/usr/bin/php
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< ? php  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  LibreNMS 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  Copyright  ( c )  2014  Neil  Lathwood  < https :// github . com / laf /  http :// www . lathwood . co . uk / fa > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  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 . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$options  =  getopt ( 'm:h::' );  
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( isset ( $options [ 'h' ]))  {  
						 
					
						
							
								
									
										
										
										
											2015-08-06 19:02:05 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    echo   
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        " \n  Validate setup tool
 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    Usage :  ./ validate . php  [ - m  < module > ]  [ - h ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        - h  This  help  section . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        - m  Any  sub  modules  you  want  to  run ,  comma  separated : 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-24 07:39:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								          -  mail :  this  will  test  your  email  settings   ( uses  default_mail  option  even  if  default_only  is  not  set ) . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          -  dist - poller :  this  will  test  for  the  install  running  as  a  distributed  poller . 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-01 23:29:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								          -  rrdcheck :  this  will  check  to  see  if  your  rrd  files  are  corrupt 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Example :  ./ validate . php  - m  mail . 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        " 
 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-06 19:02:05 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    exit ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								if  ( strstr ( `php -ln config.php` ,  'No syntax errors detected' ))  {  
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    $first_line  =  `head -n1 config.php` ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    $last_lines  =  explode ( PHP_EOL ,  `tail -n2 config.php` ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-01 12:47:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( substr ( $first_line ,  0 ,  5 )  !==  '<?php' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        print_fail ( " config.php doesn't start with a <?php - please fix this ( $first_line ) " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    else  if  ( $last_lines [ 0 ]  ==  '?>'  &&  $last_lines [ 1 ]  ==  '' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        print_fail ( 'config.php contains a new line at the end, please remove any whitespace at the end of the file and also remove ?>' ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    else  if  ( $last_lines [ 1 ]  ==  '?>' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 10:18:16 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        print_warn ( " It looks like you have ?> at the end of config.php, it is suggested you remove this " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								else  {  
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    print_fail ( 'Syntax error in config.php' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-10 23:02:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Check we are running this as the root user
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								$username  =  getenv ( 'USERNAME' )  ? :  getenv ( 'USER' ); //http://php.net/manual/en/function.get-current-user.php
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( $username  !==  'root' )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    print_fail ( " You need to run this script as root " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// load config.php now
  
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								require_once  'includes/defaults.inc.php' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								require_once  'config.php' ;  
						 
					
						
							
								
									
										
										
										
											2016-04-29 12:53:02 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// make sure install_dir is set correctly, or the next includes will fail
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if ( ! file_exists ( $config [ 'install_dir' ] . '/config.php' ))  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    print_fail ( '$config[\'install_dir\'] is not set correctly.  It should probably be set to: '  .  getcwd ()); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    exit ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// continue loading includes
  
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								require_once  'includes/definitions.inc.php' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								require_once  'includes/functions.php' ;  
						 
					
						
							
								
									
										
										
										
											2016-01-06 00:14:35 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								require_once  'includes/common.php' ;  
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								require_once  $config [ 'install_dir' ] . '/includes/alerts.inc.php' ;  
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-01-06 00:14:35 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$versions  =  version_info ();  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								echo  " Version info: \n " ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								$cur_sha  =  $versions [ 'local_sha' ];  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( $config [ 'update_channel' ]  ==  'master'  &&  $cur_sha  !=  $versions [ 'github' ][ 'sha' ])  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    print_warn ( " Your install is out of date:  $cur_sha " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								else  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    echo  " Commit SHA:  $cur_sha\n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2016-04-29 12:53:02 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								if ( $versions [ 'local_branch' ]  !=  'master' )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    print_warn ( " Your local git branch is not master, this will prevent automatic updates. " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2016-07-01 12:47:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-01 16:16:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// check for modified files
  
						 
					
						
							
								
									
										
										
										
											2016-07-01 12:47:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$modifiedcmd  =  'git diff --name-only --exit-code' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if ( $username  ===  'root' )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $modifiedcmd  =  'su ' . $config [ 'user' ] . ' -c "' . $modifiedcmd . '"' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2016-07-01 16:16:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								exec ( $modifiedcmd ,  $cmdoutput ,  $code );  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if ( $code  !==  0 )  {  
						 
					
						
							
								
									
										
										
										
											2016-04-29 12:53:02 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    print_warn ( " Your local git contains modified files, this could prevent automatic updates. \n Modified files: " ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-01 12:47:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    echo ( implode ( " \n " ,  $cmdoutput )  .  " \n " ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-29 12:53:02 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-01-06 00:14:35 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								echo  " DB Schema:  " . $versions [ 'db_schema' ] . " \n " ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								echo  " PHP:  " . $versions [ 'php_ver' ] . " \n " ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								echo  " MySQL:  " . $versions [ 'mysql_ver' ] . " \n " ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								echo  " RRDTool:  " . $versions [ 'rrdtool_ver' ] . " \n " ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								echo  " SNMP:  " . $versions [ 'netsnmp_ver' ] . " \n " ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-10 23:02:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Check php modules we use to make sure they are loaded
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								$extensions  =  array ( 'pcre' , 'curl' , 'session' , 'snmp' , 'mcrypt' );  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								foreach  ( $extensions  as  $extension )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( extension_loaded ( $extension )  ===  false )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $missing_extensions []  =  $extension ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( ! empty ( $missing_extensions ))  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    print_fail ( " We couldn't find the following php extensions, please ensure they are installed: " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    foreach  ( $missing_extensions  as  $extension )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        echo  " $extension\n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( class_exists ( 'Net_IPv4' )  ===  false )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    print_fail ( " It doesn't look like Net_IPv4 is installed " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( class_exists ( 'Net_IPv6' )  ===  false )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    print_fail ( " It doesn't look like Net_IPv6 is installed " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-09-21 21:06:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Let's test the user configured if we have it
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( isset ( $config [ 'user' ]))  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $tmp_user  =  $config [ 'user' ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $tmp_dir  =  $config [ 'install_dir' ]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-25 23:17:02 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    $find_result  =  rtrim ( `find $tmp_dir \! -user $tmp_user` ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-21 21:06:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( ! empty ( $find_result ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // This isn't just the log directory, let's print the list to the user
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $files  =  explode ( PHP_EOL ,  $find_result ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( is_array ( $files ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-23 15:13:43 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            print_fail ( " We have found some files that are owned by a different user than  $tmp_user , this will stop you updating automatically and / or rrd files being updated causing graphs to fail: \n If you don't run a bespoke install then you can fix this by running `chown -R  $tmp_user : $tmp_user   " . $config [ 'install_dir' ] . " ` " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-21 21:06:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            foreach  ( $files  as  $file )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                echo  " $file\n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            echo  " \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2015-12-10 23:02:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								else  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    print_warn ( 'You don\'t have $config["user"] set, this most likely needs to be set to librenms' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2015-09-21 21:06:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// Run test on MySQL
  
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$test_db  =  @ mysqli_connect ( $config [ 'db_host' ],  $config [ 'db_user' ],  $config [ 'db_pass' ],  $config [ 'db_name' ]);  
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								if  ( mysqli_connect_error ())  {  
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    print_fail ( 'Error connecting to your database ' . mysqli_connect_error ()); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								else  {  
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    print_ok ( 'Database connection successful' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-06 19:02:05 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Test for MySQL Strict mode
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								$strict_mode  =  dbFetchCell ( " SELECT @@global.sql_mode " );  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if ( strstr ( $strict_mode ,  'STRICT_TRANS_TABLES' ))  {  
						 
					
						
							
								
									
										
										
										
											2016-07-06 14:47:07 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    print_fail ( 'You have MySQL STRICT_TRANS_TABLES enabled, please disable this until full support has been added: https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html' ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-06 19:02:05 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-05-02 21:41:36 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$tz  =  ini_get ( 'date.timezone' );  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( empty ( $tz ))  {  
						 
					
						
							
								
									
										
										
										
											2016-04-26 13:08:21 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    print_fail ( 'You have no timezone set for php: http://php.net/manual/en/datetime.configuration.php#ini.date.timezone' ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-19 10:20:56 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// Test transports
  
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								if  ( $config [ 'alerts' ][ 'email' ][ 'enable' ]  ===  true )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    print_warn ( 'You have the old alerting system enabled - this is to be deprecated on the 1st of June 2015: https://groups.google.com/forum/#!topic/librenms-project/1llxos4m0p4' ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-05-24 21:41:42 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Test rrdcached
  
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								if  ( ! $config [ 'rrdcached' ])  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $rrd_dir  =  stat ( $config [ 'rrd_dir' ]); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( $rrd_dir [ 4 ]  ==  0  ||  $rrd_dir [ 5 ]  ==  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        print_warn ( 'Your RRD directory is owned by root, please consider changing over to user a non-root user' ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    if  ( substr ( sprintf ( '%o' ,  fileperms ( $config [ 'rrd_dir' ])),  - 3 )  !=  775 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        print_warn ( 'Your RRD directory is not set to 0775, please check our installation instructions' ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-11 21:26:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								if  ( isset ( $config [ 'rrdcached' ]))  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    check_rrdcached (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-05-24 21:41:42 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Disk space and permission checks
  
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								if  ( substr ( sprintf ( '%o' ,  fileperms ( $config [ 'temp_dir' ])),  - 3 )  !=  777 )  {  
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    print_warn ( 'Your tmp directory (' . $config [ 'temp_dir' ] . " ) is not set to 777 so graphs most likely won't be generated " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$space_check  =  ( disk_free_space ( $config [ 'install_dir' ])  /  1024  /  1024 );  
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								if  ( $space_check  <  512  &&  $space_check  >  1 )  {  
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    print_warn ( 'Disk space where ' . $config [ 'install_dir' ] . ' is located is less than 512Mb' ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								if  ( $space_check  <  1 )  {  
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    print_fail ( 'Disk space where ' . $config [ 'install_dir' ] . ' is located is empty!!!' ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-05-24 21:41:42 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Check programs
  
						 
					
						
							
								
									
										
										
										
											2016-02-11 21:26:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$bins  =  array ( 'fping' , 'rrdtool' , 'snmpwalk' , 'snmpget' , 'snmpbulkwalk' );  
						 
					
						
							
								
									
										
										
										
											2015-05-24 21:41:42 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								foreach  ( $bins  as  $bin )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( ! is_file ( $config [ $bin ]))  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-27 09:35:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        print_fail ( " $bin  location is incorrect or bin not installed " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-11 21:26:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								$disabled_functions  =  explode ( ',' ,  ini_get ( 'disable_functions' ));  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								$required_functions  =  array ( 'exec' , 'passthru' , 'shell_exec' , 'escapeshellarg' , 'escapeshellcmd' , 'proc_close' , 'proc_open' , 'popen' );  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								foreach  ( $required_functions  as  $function )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( in_array ( $function ,  $disabled_functions ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        print_fail ( " $function  is disabled in php.ini " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( ! function_exists ( 'openssl_random_pseudo_bytes' ))  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    print_warn ( " openssl_random_pseudo_bytes is not being used for user password hashing. This is a recommended function (https://secure.php.net/openssl_random_pseudo_bytes) " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( ! is_readable ( '/dev/urandom' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        print_warn ( " It also looks like we can't use /dev/urandom for user password hashing. We will fall back to generating our own hash - be warned " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-24 21:41:42 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Modules test
  
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$modules  =  explode ( ',' ,  $options [ 'm' ]);  
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								foreach  ( $modules  as  $module )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    switch  ( $module )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    case  'mail' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( $config [ 'alert' ][ 'transports' ][ 'mail' ]  ===  true )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $run_test  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( empty ( $config [ 'alert' ][ 'default_mail' ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print_fail ( 'default_mail config option needs to be specified to test email' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                $run_test  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else  if  ( $config [ 'email_backend' ]  ==  'sendmail' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 10:18:16 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                if  ( empty ( $config [ 'email_sendmail_path' ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    print_fail ( " You have selected sendmail but not configured email_sendmail_path " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    $run_test  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                elseif  ( ! file_exists ( $config [ 'email_sendmail_path' ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    print_fail ( " The configured email_sendmail_path is not valid " ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    $run_test  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else  if  ( $config [ 'email_backend' ]  ==  'smtp' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( empty ( $config [ 'email_smtp_host' ]))  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 10:18:16 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    print_fail ( 'You have selected SMTP but not configured an SMTP host' ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                    $run_test  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                if  ( empty ( $config [ 'email_smtp_port' ]))  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 10:18:16 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    print_fail ( 'You have selected SMTP but not configured an SMTP port' ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    $run_test  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  (( $config [ 'email_smtp_auth' ]  ===  true )  &&  ( empty ( $config [ 'email_smtp_username' ])  ||  empty ( $config [ 'email_smtp_password' ])))  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 10:18:16 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    print_fail ( 'You have selected SMTP auth but have not configured both username and password' ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    $run_test  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } //end if
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( $run_test  ==  1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( $err  =  send_mail ( $config [ 'alert' ][ 'default_mail' ],  'Test email' ,  'Testing email from NMS' ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    print_ok ( 'Email has been sent' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    print_fail ( 'Issue sending email to ' . $config [ 'alert' ][ 'default_mail' ] . ' with error ' . $err ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } //end if
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        break ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-24 07:39:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    case  'dist-poller' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( $config [ 'distributed_poller' ]  !==  true )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print_fail ( 'You have not enabled distributed_poller' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( empty ( $config [ 'distributed_poller_memcached_host' ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print_fail ( 'You have not configured $config[\'distributed_poller_memcached_host\']' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            elseif  ( empty ( $config [ 'distributed_poller_memcached_port' ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print_fail ( 'You have not configured $config[\'distributed_poller_memcached_port\']' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-24 07:52:28 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                $connection  =  @ fsockopen ( $config [ 'distributed_poller_memcached_host' ],  $config [ 'distributed_poller_memcached_port' ]); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( ! is_resource ( $connection ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-24 07:39:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    print_fail ( 'We could not get memcached stats, it is possible that we cannot connect to your memcached server, please check' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-24 07:52:28 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    fclose ( $connection ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    print_ok ( 'Connection to memcached is ok' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-24 07:39:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( empty ( $config [ 'rrdcached' ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print_fail ( 'You have not configured $config[\'rrdcached\']' );  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            elseif  ( empty ( $config [ 'rrd_dir' ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print_fail ( 'You have not configured $config[\'rrd_dir\']' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-11 21:26:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                check_rrdcached (); 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-24 07:39:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-01 23:29:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  'rrdcheck' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-01 23:46:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        // Loop through the rrd_dir
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $rrd_directory  =  new  RecursiveDirectoryIterator ( $config [ 'rrd_dir' ]); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // Filter out any non rrd files
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $rrd_directory_filter  =  new  RRDRecursiveFilterIterator ( $rrd_directory ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $rrd_iterator  =  new  RecursiveIteratorIterator ( $rrd_directory_filter ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $rrd_total  =  iterator_count ( $rrd_iterator ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $rrd_iterator -> rewind ();  // Rewind iterator in case iterator_count left iterator in unknown state
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        echo  " \n Scanning  " . $rrd_total . "  rrd files in  " . $config [ 'rrd_dir' ] . " ... \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // Count loops so we can push status to the user
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $loopcount  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-01 23:29:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        $screenpad  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-01 23:46:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        foreach  ( $rrd_iterator  as  $filename  =>  $file )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-01 23:29:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-01 23:46:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                $rrd_test_result  =  rrdtest ( $filename ,  $output ,  $error ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-01 23:29:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-01 23:46:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                $loopcount ++ ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  (( $loopcount  %  50 )  ==  0  )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        //This lets us update the previous status update without spamming in most consoles
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        echo  " \033 [ " . $screenpad . " D " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        $test_status  =  'Status: ' . $loopcount . '/' . $rrd_total ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        echo  $test_status ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        $screenpad  =  strlen ( $test_status ); 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-01 23:29:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-01 23:46:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                // A non zero result means there was some kind of error
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( $rrd_test_result  >  0 )   { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        echo  " \033 [ " . $screenpad . " D " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        print_fail ( 'Error parsing "' . $filename . '" RRD ' . trim ( $error )); 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-01 23:29:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        $screenpad  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-01 23:46:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        echo  " \033 [ " . $screenpad . " D " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        echo  " Status:  " . $loopcount . " / " . $rrd_total . "  - Complete \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-01 23:29:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-24 07:39:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        break ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } //end switch
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} //end foreach
  
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// End
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								function  print_ok ( $msg )  {  
						 
					
						
							
								
									
										
										
										
											2015-08-06 19:02:05 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    echo  " [OK]       $msg\n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} //end print_ok()
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function  print_fail ( $msg )  {  
						 
					
						
							
								
									
										
										
										
											2015-08-06 19:02:05 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    echo  " [FAIL]     $msg\n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} //end print_fail()
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-05-22 16:35:38 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function  print_warn ( $msg )  {  
						 
					
						
							
								
									
										
										
										
											2015-08-06 19:02:05 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    echo  " [WARN]     $msg\n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-13 20:10:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} //end print_warn()
  
						 
					
						
							
								
									
										
										
										
											2016-02-11 21:26:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function  check_rrdcached ()  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    global  $config ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    list ( $host , $port )  =  explode ( ':' , $config [ 'rrdcached' ]); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( $host  ==  'unix' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // Using socket, check that file exists
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! file_exists ( $port ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print_fail ( " $port  doesn't appear to exist, rrdcached test failed " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $connection  =  @ fsockopen ( $host ,  $port ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( is_resource ( $connection ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            fclose ( $connection ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print_fail ( 'Cannot connect to rrdcached instance' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} //end check_rrdcached