Location: PHPKode > projects > Openology PHP Application Integration > openology/forum/install.php
<?php
/* ¸ÀŽØ¸ŽÀ¹)ö)ÿüó¥ê
 * First 20 bytes of linux 2.4.18, so various windows utils think
 * this is a binary file and don't apply CR/LF logic
 */

/***************************************************************************
* copyright            : (C) 2001-2004 Advanced Internet Designs Inc.
* email                : hide@address.com
* $Id: install.php,v 1.151 2005/12/23 03:44:54 hackie Exp $
*
* 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.
***************************************************************************/

function fud_ini_get($opt)
{
	return (ini_get($opt) == '1' ? 1 : 0);
}

	if (!fud_ini_get('track_errors')) {
		ini_set('track_errors', 1);
	}
	if (!fud_ini_get('display_errors')) {
		ini_set('display_errors', 1);
	}

	error_reporting(E_ALL);
	$no_mem_limit = ini_get("memory_limit");
	if ($no_mem_limit) {
		$no_mem_limit = (int) str_replace(array('k', 'm', 'g'), array('000', '000000', '000000000'), strtolower($no_mem_limit));
		if ($no_mem_limit < 1 || $no_mem_limit > 50000000) {
			$no_mem_limit = 0;
		}
	}

	ignore_user_abort(true);
	set_magic_quotes_runtime(0);
	@set_time_limit(600);

	/* uncomment the line below if the installer stalls after the 1st page */
	// ini_set("allow_url_fopen", 0);

	/* opening a connection to itself should not take more then 5 seconds */
	ini_set("default_socket_timeout", 5);

	/* Determine SafeMode limitations */
	define('SAFE_MODE', fud_ini_get('safe_mode'));

	/* Determine open_basedir limitations */
	define('open_basedir', ini_get('open_basedir'));

	/* determine if magic_guotes_gpc are off */
	$magic_guotes_gpc = get_magic_quotes_gpc();
	
	/* mbstring hackery, necessary if function overload is enabled */
	if (extension_loaded('mbstring') && ini_get("mbstring.func_overload") > 0) {
		mb_internal_encoding('ASCII');
	}

	if (!isset($_SERVER['PATH_TRANSLATED'])) {
		$_SERVER['PATH_TRANSLATED'] = isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : realpath(__FILE__);
	}
	$module_status = module_check();

	if (strncmp(PHP_SAPI, 'apache', 6)) {
		define('file_perms', 0644);
		define('dir_perms', 0755);
	} else {
		define('file_perms', 0600);
		define('dir_perms', 0711);
	}

/* we need this for PDO in 5.0+ */
if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
	function ex_handle($ex) { seterr('DBHOST', $ex->getMessage()); }
	set_exception_handler('ex_handle');
	$GLOBALS['PDO'] = null;
	function pdo_fetch($res) { return $res->fetch(PDO_FETCH_NUM); }
}

function module_check()
{
	$status = array();
	foreach (array('zlib', 'mysql', 'pdo_mysql', 'pdo_pgsql', 'pdo_sqlite', 'pgsql', 'pcre', 'pspell', 'posix') as $m) {
		$status[$m] = extension_loaded($m);
	}
	return $status;
}

function initdb($init=0)
{
	switch ($_POST['DBTYPE']) {
		case 'mysql':
			if (!($conn = mysql_connect($_POST['DBHOST'], $_POST['DBHOST_USER'], $_POST['DBHOST_PASSWORD']))) {
				seterr('DBHOST', 'Failed to connect to the MySQL Server, SQL Reason: '.mysql_error());
			}
			define('__FUD_SQL_LNK__', $conn);
			if (!mysql_select_db($_POST['DBHOST_DBNAME'], __FUD_SQL_LNK__)) {
				seterr('DBHOST_DBNAME', 'Could not open the database you\'ve specified, SQL Reason: '.mysql_error());
			}
			break;

		case 'pgsql':
			$connect_str = '';
			$vals = array('DBHOST' => 'host', 'DBHOST_USER' => 'user', 'DBHOST_PASSWORD' => 'password', 'DBHOST_DBNAME' => 'dbname');
			foreach ($vals as $k => $v) {
				if (!empty($_POST[$k])) {
					$connect_str .= ' '.$v.'='.$_POST[$k];
				}
			}

			if (!($conn = pg_connect(ltrim($connect_str)))) {
				seterr('DBHOST', 'Failed to establish database connection to '.$_POST['DBHOST']);
			}
			define('__FUD_SQL_LNK__', $conn);
			break;

		case 'pdo_mysql':
			if ($_POST['DBHOST']{0} == ':') {
				$host = 'unix_socket='.substr($_POST['DBHOST'], 1);
			} else {
				$host = 'host='.$_POST['DBHOST'];
			}
		
			$dsn = 'mysql:'.$host.';dbname='.$_POST['DBHOST_DBNAME'];
			$GLOBALS['PDO'] = new PDO($dsn, $_POST['DBHOST_USER'], $_POST['DBHOST_PASSWORD']);
			break;

		case 'pdo_pgsql':
			$dsn = 'pgsql:';
			$vals = array('DBHOST' => 'host', 'DBHOST_USER' => 'user', 'DBHOST_PASSWORD' => 'password', 'DBHOST_DBNAME' => 'dbname');
			foreach ($vals as $k => $v) {
				if (!empty($_POST[$k])) {
					$dsn .= $v.'='.$_POST[$k].' ';
				}
			}
			$GLOBALS['PDO'] = new PDO($dsn);
			break;
		
		case 'pdo_sqlite':
			$_POST['DBHOST'] = $_POST['SERVER_DATA_ROOT'].'/forum.db.php';
			if ($init) {
				@unlink($_POST['DBHOST']);
			}
			$GLOBALS['PDO'] = new PDO('sqlite:'.$_POST['DBHOST']);
			break;
		
		default:
			exit("Invalid DB Type.");
	}			
}

function dbquery($qry, $fetch=0)
{
	if (!defined('__FUD_SQL_LNK__') && !$GLOBALS['PDO']) {
		return FALSE;
	}

	switch ($_POST['DBTYPE']) {
		case 'mysql':
			return mysql_query($qry, __FUD_SQL_LNK__);
			break;
		case 'pgsql':
			return pg_query(__FUD_SQL_LNK__, $qry);
			break;
		case 'pdo_mysql':
		case 'pdo_pgsql':
		case 'pdo_sqlite':
			if (!$fetch) {
				return ($GLOBALS['PDO']->exec($qry) !== FALSE);
			} else {
				return $GLOBALS['PDO']->query($qry);
			}
			break;
		
	}
}

function dberror()
{
	switch ($_POST['DBTYPE']) {
		case 'mysql':
			return mysql_error(__FUD_SQL_LNK__);
			break;
		case 'pgsql':
			return pg_last_error(__FUD_SQL_LNK__);
			break;
		case 'pdo_mysql':
		case 'pdo_pgsql':
		case 'pdo_sqlite':
			$err = $GLOBALS['PDO']->errorInfo();
			return end($err);
			break;
	}
}

function dbperms_check()
{
	$qry = array(
		'CREATE TABLE fud_forum_install_test_table (test_val INT)',
		'ALTER TABLE fud_forum_install_test_table ADD test_val2 INT',
		array(
			'mysql' => 'LOCK TABLES fud_forum_install_test_table WRITE',
			'pgsql' => 'BEGIN WORK; COMMIT WORK'
		),	
		'DROP TABLE fud_forum_install_test_table'
	);
	$err = array(
		'FATAL ERROR: your %name% account does not have permissions to create new %name% tables.<br>Enable this functionality and restart the script.',
		'FATAL ERROR: your %name% account does not have permissions to run ALTER queries on existing %name% tables<br>Enable this functionality and restart the script.',
		'FATAL ERROR: your %name% account does not have permissions to run LOCK queries on existing %name% tables<br>Enable this functionality and restart the script.',
		'FATAL ERROR: your %name% account does not have permissions to run DROP TABLE queries on existing %name% tables<br>Enable this functionality and restart the script.'
	);

	switch ($_POST['DBTYPE']) {
		case 'mysql':
		case 'pdo_mysql':
			$acc = 'MySQL';
			break;
		case 'pgsql':
		case 'pdo_pgsql':
			$acc = 'PostgreSQL';
			break;
		case 'pdo_sqlite': /* no need to check perms, we've got our own DB */
			return;

		default:
			exit("Invalid DB Type.");
	}

	@dbquery('DROP /*!10000 TABLE IF EXISTS */fud_forum_install_test_table');

	foreach ($qry as $k => $v) {
		if (is_array($v)) {
			$key = strpos($_POST['DBTYPE'], 'mysql') !== FALSE ? 'mysql' : 'pgsql';
			$v = $v[$key];
		}

		if (!dbquery($v)) {
			seterr('DBHOST', str_replace('%name%', $acc, $err[$k]));
		}
	}
}

function make_into_query($data)
{
	return trim(str_replace('{SQL_TABLE_PREFIX}', $_POST['DBHOST_TBL_PREFIX'], preg_replace('!\s+!', ' ', preg_replace('!\#.*$!s', '', $data))));
}

