Location: PHPKode > projects > Epiware Document Management > Epiware_4.8.6/epi/verify.php
<?
/******************************************************************************
Epiware: Project and Document Management
http://www.epiware.com
Copyright (C) 2006 James Kern

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 2
of the License, or (at your option) any later version. 

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. 

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Epiware, Inc. and Praxis Inc, hereby disclaims all copyright
interest in the program 'Epiware' written
by James Kern, Edward Kline, Ryan Gilfether, Ray Gorospe, Patrick Waddingham

06 September 2006
James Kern, President of Epiware 
Jack Chapman, President of Praxis
*****************************************************************************/ 
  define("TEMP_FONT","arial,verdana.helvetica");
  print_header();
 

   

 
	check_for_config_file(  $title, $message, $status,  $path,  $file);
	if($status){
	$final_location  =  $path . $file;
	  require("$final_location");
     define("CONFIG_FILE",$final_location);    
	}
	display_status($title,$message,$status);
	// If I have the config file then continue.
   if($status){ 
       check_for_db_connection(  $title, $message, $status);    
       display_status($title,$message,$status);

       check_for_write_permission(  $title, $message,  $status);    
       display_status($title,$message,$status);

       //check_for_php_upload( & $title,& $message, & $status);    
       //display_status($title,$message,$status)		
   	}





//----------------------------------------------------
//----------------------------------------------------
//
//   All functions are declare below.
// 
//----------------------------------------------------
//----------------------------------------------------



function check_for_php_upload( & $title,& $message, & $status){
     $message="";
 	  $title="Verifying PHP upload parameters set in file php.ini";
	  $status=false;

	   
					 
	  if(ini_get("file_uploads")){
	     $status=true;
		  $message = "Success, the parameter \"<I>file_uploads</i>\" in the <B>php.ini</b> file 
		    has been set to enable document uploads.
		  ";
		  // OK lets grab the parameter that limit the upload
		  // size and time..
		  $upload_max_filesize = ini_get("upload_max_filesize");
		  $post_max_size = ini_get("post_max_size");
		  $max_execution_time = ini_get("max_execution_time"); 
		  $upload_tmp_dir = ini_get("upload_tmp_dir");


		  $message .= " <BR><BR>
		  Your file uploads will be limited in size by the following
		  variables that are set in the <B>php.ini</b> file. Your
		  current values are as follows
		  
		  <BR><BR>
		<I>
        upload_max_filesize= <B>$upload_max_filesize</b> <BR>
		  post_max_size= <B>$post_max_size </b><BR>
		  max_execution_time= <B>$max_execution_time </b><BR>
		</i><BR>
		 <b>Suggestion:</B><BR>
		  Set <i><B>upload_max_filesize</b></i>  and <I><B>post_max_size</b></i>
		  to the same size. These  parameters will directly limit
		  the maximun file size that can be uploaded. <BR>
		  Set <i><B>max_execution_time</b></i> to something like 1500 seconds.
		  If it is too small the connection will timeout before the file is uploaded.
		  <BR><BR>
		  Also pay attention to the following variable<BR><BR>
		  <I>
		  upload_tmp_dir=<b>$upload_tmp_dir </b></i>
		  <BR><BR>
        This is the directory where PHP temporarily holds files that
		  are being uploaded to the server.  If it is not 
		  set it will default to the /tmp directory.<br>
		  If this directory is on a seperate partition, be very 
		  careful about the size.  Because this will also limit
		  the maximiun file size that can be uploaded. <BR>
		  ie.. (a 2Meg partition will only hold a 2Meg file!!)
        <br><br>
		



		  ";





        //$memory_limit = ini_get("memory_limit"); 
		  

  

	  } else {
	     $status=false;
		  $message="
		    Error, file uploads have been disable in your <B>php.ini</b>
			 file. You will not be able to upload files to your projects.<BR><BR>
			 <B>Suggestion:</b><BR>
			 Edit your <B>php.ini</b> file and make sure the following variable
			 is set <BR> <b>file_uploads=On</b><BR><BR>
			 You must then restart the Apache webserver for changes 
			 made in the php.ini to take effect.<BR>
			 /usr/local/apache/bin/apachectl restart <BR>
			 <I>(or wherever apache is located)</i>
		  ";
	  }
} // END OF FUNCTION CHECK FOR PHP UPLOAD





