Location: PHPKode > projects > O - OpenSource GroupWare > osgw/config/config_setup.php
<?php
/**************************************************************************
   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.

   @Authors:	Ryan Thompson(hide@address.com)
**************************************************************************/
if($_SERVER['HTTP_REFERER'] != "http://{$_SERVER['HTTP_HOST']}/config/")
{
	die("Error");
}
require("../osgw/classes/class.config.php");
require("global.inc.php");
$cfg = new setup();


$config_file = $cfg->create_config_file($_POST);

if(isset($_POST['save_settings']))	//O will create config.inc.php and write data to it
{
	if(!$fp = @fopen($cfg->change_str("../config.inc.php"), 'w'))
	{
	
		$output = "<p>There was an error trying to write to the filesystem. Displaying file below </p>";
		$output .= "&lt;?php<br />";
		$output .=  str_replace("\n", "<br />", $config_file);

	} else {
		
		$output .= "&lt;?php<br />";
		$output .=  str_replace("\n", "<br />", $config_file);
		fputs($fp, $config_file);
		fclose($fp);
	}
	
} elseif(isset($_POST['download_settings'])) //Force browser to download file to be saved
{
	$temp_file = tempnam('/tmp', 'o_');
	$fp = fopen($temp_file, 'w');
	$config_file = str_replace('&lt;','<', $config_file);
	fwrite($fp, $config_file);
	fclose($fp);
	
	$size = filesize($temp_file);
	
	header("Content-Length: ".$size);
	header("Content-disposition: attachment; filename=$temp_file");
	header("Content-type: application/octet-stream");
	header('Pragma: no-cache');
	header('Expires: 0');

	$fp = fopen($temp_file, 'r');
	fpassthru($fp);
	fclose($fp);
	unlink($temp_file);
} elseif(isset($_POST['print_settings'])) //Display config.inc.php in browser window manually save
{
	$output .= "<br />";
	$output .= str_replace("\n", "<br />", $config_file);	
}

if ($dh = opendir($_POST['root_dir'])) 
{
	
	while (($file = readdir($dh)) !== false) 
	{
		
		if(is_dir($_POST['root_dir'] ."/".$file))
		{	
			$i = 0;
		
			if(!in_array($file, $system_dirs))
			{
				$services .= $file ."\n";	
			}
			
		}
	}
closedir($dh);
} else {
	echo "error";
	
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>OpenSource GroupWare Setup</title>
<?php
	$stylesheet = $cfg->change_str('./stylesheet.css');
	include($stylesheet);
?>

<script type="text/javascript">
function check_password(form_data)
{
	if(form_data.db_password.value != form_data.confirm_db_password.value)
	{
		alert ("Database passwords did not match");
		return false;
	} else {
		return true;
	}
}
</script>
</head>
<body>
<?php
	$return_button = "<input type=\"submit\" name=\"return\" value=\"Go Back\">";
	$pass = "<font style=\"color:#009900\">Passed</font><br>";
	$yes = "<font style=\"color:#009900\">Yes</font><br>";
	$fail = "<font style=\"color:#FF0000\">Failed</font><br>";
	$no = "<font style=\"color:#FF0000\">No</font><br>";
	$untested = "<font style=\"color:#0000FF\">Untested</font><br>";
	


?>

<table align="center" width="700" style="border: 1px solid #FFFFFF; background: #336699;">
<tr>
<td style="text-align:right;font-size:16pt;font-family: Arial; padding:0px">config.inc.php Creation</td>
</tr>
<?php 
	if(!is_null($output))
	{
?>
<tr>
<td class="general">The data below needs to be saved to a file name config.inc.php. Save the file to the root
directory of O ( <?php echo $_POST['root_dir']?> )</td>
</tr>

<tr>

<td class="general">

<?php echo $output?>
</td>
</tr>

<?php
	}

	if(!$fp = fopen($_POST['root_dir'] ."/services", 'w'))
	{
		echo str_replace("\n", "<br />", $services);
	} else {
		fputs($fp, $services);	
	}
?>

<tr>
<td class="general">
<br />
Checking Server Operating System.....
	<?php echo PHP_OS?>
<br>
Is it compatible...........
<?php
	if(PHP_OS == 'Linux' || PHP_OS == 'Unix')
	{
		echo $pass;
	} elseif(PHP_OS == 'WINNT')
	{
		echo $untested;
	} else {
		echo $untested;
	}

?>

Checking PHP Version........
	<?php echo $php = floor(PHP_VERSION);?>
<br />

If this version compatible........
	<?php
		if($php < 4)
		{
			echo $fail;
		} elseif(PHP_VERSION != '4.3.1')
		{
			echo $untested;
		} else {
			echo $pass;
		}
	?>
<br />
What database was selected........
	<?php
		switch($_POST['db_type'])
		{
			case 'mysql':
				echo $db = "MySQL";
				$db_t = 1;
				 
			break;
			case 'pgsql':
				echo $db = "PostgreSQL";
				$db_t = 2;
				
			break;
		}
	?>
<br />
Attempting to connect to <?php echo $db?> server......
	<?php
		if($db_t == 1)
		{
			if(!$conn = mysql_connect ($_POST[db_hostname], $_POST[db_username], $_POST[db_password]))
			{
				echo $fail;
				exit();
			} else {
				echo $pass;
			}
	?>
Does the database <?php echo $_POST['db_name']?> already exist.............
	<?php
	
		if(!mysql_select_db($_POST['db_name']))
		{
			echo $no;
			echo "Attempting to create database ". $_POST['db_name'];
			if(mysql_query("CREATE DATABASE $_POST[db_name]"))
			{
				echo $yes;	
			}
		} else {
			echo $yes;

	?>
Does it belong to O..........
	<?php
			if($query = mysql_query("SELECT * FROM o_info"))
			{
				$results = mysql_fetch_array($query);
				echo $yes;

			} else {
				echo $no;
			}

		}

		} elseif($db_t == 2)
		{
		
			if(!$conn = pg_connect("host=$_POST[db_hostname] dbname=$_POST[db_name] user=$_POST[db_username] password=$_POST[db_password]"))
			{
				echo $fail;
			} else {
				echo $pass;
			}
		}
		 	
		$next_page = "install.". $_POST['db_type'] .".php";
		
	
	?>
</td>
</tr>
<tr>
<td class="general">

<input type="submit" value="Back" onClick="window.location='index.php'" class="button"> 
<input type="submit" value="Continue" onClick="window.location='db_create.php'" class="button">
</td>
</tr>
</table>



Return current item: O - OpenSource GroupWare