function change_global_settings($list)
{
	$settings = file_get_contents($GLOBALS['INCLUDE'] . 'GLOBALS.php');
	foreach ($list as $k => $v) {
		if (($p = strpos($settings, '$' . $k)) === false) {
			$pos = strpos($settings, '$ADMIN_EMAIL');
			if (is_int($v)) {
				$settings = substr_replace($settings, "\${$k}\t= {$v};\n\t", $p, 0);
			} else {
				$v = addcslashes($v, '\\"$');
				$settings = substr_replace($settings, "\${$k}\t= \"{$v}\";\n\t", $p, 0);
			}
		} else {
			$p = strpos($settings, '=', $p) + 1;
			$e = $p + strrpos(substr($settings, $p, (strpos($settings, "\n", $p) - $p)), ';');

			if (is_int($v)) {
				$settings = substr_replace($settings, ' '.$v, $p, ($e - $p));
			} else {
				$v = addcslashes($v, '\\"$');
				$settings = substr_replace($settings, ' "'.$v.'"', $p, ($e - $p));
			}
		}
	}

	$fp = fopen($GLOBALS['INCLUDE'].'GLOBALS.php', 'w');
	fwrite($fp, $settings);
	fclose($fp);
}

/* un-quote the string if it is quotes */
if ($magic_guotes_gpc) {
	function strip_quotes(&$var)
	{
		$var = stripslashes($var);
	}

	if (!empty($_GET)) {
		array_walk($_GET, 'strip_quotes');
	}
        if (!empty($_POST)) {
		array_walk($_POST, 'strip_quotes');
	}
}

/* Perform various sanity checks, which check for required components */
if (!count($_POST)) {
	/* php version check */
	if (!version_compare(PHP_VERSION, '4.3.0', '>=')) {
?>
<html>
<body bgcolor="white">
Your php version <b>(<?php echo PHP_VERSION; ?>)</b> is older then the minimum required version <b>(4.3.0)</b>.
Please install the newer version and try again.<br>The reasons for this restriction are numerous, most important ones
being security &amp; performance.
</body>
</html>
<?php
		exit;
	}

	/* file permission check */
	if ($no_mem_limit && !@is_writeable(__FILE__)) {
?>
<html>
<body bgcolor="white">
You need to chmod the <?php echo __FILE__; ?> file 666 (-rw-rw-rw-), so that the installer can modify itself. This
is needed to avoid problems since your PHP installation enforces memory limit setting.
</body>
</html>
<?php
		exit;
	}


	/* check for installer validatity */
	$fsize = filesize(__FILE__);
	if ($fsize < 200000 && !file_exists("./fudforum_archive")) {
?>
<html>
<body bgcolor="white">
The installer is missing the data archive, append the archive to the installer and try again.
</body>
</html>
<?php
		exit;
	} else if ($fsize > 200000) {
		/* zlib check */
		if (($zl = ($fsize < 3500000)) && !$module_status['zlib']) {
?>
<html>
<body bgcolor="white">
zlib extension required to decompress the archive is not loaded.
Please recompile your PHP with zlib support or load the zlib extension, in the event this is not possible download
the non-zlib version of the install or upgrade script from FUDforum's website at: <a href="http://fud.prohost.org/forum/">http://fud.prohost.org/forum/</a>.
</body>
</html>
<?php
			exit;
		}
	}

	/* database check */
	if (!$module_status['mysql'] && !$module_status['pgsql'] &&
			!$module_status['pdo_pgsql'] && 
			!$module_status['pdo_mysql'] &&
			!$module_status['pdo_sqlite']) {
?>
<html>
<body bgcolor="white">
FUDforum can utilize either MySQL PosgreSQL or SQLite database to store it's data, unfortunately, your PHP does not have
support for either one. Please install or load the appropriate database extension and then re-run the install script.
</body>
</html>
<?php
		exit;
	}
	/* pcre check */
	if (!$module_status['pcre']) {
?>
<html>
<body bgcolor="white">
PCRE (Perl Compatible Regular Expression) extension required for proper forum operation is not avaliable, please load or install
this extension and then re-run the installer.
</body>
</html>
<?php
		exit;
	}

	if (isset($zl) && $no_mem_limit) {
		/* move archive to separate file */
		if (!($fp = @fopen("./fudforum_archive", "wb"))) {
			echo '<html><body bgcolor="white">Please make sure that the intaller has permission to write to the current directory ('.getcwd().')';
			if (!SAFE_MODE) {
				echo '<br/ >or create a "fudforum_archive" file inside the current directory and make it writable to the webserver.';
			}
			exit('</body></html>');
		}
		
		if (defined('__COMPILER_HALT_OFFSET__')) { /*  PHP 5.1 with halt support */
			$fp2 = fopen(__FILE__, 'rb');
			$main = stream_get_contents($fp2, __COMPILER_HALT_OFFSET__ + 4); /* 4 == " ?>\n" */
			fwrite($fp, stream_get_contents($fp2, -1, __COMPILER_HALT_OFFSET__ + 4));
		} else {
			$main = '';

			$l = strlen("<?php __HALT_"."COMPILER(); ?>");

			$fp2 = fopen(__FILE__, 'rb');
			while (($line = fgets($fp2))) {
				$main .= $line;
				if (!strncmp($line, "<?php __HALT_"."COMPILER(); ?>", $l)) {
					break;
				}
			}

			while (($tmp = fread($fp2, 20000))) {
				fwrite($fp, $tmp);
			}
		}
		fclose($fp);
		fclose($fp2);

		$fp = fopen(__FILE__, "wb");
		fwrite($fp, $main);
		fclose($fp);

		unset($main, $tmp);
	}
}

	/* determine directory separator */
	$WINDOWS = DIRECTORY_SEPARATOR != '/';

function __mkdir($dir)
{
	if (@is_dir($dir)) {
		@chmod($dir, dir_perms);
		return 1;
	} else if (file_exists($dir)) {
		unlink($dir);
	}
	$ret = (mkdir($dir, dir_perms) || mkdir(dirname($dir), dir_perms));

	return $ret;
}

function draw_row($title, $var, $def, $descr=NULL)
{
	echo '<tr bgcolor="#bff8ff"><td valign="top"><b>'.$title.'</b>'.($descr ? '<br><font size=-1>'.$descr.'</font>' : '').'</td><td>'.(isset($GLOBALS['errors'][$var]) ? $GLOBALS['errors'][$var] : '').'<input type="text" name="'.$var.'" value="'.htmlspecialchars($def).'" size=40></td></tr>';
}

function draw_row_sel($title, $var, $opt_list, $val_list, $descr=NULL, $def=NULL)
{
	$val_list = explode("\n", $val_list);
	$opt_list = explode("\n", $opt_list);

	if (($c = count($val_list)) != count($opt_list)) {
		exit('Value list does not match option count');
	}

	echo '<tr bgcolor="#bff8ff"><td valign="top"><b>'.$title.'</b>'.($descr ? '<br><font size=-1>'.$descr.'</font>' : '').'</td><td><select name="'.$var.'">';
	for ($i = 0; $i < $c; $i++) {
		echo '<option value="'.htmlspecialchars($val_list[$i]).'"'.($def == $val_list[$i] ? ' selected' : '').'>'.htmlspecialchars($opt_list[$i]).'</option>';
	}
	echo '</select></td></tr>';
}

function draw_dialog_start($title, $help)
{
?>
<table bgcolor="#000000" align="center" border="0" cellspacing="0" cellpadding="1">
<tr><td><table bgcolor="#FFFFFF" border=0 cellspacing=1 cellpadding=4 align="center">
	<tr><td colspan=2 bgcolor="#e5ffe7"><?php echo $title; ?></td></tr>
	<tr><td colspan=2 bgcolor="#fffee5"><?php echo $help; ?></td></tr>
<?php
}

function draw_dialog_end($section)
{
	if ($section != 'done') {
		echo '<tr bgcolor="#FFFFFF">';
		if ($section != 'stor_path') {
			echo '<td align="left"><input type="button" onClick="history.go(-1)" name="buttn" value="&lt;&lt; Back"></td>';
		} else {
			echo '<td>&nbsp;</td>';
		}
		echo '<td align="right"><input type="submit" name="submit" value="Next &gt;&gt;"></td></tr></table></td></tr></table>';
	}
}

function seterr($name, $text)
{
	$GLOBALS['errors'][$name] = '<font color="#ff0000">'.$text.'</font><br>';
}

function chkslash(&$val)
{
	if (!empty($val)) {
		$last_char = substr($val, -1);
		if ($last_char != '/' && $last_char != '\\') {
			$val .= DIRECTORY_SEPARATOR;
		}
	}
	return $val;
}

