install/install_install.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/install/install_install.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,2248 @@
     1.4 +<?php
     1.5 +/**
     1.6 +*
     1.7 +* @package install
     1.8 +* @version $Id$
     1.9 +* @copyright (c) 2005 phpBB Group
    1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    1.11 +*
    1.12 +*/
    1.13 +
    1.14 +/**
    1.15 +*/
    1.16 +if (!defined('IN_INSTALL'))
    1.17 +{
    1.18 +	// Someone has tried to access the file direct. This is not a good idea, so exit
    1.19 +	exit;
    1.20 +}
    1.21 +
    1.22 +if (!empty($setmodules))
    1.23 +{
    1.24 +	// If phpBB is already installed we do not include this module
    1.25 +	if (@file_exists($phpbb_root_path . 'config.' . $phpEx) && !file_exists($phpbb_root_path . 'cache/install_lock'))
    1.26 +	{
    1.27 +		include_once($phpbb_root_path . 'config.' . $phpEx);
    1.28 +
    1.29 +		if (defined('PHPBB_INSTALLED'))
    1.30 +		{
    1.31 +			return;
    1.32 +		}
    1.33 +	}
    1.34 +
    1.35 +	$module[] = array(
    1.36 +		'module_type'		=> 'install',
    1.37 +		'module_title'		=> 'INSTALL',
    1.38 +		'module_filename'	=> substr(basename(__FILE__), 0, -strlen($phpEx)-1),
    1.39 +		'module_order'		=> 10,
    1.40 +		'module_subs'		=> '',
    1.41 +		'module_stages'		=> array('INTRO', 'REQUIREMENTS', 'DATABASE', 'ADMINISTRATOR', 'CONFIG_FILE', 'ADVANCED', 'CREATE_TABLE', 'FINAL'),
    1.42 +		'module_reqs'		=> ''
    1.43 +	);
    1.44 +}
    1.45 +
    1.46 +/**
    1.47 +* Installation
    1.48 +* @package install
    1.49 +*/
    1.50 +class install_install extends module
    1.51 +{
    1.52 +	function install_install(&$p_master)
    1.53 +	{
    1.54 +		$this->p_master = &$p_master;
    1.55 +	}
    1.56 +
    1.57 +	function main($mode, $sub)
    1.58 +	{
    1.59 +		global $lang, $template, $language, $phpbb_root_path;
    1.60 +
    1.61 +		switch ($sub)
    1.62 +		{
    1.63 +			case 'intro':
    1.64 +				$this->page_title = $lang['SUB_INTRO'];
    1.65 +
    1.66 +				$template->assign_vars(array(
    1.67 +					'TITLE'			=> $lang['INSTALL_INTRO'],
    1.68 +					'BODY'			=> $lang['INSTALL_INTRO_BODY'],
    1.69 +					'L_SUBMIT'		=> $lang['NEXT_STEP'],
    1.70 +					'S_LANG_SELECT'	=> '<select id="language" name="language">' . $this->p_master->inst_language_select($language) . '</select>',
    1.71 +					'U_ACTION'		=> $this->p_master->module_url . "?mode=$mode&amp;sub=requirements&amp;language=$language",
    1.72 +				));
    1.73 +
    1.74 +			break;
    1.75 +
    1.76 +			case 'requirements':
    1.77 +				$this->check_server_requirements($mode, $sub);
    1.78 +
    1.79 +			break;
    1.80 +
    1.81 +			case 'database':
    1.82 +				$this->obtain_database_settings($mode, $sub);
    1.83 +
    1.84 +			break;
    1.85 +
    1.86 +			case 'administrator':
    1.87 +				$this->obtain_admin_settings($mode, $sub);
    1.88 +
    1.89 +			break;
    1.90 +
    1.91 +			case 'config_file':
    1.92 +				$this->create_config_file($mode, $sub);
    1.93 +
    1.94 +			break;
    1.95 +
    1.96 +			case 'advanced':
    1.97 +				$this->obtain_advanced_settings($mode, $sub);
    1.98 +
    1.99 +			break;
   1.100 +
   1.101 +			case 'create_table':
   1.102 +				$this->load_schema($mode, $sub);
   1.103 +			break;
   1.104 +
   1.105 +			case 'final':
   1.106 +				$this->build_search_index($mode, $sub);
   1.107 +				$this->add_modules($mode, $sub);
   1.108 +				$this->add_language($mode, $sub);
   1.109 +				$this->add_bots($mode, $sub);
   1.110 +				$this->email_admin($mode, $sub);
   1.111 +
   1.112 +				// Remove the lock file
   1.113 +				@unlink($phpbb_root_path . 'cache/install_lock');
   1.114 +
   1.115 +			break;
   1.116 +		}
   1.117 +
   1.118 +		$this->tpl_name = 'install_install';
   1.119 +	}
   1.120 +
   1.121 +	/**
   1.122 +	* Checks that the server we are installing on meets the requirements for running phpBB
   1.123 +	*/
   1.124 +	function check_server_requirements($mode, $sub)
   1.125 +	{
   1.126 +		global $lang, $template, $phpbb_root_path, $phpEx, $language;
   1.127 +
   1.128 +		$this->page_title = $lang['STAGE_REQUIREMENTS'];
   1.129 +
   1.130 +		$template->assign_vars(array(
   1.131 +			'TITLE'		=> $lang['REQUIREMENTS_TITLE'],
   1.132 +			'BODY'		=> $lang['REQUIREMENTS_EXPLAIN'],
   1.133 +		));
   1.134 +
   1.135 +		$passed = array('php' => false, 'db' => false, 'files' => false, 'pcre' => false, 'imagesize' => false,);
   1.136 +
   1.137 +		// Test for basic PHP settings
   1.138 +		$template->assign_block_vars('checks', array(
   1.139 +			'S_LEGEND'			=> true,
   1.140 +			'LEGEND'			=> $lang['PHP_SETTINGS'],
   1.141 +			'LEGEND_EXPLAIN'	=> $lang['PHP_SETTINGS_EXPLAIN'],
   1.142 +		));
   1.143 +
   1.144 +		// Test the minimum PHP version
   1.145 +		$php_version = PHP_VERSION;
   1.146 +
   1.147 +		if (version_compare($php_version, '4.3.3') < 0)
   1.148 +		{
   1.149 +			$result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
   1.150 +		}
   1.151 +		else
   1.152 +		{
   1.153 +			$passed['php'] = true;
   1.154 +
   1.155 +			// We also give feedback on whether we're running in safe mode
   1.156 +			$result = '<strong style="color:green">' . $lang['YES'];
   1.157 +			if (@ini_get('safe_mode') == '1' || strtolower(@ini_get('safe_mode')) == 'on')
   1.158 +			{
   1.159 +				$result .= ', ' . $lang['PHP_SAFE_MODE'];
   1.160 +			}
   1.161 +			$result .= '</strong>';
   1.162 +		}
   1.163 +
   1.164 +		$template->assign_block_vars('checks', array(
   1.165 +			'TITLE'			=> $lang['PHP_VERSION_REQD'],
   1.166 +			'RESULT'		=> $result,
   1.167 +
   1.168 +			'S_EXPLAIN'		=> false,
   1.169 +			'S_LEGEND'		=> false,
   1.170 +		));
   1.171 +
   1.172 +		// Check for register_globals being enabled
   1.173 +		if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on')
   1.174 +		{
   1.175 +			$result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
   1.176 +		}
   1.177 +		else
   1.178 +		{
   1.179 +			$result = '<strong style="color:green">' . $lang['YES'] . '</strong>';
   1.180 +		}
   1.181 +
   1.182 +		$template->assign_block_vars('checks', array(
   1.183 +			'TITLE'			=> $lang['PHP_REGISTER_GLOBALS'],
   1.184 +			'TITLE_EXPLAIN'	=> $lang['PHP_REGISTER_GLOBALS_EXPLAIN'],
   1.185 +			'RESULT'		=> $result,
   1.186 +
   1.187 +			'S_EXPLAIN'		=> true,
   1.188 +			'S_LEGEND'		=> false,
   1.189 +		));
   1.190 +
   1.191 +
   1.192 +		// Check for url_fopen
   1.193 +		if (@ini_get('allow_url_fopen') == '1' || strtolower(@ini_get('allow_url_fopen')) == 'on')
   1.194 +		{
   1.195 +			$result = '<strong style="color:green">' . $lang['YES'] . '</strong>';
   1.196 +		}
   1.197 +		else
   1.198 +		{
   1.199 +			$result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
   1.200 +		}
   1.201 +
   1.202 +		$template->assign_block_vars('checks', array(
   1.203 +			'TITLE'			=> $lang['PHP_URL_FOPEN_SUPPORT'],
   1.204 +			'TITLE_EXPLAIN'	=> $lang['PHP_URL_FOPEN_SUPPORT_EXPLAIN'],
   1.205 +			'RESULT'		=> $result,
   1.206 +
   1.207 +			'S_EXPLAIN'		=> true,
   1.208 +			'S_LEGEND'		=> false,
   1.209 +		));
   1.210 +
   1.211 +
   1.212 +		// Check for getimagesize
   1.213 +		if (@function_exists('getimagesize'))
   1.214 +		{
   1.215 +			$passed['imagesize'] = true;
   1.216 +			$result = '<strong style="color:green">' . $lang['YES'] . '</strong>';
   1.217 +		}
   1.218 +		else
   1.219 +		{
   1.220 +			$result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
   1.221 +		}
   1.222 +
   1.223 +		$template->assign_block_vars('checks', array(
   1.224 +			'TITLE'			=> $lang['PHP_GETIMAGESIZE_SUPPORT'],
   1.225 +			'TITLE_EXPLAIN'	=> $lang['PHP_GETIMAGESIZE_SUPPORT_EXPLAIN'],
   1.226 +			'RESULT'		=> $result,
   1.227 +
   1.228 +			'S_EXPLAIN'		=> true,
   1.229 +			'S_LEGEND'		=> false,
   1.230 +		));
   1.231 +
   1.232 +		// Check for PCRE UTF-8 support
   1.233 +		if (@preg_match('//u', ''))
   1.234 +		{
   1.235 +			$passed['pcre'] = true;
   1.236 +			$result = '<strong style="color:green">' . $lang['YES'] . '</strong>';
   1.237 +		}
   1.238 +		else
   1.239 +		{
   1.240 +			$result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
   1.241 +		}
   1.242 +
   1.243 +		$template->assign_block_vars('checks', array(
   1.244 +			'TITLE'			=> $lang['PCRE_UTF_SUPPORT'],
   1.245 +			'TITLE_EXPLAIN'	=> $lang['PCRE_UTF_SUPPORT_EXPLAIN'],
   1.246 +			'RESULT'		=> $result,
   1.247 +
   1.248 +			'S_EXPLAIN'		=> true,
   1.249 +			'S_LEGEND'		=> false,
   1.250 +		));
   1.251 +
   1.252 +/**
   1.253 +*		Better not enabling and adding to the loaded extensions due to the specific requirements needed
   1.254 +		if (!@extension_loaded('mbstring'))
   1.255 +		{
   1.256 +			can_load_dll('mbstring');
   1.257 +		}
   1.258 +*/
   1.259 +
   1.260 +		$passed['mbstring'] = true;
   1.261 +		if (@extension_loaded('mbstring'))
   1.262 +		{
   1.263 +			// Test for available database modules
   1.264 +			$template->assign_block_vars('checks', array(
   1.265 +				'S_LEGEND'			=> true,
   1.266 +				'LEGEND'			=> $lang['MBSTRING_CHECK'],
   1.267 +				'LEGEND_EXPLAIN'	=> $lang['MBSTRING_CHECK_EXPLAIN'],
   1.268 +			));
   1.269 +
   1.270 +			$checks = array(
   1.271 +				array('func_overload', '&', MB_OVERLOAD_MAIL|MB_OVERLOAD_STRING),
   1.272 +				array('encoding_translation', '!=', 0),
   1.273 +				array('http_input', '!=', 'pass'),
   1.274 +				array('http_output', '!=', 'pass')
   1.275 +			);
   1.276 +
   1.277 +			foreach ($checks as $mb_checks)
   1.278 +			{
   1.279 +				$ini_val = @ini_get('mbstring.' . $mb_checks[0]);
   1.280 +				switch ($mb_checks[1])
   1.281 +				{
   1.282 +					case '&':
   1.283 +						if (intval($ini_val) & $mb_checks[2])
   1.284 +						{
   1.285 +							$result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
   1.286 +							$passed['mbstring'] = false;
   1.287 +						}
   1.288 +						else
   1.289 +						{
   1.290 +							$result = '<strong style="color:green">' . $lang['YES'] . '</strong>';
   1.291 +						}
   1.292 +					break;
   1.293 +
   1.294 +					case '!=':
   1.295 +						if ($ini_val != $mb_checks[2])
   1.296 +						{
   1.297 +							$result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
   1.298 +							$passed['mbstring'] = false;
   1.299 +						}
   1.300 +						else
   1.301 +						{
   1.302 +							$result = '<strong style="color:green">' . $lang['YES'] . '</strong>';
   1.303 +						}
   1.304 +					break;
   1.305 +				}
   1.306 +				$template->assign_block_vars('checks', array(
   1.307 +					'TITLE'			=> $lang['MBSTRING_' . strtoupper($mb_checks[0])],
   1.308 +					'TITLE_EXPLAIN'	=> $lang['MBSTRING_' . strtoupper($mb_checks[0]) . '_EXPLAIN'],
   1.309 +					'RESULT'		=> $result,
   1.310 +
   1.311 +					'S_EXPLAIN'		=> true,
   1.312 +					'S_LEGEND'		=> false,
   1.313 +				));
   1.314 +			}
   1.315 +		}
   1.316 +
   1.317 +		// Test for available database modules
   1.318 +		$template->assign_block_vars('checks', array(
   1.319 +			'S_LEGEND'			=> true,
   1.320 +			'LEGEND'			=> $lang['PHP_SUPPORTED_DB'],
   1.321 +			'LEGEND_EXPLAIN'	=> $lang['PHP_SUPPORTED_DB_EXPLAIN'],
   1.322 +		));
   1.323 +
   1.324 +		$available_dbms = get_available_dbms(false, true);
   1.325 +		$passed['db'] = $available_dbms['ANY_DB_SUPPORT'];
   1.326 +		unset($available_dbms['ANY_DB_SUPPORT']);
   1.327 +
   1.328 +		foreach ($available_dbms as $db_name => $db_ary)
   1.329 +		{
   1.330 +			if (!$db_ary['AVAILABLE'])
   1.331 +			{
   1.332 +				$template->assign_block_vars('checks', array(
   1.333 +					'TITLE'		=> $lang['DLL_' . strtoupper($db_name)],
   1.334 +					'RESULT'	=> '<span style="color:red">' . $lang['UNAVAILABLE'] . '</span>',
   1.335 +
   1.336 +					'S_EXPLAIN'	=> false,
   1.337 +					'S_LEGEND'	=> false,
   1.338 +				));
   1.339 +			}
   1.340 +			else
   1.341 +			{
   1.342 +				$template->assign_block_vars('checks', array(
   1.343 +					'TITLE'		=> $lang['DLL_' . strtoupper($db_name)],
   1.344 +					'RESULT'	=> '<strong style="color:green">' . $lang['AVAILABLE'] . '</strong>',
   1.345 +
   1.346 +					'S_EXPLAIN'	=> false,
   1.347 +					'S_LEGEND'	=> false,
   1.348 +				));
   1.349 +			}
   1.350 +		}
   1.351 +
   1.352 +		// Test for other modules
   1.353 +		$template->assign_block_vars('checks', array(
   1.354 +			'S_LEGEND'			=> true,
   1.355 +			'LEGEND'			=> $lang['PHP_OPTIONAL_MODULE'],
   1.356 +			'LEGEND_EXPLAIN'	=> $lang['PHP_OPTIONAL_MODULE_EXPLAIN'],
   1.357 +		));
   1.358 +
   1.359 +		foreach ($this->php_dlls_other as $dll)
   1.360 +		{
   1.361 +			if (!@extension_loaded($dll))
   1.362 +			{
   1.363 +				if (!can_load_dll($dll))
   1.364 +				{
   1.365 +					$template->assign_block_vars('checks', array(
   1.366 +						'TITLE'		=> $lang['DLL_' . strtoupper($dll)],
   1.367 +						'RESULT'	=> '<strong style="color:red">' . $lang['UNAVAILABLE'] . '</strong>',
   1.368 +
   1.369 +						'S_EXPLAIN'	=> false,
   1.370 +						'S_LEGEND'	=> false,
   1.371 +					));
   1.372 +					continue;
   1.373 +				}
   1.374 +			}
   1.375 +
   1.376 +			$template->assign_block_vars('checks', array(
   1.377 +				'TITLE'		=> $lang['DLL_' . strtoupper($dll)],
   1.378 +				'RESULT'	=> '<strong style="color:green">' . $lang['AVAILABLE'] . '</strong>',
   1.379 +
   1.380 +				'S_EXPLAIN'	=> false,
   1.381 +				'S_LEGEND'	=> false,
   1.382 +			));
   1.383 +		}
   1.384 +
   1.385 +		// Can we find Imagemagick anywhere on the system?
   1.386 +		$exe = (DIRECTORY_SEPARATOR == '\\') ? '.exe' : '';
   1.387 +
   1.388 +		$magic_home = getenv('MAGICK_HOME');
   1.389 +		$img_imagick = '';
   1.390 +		if (empty($magic_home))
   1.391 +		{
   1.392 +			$locations = array('C:/WINDOWS/', 'C:/WINNT/', 'C:/WINDOWS/SYSTEM/', 'C:/WINNT/SYSTEM/', 'C:/WINDOWS/SYSTEM32/', 'C:/WINNT/SYSTEM32/', '/usr/bin/', '/usr/sbin/', '/usr/local/bin/', '/usr/local/sbin/', '/opt/', '/usr/imagemagick/', '/usr/bin/imagemagick/');
   1.393 +			$path_locations = str_replace('\\', '/', (explode(($exe) ? ';' : ':', getenv('PATH'))));
   1.394 +
   1.395 +			$locations = array_merge($path_locations, $locations);
   1.396 +			foreach ($locations as $location)
   1.397 +			{
   1.398 +				// The path might not end properly, fudge it
   1.399 +				if (substr($location, -1, 1) !== '/')
   1.400 +				{
   1.401 +					$location .= '/';
   1.402 +				}
   1.403 +
   1.404 +				if (@file_exists($location) && @is_readable($location . 'mogrify' . $exe) && @filesize($location . 'mogrify' . $exe) > 3000)
   1.405 +				{
   1.406 +					$img_imagick = str_replace('\\', '/', $location);
   1.407 +					continue;
   1.408 +				}
   1.409 +			}
   1.410 +		}
   1.411 +		else
   1.412 +		{
   1.413 +			$img_imagick = str_replace('\\', '/', $magic_home);
   1.414 +		}
   1.415 +
   1.416 +		$template->assign_block_vars('checks', array(
   1.417 +			'TITLE'		=> $lang['APP_MAGICK'],
   1.418 +			'RESULT'	=> ($img_imagick) ? '<strong style="color:green">' . $lang['AVAILABLE'] . ', ' . $img_imagick . '</strong>' : '<strong style="color:blue">' . $lang['NO_LOCATION'] . '</strong>',
   1.419 +
   1.420 +			'S_EXPLAIN'	=> false,
   1.421 +			'S_LEGEND'	=> false,
   1.422 +		));
   1.423 +
   1.424 +		// Check permissions on files/directories we need access to
   1.425 +		$template->assign_block_vars('checks', array(
   1.426 +			'S_LEGEND'			=> true,
   1.427 +			'LEGEND'			=> $lang['FILES_REQUIRED'],
   1.428 +			'LEGEND_EXPLAIN'	=> $lang['FILES_REQUIRED_EXPLAIN'],
   1.429 +		));
   1.430 +
   1.431 +		$directories = array('cache/', 'files/', 'store/');
   1.432 +
   1.433 +		umask(0);
   1.434 +
   1.435 +		$passed['files'] = true;
   1.436 +		foreach ($directories as $dir)
   1.437 +		{
   1.438 +			$exists = $write = false;
   1.439 +
   1.440 +			// Try to create the directory if it does not exist
   1.441 +			if (!file_exists($phpbb_root_path . $dir))
   1.442 +			{
   1.443 +				@mkdir($phpbb_root_path . $dir, 0777);
   1.444 +				phpbb_chmod($phpbb_root_path . $dir, CHMOD_READ | CHMOD_WRITE);
   1.445 +			}
   1.446 +
   1.447 +			// Now really check
   1.448 +			if (file_exists($phpbb_root_path . $dir) && is_dir($phpbb_root_path . $dir))
   1.449 +			{
   1.450 +				phpbb_chmod($phpbb_root_path . $dir, CHMOD_READ | CHMOD_WRITE);
   1.451 +				$exists = true;
   1.452 +			}
   1.453 +
   1.454 +			// Now check if it is writable by storing a simple file
   1.455 +			$fp = @fopen($phpbb_root_path . $dir . 'test_lock', 'wb');
   1.456 +			if ($fp !== false)
   1.457 +			{
   1.458 +				$write = true;
   1.459 +			}
   1.460 +			@fclose($fp);
   1.461 +
   1.462 +			@unlink($phpbb_root_path . $dir . 'test_lock');
   1.463 +
   1.464 +			$passed['files'] = ($exists && $write && $passed['files']) ? true : false;
   1.465 +
   1.466 +			$exists = ($exists) ? '<strong style="color:green">' . $lang['FOUND'] . '</strong>' : '<strong style="color:red">' . $lang['NOT_FOUND'] . '</strong>';
   1.467 +			$write = ($write) ? ', <strong style="color:green">' . $lang['WRITABLE'] . '</strong>' : (($exists) ? ', <strong style="color:red">' . $lang['UNWRITABLE'] . '</strong>' : '');
   1.468 +
   1.469 +			$template->assign_block_vars('checks', array(
   1.470 +				'TITLE'		=> $dir,
   1.471 +				'RESULT'	=> $exists . $write,
   1.472 +
   1.473 +				'S_EXPLAIN'	=> false,
   1.474 +				'S_LEGEND'	=> false,
   1.475 +			));
   1.476 +		}
   1.477 +
   1.478 +		// Check permissions on files/directories it would be useful access to
   1.479 +		$template->assign_block_vars('checks', array(
   1.480 +			'S_LEGEND'			=> true,
   1.481 +			'LEGEND'			=> $lang['FILES_OPTIONAL'],
   1.482 +			'LEGEND_EXPLAIN'	=> $lang['FILES_OPTIONAL_EXPLAIN'],
   1.483 +		));
   1.484 +
   1.485 +		$directories = array('config.' . $phpEx, 'images/avatars/upload/');
   1.486 +
   1.487 +		foreach ($directories as $dir)
   1.488 +		{
   1.489 +			$write = $exists = true;
   1.490 +			if (file_exists($phpbb_root_path . $dir))
   1.491 +			{
   1.492 +				if (!phpbb_is_writable($phpbb_root_path . $dir))
   1.493 +				{
   1.494 +					$write = false;
   1.495 +				}
   1.496 +			}
   1.497 +			else
   1.498 +			{
   1.499 +				$write = $exists = false;
   1.500 +			}
   1.501 +
   1.502 +			$exists_str = ($exists) ? '<strong style="color:green">' . $lang['FOUND'] . '</strong>' : '<strong style="color:red">' . $lang['NOT_FOUND'] . '</strong>';
   1.503 +			$write_str = ($write) ? ', <strong style="color:green">' . $lang['WRITABLE'] . '</strong>' : (($exists) ? ', <strong style="color:red">' . $lang['UNWRITABLE'] . '</strong>' : '');
   1.504 +
   1.505 +			$template->assign_block_vars('checks', array(
   1.506 +				'TITLE'		=> $dir,
   1.507 +				'RESULT'	=> $exists_str . $write_str,
   1.508 +
   1.509 +				'S_EXPLAIN'	=> false,
   1.510 +				'S_LEGEND'	=> false,
   1.511 +			));
   1.512 +		}
   1.513 +
   1.514 +		// And finally where do we want to go next (well today is taken isn't it :P)
   1.515 +		$s_hidden_fields = ($img_imagick) ? '<input type="hidden" name="img_imagick" value="' . addslashes($img_imagick) . '" />' : '';
   1.516 +
   1.517 +		$url = (!in_array(false, $passed)) ? $this->p_master->module_url . "?mode=$mode&amp;sub=database&amp;language=$language" : $this->p_master->module_url . "?mode=$mode&amp;sub=requirements&amp;language=$language	";
   1.518 +		$submit = (!in_array(false, $passed)) ? $lang['INSTALL_START'] : $lang['INSTALL_TEST'];
   1.519 +
   1.520 +
   1.521 +		$template->assign_vars(array(
   1.522 +			'L_SUBMIT'	=> $submit,
   1.523 +			'S_HIDDEN'	=> $s_hidden_fields,
   1.524 +			'U_ACTION'	=> $url,
   1.525 +		));
   1.526 +	}
   1.527 +
   1.528 +	/**
   1.529 +	* Obtain the information required to connect to the database
   1.530 +	*/
   1.531 +	function obtain_database_settings($mode, $sub)
   1.532 +	{
   1.533 +		global $lang, $template, $phpEx;
   1.534 +
   1.535 +		$this->page_title = $lang['STAGE_DATABASE'];
   1.536 +
   1.537 +		// Obtain any submitted data
   1.538 +		$data = $this->get_submitted_data();
   1.539 +
   1.540 +		$connect_test = false;
   1.541 +		$error = array();
   1.542 +		$available_dbms = get_available_dbms(false, true);
   1.543 +
   1.544 +		// Has the user opted to test the connection?
   1.545 +		if (isset($_POST['testdb']))
   1.546 +		{
   1.547 +			if (!isset($available_dbms[$data['dbms']]) || !$available_dbms[$data['dbms']]['AVAILABLE'])
   1.548 +			{
   1.549 +				$error[] = $lang['INST_ERR_NO_DB'];
   1.550 +				$connect_test = false;
   1.551 +			}
   1.552 +			else if (!preg_match(get_preg_expression('table_prefix'), $data['table_prefix']))
   1.553 +			{
   1.554 +				$error[] = $lang['INST_ERR_DB_INVALID_PREFIX'];
   1.555 +				$connect_test = false;
   1.556 +			}
   1.557 +			else
   1.558 +			{
   1.559 +				$connect_test = connect_check_db(true, $error, $available_dbms[$data['dbms']], $data['table_prefix'], $data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport']);
   1.560 +			}
   1.561 +
   1.562 +			$template->assign_block_vars('checks', array(
   1.563 +				'S_LEGEND'			=> true,
   1.564 +				'LEGEND'			=> $lang['DB_CONNECTION'],
   1.565 +				'LEGEND_EXPLAIN'	=> false,
   1.566 +			));
   1.567 +
   1.568 +			if ($connect_test)
   1.569 +			{
   1.570 +				$template->assign_block_vars('checks', array(
   1.571 +					'TITLE'		=> $lang['DB_TEST'],
   1.572 +					'RESULT'	=> '<strong style="color:green">' . $lang['SUCCESSFUL_CONNECT'] . '</strong>',
   1.573 +
   1.574 +					'S_EXPLAIN'	=> false,
   1.575 +					'S_LEGEND'	=> false,
   1.576 +				));
   1.577 +			}
   1.578 +			else
   1.579 +			{
   1.580 +				$template->assign_block_vars('checks', array(
   1.581 +					'TITLE'		=> $lang['DB_TEST'],
   1.582 +					'RESULT'	=> '<strong style="color:red">' . implode('<br />', $error) . '</strong>',
   1.583 +
   1.584 +					'S_EXPLAIN'	=> false,
   1.585 +					'S_LEGEND'	=> false,
   1.586 +				));
   1.587 +			}
   1.588 +		}
   1.589 +
   1.590 +		if (!$connect_test)
   1.591 +		{
   1.592 +			// Update the list of available DBMS modules to only contain those which can be used
   1.593 +			$available_dbms_temp = array();
   1.594 +			foreach ($available_dbms as $type => $dbms_ary)
   1.595 +			{
   1.596 +				if (!$dbms_ary['AVAILABLE'])
   1.597 +				{
   1.598 +					continue;
   1.599 +				}
   1.600 +
   1.601 +				$available_dbms_temp[$type] = $dbms_ary;
   1.602 +			}
   1.603 +
   1.604 +			$available_dbms = &$available_dbms_temp;
   1.605 +
   1.606 +			// And now for the main part of this page
   1.607 +			$data['table_prefix'] = (!empty($data['table_prefix']) ? $data['table_prefix'] : 'phpbb_');
   1.608 +
   1.609 +			foreach ($this->db_config_options as $config_key => $vars)
   1.610 +			{
   1.611 +				if (!is_array($vars) && strpos($config_key, 'legend') === false)
   1.612 +				{
   1.613 +					continue;
   1.614 +				}
   1.615 +
   1.616 +				if (strpos($config_key, 'legend') !== false)
   1.617 +				{
   1.618 +					$template->assign_block_vars('options', array(
   1.619 +						'S_LEGEND'		=> true,
   1.620 +						'LEGEND'		=> $lang[$vars])
   1.621 +					);
   1.622 +
   1.623 +					continue;
   1.624 +				}
   1.625 +
   1.626 +				$options = isset($vars['options']) ? $vars['options'] : '';
   1.627 +
   1.628 +				$template->assign_block_vars('options', array(
   1.629 +					'KEY'			=> $config_key,
   1.630 +					'TITLE'			=> $lang[$vars['lang']],
   1.631 +					'S_EXPLAIN'		=> $vars['explain'],
   1.632 +					'S_LEGEND'		=> false,
   1.633 +					'TITLE_EXPLAIN'	=> ($vars['explain']) ? $lang[$vars['lang'] . '_EXPLAIN'] : '',
   1.634 +					'CONTENT'		=> $this->p_master->input_field($config_key, $vars['type'], $data[$config_key], $options),
   1.635 +					)
   1.636 +				);
   1.637 +			}
   1.638 +		}
   1.639 +
   1.640 +		// And finally where do we want to go next (well today is taken isn't it :P)
   1.641 +		$s_hidden_fields = ($data['img_imagick']) ? '<input type="hidden" name="img_imagick" value="' . addslashes($data['img_imagick']) . '" />' : '';
   1.642 +		$s_hidden_fields .= '<input type="hidden" name="language" value="' . $data['language'] . '" />';
   1.643 +		if ($connect_test)
   1.644 +		{
   1.645 +			foreach ($this->db_config_options as $config_key => $vars)
   1.646 +			{
   1.647 +				if (!is_array($vars))
   1.648 +				{
   1.649 +					continue;
   1.650 +				}
   1.651 +				$s_hidden_fields .= '<input type="hidden" name="' . $config_key . '" value="' . $data[$config_key] . '" />';
   1.652 +			}
   1.653 +		}
   1.654 +
   1.655 +		$url = ($connect_test) ? $this->p_master->module_url . "?mode=$mode&amp;sub=administrator" : $this->p_master->module_url . "?mode=$mode&amp;sub=database";
   1.656 +		$s_hidden_fields .= ($connect_test) ? '' : '<input type="hidden" name="testdb" value="true" />';
   1.657 +
   1.658 +		$submit = $lang['NEXT_STEP'];
   1.659 +
   1.660 +		$template->assign_vars(array(
   1.661 +			'L_SUBMIT'	=> $submit,
   1.662 +			'S_HIDDEN'	=> $s_hidden_fields,
   1.663 +			'U_ACTION'	=> $url,
   1.664 +		));
   1.665 +	}
   1.666 +
   1.667 +	/**
   1.668 +	* Obtain the administrator's name, password and email address
   1.669 +	*/
   1.670 +	function obtain_admin_settings($mode, $sub)
   1.671 +	{
   1.672 +		global $lang, $template, $phpEx;
   1.673 +
   1.674 +		$this->page_title = $lang['STAGE_ADMINISTRATOR'];
   1.675 +
   1.676 +		// Obtain any submitted data
   1.677 +		$data = $this->get_submitted_data();
   1.678 +
   1.679 +		if ($data['dbms'] == '')
   1.680 +		{
   1.681 +			// Someone's been silly and tried calling this page direct
   1.682 +			// So we send them back to the start to do it again properly
   1.683 +			$this->p_master->redirect("index.$phpEx?mode=install");
   1.684 +		}
   1.685 +
   1.686 +		$s_hidden_fields = ($data['img_imagick']) ? '<input type="hidden" name="img_imagick" value="' . addslashes($data['img_imagick']) . '" />' : '';
   1.687 +		$passed = false;
   1.688 +
   1.689 +		$data['default_lang'] = ($data['default_lang'] !== '') ? $data['default_lang'] : $data['language'];
   1.690 +
   1.691 +		if (isset($_POST['check']))
   1.692 +		{
   1.693 +			$error = array();
   1.694 +
   1.695 +			// Check the entered email address and password
   1.696 +			if ($data['admin_name'] == '' || $data['admin_pass1'] == '' || $data['admin_pass2'] == '' || $data['board_email1'] == '' || $data['board_email2'] == '')
   1.697 +			{
   1.698 +				$error[] = $lang['INST_ERR_MISSING_DATA'];
   1.699 +			}
   1.700 +
   1.701 +			if ($data['admin_pass1'] != $data['admin_pass2'] && $data['admin_pass1'] != '')
   1.702 +			{
   1.703 +				$error[] = $lang['INST_ERR_PASSWORD_MISMATCH'];
   1.704 +			}
   1.705 +
   1.706 +			// Test against the default username rules
   1.707 +			if ($data['admin_name'] != '' && utf8_strlen($data['admin_name']) < 3)
   1.708 +			{
   1.709 +				$error[] = $lang['INST_ERR_USER_TOO_SHORT'];
   1.710 +			}
   1.711 +
   1.712 +			if ($data['admin_name'] != '' && utf8_strlen($data['admin_name']) > 20)
   1.713 +			{
   1.714 +				$error[] = $lang['INST_ERR_USER_TOO_LONG'];
   1.715 +			}
   1.716 +
   1.717 +			// Test against the default password rules
   1.718 +			if ($data['admin_pass1'] != '' && utf8_strlen($data['admin_pass1']) < 6)
   1.719 +			{
   1.720 +				$error[] = $lang['INST_ERR_PASSWORD_TOO_SHORT'];
   1.721 +			}
   1.722 +
   1.723 +			if ($data['admin_pass1'] != '' && utf8_strlen($data['admin_pass1']) > 30)
   1.724 +			{
   1.725 +				$error[] = $lang['INST_ERR_PASSWORD_TOO_LONG'];
   1.726 +			}
   1.727 +
   1.728 +			if ($data['board_email1'] != $data['board_email2'] && $data['board_email1'] != '')
   1.729 +			{
   1.730 +				$error[] = $lang['INST_ERR_EMAIL_MISMATCH'];
   1.731 +			}
   1.732 +
   1.733 +			if ($data['board_email1'] != '' && !preg_match('/^' . get_preg_expression('email') . '$/i', $data['board_email1']))
   1.734 +			{
   1.735 +				$error[] = $lang['INST_ERR_EMAIL_INVALID'];
   1.736 +			}
   1.737 +
   1.738 +			$template->assign_block_vars('checks', array(
   1.739 +				'S_LEGEND'			=> true,
   1.740 +				'LEGEND'			=> $lang['STAGE_ADMINISTRATOR'],
   1.741 +				'LEGEND_EXPLAIN'	=> false,
   1.742 +			));
   1.743 +
   1.744 +			if (!sizeof($error))
   1.745 +			{
   1.746 +				$passed = true;
   1.747 +				$template->assign_block_vars('checks', array(
   1.748 +					'TITLE'		=> $lang['ADMIN_TEST'],
   1.749 +					'RESULT'	=> '<strong style="color:green">' . $lang['TESTS_PASSED'] . '</strong>',
   1.750 +
   1.751 +					'S_EXPLAIN'	=> false,
   1.752 +					'S_LEGEND'	=> false,
   1.753 +				));
   1.754 +			}
   1.755 +			else
   1.756 +			{
   1.757 +				$template->assign_block_vars('checks', array(
   1.758 +					'TITLE'		=> $lang['ADMIN_TEST'],
   1.759 +					'RESULT'	=> '<strong style="color:red">' . implode('<br />', $error) . '</strong>',
   1.760 +
   1.761 +					'S_EXPLAIN'	=> false,
   1.762 +					'S_LEGEND'	=> false,
   1.763 +				));
   1.764 +			}
   1.765 +		}
   1.766 +
   1.767 +		if (!$passed)
   1.768 +		{
   1.769 +			foreach ($this->admin_config_options as $config_key => $vars)
   1.770 +			{
   1.771 +				if (!is_array($vars) && strpos($config_key, 'legend') === false)
   1.772 +				{
   1.773 +					continue;
   1.774 +				}
   1.775 +
   1.776 +				if (strpos($config_key, 'legend') !== false)
   1.777 +				{
   1.778 +					$template->assign_block_vars('options', array(
   1.779 +						'S_LEGEND'		=> true,
   1.780 +						'LEGEND'		=> $lang[$vars])
   1.781 +					);
   1.782 +
   1.783 +					continue;
   1.784 +				}
   1.785 +
   1.786 +				$options = isset($vars['options']) ? $vars['options'] : '';
   1.787 +
   1.788 +				$template->assign_block_vars('options', array(
   1.789 +					'KEY'			=> $config_key,
   1.790 +					'TITLE'			=> $lang[$vars['lang']],
   1.791 +					'S_EXPLAIN'		=> $vars['explain'],
   1.792 +					'S_LEGEND'		=> false,
   1.793 +					'TITLE_EXPLAIN'	=> ($vars['explain']) ? $lang[$vars['lang'] . '_EXPLAIN'] : '',
   1.794 +					'CONTENT'		=> $this->p_master->input_field($config_key, $vars['type'], $data[$config_key], $options),
   1.795 +					)
   1.796 +				);
   1.797 +			}
   1.798 +		}
   1.799 +		else
   1.800 +		{
   1.801 +			foreach ($this->admin_config_options as $config_key => $vars)
   1.802 +			{
   1.803 +				if (!is_array($vars))
   1.804 +				{
   1.805 +					continue;
   1.806 +				}
   1.807 +				$s_hidden_fields .= '<input type="hidden" name="' . $config_key . '" value="' . $data[$config_key] . '" />';
   1.808 +			}
   1.809 +		}
   1.810 +
   1.811 +		$s_hidden_fields .= ($data['img_imagick']) ? '<input type="hidden" name="img_imagick" value="' . addslashes($data['img_imagick']) . '" />' : '';
   1.812 +		$s_hidden_fields .= '<input type="hidden" name="language" value="' . $data['language'] . '" />';
   1.813 +
   1.814 +		foreach ($this->db_config_options as $config_key => $vars)
   1.815 +		{
   1.816 +			if (!is_array($vars))
   1.817 +			{
   1.818 +				continue;
   1.819 +			}
   1.820 +			$s_hidden_fields .= '<input type="hidden" name="' . $config_key . '" value="' . $data[$config_key] . '" />';
   1.821 +		}
   1.822 +
   1.823 +		$submit = $lang['NEXT_STEP'];
   1.824 +
   1.825 +		$url = ($passed) ? $this->p_master->module_url . "?mode=$mode&amp;sub=config_file" : $this->p_master->module_url . "?mode=$mode&amp;sub=administrator";
   1.826 +		$s_hidden_fields .= ($passed) ? '' : '<input type="hidden" name="check" value="true" />';
   1.827 +
   1.828 +		$template->assign_vars(array(
   1.829 +			'L_SUBMIT'	=> $submit,
   1.830 +			'S_HIDDEN'	=> $s_hidden_fields,
   1.831 +			'U_ACTION'	=> $url,
   1.832 +		));
   1.833 +	}
   1.834 +
   1.835 +	/**
   1.836 +	* Writes the config file to disk, or if unable to do so offers alternative methods
   1.837 +	*/
   1.838 +	function create_config_file($mode, $sub)
   1.839 +	{
   1.840 +		global $lang, $template, $phpbb_root_path, $phpEx;
   1.841 +
   1.842 +		$this->page_title = $lang['STAGE_CONFIG_FILE'];
   1.843 +
   1.844 +		// Obtain any submitted data
   1.845 +		$data = $this->get_submitted_data();
   1.846 +
   1.847 +		if ($data['dbms'] == '')
   1.848 +		{
   1.849 +			// Someone's been silly and tried calling this page direct
   1.850 +			// So we send them back to the start to do it again properly
   1.851 +			$this->p_master->redirect("index.$phpEx?mode=install");
   1.852 +		}
   1.853 +
   1.854 +		$s_hidden_fields = ($data['img_imagick']) ? '<input type="hidden" name="img_imagick" value="' . addslashes($data['img_imagick']) . '" />' : '';
   1.855 +		$s_hidden_fields .= '<input type="hidden" name="language" value="' . $data['language'] . '" />';
   1.856 +		$written = false;
   1.857 +
   1.858 +		// Create a list of any PHP modules we wish to have loaded
   1.859 +		$load_extensions = array();
   1.860 +		$available_dbms = get_available_dbms($data['dbms']);
   1.861 +		$check_exts = array_merge(array($available_dbms[$data['dbms']]['MODULE']), $this->php_dlls_other);
   1.862 +
   1.863 +		foreach ($check_exts as $dll)
   1.864 +		{
   1.865 +			if (!@extension_loaded($dll))
   1.866 +			{
   1.867 +				if (!can_load_dll($dll))
   1.868 +				{
   1.869 +					continue;
   1.870 +				}
   1.871 +
   1.872 +				$load_extensions[] = $dll . '.' . PHP_SHLIB_SUFFIX;
   1.873 +			}
   1.874 +		}
   1.875 +
   1.876 +		// Create a lock file to indicate that there is an install in progress
   1.877 +		$fp = @fopen($phpbb_root_path . 'cache/install_lock', 'wb');
   1.878 +		if ($fp === false)
   1.879 +		{
   1.880 +			// We were unable to create the lock file - abort
   1.881 +			$this->p_master->error($lang['UNABLE_WRITE_LOCK'], __LINE__, __FILE__);
   1.882 +		}
   1.883 +		@fclose($fp);
   1.884 +
   1.885 +		@chmod($phpbb_root_path . 'cache/install_lock', 0777);
   1.886 +
   1.887 +		$load_extensions = implode(',', $load_extensions);
   1.888 +
   1.889 +		// Time to convert the data provided into a config file
   1.890 +		$config_data = "<?php\n";
   1.891 +		$config_data .= "// phpBB 3.0.x auto-generated configuration file\n// Do not change anything in this file!\n";
   1.892 +
   1.893 +		$config_data_array = array(
   1.894 +			'dbms'			=> $available_dbms[$data['dbms']]['DRIVER'],
   1.895 +			'dbhost'		=> $data['dbhost'],
   1.896 +			'dbport'		=> $data['dbport'],
   1.897 +			'dbname'		=> $data['dbname'],
   1.898 +			'dbuser'		=> $data['dbuser'],
   1.899 +			'dbpasswd'		=> htmlspecialchars_decode($data['dbpasswd']),
   1.900 +			'table_prefix'	=> $data['table_prefix'],
   1.901 +			'acm_type'		=> 'file',
   1.902 +			'load_extensions'	=> $load_extensions,
   1.903 +		);
   1.904 +
   1.905 +		foreach ($config_data_array as $key => $value)
   1.906 +		{
   1.907 +			$config_data .= "\${$key} = '" . str_replace("'", "\\'", str_replace('\\', '\\\\', $value)) . "';\n";
   1.908 +		}
   1.909 +		unset($config_data_array);
   1.910 +
   1.911 +		$config_data .= "\n@define('PHPBB_INSTALLED', true);\n";
   1.912 +		$config_data .= "// @define('DEBUG', true);\n";
   1.913 +		$config_data .= "// @define('DEBUG_EXTRA', true);\n";
   1.914 +		$config_data .= '?' . '>'; // Done this to prevent highlighting editors getting confused!
   1.915 +
   1.916 +		// Attempt to write out the config file directly. If it works, this is the easiest way to do it ...
   1.917 +		if ((file_exists($phpbb_root_path . 'config.' . $phpEx) && phpbb_is_writable($phpbb_root_path . 'config.' . $phpEx)) || phpbb_is_writable($phpbb_root_path))
   1.918 +		{
   1.919 +			// Assume it will work ... if nothing goes wrong below
   1.920 +			$written = true;
   1.921 +
   1.922 +			if (!($fp = @fopen($phpbb_root_path . 'config.' . $phpEx, 'w')))
   1.923 +			{
   1.924 +				// Something went wrong ... so let's try another method
   1.925 +				$written = false;
   1.926 +			}
   1.927 +
   1.928 +			if (!(@fwrite($fp, $config_data)))
   1.929 +			{
   1.930 +				// Something went wrong ... so let's try another method
   1.931 +				$written = false;
   1.932 +			}
   1.933 +
   1.934 +			@fclose($fp);
   1.935 +
   1.936 +			if ($written)
   1.937 +			{
   1.938 +				// We may revert back to chmod() if we see problems with users not able to change their config.php file directly
   1.939 +				phpbb_chmod($phpbb_root_path . 'config.' . $phpEx, CHMOD_READ);
   1.940 +			}
   1.941 +		}
   1.942 +
   1.943 +		if (isset($_POST['dldone']))
   1.944 +		{
   1.945 +			// Do a basic check to make sure that the file has been uploaded
   1.946 +			// Note that all we check is that the file has _something_ in it
   1.947 +			// We don't compare the contents exactly - if they can't upload
   1.948 +			// a single file correctly, it's likely they will have other problems....
   1.949 +			if (filesize($phpbb_root_path . 'config.' . $phpEx) > 10)
   1.950 +			{
   1.951 +				$written = true;
   1.952 +			}
   1.953 +		}
   1.954 +
   1.955 +		$config_options = array_merge($this->db_config_options, $this->admin_config_options);
   1.956 +
   1.957 +		foreach ($config_options as $config_key => $vars)
   1.958 +		{
   1.959 +			if (!is_array($vars))
   1.960 +			{
   1.961 +				continue;
   1.962 +			}
   1.963 +			$s_hidden_fields .= '<input type="hidden" name="' . $config_key . '" value="' . $data[$config_key] . '" />';
   1.964 +		}
   1.965 +
   1.966 +		if (!$written)
   1.967 +		{
   1.968 +			// OK, so it didn't work let's try the alternatives
   1.969 +
   1.970 +			if (isset($_POST['dlconfig']))
   1.971 +			{
   1.972 +				// They want a copy of the file to download, so send the relevant headers and dump out the data
   1.973 +				header("Content-Type: text/x-delimtext; name=\"config.$phpEx\"");
   1.974 +				header("Content-disposition: attachment; filename=config.$phpEx");
   1.975 +				echo $config_data;
   1.976 +				exit;
   1.977 +			}
   1.978 +
   1.979 +			// The option to download the config file is always available, so output it here
   1.980 +			$template->assign_vars(array(
   1.981 +				'BODY'					=> $lang['CONFIG_FILE_UNABLE_WRITE'],
   1.982 +				'L_DL_CONFIG'			=> $lang['DL_CONFIG'],
   1.983 +				'L_DL_CONFIG_EXPLAIN'	=> $lang['DL_CONFIG_EXPLAIN'],
   1.984 +				'L_DL_DONE'				=> $lang['DONE'],
   1.985 +				'L_DL_DOWNLOAD'			=> $lang['DL_DOWNLOAD'],
   1.986 +				'S_HIDDEN'				=> $s_hidden_fields,
   1.987 +				'S_SHOW_DOWNLOAD'		=> true,
   1.988 +				'U_ACTION'				=> $this->p_master->module_url . "?mode=$mode&amp;sub=config_file",
   1.989 +			));
   1.990 +			return;
   1.991 +		}
   1.992 +		else
   1.993 +		{
   1.994 +			$template->assign_vars(array(
   1.995 +				'BODY'		=> $lang['CONFIG_FILE_WRITTEN'],
   1.996 +				'L_SUBMIT'	=> $lang['NEXT_STEP'],
   1.997 +				'S_HIDDEN'	=> $s_hidden_fields,
   1.998 +				'U_ACTION'	=> $this->p_master->module_url . "?mode=$mode&amp;sub=advanced",
   1.999 +			));
  1.1000 +			return;
  1.1001 +		}
  1.1002 +	}
  1.1003 +
  1.1004 +	/**
  1.1005 +	* Provide an opportunity to customise some advanced settings during the install
  1.1006 +	* in case it is necessary for them to be set to access later
  1.1007 +	*/
  1.1008 +	function obtain_advanced_settings($mode, $sub)
  1.1009 +	{
  1.1010 +		global $lang, $template, $phpEx;
  1.1011 +
  1.1012 +		$this->page_title = $lang['STAGE_ADVANCED'];
  1.1013 +
  1.1014 +		// Obtain any submitted data
  1.1015 +		$data = $this->get_submitted_data();
  1.1016 +
  1.1017 +		if ($data['dbms'] == '')
  1.1018 +		{
  1.1019 +			// Someone's been silly and tried calling this page direct
  1.1020 +			// So we send them back to the start to do it again properly
  1.1021 +			$this->p_master->redirect("index.$phpEx?mode=install");
  1.1022 +		}
  1.1023 +
  1.1024 +		$s_hidden_fields = ($data['img_imagick']) ? '<input type="hidden" name="img_imagick" value="' . addslashes($data['img_imagick']) . '" />' : '';
  1.1025 +		$s_hidden_fields .= '<input type="hidden" name="language" value="' . $data['language'] . '" />';
  1.1026 +
  1.1027 +		// HTTP_HOST is having the correct browser url in most cases...
  1.1028 +		$server_name = (!empty($_SERVER['HTTP_HOST'])) ? strtolower($_SERVER['HTTP_HOST']) : ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME'));
  1.1029 +
  1.1030 +		// HTTP HOST can carry a port number...
  1.1031 +		if (strpos($server_name, ':') !== false)
  1.1032 +		{
  1.1033 +			$server_name = substr($server_name, 0, strpos($server_name, ':'));
  1.1034 +		}
  1.1035 +
  1.1036 +		$data['email_enable'] = ($data['email_enable'] !== '') ? $data['email_enable'] : true;
  1.1037 +		$data['server_name'] = ($data['server_name'] !== '') ? $data['server_name'] : $server_name;
  1.1038 +		$data['server_port'] = ($data['server_port'] !== '') ? $data['server_port'] : ((!empty($_SERVER['SERVER_PORT'])) ? (int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT'));
  1.1039 +		$data['server_protocol'] = ($data['server_protocol'] !== '') ? $data['server_protocol'] : ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://');
  1.1040 +		$data['cookie_secure'] = ($data['cookie_secure'] !== '') ? $data['cookie_secure'] : ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? true : false);
  1.1041 +
  1.1042 +		if ($data['script_path'] === '')
  1.1043 +		{
  1.1044 +			$name = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF');
  1.1045 +			if (!$name)
  1.1046 +			{
  1.1047 +				$name = (!empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI');
  1.1048 +			}
  1.1049 +
  1.1050 +			// Replace backslashes and doubled slashes (could happen on some proxy setups)
  1.1051 +			$name = str_replace(array('\\', '//', '/install'), '/', $name);
  1.1052 +			$data['script_path'] = trim(dirname($name));
  1.1053 +		}
  1.1054 +
  1.1055 +		foreach ($this->advanced_config_options as $config_key => $vars)
  1.1056 +		{
  1.1057 +			if (!is_array($vars) && strpos($config_key, 'legend') === false)
  1.1058 +			{
  1.1059 +				continue;
  1.1060 +			}
  1.1061 +
  1.1062 +			if (strpos($config_key, 'legend') !== false)
  1.1063 +			{
  1.1064 +				$template->assign_block_vars('options', array(
  1.1065 +					'S_LEGEND'		=> true,
  1.1066 +					'LEGEND'		=> $lang[$vars])
  1.1067 +				);
  1.1068 +
  1.1069 +				continue;
  1.1070 +			}
  1.1071 +
  1.1072 +			$options = isset($vars['options']) ? $vars['options'] : '';
  1.1073 +
  1.1074 +			$template->assign_block_vars('options', array(
  1.1075 +				'KEY'			=> $config_key,
  1.1076 +				'TITLE'			=> $lang[$vars['lang']],
  1.1077 +				'S_EXPLAIN'		=> $vars['explain'],
  1.1078 +				'S_LEGEND'		=> false,
  1.1079 +				'TITLE_EXPLAIN'	=> ($vars['explain']) ? $lang[$vars['lang'] . '_EXPLAIN'] : '',
  1.1080 +				'CONTENT'		=> $this->p_master->input_field($config_key, $vars['type'], $data[$config_key], $options),
  1.1081 +				)
  1.1082 +			);
  1.1083 +		}
  1.1084 +
  1.1085 +		$config_options = array_merge($this->db_config_options, $this->admin_config_options);
  1.1086 +		foreach ($config_options as $config_key => $vars)
  1.1087 +		{
  1.1088 +			if (!is_array($vars))
  1.1089 +			{
  1.1090 +				continue;
  1.1091 +			}
  1.1092 +			$s_hidden_fields .= '<input type="hidden" name="' . $config_key . '" value="' . $data[$config_key] . '" />';
  1.1093 +		}
  1.1094 +
  1.1095 +		$submit = $lang['NEXT_STEP'];
  1.1096 +
  1.1097 +		$url = $this->p_master->module_url . "?mode=$mode&amp;sub=create_table";
  1.1098 +
  1.1099 +		$template->assign_vars(array(
  1.1100 +			'BODY'		=> $lang['STAGE_ADVANCED_EXPLAIN'],
  1.1101 +			'L_SUBMIT'	=> $submit,
  1.1102 +			'S_HIDDEN'	=> $s_hidden_fields,
  1.1103 +			'U_ACTION'	=> $url,
  1.1104 +		));
  1.1105 +	}
  1.1106 +
  1.1107 +	/**
  1.1108 +	* Load the contents of the schema into the database and then alter it based on what has been input during the installation
  1.1109 +	*/
  1.1110 +	function load_schema($mode, $sub)
  1.1111 +	{
  1.1112 +		global $db, $lang, $template, $phpbb_root_path, $phpEx;
  1.1113 +
  1.1114 +		$this->page_title = $lang['STAGE_CREATE_TABLE'];
  1.1115 +		$s_hidden_fields = '';
  1.1116 +
  1.1117 +		// Obtain any submitted data
  1.1118 +		$data = $this->get_submitted_data();
  1.1119 +
  1.1120 +		if ($data['dbms'] == '')
  1.1121 +		{
  1.1122 +			// Someone's been silly and tried calling this page direct
  1.1123 +			// So we send them back to the start to do it again properly
  1.1124 +			$this->p_master->redirect("index.$phpEx?mode=install");
  1.1125 +		}
  1.1126 +
  1.1127 +		// HTTP_HOST is having the correct browser url in most cases...
  1.1128 +		$server_name = (!empty($_SERVER['HTTP_HOST'])) ? strtolower($_SERVER['HTTP_HOST']) : ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME'));
  1.1129 +		$referer = (!empty($_SERVER['HTTP_REFERER'])) ? strtolower($_SERVER['HTTP_REFERER']) : getenv('HTTP_REFERER');
  1.1130 +
  1.1131 +		// HTTP HOST can carry a port number...
  1.1132 +		if (strpos($server_name, ':') !== false)
  1.1133 +		{
  1.1134 +			$server_name = substr($server_name, 0, strpos($server_name, ':'));
  1.1135 +		}
  1.1136 +
  1.1137 +		$cookie_domain = ($data['server_name'] != '') ? $data['server_name'] : $server_name;
  1.1138 +
  1.1139 +		// Try to come up with the best solution for cookie domain...
  1.1140 +		if (strpos($cookie_domain, 'www.') === 0)
  1.1141 +		{
  1.1142 +			$cookie_domain = str_replace('www.', '.', $cookie_domain);
  1.1143 +		}
  1.1144 +
  1.1145 +		// If we get here and the extension isn't loaded it should be safe to just go ahead and load it
  1.1146 +		$available_dbms = get_available_dbms($data['dbms']);
  1.1147 +
  1.1148 +		if (!isset($available_dbms[$data['dbms']]))
  1.1149 +		{
  1.1150 +			// Someone's been silly and tried providing a non-existant dbms
  1.1151 +			$this->p_master->redirect("index.$phpEx?mode=install");
  1.1152 +		}
  1.1153 +
  1.1154 +		$dbms = $available_dbms[$data['dbms']]['DRIVER'];
  1.1155 +
  1.1156 +		// Load the appropriate database class if not already loaded
  1.1157 +		include($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
  1.1158 +
  1.1159 +		// Instantiate the database
  1.1160 +		$db = new $sql_db();
  1.1161 +		$db->sql_connect($data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport'], false, false);
  1.1162 +
  1.1163 +		// NOTE: trigger_error does not work here.
  1.1164 +		$db->sql_return_on_error(true);
  1.1165 +
  1.1166 +		// If mysql is chosen, we need to adjust the schema filename slightly to reflect the correct version. ;)
  1.1167 +		if ($data['dbms'] == 'mysql')
  1.1168 +		{
  1.1169 +			if (version_compare($db->sql_server_info(true), '4.1.3', '>='))
  1.1170 +			{
  1.1171 +				$available_dbms[$data['dbms']]['SCHEMA'] .= '_41';
  1.1172 +			}
  1.1173 +			else
  1.1174 +			{
  1.1175 +				$available_dbms[$data['dbms']]['SCHEMA'] .= '_40';
  1.1176 +			}
  1.1177 +		}
  1.1178 +
  1.1179 +		// Ok we have the db info go ahead and read in the relevant schema
  1.1180 +		// and work on building the table
  1.1181 +		$dbms_schema = 'schemas/' . $available_dbms[$data['dbms']]['SCHEMA'] . '_schema.sql';
  1.1182 +
  1.1183 +		// How should we treat this schema?
  1.1184 +		$remove_remarks = $available_dbms[$data['dbms']]['COMMENTS'];
  1.1185 +		$delimiter = $available_dbms[$data['dbms']]['DELIM'];
  1.1186 +
  1.1187 +		$sql_query = @file_get_contents($dbms_schema);
  1.1188 +
  1.1189 +		$sql_query = preg_replace('#phpbb_#i', $data['table_prefix'], $sql_query);
  1.1190 +
  1.1191 +		$remove_remarks($sql_query);
  1.1192 +
  1.1193 +		$sql_query = split_sql_file($sql_query, $delimiter);
  1.1194 +
  1.1195 +		foreach ($sql_query as $sql)
  1.1196 +		{
  1.1197 +			//$sql = trim(str_replace('|', ';', $sql));
  1.1198 +			if (!$db->sql_query($sql))
  1.1199 +			{
  1.1200 +				$error = $db->sql_error();
  1.1201 +				$this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__);
  1.1202 +			}
  1.1203 +		}
  1.1204 +		unset($sql_query);
  1.1205 +
  1.1206 +		// Ok tables have been built, let's fill in the basic information
  1.1207 +		$sql_query = file_get_contents('schemas/schema_data.sql');
  1.1208 +
  1.1209 +		// Deal with any special comments
  1.1210 +		switch ($data['dbms'])
  1.1211 +		{
  1.1212 +			case 'mssql':
  1.1213 +			case 'mssql_odbc':
  1.1214 +			case 'mssqlnative':
  1.1215 +				$sql_query = preg_replace('#\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \##s', 'SET IDENTITY_INSERT \1 \2;', $sql_query);
  1.1216 +			break;
  1.1217 +
  1.1218 +			case 'postgres':
  1.1219 +				$sql_query = preg_replace('#\# POSTGRES (BEGIN|COMMIT) \##s', '\1; ', $sql_query);
  1.1220 +			break;
  1.1221 +		}
  1.1222 +
  1.1223 +		// Change prefix
  1.1224 +		$sql_query = preg_replace('# phpbb_([^\s]*) #i', ' ' . $data['table_prefix'] . '\1 ', $sql_query);
  1.1225 +
  1.1226 +		// Change language strings...
  1.1227 +		$sql_query = preg_replace_callback('#\{L_([A-Z0-9\-_]*)\}#s', 'adjust_language_keys_callback', $sql_query);
  1.1228 +
  1.1229 +		// Since there is only one schema file we know the comment style and are able to remove it directly with remove_remarks
  1.1230 +		remove_remarks($sql_query);
  1.1231 +		$sql_query = split_sql_file($sql_query, ';');
  1.1232 +
  1.1233 +		foreach ($sql_query as $sql)
  1.1234 +		{
  1.1235 +			//$sql = trim(str_replace('|', ';', $sql));
  1.1236 +			if (!$db->sql_query($sql))
  1.1237 +			{
  1.1238 +				$error = $db->sql_error();
  1.1239 +				$this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__);
  1.1240 +			}
  1.1241 +		}
  1.1242 +		unset($sql_query);
  1.1243 +
  1.1244 +		$current_time = time();
  1.1245 +
  1.1246 +		$user_ip = (!empty($_SERVER['REMOTE_ADDR'])) ? htmlspecialchars($_SERVER['REMOTE_ADDR']) : '';
  1.1247 +		$user_ip = (stripos($user_ip, '::ffff:') === 0) ? substr($user_ip, 7) : $user_ip;
  1.1248 +
  1.1249 +		if ($data['script_path'] !== '/')
  1.1250 +		{
  1.1251 +			// Adjust destination path (no trailing slash)
  1.1252 +			if (substr($data['script_path'], -1) == '/')
  1.1253 +			{
  1.1254 +				$data['script_path'] = substr($data['script_path'], 0, -1);
  1.1255 +			}
  1.1256 +
  1.1257 +			$data['script_path'] = str_replace(array('../', './'), '', $data['script_path']);
  1.1258 +
  1.1259 +			if ($data['script_path'][0] != '/')
  1.1260 +			{
  1.1261 +				$data['script_path'] = '/' . $data['script_path'];
  1.1262 +			}
  1.1263 +		}
  1.1264 +
  1.1265 +		// Set default config and post data, this applies to all DB's
  1.1266 +		$sql_ary = array(
  1.1267 +			'INSERT INTO ' . $data['table_prefix'] . "config (config_name, config_value)
  1.1268 +				VALUES ('board_startdate', '$current_time')",
  1.1269 +
  1.1270 +			'INSERT INTO ' . $data['table_prefix'] . "config (config_name, config_value)
  1.1271 +				VALUES ('default_lang', '" . $db->sql_escape($data['default_lang']) . "')",
  1.1272 +
  1.1273 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1274 +				SET config_value = '" . $db->sql_escape($data['img_imagick']) . "'
  1.1275 +				WHERE config_name = 'img_imagick'",
  1.1276 +
  1.1277 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1278 +				SET config_value = '" . $db->sql_escape($data['server_name']) . "'
  1.1279 +				WHERE config_name = 'server_name'",
  1.1280 +
  1.1281 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1282 +				SET config_value = '" . $db->sql_escape($data['server_port']) . "'
  1.1283 +				WHERE config_name = 'server_port'",
  1.1284 +
  1.1285 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1286 +				SET config_value = '" . $db->sql_escape($data['board_email1']) . "'
  1.1287 +				WHERE config_name = 'board_email'",
  1.1288 +
  1.1289 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1290 +				SET config_value = '" . $db->sql_escape($data['board_email1']) . "'
  1.1291 +				WHERE config_name = 'board_contact'",
  1.1292 +
  1.1293 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1294 +				SET config_value = '" . $db->sql_escape($cookie_domain) . "'
  1.1295 +				WHERE config_name = 'cookie_domain'",
  1.1296 +
  1.1297 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1298 +				SET config_value = '" . $db->sql_escape($lang['default_dateformat']) . "'
  1.1299 +				WHERE config_name = 'default_dateformat'",
  1.1300 +
  1.1301 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1302 +				SET config_value = '" . $db->sql_escape($data['email_enable']) . "'
  1.1303 +				WHERE config_name = 'email_enable'",
  1.1304 +
  1.1305 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1306 +				SET config_value = '" . $db->sql_escape($data['smtp_delivery']) . "'
  1.1307 +				WHERE config_name = 'smtp_delivery'",
  1.1308 +
  1.1309 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1310 +				SET config_value = '" . $db->sql_escape($data['smtp_host']) . "'
  1.1311 +				WHERE config_name = 'smtp_host'",
  1.1312 +
  1.1313 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1314 +				SET config_value = '" . $db->sql_escape($data['smtp_auth']) . "'
  1.1315 +				WHERE config_name = 'smtp_auth_method'",
  1.1316 +
  1.1317 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1318 +				SET config_value = '" . $db->sql_escape($data['smtp_user']) . "'
  1.1319 +				WHERE config_name = 'smtp_username'",
  1.1320 +
  1.1321 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1322 +				SET config_value = '" . $db->sql_escape($data['smtp_pass']) . "'
  1.1323 +				WHERE config_name = 'smtp_password'",
  1.1324 +
  1.1325 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1326 +				SET config_value = '" . $db->sql_escape($data['cookie_secure']) . "'
  1.1327 +				WHERE config_name = 'cookie_secure'",
  1.1328 +
  1.1329 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1330 +				SET config_value = '" . $db->sql_escape($data['force_server_vars']) . "'
  1.1331 +				WHERE config_name = 'force_server_vars'",
  1.1332 +
  1.1333 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1334 +				SET config_value = '" . $db->sql_escape($data['script_path']) . "'
  1.1335 +				WHERE config_name = 'script_path'",
  1.1336 +
  1.1337 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1338 +				SET config_value = '" . $db->sql_escape($data['server_protocol']) . "'
  1.1339 +				WHERE config_name = 'server_protocol'",
  1.1340 +
  1.1341 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1342 +				SET config_value = '" . $db->sql_escape($data['admin_name']) . "'
  1.1343 +				WHERE config_name = 'newest_username'",
  1.1344 +
  1.1345 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1346 +				SET config_value = '" . md5(mt_rand()) . "'
  1.1347 +				WHERE config_name = 'avatar_salt'",
  1.1348 +
  1.1349 +			'UPDATE ' . $data['table_prefix'] . "users
  1.1350 +				SET username = '" . $db->sql_escape($data['admin_name']) . "', user_password='" . $db->sql_escape(md5($data['admin_pass1'])) . "', user_ip = '" . $db->sql_escape($user_ip) . "', user_lang = '" . $db->sql_escape($data['default_lang']) . "', user_email='" . $db->sql_escape($data['board_email1']) . "', user_dateformat='" . $db->sql_escape($lang['default_dateformat']) . "', user_email_hash = " . $db->sql_escape(phpbb_email_hash($data['board_email1'])) . ", username_clean = '" . $db->sql_escape(utf8_clean_string($data['admin_name'])) . "'
  1.1351 +				WHERE username = 'Admin'",
  1.1352 +
  1.1353 +			'UPDATE ' . $data['table_prefix'] . "moderator_cache
  1.1354 +				SET username = '" . $db->sql_escape($data['admin_name']) . "'
  1.1355 +				WHERE username = 'Admin'",
  1.1356 +
  1.1357 +			'UPDATE ' . $data['table_prefix'] . "forums
  1.1358 +				SET forum_last_poster_name = '" . $db->sql_escape($data['admin_name']) . "'
  1.1359 +				WHERE forum_last_poster_name = 'Admin'",
  1.1360 +
  1.1361 +			'UPDATE ' . $data['table_prefix'] . "topics
  1.1362 +				SET topic_first_poster_name = '" . $db->sql_escape($data['admin_name']) . "', topic_last_poster_name = '" . $db->sql_escape($data['admin_name']) . "'
  1.1363 +				WHERE topic_first_poster_name = 'Admin'
  1.1364 +					OR topic_last_poster_name = 'Admin'",
  1.1365 +
  1.1366 +			'UPDATE ' . $data['table_prefix'] . "users
  1.1367 +				SET user_regdate = $current_time",
  1.1368 +
  1.1369 +			'UPDATE ' . $data['table_prefix'] . "posts
  1.1370 +				SET post_time = $current_time, poster_ip = '" . $db->sql_escape($user_ip) . "'",
  1.1371 +
  1.1372 +			'UPDATE ' . $data['table_prefix'] . "topics
  1.1373 +				SET topic_time = $current_time, topic_last_post_time = $current_time",
  1.1374 +
  1.1375 +			'UPDATE ' . $data['table_prefix'] . "forums
  1.1376 +				SET forum_last_post_time = $current_time",
  1.1377 +
  1.1378 +			'UPDATE ' . $data['table_prefix'] . "config
  1.1379 +				SET config_value = '" . $db->sql_escape($db->sql_server_info(true)) . "'
  1.1380 +				WHERE config_name = 'dbms_version'",
  1.1381 +		);
  1.1382 +
  1.1383 +		if (@extension_loaded('gd') || can_load_dll('gd'))
  1.1384 +		{
  1.1385 +			$sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config
  1.1386 +				SET config_value = 'phpbb_captcha_gd'
  1.1387 +				WHERE config_name = 'captcha_plugin'";
  1.1388 +
  1.1389 +			$sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config
  1.1390 +				SET config_value = '1'
  1.1391 +				WHERE config_name = 'captcha_gd'";
  1.1392 +		}
  1.1393 +
  1.1394 +		$ref = substr($referer, strpos($referer, '://') + 3);
  1.1395 +
  1.1396 +		if (!(stripos($ref, $server_name) === 0))
  1.1397 +		{
  1.1398 +			$sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config
  1.1399 +				SET config_value = '0'
  1.1400 +				WHERE config_name = 'referer_validation'";
  1.1401 +		}
  1.1402 +
  1.1403 +		// We set a (semi-)unique cookie name to bypass login issues related to the cookie name.
  1.1404 +		$cookie_name = 'phpbb3_';
  1.1405 +		$rand_str = md5(mt_rand());
  1.1406 +		$rand_str = str_replace('0', 'z', base_convert($rand_str, 16, 35));
  1.1407 +		$rand_str = substr($rand_str, 0, 5);
  1.1408 +		$cookie_name .= strtolower($rand_str);
  1.1409 +
  1.1410 +		$sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config
  1.1411 +			SET config_value = '" . $db->sql_escape($cookie_name) . "'
  1.1412 +			WHERE config_name = 'cookie_name'";
  1.1413 +
  1.1414 +		foreach ($sql_ary as $sql)
  1.1415 +		{
  1.1416 +			//$sql = trim(str_replace('|', ';', $sql));
  1.1417 +
  1.1418 +			if (!$db->sql_query($sql))
  1.1419 +			{
  1.1420 +				$error = $db->sql_error();
  1.1421 +				$this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__);
  1.1422 +			}
  1.1423 +		}
  1.1424 +
  1.1425 +		$submit = $lang['NEXT_STEP'];
  1.1426 +
  1.1427 +		$url = $this->p_master->module_url . "?mode=$mode&amp;sub=final";
  1.1428 +
  1.1429 +		$template->assign_vars(array(
  1.1430 +			'BODY'		=> $lang['STAGE_CREATE_TABLE_EXPLAIN'],
  1.1431 +			'L_SUBMIT'	=> $submit,
  1.1432 +			'S_HIDDEN'	=> build_hidden_fields($data),
  1.1433 +			'U_ACTION'	=> $url,
  1.1434 +		));
  1.1435 +	}
  1.1436 +
  1.1437 +	/**
  1.1438 +	* Build the search index...
  1.1439 +	*/
  1.1440 +	function build_search_index($mode, $sub)
  1.1441 +	{
  1.1442 +		global $db, $lang, $phpbb_root_path, $phpEx, $config;
  1.1443 +
  1.1444 +		// Obtain any submitted data
  1.1445 +		$data = $this->get_submitted_data();
  1.1446 +		$table_prefix = $data['table_prefix'];
  1.1447 +
  1.1448 +		// If we get here and the extension isn't loaded it should be safe to just go ahead and load it
  1.1449 +		$available_dbms = get_available_dbms($data['dbms']);
  1.1450 +
  1.1451 +		if (!isset($available_dbms[$data['dbms']]))
  1.1452 +		{
  1.1453 +			// Someone's been silly and tried providing a non-existant dbms
  1.1454 +			$this->p_master->redirect("index.$phpEx?mode=install");
  1.1455 +		}
  1.1456 +
  1.1457 +		$dbms = $available_dbms[$data['dbms']]['DRIVER'];
  1.1458 +
  1.1459 +		// Load the appropriate database class if not already loaded
  1.1460 +		include($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
  1.1461 +
  1.1462 +		// Instantiate the database
  1.1463 +		$db = new $sql_db();
  1.1464 +		$db->sql_connect($data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport'], false, false);
  1.1465 +
  1.1466 +		// NOTE: trigger_error does not work here.
  1.1467 +		$db->sql_return_on_error(true);
  1.1468 +
  1.1469 +		include_once($phpbb_root_path . 'includes/constants.' . $phpEx);
  1.1470 +		include_once($phpbb_root_path . 'includes/search/fulltext_native.' . $phpEx);
  1.1471 +
  1.1472 +		// Fill the config array - it is needed by those functions we call
  1.1473 +		$sql = 'SELECT *
  1.1474 +			FROM ' . CONFIG_TABLE;
  1.1475 +		$result = $db->sql_query($sql);
  1.1476 +
  1.1477 +		$config = array();
  1.1478 +		while ($row = $db->sql_fetchrow($result))
  1.1479 +		{
  1.1480 +			$config[$row['config_name']] = $row['config_value'];
  1.1481 +		}
  1.1482 +		$db->sql_freeresult($result);
  1.1483 +
  1.1484 +		$error = false;
  1.1485 +		$search = new fulltext_native($error);
  1.1486 +
  1.1487 +		$sql = 'SELECT post_id, post_subject, post_text, poster_id, forum_id
  1.1488 +			FROM ' . POSTS_TABLE;
  1.1489 +		$result = $db->sql_query($sql);
  1.1490 +
  1.1491 +		while ($row = $db->sql_fetchrow($result))
  1.1492 +		{
  1.1493 +			$search->index('post', $row['post_id'], $row['post_text'], $row['post_subject'], $row['poster_id'], $row['forum_id']);
  1.1494 +		}
  1.1495 +		$db->sql_freeresult($result);
  1.1496 +	}
  1.1497 +
  1.1498 +	/**
  1.1499 +	* Populate the module tables
  1.1500 +	*/
  1.1501 +	function add_modules($mode, $sub)
  1.1502 +	{
  1.1503 +		global $db, $lang, $phpbb_root_path, $phpEx;
  1.1504 +
  1.1505 +		include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx);
  1.1506 +
  1.1507 +		$_module = new acp_modules();
  1.1508 +		$module_classes = array('acp', 'mcp', 'ucp');
  1.1509 +
  1.1510 +		// Add categories
  1.1511 +		foreach ($module_classes as $module_class)
  1.1512 +		{
  1.1513 +			$categories = array();
  1.1514 +
  1.1515 +			// Set the module class
  1.1516 +			$_module->module_class = $module_class;
  1.1517 +
  1.1518 +			foreach ($this->module_categories[$module_class] as $cat_name => $subs)
  1.1519 +			{
  1.1520 +				$module_data = array(
  1.1521 +					'module_basename'	=> '',
  1.1522 +					'module_enabled'	=> 1,
  1.1523 +					'module_display'	=> 1,
  1.1524 +					'parent_id'			=> 0,
  1.1525 +					'module_class'		=> $module_class,
  1.1526 +					'module_langname'	=> $cat_name,
  1.1527 +					'module_mode'		=> '',
  1.1528 +					'module_auth'		=> '',
  1.1529 +				);
  1.1530 +
  1.1531 +				// Add category
  1.1532 +				$_module->update_module_data($module_data, true);
  1.1533 +
  1.1534 +				// Check for last sql error happened
  1.1535 +				if ($db->sql_error_triggered)
  1.1536 +				{
  1.1537 +					$error = $db->sql_error($db->sql_error_sql);
  1.1538 +					$this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__);
  1.1539 +				}
  1.1540 +
  1.1541 +				$categories[$cat_name]['id'] = (int) $module_data['module_id'];
  1.1542 +				$categories[$cat_name]['parent_id'] = 0;
  1.1543 +
  1.1544 +				// Create sub-categories...
  1.1545 +				if (is_array($subs))
  1.1546 +				{
  1.1547 +					foreach ($subs as $level2_name)
  1.1548 +					{
  1.1549 +						$module_data = array(
  1.1550 +							'module_basename'	=> '',
  1.1551 +							'module_enabled'	=> 1,
  1.1552 +							'module_display'	=> 1,
  1.1553 +							'parent_id'			=> (int) $categories[$cat_name]['id'],
  1.1554 +							'module_class'		=> $module_class,
  1.1555 +							'module_langname'	=> $level2_name,
  1.1556 +							'module_mode'		=> '',
  1.1557 +							'module_auth'		=> '',
  1.1558 +						);
  1.1559 +
  1.1560 +						$_module->update_module_data($module_data, true);
  1.1561 +
  1.1562 +						// Check for last sql error happened
  1.1563 +						if ($db->sql_error_triggered)
  1.1564 +						{
  1.1565 +							$error = $db->sql_error($db->sql_error_sql);
  1.1566 +							$this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__);
  1.1567 +						}
  1.1568 +
  1.1569 +						$categories[$level2_name]['id'] = (int) $module_data['module_id'];
  1.1570 +						$categories[$level2_name]['parent_id'] = (int) $categories[$cat_name]['id'];
  1.1571 +					}
  1.1572 +				}
  1.1573 +			}
  1.1574 +
  1.1575 +			// Get the modules we want to add... returned sorted by name
  1.1576 +			$module_info = $_module->get_module_infos('', $module_class);
  1.1577 +
  1.1578 +			foreach ($module_info as $module_basename => $fileinfo)
  1.1579 +			{
  1.1580 +				foreach ($fileinfo['modes'] as $module_mode => $row)
  1.1581 +				{
  1.1582 +					foreach ($row['cat'] as $cat_name)
  1.1583 +					{
  1.1584 +						if (!isset($categories[$cat_name]))
  1.1585 +						{
  1.1586 +							continue;
  1.1587 +						}
  1.1588 +
  1.1589 +						$module_data = array(
  1.1590 +							'module_basename'	=> $module_basename,
  1.1591 +							'module_enabled'	=> 1,
  1.1592 +							'module_display'	=> (isset($row['display'])) ? (int) $row['display'] : 1,
  1.1593 +							'parent_id'			=> (int) $categories[$cat_name]['id'],
  1.1594 +							'module_class'		=> $module_class,
  1.1595 +							'module_langname'	=> $row['title'],
  1.1596 +							'module_mode'		=> $module_mode,
  1.1597 +							'module_auth'		=> $row['auth'],
  1.1598 +						);
  1.1599 +
  1.1600 +						$_module->update_module_data($module_data, true);
  1.1601 +
  1.1602 +						// Check for last sql error happened
  1.1603 +						if ($db->sql_error_triggered)
  1.1604 +						{
  1.1605 +							$error = $db->sql_error($db->sql_error_sql);
  1.1606 +							$this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__);
  1.1607 +						}
  1.1608 +					}
  1.1609 +				}
  1.1610 +			}
  1.1611 +
  1.1612 +			// Move some of the modules around since the code above will put them in the wrong place
  1.1613 +			if ($module_class == 'acp')
  1.1614 +			{
  1.1615 +				// Move main module 4 up...
  1.1616 +				$sql = 'SELECT *
  1.1617 +					FROM ' . MODULES_TABLE . "
  1.1618 +					WHERE module_basename = 'main'
  1.1619 +						AND module_class = 'acp'
  1.1620 +						AND module_mode = 'main'";
  1.1621 +				$result = $db->sql_query($sql);
  1.1622 +				$row = $db->sql_fetchrow($result);
  1.1623 +				$db->sql_freeresult($result);
  1.1624 +
  1.1625 +				$_module->move_module_by($row, 'move_up', 4);
  1.1626 +
  1.1627 +				// Move permissions intro screen module 4 up...
  1.1628 +				$sql = 'SELECT *
  1.1629 +					FROM ' . MODULES_TABLE . "
  1.1630 +					WHERE module_basename = 'permissions'
  1.1631 +						AND module_class = 'acp'
  1.1632 +						AND module_mode = 'intro'";
  1.1633 +				$result = $db->sql_query($sql);
  1.1634 +				$row = $db->sql_fetchrow($result);
  1.1635 +				$db->sql_freeresult($result);
  1.1636 +
  1.1637 +				$_module->move_module_by($row, 'move_up', 4);
  1.1638 +
  1.1639 +				// Move manage users screen module 5 up...
  1.1640 +				$sql = 'SELECT *
  1.1641 +					FROM ' . MODULES_TABLE . "
  1.1642 +					WHERE module_basename = 'users'
  1.1643 +						AND module_class = 'acp'
  1.1644 +						AND module_mode = 'overview'";
  1.1645 +				$result = $db->sql_query($sql);
  1.1646 +				$row = $db->sql_fetchrow($result);
  1.1647 +				$db->sql_freeresult($result);
  1.1648 +
  1.1649 +				$_module->move_module_by($row, 'move_up', 5);
  1.1650 +			}
  1.1651 +
  1.1652 +			if ($module_class == 'ucp')
  1.1653 +			{
  1.1654 +				// Move attachment module 4 down...
  1.1655 +				$sql = 'SELECT *
  1.1656 +					FROM ' . MODULES_TABLE . "
  1.1657 +					WHERE module_basename = 'attachments'
  1.1658 +						AND module_class = 'ucp'
  1.1659 +						AND module_mode = 'attachments'";
  1.1660 +				$result = $db->sql_query($sql);
  1.1661 +				$row = $db->sql_fetchrow($result);
  1.1662 +				$db->sql_freeresult($result);
  1.1663 +
  1.1664 +				$_module->move_module_by($row, 'move_down', 4);
  1.1665 +			}
  1.1666 +
  1.1667 +			// And now for the special ones
  1.1668 +			// (these are modules which appear in multiple categories and thus get added manually to some for more control)
  1.1669 +			if (isset($this->module_extras[$module_class]))
  1.1670 +			{
  1.1671 +				foreach ($this->module_extras[$module_class] as $cat_name => $mods)
  1.1672 +				{
  1.1673 +					$sql = 'SELECT module_id, left_id, right_id
  1.1674 +						FROM ' . MODULES_TABLE . "
  1.1675 +						WHERE module_langname = '" . $db->sql_escape($cat_name) . "'
  1.1676 +							AND module_class = '" . $db->sql_escape($module_class) . "'";
  1.1677 +					$result = $db->sql_query_limit($sql, 1);
  1.1678 +					$row2 = $db->sql_fetchrow($result);
  1.1679 +					$db->sql_freeresult($result);
  1.1680 +
  1.1681 +					foreach ($mods as $mod_name)
  1.1682 +					{
  1.1683 +						$sql = 'SELECT *
  1.1684 +							FROM ' . MODULES_TABLE . "
  1.1685 +							WHERE module_langname = '" . $db->sql_escape($mod_name) . "'
  1.1686 +								AND module_class = '" . $db->sql_escape($module_class) . "'
  1.1687 +								AND module_basename <> ''";
  1.1688 +						$result = $db->sql_query_limit($sql, 1);
  1.1689 +						$row = $db->sql_fetchrow($result);
  1.1690 +						$db->sql_freeresult($result);
  1.1691 +
  1.1692 +						$module_data = array(
  1.1693 +							'module_basename'	=> $row['module_basename'],
  1.1694 +							'module_enabled'	=> (int) $row['module_enabled'],
  1.1695 +							'module_display'	=> (int) $row['module_display'],
  1.1696 +							'parent_id'			=> (int) $row2['module_id'],
  1.1697 +							'module_class'		=> $row['module_class'],
  1.1698 +							'module_langname'	=> $row['module_langname'],
  1.1699 +							'module_mode'		=> $row['module_mode'],
  1.1700 +							'module_auth'		=> $row['module_auth'],
  1.1701 +						);
  1.1702 +
  1.1703 +						$_module->update_module_data($module_data, true);
  1.1704 +
  1.1705 +						// Check for last sql error happened
  1.1706 +						if ($db->sql_error_triggered)
  1.1707 +						{
  1.1708 +							$error = $db->sql_error($db->sql_error_sql);
  1.1709 +							$this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__);
  1.1710 +						}
  1.1711 +					}
  1.1712 +				}
  1.1713 +			}
  1.1714 +
  1.1715 +			$_module->remove_cache_file();
  1.1716 +		}
  1.1717 +	}
  1.1718 +
  1.1719 +	/**
  1.1720 +	* Populate the language tables
  1.1721 +	*/
  1.1722 +	function add_language($mode, $sub)
  1.1723 +	{
  1.1724 +		global $db, $lang, $phpbb_root_path, $phpEx;
  1.1725 +
  1.1726 +		$dir = @opendir($phpbb_root_path . 'language');
  1.1727 +
  1.1728 +		if (!$dir)
  1.1729 +		{
  1.1730 +			$this->error('Unable to access the language directory', __LINE__, __FILE__);
  1.1731 +		}
  1.1732 +
  1.1733 +		while (($file = readdir($dir)) !== false)
  1.1734 +		{
  1.1735 +			$path = $phpbb_root_path . 'language/' . $file;
  1.1736 +
  1.1737 +			if ($file == '.' || $file == '..' || is_link($path) || is_file($path) || $file == 'CVS')
  1.1738 +			{
  1.1739 +				continue;
  1.1740 +			}
  1.1741 +
  1.1742 +			if (is_dir($path) && file_exists($path . '/iso.txt'))
  1.1743 +			{
  1.1744 +				$lang_file = file("$path/iso.txt");
  1.1745 +
  1.1746 +				$lang_pack = array(
  1.1747 +					'lang_iso'			=> basename($path),
  1.1748 +					'lang_dir'			=> basename($path),
  1.1749 +					'lang_english_name'	=> trim(htmlspecialchars($lang_file[0])),
  1.1750 +					'lang_local_name'	=> trim(htmlspecialchars($lang_file[1], ENT_COMPAT, 'UTF-8')),
  1.1751 +					'lang_author'		=> trim(htmlspecialchars($lang_file[2], ENT_COMPAT, 'UTF-8')),
  1.1752 +				);
  1.1753 +
  1.1754 +				$db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $lang_pack));
  1.1755 +
  1.1756 +				if ($db->sql_error_triggered)
  1.1757 +				{
  1.1758 +					$error = $db->sql_error($db->sql_error_sql);
  1.1759 +					$this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__);
  1.1760 +				}
  1.1761 +
  1.1762 +				$valid_localized = array(
  1.1763 +					'icon_back_top', 'icon_contact_aim', 'icon_contact_email', 'icon_contact_icq', 'icon_contact_jabber', 'icon_contact_msnm', 'icon_contact_pm', 'icon_contact_yahoo', 'icon_contact_www', 'icon_post_delete', 'icon_post_edit', 'icon_post_info', 'icon_post_quote', 'icon_post_report', 'icon_user_online', 'icon_user_offline', 'icon_user_profile', 'icon_user_search', 'icon_user_warn', 'button_pm_forward', 'button_pm_new', 'button_pm_reply', 'button_topic_locked', 'button_topic_new', 'button_topic_reply',
  1.1764 +				);
  1.1765 +
  1.1766 +				$sql_ary = array();
  1.1767 +
  1.1768 +				$sql = 'SELECT *
  1.1769 +					FROM ' . STYLES_IMAGESET_TABLE;
  1.1770 +				$result = $db->sql_query($sql);
  1.1771 +
  1.1772 +				while ($imageset_row = $db->sql_fetchrow($result))
  1.1773 +				{
  1.1774 +					if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$lang_pack['lang_iso']}/imageset.cfg"))
  1.1775 +					{
  1.1776 +						$cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$lang_pack['lang_iso']}/imageset.cfg");
  1.1777 +						foreach ($cfg_data_imageset_data as $image_name => $value)
  1.1778 +						{
  1.1779 +							if (strpos($value, '*') !== false)
  1.1780 +							{
  1.1781 +								if (substr($value, -1, 1) === '*')
  1.1782 +								{
  1.1783 +									list($image_filename, $image_height) = explode('*', $value);
  1.1784 +									$image_width = 0;
  1.1785 +								}
  1.1786 +								else
  1.1787 +								{
  1.1788 +									list($image_filename, $image_height, $image_width) = explode('*', $value);
  1.1789 +								}
  1.1790 +							}
  1.1791 +							else
  1.1792 +							{
  1.1793 +								$image_filename = $value;
  1.1794 +								$image_height = $image_width = 0;
  1.1795 +							}
  1.1796 +
  1.1797 +							if (strpos($image_name, 'img_') === 0 && $image_filename)
  1.1798 +							{
  1.1799 +								$image_name = substr($image_name, 4);
  1.1800 +								if (in_array($image_name, $valid_localized))
  1.1801 +								{
  1.1802 +									$sql_ary[] = array(
  1.1803 +										'image_name'		=> (string) $image_name,
  1.1804 +										'image_filename'	=> (string) $image_filename,
  1.1805 +										'image_height'		=> (int) $image_height,
  1.1806 +										'image_width'		=> (int) $image_width,
  1.1807 +										'imageset_id'		=> (int) $imageset_row['imageset_id'],
  1.1808 +										'image_lang'		=> (string) $lang_pack['lang_iso'],
  1.1809 +									);
  1.1810 +								}
  1.1811 +							}
  1.1812 +						}
  1.1813 +					}
  1.1814 +				}
  1.1815 +				$db->sql_freeresult($result);
  1.1816 +
  1.1817 +				if (sizeof($sql_ary))
  1.1818 +				{
  1.1819 +					$db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary);
  1.1820 +
  1.1821 +					if ($db->sql_error_triggered)
  1.1822 +					{
  1.1823 +						$error = $db->sql_error($db->sql_error_sql);
  1.1824 +						$this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__);
  1.1825 +					}
  1.1826 +				}
  1.1827 +			}
  1.1828 +		}
  1.1829 +		closedir($dir);
  1.1830 +	}
  1.1831 +
  1.1832 +	/**
  1.1833 +	* Add search robots to the database
  1.1834 +	*/
  1.1835 +	function add_bots($mode, $sub)
  1.1836 +	{
  1.1837 +		global $db, $lang, $phpbb_root_path, $phpEx, $config;
  1.1838 +
  1.1839 +		// Obtain any submitted data
  1.1840 +		$data = $this->get_submitted_data();
  1.1841 +
  1.1842 +		// Fill the config array - it is needed by those functions we call
  1.1843 +		$sql = 'SELECT *
  1.1844 +			FROM ' . CONFIG_TABLE;
  1.1845 +		$result = $db->sql_query($sql);
  1.1846 +
  1.1847 +		$config = array();
  1.1848 +		while ($row = $db->sql_fetchrow($result))
  1.1849 +		{
  1.1850 +			$config[$row['config_name']] = $row['config_value'];
  1.1851 +		}
  1.1852 +		$db->sql_freeresult($result);
  1.1853 +
  1.1854 +		$sql = 'SELECT group_id
  1.1855 +			FROM ' . GROUPS_TABLE . "
  1.1856 +			WHERE group_name = 'BOTS'";
  1.1857 +		$result = $db->sql_query($sql);
  1.1858 +		$group_id = (int) $db->sql_fetchfield('group_id');
  1.1859 +		$db->sql_freeresult($result);
  1.1860 +
  1.1861 +		if (!$group_id)
  1.1862 +		{
  1.1863 +			// If we reach this point then something has gone very wrong
  1.1864 +			$this->p_master->error($lang['NO_GROUP'], __LINE__, __FILE__);
  1.1865 +		}
  1.1866 +
  1.1867 +		if (!function_exists('user_add'))
  1.1868 +		{
  1.1869 +			include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  1.1870 +		}
  1.1871 +
  1.1872 +		foreach ($this->bot_list as $bot_name => $bot_ary)
  1.1873 +		{
  1.1874 +			$user_row = array(
  1.1875 +				'user_type'				=> USER_IGNORE,
  1.1876 +				'group_id'				=> $group_id,
  1.1877 +				'username'				=> $bot_name,
  1.1878 +				'user_regdate'			=> time(),
  1.1879 +				'user_password'			=> '',
  1.1880 +				'user_colour'			=> '9E8DA7',
  1.1881 +				'user_email'			=> '',
  1.1882 +				'user_lang'				=> $data['default_lang'],
  1.1883 +				'user_style'			=> 1,
  1.1884 +				'user_timezone'			=> 0,
  1.1885 +				'user_dateformat'		=> $lang['default_dateformat'],
  1.1886 +				'user_allow_massemail'	=> 0,
  1.1887 +			);
  1.1888 +
  1.1889 +			$user_id = user_add($user_row);
  1.1890 +
  1.1891 +			if (!$user_id)
  1.1892 +			{
  1.1893 +				// If we can't insert this user then continue to the next one to avoid inconsistent data
  1.1894 +				$this->p_master->db_error('Unable to insert bot into users table', $db->sql_error_sql, __LINE__, __FILE__, true);
  1.1895 +				continue;
  1.1896 +			}
  1.1897 +
  1.1898 +			$sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
  1.1899 +				'bot_active'	=> 1,
  1.1900 +				'bot_name'		=> (string) $bot_name,
  1.1901 +				'user_id'		=> (int) $user_id,
  1.1902 +				'bot_agent'		=> (string) $bot_ary[0],
  1.1903 +				'bot_ip'		=> (string) $bot_ary[1],
  1.1904 +			));
  1.1905 +
  1.1906 +			$result = $db->sql_query($sql);
  1.1907 +		}
  1.1908 +	}
  1.1909 +
  1.1910 +	/**
  1.1911 +	* Sends an email to the board administrator with their password and some useful links
  1.1912 +	*/
  1.1913 +	function email_admin($mode, $sub)
  1.1914 +	{
  1.1915 +		global $auth, $config, $db, $lang, $template, $user, $phpbb_root_path, $phpEx;
  1.1916 +
  1.1917 +		$this->page_title = $lang['STAGE_FINAL'];
  1.1918 +
  1.1919 +		// Obtain any submitted data
  1.1920 +		$data = $this->get_submitted_data();
  1.1921 +
  1.1922 +		$sql = 'SELECT *
  1.1923 +			FROM ' . CONFIG_TABLE;
  1.1924 +		$result = $db->sql_query($sql);
  1.1925 +
  1.1926 +		$config = array();
  1.1927 +		while ($row = $db->sql_fetchrow($result))
  1.1928 +		{
  1.1929 +			$config[$row['config_name']] = $row['config_value'];
  1.1930 +		}
  1.1931 +		$db->sql_freeresult($result);
  1.1932 +
  1.1933 +		$user->session_begin();
  1.1934 +		$auth->login($data['admin_name'], $data['admin_pass1'], false, true, true);
  1.1935 +
  1.1936 +		// OK, Now that we've reached this point we can be confident that everything
  1.1937 +		// is installed and working......I hope :)
  1.1938 +		// So it's time to send an email to the administrator confirming the details
  1.1939 +		// they entered
  1.1940 +
  1.1941 +		if ($config['email_enable'])
  1.1942 +		{
  1.1943 +			include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  1.1944 +
  1.1945 +			$messenger = new messenger(false);
  1.1946 +
  1.1947 +			$messenger->template('installed', $data['language']);
  1.1948 +
  1.1949 +			$messenger->to($data['board_email1'], $data['admin_name']);
  1.1950 +
  1.1951 +			$messenger->anti_abuse_headers($config, $user);
  1.1952 +
  1.1953 +			$messenger->assign_vars(array(
  1.1954 +				'USERNAME'		=> htmlspecialchars_decode($data['admin_name']),
  1.1955 +				'PASSWORD'		=> htmlspecialchars_decode($data['admin_pass1']))
  1.1956 +			);
  1.1957 +
  1.1958 +			$messenger->send(NOTIFY_EMAIL);
  1.1959 +		}
  1.1960 +
  1.1961 +		// And finally, add a note to the log
  1.1962 +		add_log('admin', 'LOG_INSTALL_INSTALLED', $config['version']);
  1.1963 +
  1.1964 +		$template->assign_vars(array(
  1.1965 +			'TITLE'		=> $lang['INSTALL_CONGRATS'],
  1.1966 +			'BODY'		=> sprintf($lang['INSTALL_CONGRATS_EXPLAIN'], $config['version'], append_sid($phpbb_root_path . 'install/index.' . $phpEx, 'mode=convert&amp;language=' . $data['language']), '../docs/README.html'),
  1.1967 +			'L_SUBMIT'	=> $lang['INSTALL_LOGIN'],
  1.1968 +			'U_ACTION'	=> append_sid($phpbb_root_path . 'adm/index.' . $phpEx, 'i=send_statistics&amp;mode=send_statistics'),
  1.1969 +		));
  1.1970 +	}
  1.1971 +
  1.1972 +	/**
  1.1973 +	* Generate a list of available mail server authentication methods
  1.1974 +	*/
  1.1975 +	function mail_auth_select($selected_method)
  1.1976 +	{
  1.1977 +		global $lang;
  1.1978 +
  1.1979 +		$auth_methods = array('PLAIN', 'LOGIN', 'CRAM-MD5', 'DIGEST-MD5', 'POP-BEFORE-SMTP');
  1.1980 +		$s_smtp_auth_options = '';
  1.1981 +
  1.1982 +		foreach ($auth_methods as $method)
  1.1983 +		{
  1.1984 +			$s_smtp_auth_options .= '<option value="' . $method . '"' . (($selected_method == $method) ? ' selected="selected"' : '') . '>' . $lang['SMTP_' . str_replace('-', '_', $method)] . '</option>';
  1.1985 +		}
  1.1986 +
  1.1987 +		return $s_smtp_auth_options;
  1.1988 +	}
  1.1989 +
  1.1990 +	/**
  1.1991 +	* Get submitted data
  1.1992 +	*/
  1.1993 +	function get_submitted_data()
  1.1994 +	{
  1.1995 +		return array(
  1.1996 +			'language'		=> basename(request_var('language', '')),
  1.1997 +			'dbms'			=> request_var('dbms', ''),
  1.1998 +			'dbhost'		=> request_var('dbhost', ''),
  1.1999 +			'dbport'		=> request_var('dbport', ''),
  1.2000 +			'dbuser'		=> request_var('dbuser', ''),
  1.2001 +			'dbpasswd'		=> request_var('dbpasswd', '', true),
  1.2002 +			'dbname'		=> request_var('dbname', ''),
  1.2003 +			'table_prefix'	=> request_var('table_prefix', ''),
  1.2004 +			'default_lang'	=> basename(request_var('default_lang', '')),
  1.2005 +			'admin_name'	=> utf8_normalize_nfc(request_var('admin_name', '', true)),
  1.2006 +			'admin_pass1'	=> request_var('admin_pass1', '', true),
  1.2007 +			'admin_pass2'	=> request_var('admin_pass2', '', true),
  1.2008 +			'board_email1'	=> strtolower(request_var('board_email1', '')),
  1.2009 +			'board_email2'	=> strtolower(request_var('board_email2', '')),
  1.2010 +			'img_imagick'	=> request_var('img_imagick', ''),
  1.2011 +			'ftp_path'		=> request_var('ftp_path', ''),
  1.2012 +			'ftp_user'		=> request_var('ftp_user', ''),
  1.2013 +			'ftp_pass'		=> request_var('ftp_pass', ''),
  1.2014 +			'email_enable'	=> request_var('email_enable', ''),
  1.2015 +			'smtp_delivery'	=> request_var('smtp_delivery', ''),
  1.2016 +			'smtp_host'		=> request_var('smtp_host', ''),
  1.2017 +			'smtp_auth'		=> request_var('smtp_auth', ''),
  1.2018 +			'smtp_user'		=> request_var('smtp_user', ''),
  1.2019 +			'smtp_pass'		=> request_var('smtp_pass', ''),
  1.2020 +			'cookie_secure'	=> request_var('cookie_secure', ''),
  1.2021 +			'force_server_vars'	=> request_var('force_server_vars', ''),
  1.2022 +			'server_protocol'	=> request_var('server_protocol', ''),
  1.2023 +			'server_name'	=> request_var('server_name', ''),
  1.2024 +			'server_port'	=> request_var('server_port', ''),
  1.2025 +			'script_path'	=> request_var('script_path', ''),
  1.2026 +		);
  1.2027 +	}
  1.2028 +
  1.2029 +	/**
  1.2030 +	* The information below will be used to build the input fields presented to the user
  1.2031 +	*/
  1.2032 +	var $db_config_options = array(
  1.2033 +		'legend1'				=> 'DB_CONFIG',
  1.2034 +		'dbms'					=> array('lang' => 'DBMS',			'type' => 'select', 'options' => 'dbms_select(\'{VALUE}\')', 'explain' => false),
  1.2035 +		'dbhost'				=> array('lang' => 'DB_HOST',		'type' => 'text:25:100', 'explain' => true),
  1.2036 +		'dbport'				=> array('lang' => 'DB_PORT',		'type' => 'text:25:100', 'explain' => true),
  1.2037 +		'dbname'				=> array('lang' => 'DB_NAME',		'type' => 'text:25:100', 'explain' => false),
  1.2038 +		'dbuser'				=> array('lang' => 'DB_USERNAME',	'type' => 'text:25:100', 'explain' => false),
  1.2039 +		'dbpasswd'				=> array('lang' => 'DB_PASSWORD',	'type' => 'password:25:100', 'explain' => false),
  1.2040 +		'table_prefix'			=> array('lang' => 'TABLE_PREFIX',	'type' => 'text:25:100', 'explain' => true),
  1.2041 +	);
  1.2042 +	var $admin_config_options = array(
  1.2043 +		'legend1'				=> 'ADMIN_CONFIG',
  1.2044 +		'default_lang'			=> array('lang' => 'DEFAULT_LANG',				'type' => 'select', 'options' => '$this->module->inst_language_select(\'{VALUE}\')', 'explain' => false),
  1.2045 +		'admin_name'			=> array('lang' => 'ADMIN_USERNAME',			'type' => 'text:25:100', 'explain' => true),
  1.2046 +		'admin_pass1'			=> array('lang' => 'ADMIN_PASSWORD',			'type' => 'password:25:100', 'explain' => true),
  1.2047 +		'admin_pass2'			=> array('lang' => 'ADMIN_PASSWORD_CONFIRM',	'type' => 'password:25:100', 'explain' => false),
  1.2048 +		'board_email1'			=> array('lang' => 'CONTACT_EMAIL',				'type' => 'text:25:100', 'explain' => false),
  1.2049 +		'board_email2'			=> array('lang' => 'CONTACT_EMAIL_CONFIRM',		'type' => 'text:25:100', 'explain' => false),
  1.2050 +	);
  1.2051 +	var $advanced_config_options = array(
  1.2052 +		'legend1'				=> 'ACP_EMAIL_SETTINGS',
  1.2053 +		'email_enable'			=> array('lang' => 'ENABLE_EMAIL',		'type' => 'radio:enabled_disabled', 'explain' => true),
  1.2054 +		'smtp_delivery'			=> array('lang' => 'USE_SMTP',			'type' => 'radio:yes_no', 'explain' => true),
  1.2055 +		'smtp_host'				=> array('lang' => 'SMTP_SERVER',		'type' => 'text:25:50', 'explain' => false),
  1.2056 +		'smtp_auth'				=> array('lang' => 'SMTP_AUTH_METHOD',	'type' => 'select', 'options' => '$this->module->mail_auth_select(\'{VALUE}\')', 'explain' => true),
  1.2057 +		'smtp_user'				=> array('lang' => 'SMTP_USERNAME',		'type' => 'text:25:255', 'explain' => true),
  1.2058 +		'smtp_pass'				=> array('lang' => 'SMTP_PASSWORD',		'type' => 'password:25:255', 'explain' => true),
  1.2059 +
  1.2060 +		'legend2'				=> 'SERVER_URL_SETTINGS',
  1.2061 +		'cookie_secure'			=> array('lang' => 'COOKIE_SECURE',		'type' => 'radio:enabled_disabled', 'explain' => true),
  1.2062 +		'force_server_vars'		=> array('lang' => 'FORCE_SERVER_VARS',	'type' => 'radio:yes_no', 'explain' => true),
  1.2063 +		'server_protocol'		=> array('lang' => 'SERVER_PROTOCOL',	'type' => 'text:10:10', 'explain' => true),
  1.2064 +		'server_name'			=> array('lang' => 'SERVER_NAME',		'type' => 'text:40:255', 'explain' => true),
  1.2065 +		'server_port'			=> array('lang' => 'SERVER_PORT',		'type' => 'text:5:5', 'explain' => true),
  1.2066 +		'script_path'			=> array('lang' => 'SCRIPT_PATH',		'type' => 'text::255', 'explain' => true),
  1.2067 +	);
  1.2068 +
  1.2069 +	/**
  1.2070 +	* Specific PHP modules we may require for certain optional or extended features
  1.2071 +	*/
  1.2072 +	var $php_dlls_other = array('zlib', 'ftp', 'gd', 'xml');
  1.2073 +
  1.2074 +	/**
  1.2075 +	* A list of the web-crawlers/bots we recognise by default
  1.2076 +	*
  1.2077 +	* Candidates but not included:
  1.2078 +	* 'Accoona [Bot]'				'Accoona-AI-Agent/'
  1.2079 +	* 'ASPseek [Crawler]'			'ASPseek/'
  1.2080 +	* 'Boitho [Crawler]'			'boitho.com-dc/'
  1.2081 +	* 'Bunnybot [Bot]'				'powered by www.buncat.de'
  1.2082 +	* 'Cosmix [Bot]'				'cfetch/'
  1.2083 +	* 'Crawler Search [Crawler]'	'.Crawler-Search.de'
  1.2084 +	* 'Findexa [Crawler]'			'Findexa Crawler ('
  1.2085 +	* 'GBSpider [Spider]'			'GBSpider v'
  1.2086 +	* 'genie [Bot]'					'genieBot ('
  1.2087 +	* 'Hogsearch [Bot]'				'oegp v. 1.3.0'
  1.2088 +	* 'Insuranco [Bot]'				'InsurancoBot'
  1.2089 +	* 'IRLbot [Bot]'				'http://irl.cs.tamu.edu/crawler'
  1.2090 +	* 'ISC Systems [Bot]'			'ISC Systems iRc Search'
  1.2091 +	* 'Jyxobot [Bot]'				'Jyxobot/'
  1.2092 +	* 'Kraehe [Metasuche]'			'-DIE-KRAEHE- META-SEARCH-ENGINE/'
  1.2093 +	* 'LinkWalker'					'LinkWalker'
  1.2094 +	* 'MMSBot [Bot]'				'http://www.mmsweb.at/bot.html'
  1.2095 +	* 'Naver [Bot]'					'nhnbot@naver.com)'
  1.2096 +	* 'NetResearchServer'			'NetResearchServer/'
  1.2097 +	* 'Nimble [Crawler]'			'NimbleCrawler'
  1.2098 +	* 'Ocelli [Bot]'				'Ocelli/'
  1.2099 +	* 'Onsearch [Bot]'				'onCHECK-Robot'
  1.2100 +	* 'Orange [Spider]'				'OrangeSpider'
  1.2101 +	* 'Sproose [Bot]'				'http://www.sproose.com/bot'
  1.2102 +	* 'Susie [Sync]'				'!Susie (http://www.sync2it.com/susie)'
  1.2103 +	* 'Tbot [Bot]'					'Tbot/'
  1.2104 +	* 'Thumbshots [Capture]'		'thumbshots-de-Bot'
  1.2105 +	* 'Vagabondo [Crawler]'			'http://webagent.wise-guys.nl/'
  1.2106 +	* 'Walhello [Bot]'				'appie 1.1 (www.walhello.com)'
  1.2107 +	* 'WissenOnline [Bot]'			'WissenOnline-Bot'
  1.2108 +	* 'WWWeasel [Bot]'				'WWWeasel Robot v'
  1.2109 +	* 'Xaldon [Spider]'				'Xaldon WebSpider'
  1.2110 +	*/
  1.2111 +	var $bot_list = array(
  1.2112 +		'AdsBot [Google]'			=> array('AdsBot-Google', ''),
  1.2113 +		'Alexa [Bot]'				=> array('ia_archiver', ''),
  1.2114 +		'Alta Vista [Bot]'			=> array('Scooter/', ''),
  1.2115 +		'Ask Jeeves [Bot]'			=> array('Ask Jeeves', ''),
  1.2116 +		'Baidu [Spider]'			=> array('Baiduspider+(', ''),
  1.2117 +		'Bing [Bot]'                => array('bingbot/', ''),
  1.2118 +		'Exabot [Bot]'				=> array('Exabot/', ''),
  1.2119 +		'FAST Enterprise [Crawler]'	=> array('FAST Enterprise Crawler', ''),
  1.2120 +		'FAST WebCrawler [Crawler]'	=> array('FAST-WebCrawler/', ''),
  1.2121 +		'Francis [Bot]'				=> array('http://www.neomo.de/', ''),
  1.2122 +		'Gigabot [Bot]'				=> array('Gigabot/', ''),
  1.2123 +		'Google Adsense [Bot]'		=> array('Mediapartners-Google', ''),
  1.2124 +		'Google Desktop'			=> array('Google Desktop', ''),
  1.2125 +		'Google Feedfetcher'		=> array('Feedfetcher-Google', ''),
  1.2126 +		'Google [Bot]'				=> array('Googlebot', ''),
  1.2127 +		'Heise IT-Markt [Crawler]'	=> array('heise-IT-Markt-Crawler', ''),
  1.2128 +		'Heritrix [Crawler]'		=> array('heritrix/1.', ''),
  1.2129 +		'IBM Research [Bot]'		=> array('ibm.com/cs/crawler', ''),
  1.2130 +		'ICCrawler - ICjobs'		=> array('ICCrawler - ICjobs', ''),
  1.2131 +		'ichiro [Crawler]'			=> array('ichiro/', ''),
  1.2132 +		'Majestic-12 [Bot]'			=> array('MJ12bot/', ''),
  1.2133 +		'Metager [Bot]'				=> array('MetagerBot/', ''),
  1.2134 +		'MSN NewsBlogs'				=> array('msnbot-NewsBlogs/', ''),
  1.2135 +		'MSN [Bot]'					=> array('msnbot/', ''),
  1.2136 +		'MSNbot Media'				=> array('msnbot-media/', ''),
  1.2137 +		'NG-Search [Bot]'			=> array('NG-Search/', ''),
  1.2138 +		'Nutch [Bot]'				=> array('http://lucene.apache.org/nutch/', ''),
  1.2139 +		'Nutch/CVS [Bot]'			=> array('NutchCVS/', ''),
  1.2140 +		'OmniExplorer [Bot]'		=> array('OmniExplorer_Bot/', ''),
  1.2141 +		'Online link [Validator]'	=> array('online link validator', ''),
  1.2142 +		'psbot [Picsearch]'			=> array('psbot/0', ''),
  1.2143 +		'Seekport [Bot]'			=> array('Seekbot/', ''),
  1.2144 +		'Sensis [Crawler]'			=> array('Sensis Web Crawler', ''),
  1.2145 +		'SEO Crawler'				=> array('SEO search Crawler/', ''),
  1.2146 +		'Seoma [Crawler]'			=> array('Seoma [SEO Crawler]', ''),
  1.2147 +		'SEOSearch [Crawler]'		=> array('SEOsearch/', ''),
  1.2148 +		'Snappy [Bot]'				=> array('Snappy/1.1 ( http://www.urltrends.com/ )', ''),
  1.2149 +		'Steeler [Crawler]'			=> array('http://www.tkl.iis.u-tokyo.ac.jp/~crawler/', ''),
  1.2150 +		'Synoo [Bot]'				=> array('SynooBot/', ''),
  1.2151 +		'Telekom [Bot]'				=> array('crawleradmin.t-info@telekom.de', ''),
  1.2152 +		'TurnitinBot [Bot]'			=> array('TurnitinBot/', ''),
  1.2153 +		'Voyager [Bot]'				=> array('voyager/1.0', ''),
  1.2154 +		'W3 [Sitesearch]'			=> array('W3 SiteSearch Crawler', ''),
  1.2155 +		'W3C [Linkcheck]'			=> array('W3C-checklink/', ''),
  1.2156 +		'W3C [Validator]'			=> array('W3C_*Validator', ''),
  1.2157 +		'WiseNut [Bot]'				=> array('http://www.WISEnutbot.com', ''),
  1.2158 +		'YaCy [Bot]'				=> array('yacybot', ''),
  1.2159 +		'Yahoo MMCrawler [Bot]'		=> array('Yahoo-MMCrawler/', ''),
  1.2160 +		'Yahoo Slurp [Bot]'			=> array('Yahoo! DE Slurp', ''),
  1.2161 +		'Yahoo [Bot]'				=> array('Yahoo! Slurp', ''),
  1.2162 +		'YahooSeeker [Bot]'			=> array('YahooSeeker/', ''),
  1.2163 +	);
  1.2164 +
  1.2165 +	/**
  1.2166 +	* Define the module structure so that we can populate the database without
  1.2167 +	* needing to hard-code module_id values
  1.2168 +	*/
  1.2169 +	var $module_categories = array(
  1.2170 +		'acp'	=> array(
  1.2171 +			'ACP_CAT_GENERAL'		=> array(
  1.2172 +				'ACP_QUICK_ACCESS',
  1.2173 +				'ACP_BOARD_CONFIGURATION',
  1.2174 +				'ACP_CLIENT_COMMUNICATION',
  1.2175 +				'ACP_SERVER_CONFIGURATION',
  1.2176 +			),
  1.2177 +			'ACP_CAT_FORUMS'		=> array(
  1.2178 +				'ACP_MANAGE_FORUMS',
  1.2179 +				'ACP_FORUM_BASED_PERMISSIONS',
  1.2180 +			),
  1.2181 +			'ACP_CAT_POSTING'		=> array(
  1.2182 +				'ACP_MESSAGES',
  1.2183 +				'ACP_ATTACHMENTS',
  1.2184 +			),
  1.2185 +			'ACP_CAT_USERGROUP'		=> array(
  1.2186 +				'ACP_CAT_USERS',
  1.2187 +				'ACP_GROUPS',
  1.2188 +				'ACP_USER_SECURITY',
  1.2189 +			),
  1.2190 +			'ACP_CAT_PERMISSIONS'	=> array(
  1.2191 +				'ACP_GLOBAL_PERMISSIONS',
  1.2192 +				'ACP_FORUM_BASED_PERMISSIONS',
  1.2193 +				'ACP_PERMISSION_ROLES',
  1.2194 +				'ACP_PERMISSION_MASKS',
  1.2195 +			),
  1.2196 +			'ACP_CAT_STYLES'		=> array(
  1.2197 +				'ACP_STYLE_MANAGEMENT',
  1.2198 +				'ACP_STYLE_COMPONENTS',
  1.2199 +			),
  1.2200 +			'ACP_CAT_MAINTENANCE'	=> array(
  1.2201 +				'ACP_FORUM_LOGS',
  1.2202 +				'ACP_CAT_DATABASE',
  1.2203 +			),
  1.2204 +			'ACP_CAT_SYSTEM'		=> array(
  1.2205 +				'ACP_AUTOMATION',
  1.2206 +				'ACP_GENERAL_TASKS',
  1.2207 +				'ACP_MODULE_MANAGEMENT',
  1.2208 +			),
  1.2209 +			'ACP_CAT_DOT_MODS'		=> null,
  1.2210 +		),
  1.2211 +		'mcp'	=> array(
  1.2212 +			'MCP_MAIN'		=> null,
  1.2213 +			'MCP_QUEUE'		=> null,
  1.2214 +			'MCP_REPORTS'	=> null,
  1.2215 +			'MCP_NOTES'		=> null,
  1.2216 +			'MCP_WARN'		=> null,
  1.2217 +			'MCP_LOGS'		=> null,
  1.2218 +			'MCP_BAN'		=> null,
  1.2219 +		),
  1.2220 +		'ucp'	=> array(
  1.2221 +			'UCP_MAIN'			=> null,
  1.2222 +			'UCP_PROFILE'		=> null,
  1.2223 +			'UCP_PREFS'			=> null,
  1.2224 +			'UCP_PM'			=> null,
  1.2225 +			'UCP_USERGROUPS'	=> null,
  1.2226 +			'UCP_ZEBRA'			=> null,
  1.2227 +		),
  1.2228 +	);
  1.2229 +
  1.2230 +	var $module_extras = array(
  1.2231 +		'acp'	=> array(
  1.2232 +			'ACP_QUICK_ACCESS' => array(
  1.2233 +				'ACP_MANAGE_USERS',
  1.2234 +				'ACP_GROUPS_MANAGE',
  1.2235 +				'ACP_MANAGE_FORUMS',
  1.2236 +				'ACP_MOD_LOGS',
  1.2237 +				'ACP_BOTS',
  1.2238 +				'ACP_PHP_INFO',
  1.2239 +			),
  1.2240 +			'ACP_FORUM_BASED_PERMISSIONS' => array(
  1.2241 +				'ACP_FORUM_PERMISSIONS',
  1.2242 +				'ACP_FORUM_PERMISSIONS_COPY',
  1.2243 +				'ACP_FORUM_MODERATORS',
  1.2244 +				'ACP_USERS_FORUM_PERMISSIONS',
  1.2245 +				'ACP_GROUPS_FORUM_PERMISSIONS',
  1.2246 +			),
  1.2247 +		),
  1.2248 +	);
  1.2249 +}
  1.2250 +
  1.2251 +?>
  1.2252 \ No newline at end of file