Location: PHPKode > projects > DebWeb GUI > debwgui/ccheck.php
<?php 
require('config.php');
include('includes/boxes.inc');
include('classes/validator.php');
$configcheck = new Validator();

// function to check binary files
function check_file($file, $title) {
  global $SUDO;
  global $configcheck;
  // remove SUDO location and all spaces
	$fileexist = str_replace("$SUDO", "",$file);
  $fileexist = str_replace(" ", "",$fileexist);

	if(file_exists($fileexist)) {
    $result = "<td>$fileexist exists</td>".
              "<td align=\"center\"><img src=\"images/y.gif\" alt=\"PASSED\"></td>";
  } else {
    $result = "<td bgcolor=\"#FFD9D1\">$fileexist does not exist (Check the configuration file config.php)</td>".
              "<td align=\"center\"><img src=\"images/x.gif\" alt=\"FAILED\"></td>";
    $configcheck->addError("binary file $fileexist does not exist");
  }

  print "<tr>";
  print "<td align=\"center\">$title</td>";
  print "$result";
  print "</tr>";
}

// function to check directories
function check_dir($dir, $title) {
  global $configcheck;
  if(file_exists($dir) && is_dir($dir)) {
    $result = "<td>directory $dir exists</td>".
              "<td align=\"center\"><img src=\"images/y.gif\" alt=\"PASSED\"></td>";
  } else {
    $result = "<td bgcolor=\"#FFD9D1\">directory $dir does not exist (Check the configuration file config.php)</td>".
              "<td align=\"center\"><img src=\"images/x.gif\" alt=\"FAILED\"></td>";
    $configcheck->addError("directory $dir does not exist");
  }
  print "<tr>";
  print "<td align=\"center\">$title</td>";
  print "$result";
  print "</tr>";
}

// function to check sudo
function check_sudo() {
  global $SUDO;
  global $settings;
  global $configcheck;
	if($settings['USE_SUDO']) {
  // remove spaces
  $FSUDO = str_replace(" ", "",$SUDO);
  if(file_exists($FSUDO)) {
    exec("$SUDO -l",$rresult,$errorlevel);
      if($errorlevel == '0') {
        $working = "and is working properly";
        $image = "<td align=\"center\"><img src=\"images/y.gif\" alt=\"PASSED\"></td>";
      } else {
        $working = "but is not working correctly, check your sudoers file (or read the FAQ/REAME files)";
        $image = "<td align=\"center\"><img src=\"images/x.gif\" alt=\"FAILED\"></td>";
	$configcheck->addError("sudo binary exists, but is not working properly");
      }
    $result = "<td>$SUDO exists $working</td>".
              "$image";
  } else {
    $result = "<td bgcolor=\"#FFD9D1\">$SUDO does not exist, correct your config file or install it by \"apt-get install sudo\"</td>".
              "<td align=\"center\"><img src=\"images/x.gif\" alt=\"FAILED\"></td>";
    $configcheck->addError("sudo binary $SUDO does not exist");
  }

  print "<tr>";
  print "<td align=\"center\">Sudo Status</td>";
  print "$result";
  print "</tr>";

} else {
  	  	print "<td align=\"center\"></td>".
			  "<td>SUDO is disabled in the config file and will not be checked</td>".
			  "<td align=\"center\"></td>".
			  "</tr>";
}
}

// function to check mrtg (only checks default locations installed by apt-get) (needs some improvement)
function check_mrtg() {
	global $configcheck;
	global $settings;
	if ($settings['USE_MRTG']) {
		if(file_exists($settings['MRTG_BIN'])) {
	  		print "<tr>".
				  "<td align=\"center\">installed MRTG</td>".
				  "<td>MRTG is installed</td>".
				  "<td align=\"center\"><img src=\"images/y.gif\" alt=\"PASSED\"></td>".
				  "</tr>";
			$cron = file_get_contents('/etc/cron.d/mrtg');
			// replace regexp with config.php directive of site
			$cron = preg_match('@hide@address.com',$cron,$cron);

			if($cron != '0') {
		  		print "<tr>".
					  "<td align=\"center\">MRTG cron job</td>".
					  "<td>A cron job for MRTG is configured</td>".
					  "<td align=\"center\"><img src=\"images/y.gif\" alt=\"PASSED\"></td>".
					  "</tr>";
			} else {
	  			print "<tr>".
					  "<td align=\"center\">MRTG cron job</td>".
					  "<td bgcolor=\"#FFD9D1\">A cron job for MRTG is not configured</td>".
					  "<td align=\"center\"><img src=\"images/x.gif\" alt=\"FAILED\"></td>".
					  "</tr>";
					$configcheck->addError('Missing MRTG cron job');
			}

		} else {
		  		print "<tr>".
					  "<td align=\"center\">installed MRTG</td>".
					  "<td bgcolor=\"#FFD9D1\">MRTG is not installed (install with apt-get install mrtg)</td>".
					  "<td align=\"center\"><img src=\"images/x.gif\" alt=\"FAILED\"></td>".
					  "</tr>";
					$configcheck->addError('MRTG is not installed');
		}

	} else {
	  	print "<td align=\"center\"></td>".
			  "<td>MRTG is disabled in the config file and will not be checked</td>".
			  "<td align=\"center\"></td>".
			  "</tr>";
	}
}