function decompress_archive($data_root, $web_root)
{
	$clean = array('PHP_OPEN_TAG'=>'<?', 'PHP_OPEN_ASP_TAG'=>'<%');

	if ($GLOBALS['no_mem_limit']) {
		$size = filesize("./fudforum_archive");
		$fp = fopen("./fudforum_archive", "rb");
		$checksum = fread($fp, 32);
		$tmp = fread($fp, 20000);
		fseek($fp, (ftell($fp) - 20000), SEEK_SET);
		if (strpos($tmp, 'RAW_PHP_OPEN_TAG') !== FALSE) {
			unset($clean['PHP_OPEN_TAG']); $clean['RAW_PHP_OPEN_TAG'] = '<?';
			$data = '';
			while (($tmp = fgets($fp))) {
				$data .= strtr($tmp, $clean);
			}
		} else {
			$data_len = (int) fread($fp, 10);
			// data should be @ least 100k
			if ($data_len < 100000) {
				exit("Failed getting archive size from ".htmlentities(fread($fp, 10)));
			}
			$data = gzuncompress(strtr(fread($fp, $data_len), $clean), $data_len);
		}
		fclose($fp);
	} else {
		if (defined('__COMPILER_HALT_OFFSET__')) {
			$data = file_get_contents(__FILE__, NULL, NULL, __COMPILER_HALT_OFFSET__ + 4); /* 4 = " ?>\n" */
			$p = 0;
		} else { 
			$data = file_get_contents(__FILE__);
			$p = strpos($data, "<?php __HALT_"."COMPILER(); ?>") + strlen("<?php __HALT_"."COMPILER(); ?>") + 1;
		}
		$checksum = substr($data, $p, 32);
		$data = substr($data, $p + 32);
		if (strpos($data, 'RAW_PHP_OPEN_TAG') !== FALSE) { /* no compression */
			unset($clean['PHP_OPEN_TAG']); $clean['RAW_PHP_OPEN_TAG'] = '<?';
			$data = strtr($data, $clean);
		} else {
			$data_len = (int) substr($data, 0, 10);
			// data should be @ least 100k
			if ($data_len < 100000) {
				exit("Failed getting archive size from ".htmlentities(substr($data, 0, 10)));
			}
			$data = strtr(substr($data, 10), $clean);

			if (!($data = gzuncompress($data, $data_len))) { /* compression */
				exit('Failed decompressing the archive');
			}
		}
	}

	if (md5($data) != $checksum) {
		exit("Archive did not pass checksum test, CORRUPT ARCHIVE!<br>\nIf you've encountered this error it means that you've:<br>\n&nbsp;&nbsp;&nbsp;&nbsp;downloaded a corrupt archive<br>\n&nbsp;&nbsp;&nbsp;&nbsp;uploaded the archive in ASCII and not BINARY mode<br>\n&nbsp;&nbsp;&nbsp;&nbsp;your FTP Server/Decompression software/Operating System added un-needed cartrige return ('\r') characters to the archive, resulting in archive corruption.<br>\n");
	}

	$pos = 0;

	do {
		$end = strpos($data, "\n", $pos+1);
		$meta_data = explode('//',  substr($data, $pos, ($end-$pos)));
		$pos = $end;

		if (!isset($meta_data[3]) || $meta_data[3] == '/install') {
			continue;
		}

		if (!strncmp($meta_data[3], 'install/forum_data', 18)) {
			$path = $data_root . substr($meta_data[3], 18);
		} else if (!strncmp($meta_data[3], 'install/www_root', 16)) {
			$path = $web_root . substr($meta_data[3], 16);
		} else {
			continue;
		}
		$path .= '/' . $meta_data[1];

		$path = str_replace('//', '/', $path);

		if (isset($meta_data[5])) {
			$file = substr($data, ($pos + 1), $meta_data[5]);
			if (md5($file) != $meta_data[4]) {
				exit('ERROR: file '.$meta_data[1].' was not read properly from archive');
			}

			if ($path == $web_root . '.htaccess' && @file_exists($path)) {
				define('old_htaccess', 1);
				continue;
			}

			$fp = @fopen($path, 'wb');
			if (!$fp) {
				if (basename($path) != '.htaccess') {
					exit('Couldn\'t open '.$path.' for write');
				}
			}
			fwrite($fp, $file);
			fclose($fp);

			@chmod($path, file_perms);
		} else {
			if (substr($path, -1) == '/') {
				$path = preg_replace('!/+$!', '', $path);
			}
			if (!__mkdir($path)) {
				exit('ERROR: failed creating '.$path.' directory');
			}
		}
	} while (($pos = strpos($data, "\n//", $pos)) !== false);
}

/* win32 does not have symlinks, so we use this crude emulation */
if ($WINDOWS) {
	function fud_symlink($src, $dest)
	{
		if (!($fp = fopen($dest, 'wb'))) {
			return FALSE;
		}
		fwrite($fp, '<?php include_once "'.$src.'"; ?>');
		fclose($fp);
	}
}

function get_server_uid_gid()
{
	if ($GLOBALS['module_status']['posix']) {
		$u = posix_getpwuid(posix_getuid());
		$g = posix_getgrgid($u['gid']);
		return '(' . $u['name'] . '/' . $g['name'] . ')';
	}
	return;
}

function check_perimary_dir($dir, $type)
{
	if (!__mkdir($dir)) {
		seterr($type, 'Install script failed to create "'.$dir.'". Create it manually and chmod it 777 or make it\'s user/group same as the web-server '.get_server_uid_gid());
		return 1;
	}
	if (!@is_writable($dir)) {
		seterr($type, 'Directory "'.$dir.'" exist, however install script has no permission to write to this directory. Chmod it 777 or make it\'s user/group same as the '.get_server_uid_gid());
		return 1;
	}
	if (SAFE_MODE) {
		if (($safe = $st = @stat($dir))) {
			if (!ini_get('safe_mode_gid')) {
				$safe = (getmyuid() == $st['uid']);
			} else {
				$safe = (getmygid() == $st['gid']);
			}
		}
		if (!$safe && basename(__FILE__) != 'install.php') {
			seterr($type, 'Safe mode limitation prevents the install script from writing to "'.$dir.'". Please make sure that this directory is owned by the same user/group same as the web-server '.get_server_uid_gid());
			return 1;
		}
	}
	if (open_basedir) {
		$safe = 1;
		foreach (explode(PATH_SEPARATOR, open_basedir) as $d) {
			if (!strncasecmp($dir, $d, strlen($d))) {
				$safe = 0;
				break;
			}
		}
		if ($safe) {
			seterr($type, 'open_basedir limitation "'.open_basedir.'" prevents the install script from writing to "'.$dir.'". Please ensure that the specified directory is inside the directories listed in the open_basedir directive');
			return 1;
		}
	}
}