function check_for_write_permission( & $title,& $message, & $status){
     $message="";
 	  $title="Verifying where documents will be stored on server";
	  $status=false;

	  //Going to check to make sure I can write 
	  // DOCUMENT_DIRECTOR
	  // to either the /tmp or the upload directory 
	  // that is specified in the php.ini file 
	  //----------------------------------------
	  //Check to make sure exits.
	  if(@is_dir(DOCUMENT_DIRECTORY)){
		 // OK it exists 
		 // Check to make sure I can write to it!!
 		 // Create adummy file then close
		 //------------------------------------
		 $file_name =  DOCUMENT_DIRECTORY . "/garbage.txt";
       $ptr = @fopen($file_name,"w");
		 if($ptr){
 		    fclose($ptr);
			 $message="     
				Success, able to write to the
			   directory  <B>" . DOCUMENT_DIRECTORY . "</b> 
				<BR><BR>
				This is where all uploaded documents will
				be stored.<BR><BR>
				This parameter DOCUMENT_DIRECTORY can be changed
				in the file <B>"  .  CONFIG_FILE  . "</b> 
			 ";
			 $status=true;
		 } else { 
			$status=false; 
			 $message="     
				Error, unable to write to the
			   directory  <B>" . DOCUMENT_DIRECTORY . "</b>.<BR> 
				This directory exists, but do not have permission to
				write to it.
				<BR><BR>
				This is where all uploaded documents will
				be stored. You will not 
				<BR><BR>
			   <B>Suggestion:</b><BR>
				Make sure that owner of the \"httpd\" process 
				has write privileges to the directory 
				<B>" . DOCUMENT_DIRECTORY . "</b> <BR>
			    or change this directory to a different one by changing 
			    the variable <B>DOCUMENT_DIRECTORY</b> in the file 
				 <b>" . CONFIG_FILE  . "
			 ";
		 }
	  } else {
	    // Directory does not even exits
		 // Inform user Or cannot read it!!
		 // State the 2 problems!!!
		 //------------------------------
		  $message="
		      Error, either the directory  <B>" . DOCUMENT_DIRECTORY . "</b> does
				not exist or the owner of the \"httpd\" process does not have
				permission to read it.
				<BR><BR>
			
			  This is location where all of the uploaded documents will be 
			  stored.  
			  <BR><BR>
			  <b>Suggestion:</b>
				<BR>
			  You can <BR>
			  Create the directory <B>" . DOCUMENT_DIRECTORY . "</b>,
			  <BR>
			  or change this directory to a different one by changing 
			  the variable <B>DOCUMENT_DIRECTORY</b> in the file <b>" . CONFIG_FILE  . "
			  </B>
		  ";
	  }
	  
	   



} // END OF FUNCTION CHECK FOR WRITE PERMISSION 










function check_for_db_connection( & $title,& $message, & $status){
   //----------------------------------------
   // Check for the connection to the 
	// database. Point if there are any errors.
	//-----------------------------------------	
	$title="Checking connection to database";
	$message="";
	$status=true;

	$connect = mysql_connect(IP_ADDRESS,USERNAME,PASSWORD);
	if($connect){
	  if(!mysql_select_db(DB_NAME))  {
        $reason = "Unable to connect to database <B>" . DB_NAME . "</B>";
		  $status = false;
      } else  {
        $message = "Sucess connected to database <B> " . DB_NAME . "</B>"; 
		  $status=true;
      }
 	} else {
	  $status=false;
	  $message = "Unable to connect to database <B>" . DB_NAME . "</B>";
   }      
	if(!$connect) {
     $error_msg = @mysql_error();
     $error_num = @mysql_errno();
	  $message .= "<BR><BR><font color=990000>MYSQL error #" . $error_num ;  
     $message .=  "<BR>" . $error_msg ."</font>"; 

	  switch($error_num) {
         case "2002": 	   
	   	   $message .= "<BR><BR><B>Suggestion:</b> 
			   <BR>Check to make MYSQL database is running. 
				";
			  
 
			   // OK lets check for temp file.
				// and tell them where I am looking
				//------------------------
			  $pieces = explode(":","IP_ADDRESS");
			  if($pieces[1]==""){
				  $socket= "/tmp/mysql.sock";
			  } else {
				 $socket = $pieces[1];
			  }
			  //Check for socket file
			  if(!file_exists($socket)){
			     // Cannot find Socket FILE!!!
   			  // Tell where looking and 
				  // and where to change 
              $message .= "<BR>Make sure file <b>$socket</b> exists
				  after starting DB.<br>You can point to a different location
 				  by updating the variable IP_ADDRESS in file 
				  <B>"  .  CONFIG_FILE . "</B> 
				  Also note with some configurations, instead of 
				  <B>mysql.sock</B> the file is called <B>mysqld.sock</B>
				  Check for this file also.
				    
				  ";
			  }
		 	 break;
			 case "2005":



			  break;
         case "1045": 
				 $message .= "<BR><BR>
				 <B>Suggestion:</b><BR>
				 Make sure user <B>" . USERNAME . "</b> has 
				 access the database <B> " . DB_NAME . "</B><BR>
				 Try to connect to the database from the 
				 command line by using the following<BR><BR>
				 <i>
					mysql -u" . USERNAME . " -p " . DB_NAME . "
				 </i> <BR>
				 (you will then need to type in the password)


				 ";
			 break;

	  }
	  

	}

	if($connect){
    	mysql_close($connect);     
	}
} // END OF FUNCTION CHECK_FOR_DB_CONNECTION 
 




	