function check_miscsettings() {
	global $settings;
	global $configcheck;
	// checking hostname || IP
	if($settings['HOSTNAME'] == $_SERVER['SERVER_ADDR'] or $settings['HOSTNAME'] == $_SERVER['SERVER_NAME']) {
        	print "<tr>".
                      "<td align=\"center\">Hostname/IP</td>".
                      "<td>Hostname/IP adress is correct</td>".
                      "<td align=\"center\"><img src=\"images/y.gif\" alt=\"PASSED\"></td>".
                      "</tr>";
	} else {
                print "<tr>".
                      "<td align=\"center\">Hostname/IP</td>".
                      "<td bgcolor=\"#FFD9D1\">hostname/ip entry in config file is not correct, you will not be able to login. (correct this in your config.php file)</td>".
                      "<td align=\"center\"><img src=\"images/x.gif\" alt=\"FAILED\"></td>".
                      "</tr>";
                      $configcheck->addError('hostname/ip entry in config file is not correct');
	}

}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<title>Configuration check</title>
<link href="css/debwebgui.css" rel="stylesheet" type="text/css">
</head>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<center>
<!--check start-->
<table width="640" border="0">
  <tr>
    <td bgcolor="#CCCCCC" align="center" width="30%" >Checking sudo</td>
    <td bgcolor="#CCCCCC" align="center" width="60%">Information</td>
    <td bgcolor="#CCCCCC" align="center" width="10%">Status</td>
  </tr>
<?php check_sudo(); ?>
</table><br>
<table width="640" border="0">
  <tr>
    <td bgcolor="#CCCCCC" align="center" width="30%" >Checking MRTG</td>
    <td bgcolor="#CCCCCC" align="center" width="60%">Information</td>
    <td bgcolor="#CCCCCC" align="center" width="10%">Status</td>
  </tr>
<?php check_mrtg(); ?>
</table><br>
<table width="640" border="0">
  <tr>
    <td bgcolor="#CCCCCC" align="center" width="30%" >Checking binary files</td>
    <td bgcolor="#CCCCCC" align="center" width="60%">Information</td>
    <td bgcolor="#CCCCCC" align="center" width="10%">Status</td>
  </tr>
<?
check_file($CMD_PS,"ps Binary");
check_file($CMD_LS,"ls Binary");
check_file($CMD_CAT,"cat Binary");
check_file($CMD_GREP,"grep Binary");
check_file($CMD_UPDATERCD,"update-rc.d Binary");
check_file($CMD_SYSCTL,"sysctl Binary");
check_file($CMD_UPTIME,"uptime Binary");
check_file($CMD_VMSTAT,"vmstat Binary");
?>
</table><br>
<table width="640" border="0">
  <tr>
    <td bgcolor="#CCCCCC" align="center" width="30%" >Checking directories</td>
    <td bgcolor="#CCCCCC" align="center" width="60%">Information</td>
    <td bgcolor="#CCCCCC" align="center" width="10%">Status</td>
  </tr>
<?php
check_dir($DIR_INITD,"init.d Directory");
check_dir($DIR_PIDFILES,"pid Directory");
?>
</table><br>
<table width="640" border="0">
  <tr>
    <td bgcolor="#CCCCCC" align="center" width="30%" >Checking misc config entries</td>
    <td bgcolor="#CCCCCC" align="center" width="60%">Information</td>
    <td bgcolor="#CCCCCC" align="center" width="10%">Status</td>
  </tr>
<?php
check_miscsettings();
?>
</table><br>
<!-- check end -->
<!-- summary -->
<br>
<?php 
if ($configcheck->foundErrors()) {
	$configcheck->showErrors('Configuration check summary, the following errors occured:',"640");
} else {
successbox("Configuration check summary","Configuration check passed","640");
}
?>
</center>
</body>
</html>
Return current item: DebWeb GUI