function htaccess_handler($web_root, $ht_pass)
{
	if (!fud_ini_get('allow_url_fopen') || strncmp(PHP_SAPI, 'apache', 6)) {
		unlink($ht_pass);
		return;
	}

	/* opening a connection to itself should not take more then 5 seconds */
	ini_set("default_socket_timeout", 5);
	if (@fopen($web_root . 'blank.gif', 'r') === FALSE) {
		unlink($ht_pass);
	}
}

	$section = isset($_POST['section']) ? $_POST['section'] : (isset($_GET['section']) ? $_GET['section'] : '');

	switch ($section) {
		case 'stor_path':
			if (isset($_GET['sfh'])) {
				$_POST['SERVER_ROOT'] = $_GET['SERVER_ROOT'];
				$_POST['SERVER_DATA_ROOT'] = $_GET['SERVER_DATA_ROOT'];
				$_POST['WWW_ROOT'] = $_GET['WWW_ROOT'];
			}
			$SERVER_ROOT = str_replace('\\', '/', $_POST['SERVER_ROOT']);
			$SERVER_DATA_ROOT = str_replace('\\', '/', $_POST['SERVER_DATA_ROOT']);
			$WWW_ROOT = $_POST['WWW_ROOT'];
			if (substr($WWW_ROOT, -1) != '/') {
				$WWW_ROOT .= '/';
			}
			chkslash($SERVER_ROOT);
			chkslash($SERVER_DATA_ROOT);

			$_POST['SERVER_ROOT'] = $SERVER_ROOT;
			$_POST['SERVER_DATA_ROOT'] = $SERVER_DATA_ROOT;
			$_POST['WWW_ROOT'] = $WWW_ROOT;

			$err = check_perimary_dir($SERVER_ROOT, 'SERVER_ROOT');
			if ($SERVER_ROOT != $SERVER_DATA_ROOT) {
				if (check_perimary_dir($SERVER_DATA_ROOT, 'SERVER_DATA_ROOT') && !$err) {
					$err = 1;
				}
			}

			if (!$err) {
				if (SAFE_MODE && !isset($_GET['sfh'])) {
					$s = realpath(__FILE__);
					$d = dirname($s) . '/install_safe.php';
					if (!copy($s, $d)) {
						exit('Failed to copy "'.$s.'" to "'.$d.'"');
					}
					header('Location: install_safe.php?SERVER_ROOT='.urlencode($SERVER_ROOT).'&SERVER_DATA_ROOT='.urlencode($SERVER_DATA_ROOT).'&WWW_ROOT='.urlencode($WWW_ROOT).'&section=stor_path&sfh=1');
					exit;
				}

				/* try to ensure that SERVER_ROOT resolves to WWW_ROOT */
				if (fud_ini_get('allow_url_fopen')) {
					$check_tm = time();

					$fp = fopen($SERVER_ROOT . 'WWW_ROOT_CHECK', 'wb');
					fwrite($fp, $check_tm);
					fclose($fp);

					if (($d = @file_get_contents($WWW_ROOT . 'WWW_ROOT_CHECK')) != $check_tm) {
						seterr('WWW_ROOT', 'Your WWW_ROOT does not correspond with the SERVER_ROOT path you have specified. (unable to retrive: '.$WWW_ROOT.'WWW_ROOT_CHECK, on disk as: '.$SERVER_ROOT.'WWW_ROOT_CHECK, received data: '.$d.' w/error: ' . $php_errormsg);
					}
					unlink($SERVER_ROOT . 'WWW_ROOT_CHECK');
				}
			}
			if (!isset($GLOBALS['errors'])) {
				decompress_archive($SERVER_DATA_ROOT, $SERVER_ROOT);
				/* verify that all the important directories exist (old php bug) */
				foreach (array('include', 'errors', 'messages', 'files', 'template', 'tmp', 'cache', 'errors/.nntp', 'errors/.mlist') as $v) {
					if (!__mkdir($SERVER_DATA_ROOT . $v)) {
						exit('FATAL ERROR: Couldn\'t create "'.$SERVER_DATA_ROOT . $v.'".<br>You can try creating it manually. If you do, be sure to chmod the directory 777.');
					}
				}
				/* determine if this host can support .htaccess directives */
				if (!defined('old_htaccess')) {
					htaccess_handler($WWW_ROOT, $SERVER_ROOT . '.htaccess');
				}

				$INCLUDE = $SERVER_DATA_ROOT.'include/';
				$ERROR_PATH  = $SERVER_DATA_ROOT.'errors/';
				$MSG_STORE_DIR = $SERVER_DATA_ROOT.'messages/';
				$FILE_STORE = $SERVER_DATA_ROOT.'files/';
				$TMP = $SERVER_DATA_ROOT.'tmp/';
				$FORUM_SETTINGS_PATH = $SERVER_DATA_ROOT.'cache/';

				@chmod($INCLUDE . 'GLOBALS.php', file_perms);
				touch($ERROR_PATH . 'FILE_LOCK');

				/* ensure we don't have any bogus symlinks (re-installing over old forum) */
				@unlink($SERVER_ROOT . 'GLOBALS.php');
				@unlink($SERVER_ROOT . 'adm/GLOBALS.php');
				@unlink($SERVER_DATA_ROOT . 'scripts/GLOBALS.php');

				/* make symlinks to GLOBALS.php */
				if (!$WINDOWS) {
					symlink($INCLUDE . 'GLOBALS.php', $SERVER_ROOT . 'GLOBALS.php');
					symlink($INCLUDE . 'GLOBALS.php', $SERVER_ROOT . 'adm/GLOBALS.php');
					symlink($INCLUDE . 'GLOBALS.php', $SERVER_DATA_ROOT . 'scripts/GLOBALS.php');
				} else {
					fud_symlink($INCLUDE . 'GLOBALS.php', $SERVER_ROOT . 'GLOBALS.php');
					fud_symlink($INCLUDE . 'GLOBALS.php', $SERVER_ROOT . 'adm/GLOBALS.php');
					fud_symlink($INCLUDE . 'GLOBALS.php', $SERVER_DATA_ROOT . 'scripts/GLOBALS.php');
				}

				$url_parts = parse_url($WWW_ROOT);
				/* default bitmask values */
				$FUD_OPT_1 = 1744762047;
				if (!$module_status['pspell']) {
					$FUD_OPT_1 ^= 2097152;
				}
				$FUD_OPT_2 = 695668799 | 8388608;

				change_global_settings(array(
					'INCLUDE' => $INCLUDE,
					'ERROR_PATH' => $ERROR_PATH,
					'MSG_STORE_DIR' => $MSG_STORE_DIR,
					'FILE_STORE' => $FILE_STORE,
					'TMP' => $TMP,
					'WWW_ROOT' => $WWW_ROOT,
					'WWW_ROOT_DISK' => $SERVER_ROOT,
					'FORUM_SETTINGS_PATH' => $FORUM_SETTINGS_PATH,
					'COOKIE_NAME' => 'fud_session_'.time(),
					'FUD_OPT_2' => $FUD_OPT_2,
					'FUD_OPT_1' => $FUD_OPT_1,
					'COOKIE_PATH' => $url_parts['path'],
					'DATA_DIR' => $SERVER_DATA_ROOT));

				$section = 'db';
			}
			break;

		case 'db':
			if (empty($_POST['DBHOST_TBL_PREFIX']) || preg_match('![^A-Za-z0-9_]!', $_POST['DBHOST_TBL_PREFIX'])) {
				seterr('DBHOST_TBL_PREFIX', 'SQL prefix cannot be empty or contain non A-Za-z0-9_ characters');
			} else {
				/* verify that we can connect to database & validate version @ the same time*/
				initdb(1);
				if (($r = dbquery('SELECT VERSION()', 1)) && $_POST['DBTYPE'] != 'pdo_sqlite') {
					switch ($_POST['DBTYPE']) {
						case 'mysql':
							$val = mysql_fetch_row($r);
							break;
						case 'pgsql':
							$val = pg_fetch_row($r);
							break;
						case 'pdo_mysql':
						case 'pdo_pgsql':
							$val = array($r->fetchColumn());
							break;
					}
					if ($val && preg_match('!([3-8]\.[0-9]+(?:\.[0-9]+)?)!', ($val ? $val[0] : null), $m)) {
						$version = $m[1];
					} else {
						$version = 0;
					}
					if (($_POST['DBTYPE'] == 'mysql' || $_POST['DBTYPE'] == 'pdo_mysql') && !version_compare($version, '3.23.0', '>=')) {
						seterr('DBHOST', 'The specified MySQL server is running version "'.$version.'", which is older then the minimum required version "3.23.0"');
					} else if (($_POST['DBTYPE'] == 'pgsql' || $_POST['DBTYPE'] == 'pdo_pgsql') && !version_compare($version, '7.2.0', '>=')) {
						seterr('DBHOST', 'The specified PostgreSQL server is running version "'.$version.'", which is older then the minimum required version "7.2.0"');
					}
				}
				unset($r);
				if (!isset($GLOBALS['errors'])) {
					dbperms_check();
				}

				if (!isset($GLOBALS['errors'])) {
					$tables = $def_data = array();
					if ($_POST['DBTYPE'] == 'pgsql' || $_POST['DBTYPE'] == 'pdo_pgsql') {
						/* remove possibly conflicting tables & sequences */
						$drop = array('r'=>array(), 'S'=>array());
						$c = dbquery("select relname,relkind from pg_class WHERE relkind IN('r','S') AND relname LIKE '".str_replace('_', '\\\\_', $_POST['DBHOST_TBL_PREFIX'])."%'", 1);
						$f = $_POST['DBTYPE'] == 'pgsql' ? 'pg_fetch_row' : 'pdo_fetch';
						while ($r = $f($c)) {
							$drop[$r[1]][] = $r[0];
						}
						unset($c);
		
						if ($drop['r'] && !dbquery('DROP TABLE '.implode(',', $drop['r']))) {
							echo dberror();
						}
						if ($drop['S']) {
							@dbquery('DROP SEQUENCE '.implode(',', $drop['S']));
						}
						unset($drop);
					}
					$tbl = glob($_POST['SERVER_DATA_ROOT'] . 'sql/*.tbl', GLOB_NOSORT);
					$sql = glob($_POST['SERVER_DATA_ROOT'] . 'sql/*.sql', GLOB_NOSORT);

					if (!$tbl || !$sql) {
						fe("Failed to get a list of table defenitions and/or base table data from: '{$_POST['SERVER_DATA_ROOT']}sql/'\n");
					}

					/* import tables */
					foreach ($tbl as $t) {
						foreach (explode(';', preg_replace('!#.*?\n!s', '', file_get_contents($t))) as $q) {
							$q = trim($q);
						
							if ($_POST['DBTYPE'] != 'mysql' && $_POST['DBTYPE'] != 'pdo_mysql') {
								if (!strncmp($q, 'DROP TABLE IF EXISTS', strlen('DROP TABLE IF EXISTS')) ||
									!strncmp($q, 'ALTER TABLE', strlen('ALTER TABLE'))) {
									continue;
								}
								$rep = array('BINARY'=>'', 'INT NOT NULL AUTO_INCREMENT'=> ($_POST['DBTYPE'] == 'pdo_sqlite' ? 'INTEGER' : 'SERIAL'));
								$q = strtr($q, $rep);
							} else if (version_compare($version, '4.1.2', '>=') && !strncmp($q, 'CREATE TABLE', strlen('CREATE TABLE'))) {
								/* because mysql with InnoDB table refuses to resolve indexes correctly, we need to force MyISAM table type */
								if (strpos($q, 'thread_view') !== false) {
									$q .= ' ENGINE=MyISAM ' ;
								}
							 	/* for MySQL 4.1.2+ we need to specify a default charset */
							 	$q .= " DEFAULT CHARACTER SET latin1";
							} 
							if (($q = make_into_query(trim($q)))) {
								if (!dbquery($q)) {
									seterr('DBHOST_DBNAME', 'Failed to create table "'.basename($t, '.tbl').'" ("'.$q.'"), SQL Reason: '.dberror());
									break 2;
								}
							}
						}
					}
					if (!isset($GLOBALS['errors'])) {
						/* import table data */
						foreach ($sql as $t) {
							foreach (explode(";\n", file_get_contents($t)) as $q) {
								if (strpos($q, 'UNIX_TIMESTAMP') !== false) {
									$q = str_replace('UNIX_TIMESTAMP', time(), $q);
								}
								if (($q = make_into_query(trim($q)))) {
									if (!dbquery($q)) {
										seterr('DBHOST_DBNAME', 'Failed to import default data ("'.$q.'") into table '.basename($t, '.sql').', SQL Reason: '.dberror());
										break 2;
									}
								}
							}
						}

						if (!isset($GLOBALS['errors'])) {
							$INCLUDE = $_POST['SERVER_DATA_ROOT'] . 'include/';
							change_global_settings(array(
								'DBHOST' => $_POST['DBHOST'],
								'DBHOST_USER' => $_POST['DBHOST_USER'],
								'DBHOST_PASSWORD' => $_POST['DBHOST_PASSWORD'],
								'DBHOST_DBNAME' => $_POST['DBHOST_DBNAME'],
								'DBHOST_TBL_PREFIX' => $_POST['DBHOST_TBL_PREFIX']
							));

							if (!strncmp($_POST['DBTYPE'], 'pdo_', 4)) {
								change_global_settings(array('DBHOST_DBTYPE' => $_POST['DBTYPE']));
							}
							$section = 'cookies';
						}
					}
				}
			}
			break;

		case 'cookies':
			if (empty($_POST['COOKIE_DOMAIN'])) {
				seterr('COOKIE_DOMAIN', 'You must enter a cookie domain in order for cookies to work properly.');
			} else {
				$INCLUDE = $_POST['SERVER_DATA_ROOT'] . 'include/';
				if ($_POST['COOKIE_DOMAIN'] == 'localhost' || ip2long($_POST['COOKIE_DOMAIN']) > 0) {
					$_POST['COOKIE_DOMAIN'] = '';
				}
				change_global_settings(array('COOKIE_DOMAIN' => $_POST['COOKIE_DOMAIN']));
				$section = 'language';
			}
			break;

		case 'language':
			list($la, $lc, $lp) = explode('::', $_POST['LANGUAGE']);
			initdb();
			dbquery("DELETE FROM ".$_POST['DBHOST_TBL_PREFIX']."themes");
			if (!dbquery("INSERT INTO ".$_POST['DBHOST_TBL_PREFIX']."themes(id, name, theme, lang, locale, theme_opt, pspell_lang) VALUES(1, 'default', 'default', '".addslashes($la)."', '".addslashes($lc)."', 3, '".addslashes($lp)."')")) {
				echo dberror();
			} else {
				$section = 'admin';
			}
			break;

		case 'admin':
			if (empty($_POST['ROOT_PASS'])) {
				seterr('ROOT_PASS', 'You must enter a password for the administrator account.');
			} else if ($_POST['ROOT_PASS'] != $_POST['ROOT_PASS_C']) {
				seterr('ROOT_PASS', 'Your passwords do not match.');
			}
			if (empty($_POST['ROOT_LOGIN'])) {
				seterr('ROOT_LOGIN', 'You must enter a user name for the administrator account.');
			}
			if (empty($_POST['ADMIN_EMAIL'])) {
				seterr('ADMIN_EMAIL', 'You must enter a valid email address for the administrator account.');
			}

			if(!isset($GLOBALS['errors'])) {
				initdb();
				dbquery("DELETE FROM ".$_POST['DBHOST_TBL_PREFIX']."users WHERE id > 1");
				if (!dbquery("INSERT INTO ".$_POST['DBHOST_TBL_PREFIX']."users (login, alias, passwd, name, email, users_opt, join_date, theme) VALUES('".addslashes($_POST['ROOT_LOGIN'])."', '".addslashes(htmlspecialchars($_POST['ROOT_LOGIN']))."', '".md5($_POST['ROOT_PASS'])."', 'Administrator', '".addslashes($_POST['ADMIN_EMAIL'])."', 5405687, ".time().", 1)")) {
					seterr('ROOT_LOGIN', dberror());
				} else {
					$INCLUDE = $_POST['SERVER_DATA_ROOT'] . 'include/';
					change_global_settings(array(
						'ADMIN_EMAIL' => $_POST['ADMIN_EMAIL'],
						'NOTIFY_FROM' => $_POST['ADMIN_EMAIL']
						));
					$section = 'done';
				}
			}
			break;
	}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body bgcolor="white">