function check_for_config_file(& $title, & $message, & $status,& $path, & $file ){
    //Look for the config.inc or the config.inc.php 
	 //First check in the default location install
	 // in /usr/local/lib/config.inc
	 //---------------------------------------
	 $title="Checking for configuration file";
	 $path="/usr/local/lib/";
	 $file="config.inc";
 	 $full_path=$path . $file;
	 if(file_exists($full_path)){
	     //This is standard install direceotry.
		  //We are good
		  $status=true;
	 } else {
		//Check in current working directory 
		// to see if config.inc.php exists.
		//--------------------------------------
	   $path="./";
	   $file="config.inc.php";
 	   $full_path=$path . $file;
  	   if(file_exists($full_path)){
	     //This is standard install direceotry.
		  //We are good, THis is epi_LITE..
		  $status=true;		   
 	   } else {
         //NOW checl epi_config.inc.php...
	      $path="./";
	      $file="epi_config.inc.php";
 	      $full_path=$path . $file;
   	   if(file_exists($full_path)){
	        //This is standard install direceotry.
		     //We are good, THis is epi_LITE..
		      $status=true;		   
				//GRAB the vairalbel, and load into $file
				include("./epi_config.inc.php");
				$path="";
				$file=EPI_CONFIG_FILE;
			 } else {
  		     $status=false;
			}
		}
	 }
	 if($status){
	   $message = "
		  Success, found file <b>$file</b> in this location <b>$path</b>
		";
	  } else {
	    $message = "
		  Error, unable to find file<b> $file </b>in this location <b>$path</b>		  
		";
	  }
	 $message = $message . "<BR><BR>" 
	 . "
	  Epiware uses this file to set the parameters for connecting to the 
	  database and where documents are stored on the server.
	 ";
}


	











function display_status($title,$message,$status){
    //Create a sigle table for each entry 
	 // and display the status of the check 
	 //-----------------------------
	  print "<table border=0 cellpadding=0 cellspacing=0 width=625><tr><TD BGCOLOR=\"#576373\">";

	  print "<table border=0 cellpadding=1 cellspacing=1 width=625><tr>";
	  print "<td colspan=2 bgcolor=\"#738294\"><B><font color=\"ffffff\" face=\"" . TEMP_FONT . "\">";
 
	  print $title;

	  print "</font></b></td></tr>";
	  print "<tr><td width=50 align=center bgcolor=\"ffffff\"><BR>";

	  small_table($status,30);

	  print "&nbsp;</td>";
	   // 5A8EAD
     print "<td width=575 bgcolor=\"#FFFFFF\" valign=top>";
	  print "<font color=333333 face=\"" . TEMP_FONT . "\" SIZE=\"3\">";
	      
	  print $message;

	  print "</FONT>&nbsp;</td></tr></table>"; 
	  print "</td></tr></table>"; 
}
  
function small_table($status,$size){
     $color="cc0000";    
	  if($status){
		  $color="00aa00";
	  }
	  print "<table border=0 cellpadding=0 cellspacing=0 width=$size><tr>";
	  print "<td width=$size bgcolor=$color>";
     print "&nbsp;&nbsp;<BR><BR></td></tr></table>";
}















function print_header(){
 echo "
   <html>
   <body> 
   <div align=center>   
   <table cellpadding=0 cellspacing=0 border=0 width=625><tr><td align=right>
   <font face=\"" . TEMP_FONT . "\"><b><a href=./>HOME</a></B></font>
	</td></tr></table>
	<BR>
   
  
  "; 
}








?>
</div>
</body>
</html>
Return current item: Epiware Document Management