<form name="install" action="<?php echo basename(__FILE__) . '?' . rand(); ?>" method="post">
<?php
	if (!$section) {
		$section = 'stor_path';
	}

	switch ($section) {
		case 'stor_path':
			if (count($_POST)) {
				$WWW_ROOT = $_POST['WWW_ROOT'];
				$SERVER_ROOT = $_POST['SERVER_ROOT'];
				$SERVER_DATA_ROOT = $_POST['SERVER_DATA_ROOT'];
			} else {
				$SERVER_ROOT = dirname(realpath(__FILE__)) . '/';
				$WWW_ROOT = 'http://' . $_SERVER['SERVER_NAME'];
				if (($d = dirname($_SERVER['SCRIPT_NAME']))) {
					$WWW_ROOT .= dirname(((strpos($_SERVER['SCRIPT_NAME'], basename(__FILE__)) !== false) ? $_SERVER['SCRIPT_NAME'] : $_SERVER['REQUEST_URI']));
					if ($d != '/') {
						$WWW_ROOT .= '/';
					}
				}
				$WWW_ROOT = str_replace('\\', '/', $WWW_ROOT); // win32 oriented hackery
				$SERVER_DATA_ROOT = realpath(str_replace(dirname($_SERVER['SCRIPT_NAME']) . '/', '', $SERVER_ROOT) . '/../') . '/FUDforum/';
				if (open_basedir && strpos(open_basedir, $SERVER_DATA_ROOT) === FALSE) {
					$SERVER_DATA_ROOT = $SERVER_ROOT;
				}
			}

			if (!SAFE_MODE) {
				draw_dialog_start('PATH OF SYSTEM FILES AND DIRECTORIES&nbsp;&nbsp;&nbsp;&nbsp;<font size="-1"><b>Step 1 of 5</b></font> ', 'First, you need to specify the directories where the forum files will be stored.  In order for the forum installation to work you need to chmod the directories <b>Server Root</b> &amp; <b>Forum Data Root</b> in such a way that the webserver can write to them. I suggest chmoding the directories to 777.<br>
			If you have shell access, you can change the directory permission by typing "<b>chmod 777 directory_name</b>"<br>
			In CuteFTP, you can chmod a directory by selecting it and then pressing Ctrl+Shift+A. In the Manual checkbox, enter 777 and then press OK.<br>
			In WS_FTP, right-click on the directory and choose the chmod UNIX option. In the dialog, select all the checkboxes and click OK. This will chmod the directory 777.<br>');
			} else {
				draw_dialog_start('<div align=middle><font color=red><b>SAFEMODE is ENABLED!</b></font></div><br>PATH OF SYSTEM FILES AND DIRECTORIES&nbsp;&nbsp;&nbsp;&nbsp;<font size="-1"><b>Step 1 of 5</b></font>',
					'
					Your PHP has <b><font color=red>SAFE MODE</font></b> enabled. Pay careful attention to the intructions below:<br><br>
					Due to the brain dead nature of PHP\'s safemode we <font color=red>can not</font> install the forum in a directory
					created by you. Therefor you must install the forum into a directory, which <font color=red>does not yet exist</font>, so that
					the install script can be the one to create it and thus bypass the safe_mode checks.<br>For example, if you wanted to install
					your forum to "/my/home/dir/www/forum", you will need to make sure that "/my/home/dir/www/forum" does not exist and that the
					file permissions of "/my/home/dir/www" allow install script to create "forum" directory inside "/my/home/dir/www".

					');

				if (!count($_POST)) {
					$WWW_ROOT .= 'forum/';
					$SERVER_ROOT .= 'forum/';
					$SERVER_DATA_ROOT = $SERVER_ROOT;
				}
			}

			draw_row('Server Root', 'SERVER_ROOT', $SERVER_ROOT, 'The path on the server where the browseable files of the forum (*.php) will be stored.');
			draw_row('Forum Data Root', 'SERVER_DATA_ROOT', $SERVER_DATA_ROOT, 'The path on the server where the <b>NON-</b>browseable files of the forum will be stored.');
			draw_row('Forum WWW Root', 'WWW_ROOT', $WWW_ROOT, 'This is the URL of your forum, and should point to the forum\'s front page.  This is also the URL people will need to use to get to your forum.');
			break;

		case 'db':
			draw_dialog_start('Database Settings&nbsp;&nbsp;&nbsp;&nbsp;<font size="-1"><b>Step 2 of 5</b></font>', 'FUDforum uses the database to store much of the data used in the forum. Please use the form below to enter information that will allow FUDforum to access the database (leave all but the table prefix empty if using SQLite). It is recommended you create a separate database for the forum.');

			$types = array('mysql'=>'MySQL','pgsql'=>'PostgreSQL','pdo_mysql'=>'PDO: MySQL','pdo_pgsql'=>'PDO: PostgreSQL','pdo_sqlite'=>'PDO: SQLite');
			foreach ($types as $k => $v) {
				if (!$module_status[$k]) {
					unset($types[$k]);
				}
			}

			if (count($types) > 1) {
				draw_row_sel('Database Type','DBTYPE', implode("\n", $types), implode("\n", array_keys($types)), '', (isset($_POST['DBTYPE']) ? $_POST['DBTYPE'] : 'mysql'));
			} else {
				echo '<tr bgcolor="#bff8ff"><td valign="top"><b>Database Type</b></td><td><input type="hidden" name="DBTYPE" value="'.key($types).'">Using '.current($types).'</td></tr>';
			}

			if (isset($_POST['DBHOST'])) {
				$DBHOST = $_POST['DBHOST'];
				$DBHOST_USER = $_POST['DBHOST_USER'];
				$DBHOST_PASSWORD = $_POST['DBHOST_PASSWORD'];
				$DBHOST_DBNAME = $_POST['DBHOST_DBNAME'];
				$DBHOST_TBL_PREFIX = $_POST['DBHOST_TBL_PREFIX'];
			} else {
				$DBHOST = $DBHOST_USER = $DBHOST_PASSWORD = $DBHOST_DBNAME = '';
				$DBHOST_TBL_PREFIX = 'fud26_';
			}

			if (count($types) > 1 || !isset($types['pdo_sqlite'])) { // if using sqlite, don't show non-relavent settings
				draw_row('Host', 'DBHOST', $DBHOST, 'The IP address (or unix domain socket) of the database server.');
				draw_row('User', 'DBHOST_USER', $DBHOST_USER, 'The user name for the database you intend to use the system with.');
				draw_row('Password', 'DBHOST_PASSWORD', $DBHOST_PASSWORD, 'The password for the user name.');
				draw_row('Database', 'DBHOST_DBNAME', $DBHOST_DBNAME, 'The name of the database where forum data will be stored.');
			} else {
				echo '<input type="hidden" name="DBHOST" value=""><input type="hidden" name="DBHOST_USER" value=""><input type="hidden" name="DBHOST_PASSWORD" value=""><input type="hidden" name="DBHOST_DBNAME" value="">';
			}
			draw_row('FUDforum SQL Table Prefix', 'DBHOST_TBL_PREFIX', $DBHOST_TBL_PREFIX, 'A string of text that will be appended to each table name.');
			break;

		case 'cookies':
			if (isset($_POST['COOKIE_DOMAIN'])) {
				$COOKIE_DOMAIN = $_POST['COOKIE_DOMAIN'];
			} else {
				$url_parts = parse_url($_POST['WWW_ROOT']);
				$COOKIE_DOMAIN = preg_replace('!^www\.!i', '.', $url_parts['host']);
			}

			draw_dialog_start('Cookie Domain&nbsp;&nbsp;&nbsp;&nbsp;<font size="-1"><b>Step 3 of 5</b></font>', 'The domain of the cookie that will be used by the forum.');
			draw_row('Cookie Domain', 'COOKIE_DOMAIN', $COOKIE_DOMAIN);
			break;

		case 'language':
			draw_dialog_start('Forum Language&nbsp;&nbsp;&nbsp;&nbsp;<font size="-1"><b>Step 4 of 5</b></font>', 'Choose the language for your forum.<br><font size="-1">If the language you require is not avaliable, please go to <a href="http://fud.prohost.org/forum/" target="_new">FUDforum\'s website</a> and read about translating the forum to other languages.</font>');
			if (!defined('GLOB_NOSORT')) { /* pre PHP 4.3.3 hack for Windows & FreeBSD */
				define('GLOB_NOSORT', 0);
			}
			$selnames = $selopts = '';
			foreach (glob($_POST['SERVER_DATA_ROOT'].'thm/default/i18n/*', GLOB_ONLYDIR|GLOB_NOSORT) as $f) {
				if (file_exists($f . '/locale')) {
					$name = basename($f);
					$selnames .= $name . "\n";
					$selopts .= $name . '::' . trim(file_get_contents($f . '/locale')) . '::' . @trim(file_get_contents($f . '/pspell_lang')) . "\n";
				} 
			}
			draw_row_sel('Language', 'LANGUAGE', rtrim($selnames), rtrim($selopts), NULL, 'english::C::en');
			break;

		case 'admin':
			draw_dialog_start('Admin Account&nbsp;&nbsp;&nbsp;&nbsp;<font size="-1"><b>Step 5 of 5</b></font>', 'This creates the "root" user account, which is an unrestricted account that can do anything on the forum. You must use this account to edit &amp; customize the forum.');

			if (!isset($_POST['ROOT_LOGIN'])) {
				$ROOT_LOGIN = 'admin';
				$ROOT_PASS = $ROOT_PASS_C = '';
				$ADMIN_EMAIL = get_current_user() . '@' . strtok($_SERVER['SERVER_NAME'],':'); // some servers include the port in here
			} else {
				$ROOT_LOGIN = $_POST['ROOT_LOGIN'];
				$ROOT_PASS = $_POST['ROOT_PASS'];
				$ROOT_PASS_C = $_POST['ROOT_PASS_C'];
				$ADMIN_EMAIL = $_POST['ADMIN_EMAIL'];
			}

			draw_row('Login Name', 'ROOT_LOGIN', $ROOT_LOGIN);
			draw_row('Admin Password', 'ROOT_PASS', $ROOT_PASS);
			draw_row('Confirm Password', 'ROOT_PASS_C', $ROOT_PASS_C);
			draw_row('Admin Email', 'ADMIN_EMAIL', $ADMIN_EMAIL);
			break;

		case 'done':
			$GLOBALS['WWW_ROOT_DISK']	= $_POST['SERVER_ROOT'];
			$GLOBALS['DATA_DIR'] 		= $_POST['SERVER_DATA_ROOT'];
			$GLOBALS['INCLUDE'] 		= $_POST['SERVER_DATA_ROOT'] . '/include/';
			$GLOBALS['WWW_ROOT'] 		= $_POST['WWW_ROOT'];
			$GLOBALS['DBHOST_TBL_PREFIX']	= $_POST['DBHOST_TBL_PREFIX'];
			$GLOBALS['FUD_OPT_2'] = 8388608;
			define('__dbtype__', $_POST['DBTYPE']);
			if (!strncmp($_POST['DBTYPE'], 'pdo_', 4)) {
				$GLOBALS['DBHOST_DBTYPE'] = $_POST['DBTYPE'];
			} else {
				$GLOBALS['DBHOST_DBTYPE'] = '';
			}
			$lang = strtok($_POST['LANGUAGE'], '::');

			require($_POST['SERVER_DATA_ROOT'] . 'include/compiler.inc');

			compile_all('default', $lang);

			draw_dialog_start('Installation Complete', 'You have now completed the basic installation of the forum. To continue configuring your forum, you must login and use the administrator control panel.
				Clicking "Finished" will take you to the login form.  After you login, you will be taken to the administrator control panel.<br>
				<font color="#ff0000">Before you do, however, you must delete this <b>install.php</b> script, because it can be used to overwrite your forum.  You will not be able to login until you do.</font>
			');

			/* Remove the install_safe for safe_mode users, because they will not be able to remove it themselves */
			if (SAFE_MODE) {
				unlink(__FILE__);
			}
			if ($no_mem_limit) {
				unlink("./fudforum_archive");
			}

			echo ('<tr><td colspan=2 align="center"><input type="submit" name="submit" value="Finished" onClick="javascript: window.location=\''.$_POST['WWW_ROOT'].'index.php?t=login&adm=1\'; return false;"></td></tr></table></td></tr></table></form></html>');
			break;
	}
	draw_dialog_end($section);

	/* display some system information on the 1st page of the installer */
	if ($section == 'stor_path') {
?>
	<br><table bgcolor="#000000" align="center" border="0" cellspacing="0" cellpadding="1">
	<tr><td><table bgcolor="#FFFFFF" border=0 cellspacing=1 cellpadding=4 align="center">
		<th align="left" colspan=2 bgcolor="#e5ffe7">System Information</th>
		<tr bgcolor="#fffee5"><td><b>PHP Version:</b></td><td><?php echo PHP_VERSION; ?></td></tr>
<?php
	if (open_basedir) {
		echo '<tr bgcolor="#fffee5"><td><b>Open_basedir restriction:</b><br><font size="-1">You will not be able to use PHP to create files outside of the specified directories.</font></td><td>'.open_basedir.'</td></tr>';
	}
	if (fud_ini_get('register_globals')) {
		echo '<tr bgcolor="#fffee5"><td><b>Register Globals:</b><br><font size="-1">For performance &amp; security reasons we recommend keeping this option OFF.</font></td><td><font color="green">enabled</font></td></tr>';
	}
	if ($magic_guotes_gpc) {
		echo '<tr bgcolor="#fffee5"><td><b>Magic quotes gpc:</b><br><font size="-1">For performance reasons we recommend keeping this option OFF.</font></td><td><font color="green">enabled</font></td></tr>';
	}
?>
		<tr bgcolor="#fffee5"><td><b>MySQL Extension:</b><br><font size="-1">Interface to the MySQL server, which is the recommended database for FUDforum.</font></td><td><?php echo ($module_status['mysql'] ? '<font color="green">enabled</font>' : '<font color="red">disabled</font>'); ?></td></tr>
		<tr bgcolor="#fffee5"><td><b>PostgreSQL Extension:</b><br><font size="-1">Interface to the PostgreSQL server.</font></td><td><?php echo ($module_status['pgsql'] ? '<font color="green">enabled</font>' : '<font color="red">disabled</font>'); ?></td></tr>
		<tr bgcolor="#fffee5"><td><b>PCRE Extension:</b><br><font size="-1">Perl Compatible Regular Expression (required).</font></td><td><?php echo ($module_status['pcre'] ? '<font color="green">enabled</font>' : '<font color="red">disabled</font>'); ?></td></tr>

		<tr bgcolor="#fffee5"><td><b>Zlib Extension:</b><br><font size="-1">zlib extension is optional, however we recommend enabling it. This extension allow you to compress your forum backups as well as use zlib compression for your pages.</font></td><td><?php echo ($module_status['zlib'] ? '<font color="green">enabled</font>' : '<font color="red">disabled</font>'); ?></td></tr>
		<tr bgcolor="#fffee5"><td><b>Pspell Extension:</b><br><font size="-1">Pspell extension is optional, this extension is needed by the FUDforum's built-in spellchecker. If you want to allow users to spell check their messages, enable this extension.</font></td><td><?php echo ($module_status['pspell'] ? '<font color="green">enabled</font>' : '<font color="red">disabled</font>'); ?></td></tr>
	</table></td></tr></table>
<?php
	}

	echo '<input type="hidden" name="section" value="'.$section.'">';

	if (isset($_POST['WWW_ROOT']) && $section != 'stor_path') {
		echo '<input type="hidden" name="WWW_ROOT" value="'.$_POST['WWW_ROOT'].'"><input type="hidden" name="SERVER_DATA_ROOT" value="'.$_POST['SERVER_DATA_ROOT'].'"><input type="hidden" name="SERVER_ROOT" value="'.$_POST['SERVER_ROOT'].'">';
	}
	if (isset($_POST['LANGUAGE'])) {
		echo '<input type="hidden" name="LANGUAGE" value="'.$_POST['LANGUAGE'].'">';
	}

	switch ($section) {
		case 'cookies':
		case 'language':
		case 'admin':
		case 'done':
			echo '	<input type="hidden" name="DBHOST" value="'.$_POST['DBHOST'].'">
				<input type="hidden" name="DBHOST_PASSWORD" value="'.$_POST['DBHOST_PASSWORD'].'">
				<input type="hidden" name="DBHOST_USER" value="'.$_POST['DBHOST_USER'].'">
				<input type="hidden" name="DBHOST_DBNAME" value="'.$_POST['DBHOST_DBNAME'].'">
				<input type="hidden" name="DBTYPE" value="'.$_POST['DBTYPE'].'">
				<input type="hidden" name="DBHOST_TBL_PREFIX" value="'.$_POST['DBHOST_TBL_PREFIX'].'">';
			break;
	}
?>
</form>
</body>
</html>
<?php exit; ?>
<?php __HALT_COMPILER(); ?>
897c99aab4169799092804b3b8f4aea60004429249xÚì½msÛF²0ºç©ûEªÚÿsuB2¦(¾I¤(Ë	-Ñ6ÏêmE*NŽãƒ	PBL4JÖf]uÿöýto¿Ì/”èDyžÜªÍ9kÀLOÏLwOwOOÏÎÎÔ–sÓ¶"kg§Ö®Õvv\/Œ¬ÙlggsgçîîÎ|?Êû6±&7NúƒÊ8Aàá#…¦îÌy¬ŒëMfKû±ææNZ׏'»ˆ-õiöX‰`òH‰èfþX‰ùâ‘–O|¯ÞDÖd=‡R{ù¥“ik·37ÆÍZgÜØsêÎt:µš‰]·Ú
h§±_`‹›…yk͖Žá/£Å22ÇËéÔ	\ïÚØkÕj5­À­¸Ö&ÎôÛ	Œ7GCú<Y׆;_Ì܉ÁÓ2¼1jñ—À¹vÃÈ	Ìë™?¶faî7+¸žà?·ú×¹uíNÌOK?‚F¯ý[Ýw}¯º3
,/4C×Ö8Ÿ>|ƒgý­í†‹™uo2™&‡ö»:]zÓ¿u‚™o!DðñÌò>V¯Ýéê¯ïYµýŽU³÷ÆN½±¿Û©·;ÝI§Ó±:ÓZȦՄñ~3xÝÙ·þã/ÿñ—ÿû/ùé¿gÿÏÿõ•¿üÿÀïÿõ¿Nþã/ÐîÌWy`–ë­Îx:iwì¦3·¬q½>iNÝÚ^«=mZÐh»QÛGšùöéþÛü֘ø‹ûÀ½¾‰í¿®Q:*Z­¾
ÿì=ûÖò&Žm<˜aωŒc't¯½^LªÅ™[îÌHý×5ˆ¾_þFU?¸†¢[»kðhTnzµÑÁ†vwê
à£ÞéÖÚÝ֞qcM>ºŽÑÿ¼0¶6Ñэê:°æüœŽc„þ4º³çÀ¸÷—ÆÄò€.`öÇËÈ1ÜÈ°<{ÇŒ¹o»Ó{| –}tãЛyhøSzxsve¼q<'°fÆÅr<`œ¸Ç¦ñMxƒ0¾§âè5â08¯}lE@ʆãB‘ÀÒCÒ6²
°bN dEˆy`ø¬WtÅUatŸî¿ÍM`}㿆æÛþÉÅùë×Æ¡1>v€B¿5\/ÂaBLǁP	럟Bá’íO–s(U½v¢þÌÁŸ¯îvÙøΨÄרðÙ°•(l
½Iô“…€R%Î/ú—=(ãY·îµùŠˆ w¥ÙÏçÓRá|V(/íz²úiïè±Ê§Ö$S‡ˆ(2Æþg#Œ@ˆâ (Á)‚Q0ÑȺ.ùã_*PÀº®ü[ÞüusÝ¥‡[ú²Éo¾1žQËTÝPýìƒÍ/†3e`wοÃ9:3‡ñ`6<´¦ õ¡éÃCh;Õâ©ÿÏšL=æ–Ü܀·Õ)LfX‚_6sF,§*ŽVäuéÐP¿Ÿc¡çXf°<”Î|ô9X9£„¨ñ$=Ã2ÿú=4ŠEª
uWÐy©åÇEì1½É/¾ºÇîZs*8Ÿ#V±ü¾öëaëQ5”(
á+¡ ½ë{6£³©‘¿ªáR¬n¥ZÅHÃ)Ïi<àÃrê%ª¨3Ç»Žn¨o-ÂÌnðx>‰š¯¤;¡úû9úÝB$ž´[_~+éå𧤼@'…Ou9—–wí 	˜”òŠE÷‡¨qDSD–.)¬'U$©²ñŒù˜ÇՂvùvŽÁ+ê	?‰ñ|Y°a-Z%é!ÝX« aÅ#Î2ŒF²cDñX>gi²‘uÛµfþµ’·ŸB 2ۙæŽþ'hT„ù"*Ér<ÚÐãgŸk5ÿDS<>ÕÀ=râ”vþ3Üq¡ª²RÊ'ibÌL.[RòßÓjòÑc¡c”¡ÿqGÔ°ZZ¶Ì«óðÚûö}Å(žøR"ºEx¸‰¢Ewg¾‡¶ÿ3ü@¿wàáÉ!Ð'‚þá?C¸‚1ÙÓL§Éãxâø&~RÊ)@M.´\bÕò…QKÔÜÜXÏDÌBW=0FërÛZ´OÌèAéS+º©‚mcûs1‹Šύ"üßsÍ
ɦ_§'p”¼	hô:q^¼Œ‹×5)Ù7¿Ž‰¡Ê¦¢<Ý:…„0‰³4VéψDHaág…Á.ò=VºðÃu†Õ^¢u
/òÕ)Tr…ZPœ™RD
àW©
h¸¥
áÊßrÏÕɍô¢Rò¥ Ãm£NÒ§ý;C£®!(GJK\€¹e^ª #ñ⹨¡Ydk‰&¢‹uÅGÁ’ìP"	ßD~7+™¾l|µtJ§NTâ_yrɝ[×N¢£ë66ÀšÆÕåIFºókjÿæ¶I­]À´zBH-FÁ¡P>ý”Õ5TXgb5]-‹ÿr"ª6ôR©øºQÈS1~„¯V8š[°YRs»ö)Íòkk$tø±+嘟†nQÃ0*ãm½Æ:ă]ÇÕtýŽHC0©Ëq}ë—@LTà$økG7•ýPÔtø¡s „Ùu¼*}ߦË;
@ø>ùknT‚*X¨…üÙlláa›:,<§¿Ï¢QxÁ?àÍ̙â3¢O‘¿€‡{z€\ҝ¬qèϖ‘S8HŒI¢Ou‘ôƒ–èGÅð=êotã†Çîí†'•—ʬ(.ŒøøE5ŒîgNUxF‘‘
žï9i{å—2
ã™?ùXH«
+‹LÅaz÷¦KÛDà韻¶yc…7Š4Ÿ‰Áš	%´J_©5`èiü^ªä©òÏ+<WPÒ­On<ÙôBµ›×$š	ø797¶ÿH`†dPB"Fy	r±‚ÉÍÈ	æãF~'Ût„¼¡^Í	/€Ý Íc
ÍȀþd²†š8ÊÏÈÉ÷üL¯®Ý[Ç£U¼Bµ-¬lÛFèÏ£ Ú(À‰¡ùXin”îœbàžËýüUœëå4çó"`׺h²bŒ‰j¶qÿoyBšÂêí¸g@•çV:´qcEŒ;p-P‚g¼žpûˆoÃD9!Œ’Oµîuë \Û7,cæFÑÌL¢À2@¸¹ì-³™à9w#–×…‚°\TN+Æ/BGÅW³ÉPM®>ê¡ù'þY!/¡\ú•˜:(+g1]¨âƼJ%l/®¢Ö-½ÍŠá–ÑaW‹ÙM«1³Âh ͕—,l¼LÀL”xQ`pÄ`û\k@ä‚:Ü
9°Ïµ!ˆ%¿ÈçYj†w©â%WgéJÑë2ٓseÃÅ3ÅùΨË?'¾¹ÞÒ¡§/ÂqŸ?g•÷QÜÕ[åØQ&‰¨›d븛
³°$±ÔŒƒgJôbäÍÉ×<#´²¹¬}Ȥ¨p/xݱ…˜¯:tÈ0˜0Ç1Y®ˆn	B«$hc$« {ݨT0
Ô]„'YÖ]£¤Xçþ¼040rà˜€zÞ/+	äVKA‚øÞý*ñ‹paÄRaT|þËóbá%*Ë/vðÓKv’þ"¦uscE§5.=PóHú$¡}Ž@·ø\òpu5&>Z7“Š€B?påÆöpÐoAwaðÓ»R8T¬këzÒ{„úá@•VëàÕS+5B*ëÿoS•F7^üEÏô‚z9*'†â ñnv’mþ¶
hm#[XõönÝ©Oë5«9Þß×víZ«VŸì·v£Vëà&&À<v¼{cøs\þ6)Ö 2	Ìúdf¦µºÓq{õNÇn´[»5§3mMvû}˚„zcÚyñno)è¨öã”`”êÆáK­øaÔð]­B¿é;XDadùpí÷EüR®l–èÂ
² kôý»—A6/Ÿ¦Œ§x¬o{õ½‰ÓœL:­šåì;͚³·;Þmt¦]†ugg·wíÍÉù«ÞÉð}Ñ4__›ýÓÞàÄ|=8õ/M³øAbW’a,†D”XÿÇhwÚ۝ý†cO›­i³6î·af÷'­½z£Õ‚	mí¯ÆèÇâ³ýº3ÝkØ{»{Æ´mïNÆcg:µ:V«½¿×Øm6&㝝F]™ÁÑù™y¢Z,bSuÜÕGDµÄSò[#ñÔL<µô§DÁD¹D±]ýaOhëýaŸÔPٟ×cŽ¶ÝÞo5v;öt<¶š»µÖÞ´=N;“Éx߶u`Žý=9ðäIÃ0ôÅØ6þk	-ÐVáÏ$Y¦Iešâ©EO5ñ´+ZN¶-Z¬s™r̃<.‹¯d°ý}{ºß±{ãæÔ²kÖxZëØû{¶cMÛÕ_[I΃‹ÜÅÈÌük×ûJ|:5ÛÞ·:»Îî~­iÕ[»­I½ÙØ·ö; “wñƒøœ¼9{ˆÝáºXÔËv®Ok“ÝÚ¤ª=nÖ“Úd¿Ó±œÔmtv[1Csxy” ¢‘âw~m„Áä° ––p2çÞDŠ™á$`º!y`iÇø¢Ã,`S÷ç`„ƒÂÊÒK"ŠúÚ@­þ3â%¼°ëš[v¨SKbÕ\Ò̟åA:±–×`0]p­uÁMü|xGð^ÀÚ]–7CÏ·Çß̽ua:ÎÇ<pÃ0´öºÐÂe°Ü(åGµ³6ÔüɪÉÝ_¾É……$¯Íc÷ú,˜<€?8Á½ñÖZ,î%ÔµùbÜçÎppî°vÜûúÚ\âܺ¹Ä؇÷
pÌ3õµ™æÎõrÉè¼—ÀÖfç3X î<Qü4'wƒ»6÷|ZÂچ΢¸ÿß$еÙDžE(àÞK`ksfmÉBëá	nm¶ñœeX¹~Ɵ$ȵùg\“o6ä`)µ×f ¥\Ö>v6Öæ0OîrQ{$¸µ™ÅósQ;ófk³Ç"ð—¹À.ðƒ×Z_Š-¯ó…ØR®OµÙ"ºYÎÇár‘pDߌ«…„º÷UPíó!Àk³²6,oü›<˜W7Æù„¶6‹Ü[ù¾ò±L¡ášÓñp”£9uÇLÝÕԞîBÓ[ºŸ5Õ£ŠEWÓ:emñï~§­Ú_[t»¾¶VvKÚr×-ë«U×ÖW™.¬!]}qè¢èïêRý ¬‹åî³®.N»ßuuAØE1×Õ¥Y—dUW—HÝé¤ûAŸK:/w‰S»:?vÛº:Wu‰gº:gt‘î»:yw‰Ì–‹®N]E{]¶ºH9]>º8ûÝbl˜„‹uuïš3Þo;õÆnÍj9“½©eÕÚV§eï·'5»ƒ§"Z`ĺ÷ðôļì_œ$hH‘Ï¡…#%>¡"^ìn?1<,Ô}ZŸ‹Of.@Ÿé>%<&OkÒ DzB«¦ØÙ~Zx],Ô}ZßÿÛhç‚ûÝwßuÿÈ°ä<©Á“ÿÔ»!>wŸêúh~•m4ð‡A†žuÿ(Ø¥â“å0O
-üº¼õ¥ÓZ^èî“C¤bݧ†jÿÿôÿŒE»lR”ÿ(ÏðSé¾ý‡Bg‹ár-¡ùñ„Î¥âÁöÓÂëb¡îӂ|ö£ù5.0²Öþ/˜4ûžÐ¦ìÆ'u‰¡éùäN1`¯?ª(Úý#`(>­#ÆàéAŽƒë¯çk‚ý¼¾(\Ã鋤ó5êÆZ …×ãIݙÂqòd>MåwyRצtÝ<¡ƒSóýüžÎ„érzJ—ÔSº>¥SëI ä['¦H&ù­AEÕùÌ
£²oÈ°¬çE‹5‹®ºHyò›1_£	•1å·6""	ª‹›ÅZÍL'θ^›ìÖ[ív½Ý±íN£5®O¬Ö.ü_j7k»Mé¤ÄÿÇRGh=£ü»u•?¢‰?»»n­ý‡åxªô¿7{ÄÚÉ#v677¶gG'WÇ}ccCÄZo½{÷μPHP_OPEN_TAGå¼2ÿǯ{£¼ºŒßô//Ï/͋Þè­VûtøÆŽÎ/ûɲ£Ó‹ø	ƒÅ¸”öîüòêÔöG£Áٛ¡ËñëÕ±y~12ëX¡Þn5Ûõf«]?Ð>5ðÓÞþîÞ^§½¿¯iâ:/ºut͞š½ 7—æiïGs8øï>ž¬Á;ßÂÄDNˆ¹òJN©½Öç½VŠÓ	ã³ÁGŒÒÂýì̲Á#~t~þ÷AŸzwU¼<>?í
Î2¯Ïz§ýÌËÑà´~5ÂÙ«µ:ÕЉld‡ýápp~¦­SÁTIœËWoχúœóójؿ̼¼è
‡ïÎ/Óï_%1¯G¯N̋ËþëÁøeº´{f‘°}:¤ ˜ϕ0æ
àè§PÌßðttTqù`¦HE¾¿8¿aùÆnâµ€l÷µr'çoôñÁB54zǧƒ3»4´×— ‹¾ÙzGoOûg£!|Üå]/⃥ˆÚ6µeé
)ì9èõÉñ¥,ÛÌ)ªøepúÆ<:AÙ78©ÆO
ޘ§'<N{‰Päêìèüì5ͼÙÿñbpù”k‹ù²î%bç?ôÍÑ[`÷‘V®™,'z0<œúCsøöüÝv6=& Xz¯Nàe¿7<Ç"…‘3_ø¸³{rәë0^ÌÄæO¿ŒAƒœö½g4W@0 $ú(Þô‘Ö[5’3oæqüE}@
6ß]ö.HJЫ³óÑàõOæëËóS1­„&¯D„hïøélpÄb°çùÞýÜ_†Æ‘²Úf¢99??6ÞöþNtÇÐ7r¸IØý7ƒš;;±vN}/
°Ç¨¹s矾‡=¶^Ç£b@¨Ñ»::êÇsPo7rÅÁiÿôUÿ2g$.ÎON´×©¡3‘üðÃ%3¼Ó?ë_öNø¥yt~u6âIÅ%àx0¢n›'ƒÓÁˆÅìÆ0|9ÓQÀÜõ–	jœÔ(ÕŽz0·ÜMF|¯–ËÇDÝ£ÁèD“B”øšÈ/üþ¨7BIŸä|0ÏÌÓócbú1÷è²ß7%1‘àï_€—ýÎ|^½ú/ó¤+I{— \ößè#³Š.MŒcæ)¹$ÄöS#:ъ¬:dìS¢æíŒä)_^Nú?ôO’ÐêÛûâYïî'D®YÏð¼,ÝJ<ÎnM"ÌãÀLyüš
žC¯NHÖå”)ô°TïjôÖózLŸkƶ,¡vdy˜K#Ä‘/kâõÌý
Ú™¸SP¥H¤"¢í€*é¸0s"@‹×e>)$F
½;í]
qŸHøýí#ß±ƒGW+'WwoÏCmµº»ñÝ°¸§
*/Ñ'ŽBLڂ¶q´»˜¯ú£wýþ±‘»„ajªãs䗁h :e¼êÿt~vlŒÞ†ÆÅùàld\%?_?;g¼{ÛÑSï²õAÍâ1œOK7pJR=¬'`Ë¡ÜÁÃ;dÊ	m›ò…­eH8¦Õ7›zÇnï5¬‰ÝÚí4Æöx^Õ흝F­]³eó×_Õøxs„ê´‹‡…®KЫ¬¶ó‡;w63¬ÅÂÁÃN^肨ĂtŠèy‰ç«_¾|ٌÁ÷ÏhÉوÉúfßÃì‡; éã_½¹«Ðaý„¢U€Êùrfƒ-Üß'ÀÃÎø+˜5Z8†ïi€$©o“º#2]r‡Æ@ä7`éã™I$olÚÑ@¡­"