/install/install_install.php
PHP | 2241 lines | 1651 code | 362 blank | 228 comment | 193 complexity | 5db57b8c95e1ac28d41b67ed2112d58a MD5 | raw file
Possible License(s): AGPL-1.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- *
- * @package install
- * @version $Id$
- * @copyright (c) 2005 phpBB Group
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- *
- */
- /**
- */
- if (!defined('IN_INSTALL'))
- {
- // Someone has tried to access the file direct. This is not a good idea, so exit
- exit;
- }
- if (!empty($setmodules))
- {
- // If phpBB is already installed we do not include this module
- if (@file_exists($phpbb_root_path . 'config.' . $phpEx) && !file_exists($phpbb_root_path . 'cache/install_lock'))
- {
- include_once($phpbb_root_path . 'config.' . $phpEx);
- if (defined('PHPBB_INSTALLED'))
- {
- return;
- }
- }
- $module[] = array(
- 'module_type' => 'install',
- 'module_title' => 'INSTALL',
- 'module_filename' => substr(basename(__FILE__), 0, -strlen($phpEx)-1),
- 'module_order' => 10,
- 'module_subs' => '',
- 'module_stages' => array('INTRO', 'REQUIREMENTS', 'DATABASE', 'ADMINISTRATOR', 'CONFIG_FILE', 'ADVANCED', 'CREATE_TABLE', 'FINAL'),
- 'module_reqs' => ''
- );
- }
- /**
- * Installation
- * @package install
- */
- class install_install extends module
- {
- function install_install(&$p_master)
- {
- $this->p_master = &$p_master;
- }
- function main($mode, $sub)
- {
- global $lang, $template, $language, $phpbb_root_path, $cache;
- switch ($sub)
- {
- case 'intro':
- $cache->purge();
- $this->page_title = $lang['SUB_INTRO'];
- $template->assign_vars(array(
- 'TITLE' => $lang['INSTALL_INTRO'],
- 'BODY' => $lang['INSTALL_INTRO_BODY'],
- 'L_SUBMIT' => $lang['NEXT_STEP'],
- 'S_LANG_SELECT' => '<select id="language" name="language">' . $this->p_master->inst_language_select($language) . '</select>',
- 'U_ACTION' => $this->p_master->module_url . "?mode=$mode&sub=requirements&language=$language",
- ));
- break;
- case 'requirements':
- $this->check_server_requirements($mode, $sub);
- break;
- case 'database':
- $this->obtain_database_settings($mode, $sub);
- break;
- case 'administrator':
- $this->obtain_admin_settings($mode, $sub);
- break;
- case 'config_file':
- $this->create_config_file($mode, $sub);
- break;
- case 'advanced':
- $this->obtain_advanced_settings($mode, $sub);
- break;
- case 'create_table':
- $this->load_schema($mode, $sub);
- break;
- case 'final':
- $this->build_search_index($mode, $sub);
- $this->add_modules($mode, $sub);
- $this->add_language($mode, $sub);
- $this->add_bots($mode, $sub);
- $this->email_admin($mode, $sub);
- $this->disable_avatars_if_unwritable();
- // Remove the lock file
- @unlink($phpbb_root_path . 'cache/install_lock');
- break;
- }
- $this->tpl_name = 'install_install';
- }
- /**
- * Checks that the server we are installing on meets the requirements for running phpBB
- */
- function check_server_requirements($mode, $sub)
- {
- global $lang, $template, $phpbb_root_path, $phpEx, $language;
- $this->page_title = $lang['STAGE_REQUIREMENTS'];
- $template->assign_vars(array(
- 'TITLE' => $lang['REQUIREMENTS_TITLE'],
- 'BODY' => $lang['REQUIREMENTS_EXPLAIN'],
- ));
- $passed = array('php' => false, 'db' => false, 'files' => false, 'pcre' => false, 'imagesize' => false,);
- // Test for basic PHP settings
- $template->assign_block_vars('checks', array(
- 'S_LEGEND' => true,
- 'LEGEND' => $lang['PHP_SETTINGS'],
- 'LEGEND_EXPLAIN' => $lang['PHP_SETTINGS_EXPLAIN'],
- ));
- // Test the minimum PHP version
- $php_version = PHP_VERSION;
- if (version_compare($php_version, '4.3.3') < 0)
- {
- $result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
- }
- else
- {
- $passed['php'] = true;
- // We also give feedback on whether we're running in safe mode
- $result = '<strong style="color:green">' . $lang['YES'];
- if (@ini_get('safe_mode') == '1' || strtolower(@ini_get('safe_mode')) == 'on')
- {
- $result .= ', ' . $lang['PHP_SAFE_MODE'];
- }
- $result .= '</strong>';
- }
- $template->assign_block_vars('checks', array(
- 'TITLE' => $lang['PHP_VERSION_REQD'],
- 'RESULT' => $result,
- 'S_EXPLAIN' => false,
- 'S_LEGEND' => false,
- ));
- // Don't check for register_globals on 5.4+
- if (version_compare($php_version, '5.4.0-dev') < 0)
- {
- // Check for register_globals being enabled
- if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on')
- {
- $result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
- }
- else
- {
- $result = '<strong style="color:green">' . $lang['YES'] . '</strong>';
- }
- $template->assign_block_vars('checks', array(
- 'TITLE' => $lang['PHP_REGISTER_GLOBALS'],
- 'TITLE_EXPLAIN' => $lang['PHP_REGISTER_GLOBALS_EXPLAIN'],
- 'RESULT' => $result,
- 'S_EXPLAIN' => true,
- 'S_LEGEND' => false,
- ));
- }
- // Check for url_fopen
- if (@ini_get('allow_url_fopen') == '1' || strtolower(@ini_get('allow_url_fopen')) == 'on')
- {
- $result = '<strong style="color:green">' . $lang['YES'] . '</strong>';
- }
- else
- {
- $result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
- }
- $template->assign_block_vars('checks', array(
- 'TITLE' => $lang['PHP_URL_FOPEN_SUPPORT'],
- 'TITLE_EXPLAIN' => $lang['PHP_URL_FOPEN_SUPPORT_EXPLAIN'],
- 'RESULT' => $result,
- 'S_EXPLAIN' => true,
- 'S_LEGEND' => false,
- ));
- // Check for getimagesize
- if (@function_exists('getimagesize'))
- {
- $passed['imagesize'] = true;
- $result = '<strong style="color:green">' . $lang['YES'] . '</strong>';
- }
- else
- {
- $result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
- }
- $template->assign_block_vars('checks', array(
- 'TITLE' => $lang['PHP_GETIMAGESIZE_SUPPORT'],
- 'TITLE_EXPLAIN' => $lang['PHP_GETIMAGESIZE_SUPPORT_EXPLAIN'],
- 'RESULT' => $result,
- 'S_EXPLAIN' => true,
- 'S_LEGEND' => false,
- ));
- // Check for PCRE UTF-8 support
- if (@preg_match('//u', ''))
- {
- $passed['pcre'] = true;
- $result = '<strong style="color:green">' . $lang['YES'] . '</strong>';
- }
- else
- {
- $result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
- }
- $template->assign_block_vars('checks', array(
- 'TITLE' => $lang['PCRE_UTF_SUPPORT'],
- 'TITLE_EXPLAIN' => $lang['PCRE_UTF_SUPPORT_EXPLAIN'],
- 'RESULT' => $result,
- 'S_EXPLAIN' => true,
- 'S_LEGEND' => false,
- ));
- /**
- * Better not enabling and adding to the loaded extensions due to the specific requirements needed
- if (!@extension_loaded('mbstring'))
- {
- can_load_dll('mbstring');
- }
- */
- $passed['mbstring'] = true;
- if (@extension_loaded('mbstring'))
- {
- // Test for available database modules
- $template->assign_block_vars('checks', array(
- 'S_LEGEND' => true,
- 'LEGEND' => $lang['MBSTRING_CHECK'],
- 'LEGEND_EXPLAIN' => $lang['MBSTRING_CHECK_EXPLAIN'],
- ));
- $checks = array(
- array('func_overload', '&', MB_OVERLOAD_MAIL|MB_OVERLOAD_STRING),
- array('encoding_translation', '!=', 0),
- array('http_input', '!=', 'pass'),
- array('http_output', '!=', 'pass')
- );
- foreach ($checks as $mb_checks)
- {
- $ini_val = @ini_get('mbstring.' . $mb_checks[0]);
- switch ($mb_checks[1])
- {
- case '&':
- if (intval($ini_val) & $mb_checks[2])
- {
- $result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
- $passed['mbstring'] = false;
- }
- else
- {
- $result = '<strong style="color:green">' . $lang['YES'] . '</strong>';
- }
- break;
- case '!=':
- if ($ini_val != $mb_checks[2])
- {
- $result = '<strong style="color:red">' . $lang['NO'] . '</strong>';
- $passed['mbstring'] = false;
- }
- else
- {
- $result = '<strong style="color:green">' . $lang['YES'] . '</strong>';
- }
- break;
- }
- $template->assign_block_vars('checks', array(
- 'TITLE' => $lang['MBSTRING_' . strtoupper($mb_checks[0])],
- 'TITLE_EXPLAIN' => $lang['MBSTRING_' . strtoupper($mb_checks[0]) . '_EXPLAIN'],
- 'RESULT' => $result,
- 'S_EXPLAIN' => true,
- 'S_LEGEND' => false,
- ));
- }
- }
- // Test for available database modules
- $template->assign_block_vars('checks', array(
- 'S_LEGEND' => true,
- 'LEGEND' => $lang['PHP_SUPPORTED_DB'],
- 'LEGEND_EXPLAIN' => $lang['PHP_SUPPORTED_DB_EXPLAIN'],
- ));
- $available_dbms = get_available_dbms(false, true);
- $passed['db'] = $available_dbms['ANY_DB_SUPPORT'];
- unset($available_dbms['ANY_DB_SUPPORT']);
- foreach ($available_dbms as $db_name => $db_ary)
- {
- if (!$db_ary['AVAILABLE'])
- {
- $template->assign_block_vars('checks', array(
- 'TITLE' => $lang['DLL_' . strtoupper($db_name)],
- 'RESULT' => '<span style="color:red">' . $lang['UNAVAILABLE'] . '</span>',
- 'S_EXPLAIN' => false,
- 'S_LEGEND' => false,
- ));
- }
- else
- {
- $template->assign_block_vars('checks', array(
- 'TITLE' => $lang['DLL_' . strtoupper($db_name)],
- 'RESULT' => '<strong style="color:green">' . $lang['AVAILABLE'] . '</strong>',
- 'S_EXPLAIN' => false,
- 'S_LEGEND' => false,
- ));
- }
- }
- // Test for other modules
- $template->assign_block_vars('checks', array(
- 'S_LEGEND' => true,
- 'LEGEND' => $lang['PHP_OPTIONAL_MODULE'],
- 'LEGEND_EXPLAIN' => $lang['PHP_OPTIONAL_MODULE_EXPLAIN'],
- ));
- foreach ($this->php_dlls_other as $dll)
- {
- if (!@extension_loaded($dll))
- {
- if (!can_load_dll($dll))
- {
- $template->assign_block_vars('checks', array(
- 'TITLE' => $lang['DLL_' . strtoupper($dll)],
- 'RESULT' => '<strong style="color:red">' . $lang['UNAVAILABLE'] . '</strong>',
- 'S_EXPLAIN' => false,
- 'S_LEGEND' => false,
- ));
- continue;
- }
- }
- $template->assign_block_vars('checks', array(
- 'TITLE' => $lang['DLL_' . strtoupper($dll)],
- 'RESULT' => '<strong style="color:green">' . $lang['AVAILABLE'] . '</strong>',
- 'S_EXPLAIN' => false,
- 'S_LEGEND' => false,
- ));
- }
- // Can we find Imagemagick anywhere on the system?
- $exe = (DIRECTORY_SEPARATOR == '\\') ? '.exe' : '';
- $magic_home = getenv('MAGICK_HOME');
- $img_imagick = '';
- if (empty($magic_home))
- {
- $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/');
- $path_locations = str_replace('\\', '/', (explode(($exe) ? ';' : ':', getenv('PATH'))));
- $locations = array_merge($path_locations, $locations);
- foreach ($locations as $location)
- {
- // The path might not end properly, fudge it
- if (substr($location, -1, 1) !== '/')
- {
- $location .= '/';
- }
- if (@file_exists($location) && @is_readable($location . 'mogrify' . $exe) && @filesize($location . 'mogrify' . $exe) > 3000)
- {
- $img_imagick = str_replace('\\', '/', $location);
- continue;
- }
- }
- }
- else
- {
- $img_imagick = str_replace('\\', '/', $magic_home);
- }
- $template->assign_block_vars('checks', array(
- 'TITLE' => $lang['APP_MAGICK'],
- 'RESULT' => ($img_imagick) ? '<strong style="color:green">' . $lang['AVAILABLE'] . ', ' . $img_imagick . '</strong>' : '<strong style="color:blue">' . $lang['NO_LOCATION'] . '</strong>',
- 'S_EXPLAIN' => false,
- 'S_LEGEND' => false,
- ));
- // Check permissions on files/directories we need access to
- $template->assign_block_vars('checks', array(
- 'S_LEGEND' => true,
- 'LEGEND' => $lang['FILES_REQUIRED'],
- 'LEGEND_EXPLAIN' => $lang['FILES_REQUIRED_EXPLAIN'],
- ));
- $directories = array('cache/', 'files/', 'store/');
- umask(0);
- $passed['files'] = true;
- foreach ($directories as $dir)
- {
- $exists = $write = false;
- // Try to create the directory if it does not exist
- if (!file_exists($phpbb_root_path . $dir))
- {
- @mkdir($phpbb_root_path . $dir, 0777);
- phpbb_chmod($phpbb_root_path . $dir, CHMOD_READ | CHMOD_WRITE);
- }
- // Now really check
- if (file_exists($phpbb_root_path . $dir) && is_dir($phpbb_root_path . $dir))
- {
- phpbb_chmod($phpbb_root_path . $dir, CHMOD_READ | CHMOD_WRITE);
- $exists = true;
- }
- // Now check if it is writable by storing a simple file
- $fp = @fopen($phpbb_root_path . $dir . 'test_lock', 'wb');
- if ($fp !== false)
- {
- $write = true;
- }
- @fclose($fp);
- @unlink($phpbb_root_path . $dir . 'test_lock');
- $passed['files'] = ($exists && $write && $passed['files']) ? true : false;
- $exists = ($exists) ? '<strong style="color:green">' . $lang['FOUND'] . '</strong>' : '<strong style="color:red">' . $lang['NOT_FOUND'] . '</strong>';
- $write = ($write) ? ', <strong style="color:green">' . $lang['WRITABLE'] . '</strong>' : (($exists) ? ', <strong style="color:red">' . $lang['UNWRITABLE'] . '</strong>' : '');
- $template->assign_block_vars('checks', array(
- 'TITLE' => $dir,
- 'RESULT' => $exists . $write,
- 'S_EXPLAIN' => false,
- 'S_LEGEND' => false,
- ));
- }
- // Check permissions on files/directories it would be useful access to
- $template->assign_block_vars('checks', array(
- 'S_LEGEND' => true,
- 'LEGEND' => $lang['FILES_OPTIONAL'],
- 'LEGEND_EXPLAIN' => $lang['FILES_OPTIONAL_EXPLAIN'],
- ));
- $directories = array('config.' . $phpEx, 'images/avatars/upload/');
- foreach ($directories as $dir)
- {
- $write = $exists = true;
- if (file_exists($phpbb_root_path . $dir))
- {
- if (!phpbb_is_writable($phpbb_root_path . $dir))
- {
- $write = false;
- }
- }
- else
- {
- $write = $exists = false;
- }
- $exists_str = ($exists) ? '<strong style="color:green">' . $lang['FOUND'] . '</strong>' : '<strong style="color:red">' . $lang['NOT_FOUND'] . '</strong>';
- $write_str = ($write) ? ', <strong style="color:green">' . $lang['WRITABLE'] . '</strong>' : (($exists) ? ', <strong style="color:red">' . $lang['UNWRITABLE'] . '</strong>' : '');
- $template->assign_block_vars('checks', array(
- 'TITLE' => $dir,
- 'RESULT' => $exists_str . $write_str,
- 'S_EXPLAIN' => false,
- 'S_LEGEND' => false,
- ));
- }
- // And finally where do we want to go next (well today is taken isn't it :P)
- $s_hidden_fields = ($img_imagick) ? '<input type="hidden" name="img_imagick" value="' . addslashes($img_imagick) . '" />' : '';
- $url = (!in_array(false, $passed)) ? $this->p_master->module_url . "?mode=$mode&sub=database&language=$language" : $this->p_master->module_url . "?mode=$mode&sub=requirements&language=$language ";
- $submit = (!in_array(false, $passed)) ? $lang['INSTALL_START'] : $lang['INSTALL_TEST'];
- $template->assign_vars(array(
- 'L_SUBMIT' => $submit,
- 'S_HIDDEN' => $s_hidden_fields,
- 'U_ACTION' => $url,
- ));
- }
- /**
- * Obtain the information required to connect to the database
- */
- function obtain_database_settings($mode, $sub)
- {
- global $lang, $template, $phpEx;
- $this->page_title = $lang['STAGE_DATABASE'];
- // Obtain any submitted data
- $data = $this->get_submitted_data();
- $connect_test = false;
- $error = array();
- $available_dbms = get_available_dbms(false, true);
- // Has the user opted to test the connection?
- if (isset($_POST['testdb']))
- {
- if (!isset($available_dbms[$data['dbms']]) || !$available_dbms[$data['dbms']]['AVAILABLE'])
- {
- $error[] = $lang['INST_ERR_NO_DB'];
- $connect_test = false;
- }
- else if (!preg_match(get_preg_expression('table_prefix'), $data['table_prefix']))
- {
- $error[] = $lang['INST_ERR_DB_INVALID_PREFIX'];
- $connect_test = false;
- }
- else
- {
- $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']);
- }
- $template->assign_block_vars('checks', array(
- 'S_LEGEND' => true,
- 'LEGEND' => $lang['DB_CONNECTION'],
- 'LEGEND_EXPLAIN' => false,
- ));
- if ($connect_test)
- {
- $template->assign_block_vars('checks', array(
- 'TITLE' => $lang['DB_TEST'],
- 'RESULT' => '<strong style="color:green">' . $lang['SUCCESSFUL_CONNECT'] . '</strong>',
- 'S_EXPLAIN' => false,
- 'S_LEGEND' => false,
- ));
- }
- else
- {
- $template->assign_block_vars('checks', array(
- 'TITLE' => $lang['DB_TEST'],
- 'RESULT' => '<strong style="color:red">' . implode('<br />', $error) . '</strong>',
- 'S_EXPLAIN' => false,
- 'S_LEGEND' => false,
- ));
- }
- }
- if (!$connect_test)
- {
- // Update the list of available DBMS modules to only contain those which can be used
- $available_dbms_temp = array();
- foreach ($available_dbms as $type => $dbms_ary)
- {
- if (!$dbms_ary['AVAILABLE'])
- {
- continue;
- }
- $available_dbms_temp[$type] = $dbms_ary;
- }
- $available_dbms = &$available_dbms_temp;
- // And now for the main part of this page
- $data['table_prefix'] = (!empty($data['table_prefix']) ? $data['table_prefix'] : 'phpbb_');
- foreach ($this->db_config_options as $config_key => $vars)
- {
- if (!is_array($vars) && strpos($config_key, 'legend') === false)
- {
- continue;
- }
- if (strpos($config_key, 'legend') !== false)
- {
- $template->assign_block_vars('options', array(
- 'S_LEGEND' => true,
- 'LEGEND' => $lang[$vars])
- );
- continue;
- }
- $options = isset($vars['options']) ? $vars['options'] : '';
- $template->assign_block_vars('options', array(
- 'KEY' => $config_key,
- 'TITLE' => $lang[$vars['lang']],
- 'S_EXPLAIN' => $vars['explain'],
- 'S_LEGEND' => false,
- 'TITLE_EXPLAIN' => ($vars['explain']) ? $lang[$vars['lang'] . '_EXPLAIN'] : '',
- 'CONTENT' => $this->p_master->input_field($config_key, $vars['type'], $data[$config_key], $options),
- )
- );
- }
- }
- // And finally where do we want to go next (well today is taken isn't it :P)
- $s_hidden_fields = ($data['img_imagick']) ? '<input type="hidden" name="img_imagick" value="' . addslashes($data['img_imagick']) . '" />' : '';
- $s_hidden_fields .= '<input type="hidden" name="language" value="' . $data['language'] . '" />';
- if ($connect_test)
- {
- foreach ($this->db_config_options as $config_key => $vars)
- {
- if (!is_array($vars))
- {
- continue;
- }
- $s_hidden_fields .= '<input type="hidden" name="' . $config_key . '" value="' . $data[$config_key] . '" />';
- }
- }
- $url = ($connect_test) ? $this->p_master->module_url . "?mode=$mode&sub=administrator" : $this->p_master->module_url . "?mode=$mode&sub=database";
- $s_hidden_fields .= ($connect_test) ? '' : '<input type="hidden" name="testdb" value="true" />';
- $submit = $lang['NEXT_STEP'];
- $template->assign_vars(array(
- 'L_SUBMIT' => $submit,
- 'S_HIDDEN' => $s_hidden_fields,
- 'U_ACTION' => $url,
- ));
- }
- /**
- * Obtain the administrator's name, password and email address
- */
- function obtain_admin_settings($mode, $sub)
- {
- global $lang, $template, $phpEx;
- $this->page_title = $lang['STAGE_ADMINISTRATOR'];
- // Obtain any submitted data
- $data = $this->get_submitted_data();
- if ($data['dbms'] == '')
- {
- // Someone's been silly and tried calling this page direct
- // So we send them back to the start to do it again properly
- $this->p_master->redirect("index.$phpEx?mode=install");
- }
- $s_hidden_fields = ($data['img_imagick']) ? '<input type="hidden" name="img_imagick" value="' . addslashes($data['img_imagick']) . '" />' : '';
- $passed = false;
- $data['default_lang'] = ($data['default_lang'] !== '') ? $data['default_lang'] : $data['language'];
- if (isset($_POST['check']))
- {
- $error = array();
- // Check the entered email address and password
- if ($data['admin_name'] == '' || $data['admin_pass1'] == '' || $data['admin_pass2'] == '' || $data['board_email1'] == '' || $data['board_email2'] == '')
- {
- $error[] = $lang['INST_ERR_MISSING_DATA'];
- }
- if ($data['admin_pass1'] != $data['admin_pass2'] && $data['admin_pass1'] != '')
- {
- $error[] = $lang['INST_ERR_PASSWORD_MISMATCH'];
- }
- // Test against the default username rules
- if ($data['admin_name'] != '' && utf8_strlen($data['admin_name']) < 3)
- {
- $error[] = $lang['INST_ERR_USER_TOO_SHORT'];
- }
- if ($data['admin_name'] != '' && utf8_strlen($data['admin_name']) > 20)
- {
- $error[] = $lang['INST_ERR_USER_TOO_LONG'];
- }
- // Test against the default password rules
- if ($data['admin_pass1'] != '' && utf8_strlen($data['admin_pass1']) < 6)
- {
- $error[] = $lang['INST_ERR_PASSWORD_TOO_SHORT'];
- }
- if ($data['admin_pass1'] != '' && utf8_strlen($data['admin_pass1']) > 30)
- {
- $error[] = $lang['INST_ERR_PASSWORD_TOO_LONG'];
- }
- if ($data['board_email1'] != $data['board_email2'] && $data['board_email1'] != '')
- {
- $error[] = $lang['INST_ERR_EMAIL_MISMATCH'];
- }
- if ($data['board_email1'] != '' && !preg_match('/^' . get_preg_expression('email') . '$/i', $data['board_email1']))
- {
- $error[] = $lang['INST_ERR_EMAIL_INVALID'];
- }
- $template->assign_block_vars('checks', array(
- 'S_LEGEND' => true,
- 'LEGEND' => $lang['STAGE_ADMINISTRATOR'],
- 'LEGEND_EXPLAIN' => false,
- ));
- if (!sizeof($error))
- {
- $passed = true;
- $template->assign_block_vars('checks', array(
- 'TITLE' => $lang['ADMIN_TEST'],
- 'RESULT' => '<strong style="color:green">' . $lang['TESTS_PASSED'] . '</strong>',
- 'S_EXPLAIN' => false,
- 'S_LEGEND' => false,
- ));
- }
- else
- {
- $template->assign_block_vars('checks', array(
- 'TITLE' => $lang['ADMIN_TEST'],
- 'RESULT' => '<strong style="color:red">' . implode('<br />', $error) . '</strong>',
- 'S_EXPLAIN' => false,
- 'S_LEGEND' => false,
- ));
- }
- }
- if (!$passed)
- {
- foreach ($this->admin_config_options as $config_key => $vars)
- {
- if (!is_array($vars) && strpos($config_key, 'legend') === false)
- {
- continue;
- }
- if (strpos($config_key, 'legend') !== false)
- {
- $template->assign_block_vars('options', array(
- 'S_LEGEND' => true,
- 'LEGEND' => $lang[$vars])
- );
- continue;
- }
- $options = isset($vars['options']) ? $vars['options'] : '';
- $template->assign_block_vars('options', array(
- 'KEY' => $config_key,
- 'TITLE' => $lang[$vars['lang']],
- 'S_EXPLAIN' => $vars['explain'],
- 'S_LEGEND' => false,
- 'TITLE_EXPLAIN' => ($vars['explain']) ? $lang[$vars['lang'] . '_EXPLAIN'] : '',
- 'CONTENT' => $this->p_master->input_field($config_key, $vars['type'], $data[$config_key], $options),
- )
- );
- }
- }
- else
- {
- foreach ($this->admin_config_options as $config_key => $vars)
- {
- if (!is_array($vars))
- {
- continue;
- }
- $s_hidden_fields .= '<input type="hidden" name="' . $config_key . '" value="' . $data[$config_key] . '" />';
- }
- }
- $s_hidden_fields .= ($data['img_imagick']) ? '<input type="hidden" name="img_imagick" value="' . addslashes($data['img_imagick']) . '" />' : '';
- $s_hidden_fields .= '<input type="hidden" name="language" value="' . $data['language'] . '" />';
- foreach ($this->db_config_options as $config_key => $vars)
- {
- if (!is_array($vars))
- {
- continue;
- }
- $s_hidden_fields .= '<input type="hidden" name="' . $config_key . '" value="' . $data[$config_key] . '" />';
- }
- $submit = $lang['NEXT_STEP'];
- $url = ($passed) ? $this->p_master->module_url . "?mode=$mode&sub=config_file" : $this->p_master->module_url . "?mode=$mode&sub=administrator";
- $s_hidden_fields .= ($passed) ? '' : '<input type="hidden" name="check" value="true" />';
- $template->assign_vars(array(
- 'L_SUBMIT' => $submit,
- 'S_HIDDEN' => $s_hidden_fields,
- 'U_ACTION' => $url,
- ));
- }
- /**
- * Writes the config file to disk, or if unable to do so offers alternative methods
- */
- function create_config_file($mode, $sub)
- {
- global $lang, $template, $phpbb_root_path, $phpEx;
- $this->page_title = $lang['STAGE_CONFIG_FILE'];
- // Obtain any submitted data
- $data = $this->get_submitted_data();
- if ($data['dbms'] == '')
- {
- // Someone's been silly and tried calling this page direct
- // So we send them back to the start to do it again properly
- $this->p_master->redirect("index.$phpEx?mode=install");
- }
- $s_hidden_fields = ($data['img_imagick']) ? '<input type="hidden" name="img_imagick" value="' . addslashes($data['img_imagick']) . '" />' : '';
- $s_hidden_fields .= '<input type="hidden" name="language" value="' . $data['language'] . '" />';
- $written = false;
- // Create a list of any PHP modules we wish to have loaded
- $load_extensions = array();
- $available_dbms = get_available_dbms($data['dbms']);
- $check_exts = array_merge(array($available_dbms[$data['dbms']]['MODULE']), $this->php_dlls_other);
- foreach ($check_exts as $dll)
- {
- if (!@extension_loaded($dll))
- {
- if (!can_load_dll($dll))
- {
- continue;
- }
- $load_extensions[] = $dll . '.' . PHP_SHLIB_SUFFIX;
- }
- }
- // Create a lock file to indicate that there is an install in progress
- $fp = @fopen($phpbb_root_path . 'cache/install_lock', 'wb');
- if ($fp === false)
- {
- // We were unable to create the lock file - abort
- $this->p_master->error($lang['UNABLE_WRITE_LOCK'], __LINE__, __FILE__);
- }
- @fclose($fp);
- @chmod($phpbb_root_path . 'cache/install_lock', 0777);
- // Time to convert the data provided into a config file
- $config_data = phpbb_create_config_file_data($data, $available_dbms[$data['dbms']]['DRIVER'], $load_extensions);
- // Attempt to write out the config file directly. If it works, this is the easiest way to do it ...
- if ((file_exists($phpbb_root_path . 'config.' . $phpEx) && phpbb_is_writable($phpbb_root_path . 'config.' . $phpEx)) || phpbb_is_writable($phpbb_root_path))
- {
- // Assume it will work ... if nothing goes wrong below
- $written = true;
- if (!($fp = @fopen($phpbb_root_path . 'config.' . $phpEx, 'w')))
- {
- // Something went wrong ... so let's try another method
- $written = false;
- }
- if (!(@fwrite($fp, $config_data)))
- {
- // Something went wrong ... so let's try another method
- $written = false;
- }
- @fclose($fp);
- if ($written)
- {
- // We may revert back to chmod() if we see problems with users not able to change their config.php file directly
- phpbb_chmod($phpbb_root_path . 'config.' . $phpEx, CHMOD_READ);
- }
- }
- if (isset($_POST['dldone']))
- {
- // Do a basic check to make sure that the file has been uploaded
- // Note that all we check is that the file has _something_ in it
- // We don't compare the contents exactly - if they can't upload
- // a single file correctly, it's likely they will have other problems....
- if (filesize($phpbb_root_path . 'config.' . $phpEx) > 10)
- {
- $written = true;
- }
- }
- $config_options = array_merge($this->db_config_options, $this->admin_config_options);
- foreach ($config_options as $config_key => $vars)
- {
- if (!is_array($vars))
- {
- continue;
- }
- $s_hidden_fields .= '<input type="hidden" name="' . $config_key . '" value="' . $data[$config_key] . '" />';
- }
- if (!$written)
- {
- // OK, so it didn't work let's try the alternatives
- if (isset($_POST['dlconfig']))
- {
- // They want a copy of the file to download, so send the relevant headers and dump out the data
- header("Content-Type: text/x-delimtext; name=\"config.$phpEx\"");
- header("Content-disposition: attachment; filename=config.$phpEx");
- echo $config_data;
- exit;
- }
- // The option to download the config file is always available, so output it here
- $template->assign_vars(array(
- 'BODY' => $lang['CONFIG_FILE_UNABLE_WRITE'],
- 'L_DL_CONFIG' => $lang['DL_CONFIG'],
- 'L_DL_CONFIG_EXPLAIN' => $lang['DL_CONFIG_EXPLAIN'],
- 'L_DL_DONE' => $lang['DONE'],
- 'L_DL_DOWNLOAD' => $lang['DL_DOWNLOAD'],
- 'S_HIDDEN' => $s_hidden_fields,
- 'S_SHOW_DOWNLOAD' => true,
- 'U_ACTION' => $this->p_master->module_url . "?mode=$mode&sub=config_file",
- ));
- return;
- }
- else
- {
- $template->assign_vars(array(
- 'BODY' => $lang['CONFIG_FILE_WRITTEN'],
- 'L_SUBMIT' => $lang['NEXT_STEP'],
- 'S_HIDDEN' => $s_hidden_fields,
- 'U_ACTION' => $this->p_master->module_url . "?mode=$mode&sub=advanced",
- ));
- return;
- }
- }
- /**
- * Provide an opportunity to customise some advanced settings during the install
- * in case it is necessary for them to be set to access later
- */
- function obtain_advanced_settings($mode, $sub)
- {
- global $lang, $template, $phpEx;
- $this->page_title = $lang['STAGE_ADVANCED'];
- // Obtain any submitted data
- $data = $this->get_submitted_data();
- if ($data['dbms'] == '')
- {
- // Someone's been silly and tried calling this page direct
- // So we send them back to the start to do it again properly
- $this->p_master->redirect("index.$phpEx?mode=install");
- }
- $s_hidden_fields = ($data['img_imagick']) ? '<input type="hidden" name="img_imagick" value="' . addslashes($data['img_imagick']) . '" />' : '';
- $s_hidden_fields .= '<input type="hidden" name="language" value="' . $data['language'] . '" />';
- // HTTP_HOST is having the correct browser url in most cases...
- $server_name = (!empty($_SERVER['HTTP_HOST'])) ? strtolower($_SERVER['HTTP_HOST']) : ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME'));
- // HTTP HOST can carry a port number...
- if (strpos($server_name, ':') !== false)
- {
- $server_name = substr($server_name, 0, strpos($server_name, ':'));
- }
- $data['email_enable'] = ($data['email_enable'] !== '') ? $data['email_enable'] : true;
- $data['server_name'] = ($data['server_name'] !== '') ? $data['server_name'] : $server_name;
- $data['server_port'] = ($data['server_port'] !== '') ? $data['server_port'] : ((!empty($_SERVER['SERVER_PORT'])) ? (int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT'));
- $data['server_protocol'] = ($data['server_protocol'] !== '') ? $data['server_protocol'] : ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://');
- $data['cookie_secure'] = ($data['cookie_secure'] !== '') ? $data['cookie_secure'] : ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? true : false);
- if ($data['script_path'] === '')
- {
- $name = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF');
- if (!$name)
- {
- $name = (!empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI');
- }
- // Replace backslashes and doubled slashes (could happen on some proxy setups)
- $name = str_replace(array('\\', '//', '/install'), '/', $name);
- $data['script_path'] = trim(dirname($name));
- }
- foreach ($this->advanced_config_options as $config_key => $vars)
- {
- if (!is_array($vars) && strpos($config_key, 'legend') === false)
- {
- continue;
- }
- if (strpos($config_key, 'legend') !== false)
- {
- $template->assign_block_vars('options', array(
- 'S_LEGEND' => true,
- 'LEGEND' => $lang[$vars])
- );
- continue;
- }
- $options = isset($vars['options']) ? $vars['options'] : '';
- $template->assign_block_vars('options', array(
- 'KEY' => $config_key,
- 'TITLE' => $lang[$vars['lang']],
- 'S_EXPLAIN' => $vars['explain'],
- 'S_LEGEND' => false,
- 'TITLE_EXPLAIN' => ($vars['explain']) ? $lang[$vars['lang'] . '_EXPLAIN'] : '',
- 'CONTENT' => $this->p_master->input_field($config_key, $vars['type'], $data[$config_key], $options),
- )
- );
- }
- $config_options = array_merge($this->db_config_options, $this->admin_config_options);
- foreach ($config_options as $config_key => $vars)
- {
- if (!is_array($vars))
- {
- continue;
- }
- $s_hidden_fields .= '<input type="hidden" name="' . $config_key . '" value="' . $data[$config_key] . '" />';
- }
- $submit = $lang['NEXT_STEP'];
- $url = $this->p_master->module_url . "?mode=$mode&sub=create_table";
- $template->assign_vars(array(
- 'BODY' => $lang['STAGE_ADVANCED_EXPLAIN'],
- 'L_SUBMIT' => $submit,
- 'S_HIDDEN' => $s_hidden_fields,
- 'U_ACTION' => $url,
- ));
- }
- /**
- * Load the contents of the schema into the database and then alter it based on what has been input during the installation
- */
- function load_schema($mode, $sub)
- {
- global $db, $lang, $template, $phpbb_root_path, $phpEx;
- $this->page_title = $lang['STAGE_CREATE_TABLE'];
- $s_hidden_fields = '';
- // Obtain any submitted data
- $data = $this->get_submitted_data();
- if ($data['dbms'] == '')
- {
- // Someone's been silly and tried calling this page direct
- // So we send them back to the start to do it again properly
- $this->p_master->redirect("index.$phpEx?mode=install");
- }
- // HTTP_HOST is having the correct browser url in most cases...
- $server_name = (!empty($_SERVER['HTTP_HOST'])) ? strtolower($_SERVER['HTTP_HOST']) : ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME'));
- $referer = (!empty($_SERVER['HTTP_REFERER'])) ? strtolower($_SERVER['HTTP_REFERER']) : getenv('HTTP_REFERER');
- // HTTP HOST can carry a port number...
- if (strpos($server_name, ':') !== false)
- {
- $server_name = substr($server_name, 0, strpos($server_name, ':'));
- }
- $cookie_domain = ($data['server_name'] != '') ? $data['server_name'] : $server_name;
- // Try to come up with the best solution for cookie domain...
- if (strpos($cookie_domain, 'www.') === 0)
- {
- $cookie_domain = str_replace('www.', '.', $cookie_domain);
- }
- // If we get here and the extension isn't loaded it should be safe to just go ahead and load it
- $available_dbms = get_available_dbms($data['dbms']);
- if (!isset($available_dbms[$data['dbms']]))
- {
- // Someone's been silly and tried providing a non-existant dbms
- $this->p_master->redirect("index.$phpEx?mode=install");
- }
- $dbms = $available_dbms[$data['dbms']]['DRIVER'];
- // Load the appropriate database class if not already loaded
- include($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
- // Instantiate the database
- $db = new $sql_db();
- $db->sql_connect($data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport'], false, false);
- // NOTE: trigger_error does not work here.
- $db->sql_return_on_error(true);
- // If mysql is chosen, we need to adjust the schema filename slightly to reflect the correct version. ;)
- if ($data['dbms'] == 'mysql')
- {
- if (version_compare($db->sql_server_info(true), '4.1.3', '>='))
- {
- $available_dbms[$data['dbms']]['SCHEMA'] .= '_41';
- }
- else
- {
- $available_dbms[$data['dbms']]['SCHEMA'] .= '_40';
- }
- }
- // Ok we have the db info go ahead and read in the relevant schema
- // and work on building the table
- $dbms_schema = 'schemas/' . $available_dbms[$data['dbms']]['SCHEMA'] . '_schema.sql';
- // How should we treat this schema?
- $delimiter = $available_dbms[$data['dbms']]['DELIM'];
- $sql_query = @file_get_contents($dbms_schema);
- $sql_query = preg_replace('#phpbb_#i', $data['table_prefix'], $sql_query);
- $sql_query = phpbb_remove_comments($sql_query);
- $sql_query = split_sql_file($sql_query, $delimiter);
- foreach ($sql_query as $sql)
- {
- //$sql = trim(str_replace('|', ';', $sql));
- if (!$db->sql_query($sql))
- {
- $error = $db->sql_error();
- $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__);
- }
- }
- unset($sql_query);
- // Ok tables have been built, let's fill in the basic information
- $sql_query = file_get_contents('schemas/schema_data.sql');
- // Deal with any special comments
- switch ($data['dbms'])
- {
- case 'mssql':
- case 'mssql_odbc':
- case 'mssqlnative':
- $sql_query = preg_replace('#\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \##s', 'SET IDENTITY_INSERT \1 \2;', $sql_query);
- break;
- case 'postgres':
- $sql_query = preg_replace('#\# POSTGRES (BEGIN|COMMIT) \##s', '\1; ', $sql_query);
- break;
- }
- // Change prefix
- $sql_query = preg_replace('# phpbb_([^\s]*) #i', ' ' . $data['table_prefix'] . '\1 ', $sql_query);
- // Change language strings...
- $sql_query = preg_replace_callback('#\{L_([A-Z0-9\-_]*)\}#s', 'adjust_language_keys_callback', $sql_query);
- $sql_query = phpbb_remove_comments($sql_query);
- $sql_query = split_sql_file($sql_query, ';');
- foreach ($sql_query as $sql)
- {
- //$sql = trim(str_replace('|', ';', $sql));
- if (!$db->sql_query($sql))
- {
- $error = $db->sql_error();
- $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__);
- }
- }
- unset($sql_query);
- $current_time = time();
- $user_ip = (!empty($_SERVER['REMOTE_ADDR'])) ? htmlspecialchars($_SERVER['REMOTE_ADDR']) : '';
- $user_ip = (stripos($user_ip, '::ffff:') === 0) ? substr($user_ip, 7) : $user_ip;
- if ($data['script_path'] !== '/')
- {
- // Adjust destination path (no trailing slash)
- if (substr($data['script_path'], -1) == '/')
- {
- $data['script_path'] = substr($data['script_path'], 0, -1);
- }
- $data['script_path'] = str_replace(array('../', './'), '', $data['script_path']);
- if ($data['script_path'][0] != '/')
- {
- $data['script_path'] = '/' . $data['script_path'];
- }
- }
- // Set default config and post data, this applies to all DB's
- $sql_ary = array(
- 'INSERT INTO ' . $data['table_prefix'] . "config (config_name, config_value)
- VALUES ('board_startdate', '$current_time')",
- 'INSERT INTO ' . $data['table_prefix'] . "config (config_name, config_value)
- VALUES ('default_lang', '" . $db->sql_escape($data['default_lang']) . "')",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($data['img_imagick']) . "'
- WHERE config_name = 'img_imagick'",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($data['server_name']) . "'
- WHERE config_name = 'server_name'",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($data['server_port']) . "'
- WHERE config_name = 'server_port'",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($data['board_email1']) . "'
- WHERE config_name = 'board_email'",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($data['board_email1']) . "'
- WHERE config_name = 'board_contact'",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($cookie_domain) . "'
- WHERE config_name = 'cookie_domain'",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($lang['default_dateformat']) . "'
- WHERE config_name = 'default_dateformat'",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($data['email_enable']) . "'
- WHERE config_name = 'email_enable'",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($data['smtp_delivery']) . "'
- WHERE config_name = 'smtp_delivery'",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($data['smtp_host']) . "'
- WHERE config_name = 'smtp_host'",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($data['smtp_auth']) . "'
- WHERE config_name = 'smtp_auth_method'",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($data['smtp_user']) . "'
- WHERE config_name = 'smtp_username'",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($data['smtp_pass']) . "'
- WHERE config_name = 'smtp_password'",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($data['cookie_secure']) . "'
- WHERE config_name = 'cookie_secure'",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($data['force_server_vars']) . "'
- WHERE config_name = 'force_server_vars'",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($data['script_path']) . "'
- WHERE config_name = 'script_path'",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($data['server_protocol']) . "'
- WHERE config_name = 'server_protocol'",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($data['admin_name']) . "'
- WHERE config_name = 'newest_username'",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . md5(mt_rand()) . "'
- WHERE config_name = 'avatar_salt'",
- 'UPDATE ' . $data['table_prefix'] . "users
- 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'])) . "'
- WHERE username = 'Admin'",
- 'UPDATE ' . $data['table_prefix'] . "moderator_cache
- SET username = '" . $db->sql_escape($data['admin_name']) . "'
- WHERE username = 'Admin'",
- 'UPDATE ' . $data['table_prefix'] . "forums
- SET forum_last_poster_name = '" . $db->sql_escape($data['admin_name']) . "'
- WHERE forum_last_poster_name = 'Admin'",
- 'UPDATE ' . $data['table_prefix'] . "topics
- SET topic_first_poster_name = '" . $db->sql_escape($data['admin_name']) . "', topic_last_poster_name = '" . $db->sql_escape($data['admin_name']) . "'
- WHERE topic_first_poster_name = 'Admin'
- OR topic_last_poster_name = 'Admin'",
- 'UPDATE ' . $data['table_prefix'] . "users
- SET user_regdate = $current_time",
- 'UPDATE ' . $data['table_prefix'] . "posts
- SET post_time = $current_time, poster_ip = '" . $db->sql_escape($user_ip) . "'",
- 'UPDATE ' . $data['table_prefix'] . "topics
- SET topic_time = $current_time, topic_last_post_time = $current_time",
- 'UPDATE ' . $data['table_prefix'] . "forums
- SET forum_last_post_time = $current_time",
- 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($db->sql_server_info(true)) . "'
- WHERE config_name = 'dbms_version'",
- );
- if (@extension_loaded('gd') || can_load_dll('gd'))
- {
- $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = 'phpbb_captcha_gd'
- WHERE config_name = 'captcha_plugin'";
- $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '1'
- WHERE config_name = 'captcha_gd'";
- }
- $ref = substr($referer, strpos($referer, '://') + 3);
- if (!(stripos($ref, $server_name) === 0))
- {
- $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '0'
- WHERE config_name = 'referer_validation'";
- }
- // We set a (semi-)unique cookie name to bypass login issues related to the cookie name.
- $cookie_name = 'phpbb3_';
- $rand_str = md5(mt_rand());
- $rand_str = str_replace('0', 'z', base_convert($rand_str, 16, 35));
- $rand_str = substr($rand_str, 0, 5);
- $cookie_name .= strtolower($rand_str);
- $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config
- SET config_value = '" . $db->sql_escape($cookie_name) . "'
- WHERE config_name = 'cookie_name'";
- foreach ($sql_ary as $sql)
- {
- //$sql = trim(str_replace('|', ';', $sql));
- if (!$db->sql_query($sql))
- {
- $error = $db->sql_error();
- $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__);
- }
- }
- $submit = $lang['NEXT_STEP'];
- $url = $this->p_master->module_url . "?mode=$mode&sub=final";
- $template->assign_vars(array(
- 'BODY' => $lang['STAGE_CREATE_TABLE_EXPLAIN'],
- 'L_SUBMIT' => $submit,
- 'S_HIDDEN' => build_hidden_fields($data),
- 'U_ACTION' => $url,
- ));
- }
- /**
- * Build the search index...
- */
- function build_search_index($mode, $sub)
- {
- global $db, $lang, $phpbb_root_path, $phpEx, $config;
- // Obtain any submitted data
- $data = $this->get_submitted_data();
- $table_prefix = $data['table_prefix'];
- // If we get here and the extension isn't loaded it should be safe to just go ahead and load it
- $available_dbms = get_available_dbms($data['dbms']);
- if (!isset($available_dbms[$data['dbms']]))
- {
- // Someone's been silly and tried providing a non-existant dbms
- $this->p_master->redirect("index.$phpEx?mode=install");
- }
- $dbms = $available_dbms[$data['dbms']]['DRIVER'];
- // Load the appropriate database class if not already loaded
- include($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
- // Instantiate the database
- $db = new $sql_db();
- $db->sql_connect($data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport'], false, false);
- // NOTE: trigger_error does not work here.
- $db->sql_return_on_error(true);
- include_once($phpbb_root_path . 'includes/constants.' . $phpEx);
- include_once($phpbb_root_path . 'includes/search/fulltext_native.' . $phpEx);
- // Fill the config array - it is needed by those functions we call
- $sql = 'SELECT *
- FROM ' . CONFIG_TABLE;
- $result = $db->sql_query($sql);
- $config = array();
- while ($row = $db->sql_fetchrow($result))
- {
- $config[$row['config_name']] = $row['config_value'];
- }
- $db->sql_freeresult($result);
- $error = false;
- $search = new fulltext_native($error);
- $sql = 'SELECT post_id, post_subject, post_text, poster_id, forum_id
- FROM ' . POSTS_TABLE;
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result))
- {
- $search->index('post', $row['post_id'], $row['post_text'], $row['post_subject'], $row['poster_id'], $row['forum_id']);
- }
- $db->sql_freeresult($result);
- }
- /**
- * Populate the module tables
- */
- function add_modules($mode, $sub)
- {
- global $db, $lang, $phpbb_root_path, $phpEx;
- include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx);
- $_module = new acp_modules();
- $module_classes = array('acp', 'mcp', 'ucp');
- // Add categories
- foreach ($module_classes as $module_class)
- {
- $categories = array();
- // Set the module class
- $_module->module_class = $module_class;
- foreach ($this->module_categories[$module_class] as $cat_name => $subs)
- {
- $module_data = array(
- 'module_basename' => '',
- 'module_enabled' => 1,
- 'module_display' => 1,
- 'parent_id' => 0,
- 'module_class' => $module_class,
- 'module_langname' => $cat_name,
- 'module_mode' => '',
- 'module_auth' => '',
- );
- // Add category
- $_module->update_module_data($module_data, true);
- // Check for last sql error happened
- if ($db->sql_error_triggered)
- {
- $error = $db->sql_error($db->sql_error_sql);
- $this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__);
- }
- $categories[$cat_name]['id'] = (int) $module_data['module_id'];
- $categories[$cat_name]['parent_id'] = 0;
- // Create sub-categories...
- if (is_array($subs))
- {
- foreach ($subs as $level2_name)
- {
- $module_data = array(
- 'module_basename' => '',
- 'module_enabled' => 1,
- 'module_display' => 1,
- 'parent_id' => (int) $categories[$cat_name]['id'],
- 'module_class' => $module_class,
- 'module_langname' => $level2_name,
- 'module_mode' => '',
- 'module_auth' => '',
- );
- $_module->update_module_data($module_data, true);
- // Check for last sql error happened
- if ($db->sql_error_triggered)
- {
- $error = $db->sql_error($db->sql_error_sql);
- $this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__);
- }
- $categories[$level2_name]['id'] = (int) $module_data['module_id'];
- $categories[$level2_name]['parent_id'] = (int) $categories[$cat_name]['id'];
- }
- }
- }
- // Get the modules we want to add... returned sorted by name
- $module_info = $_module->get_module_infos('', $module_class);
- foreach ($module_info as $module_basename => $fileinfo)
- {
- foreach ($fileinfo['modes'] as $module_mode => $row)
- {
- foreach ($row['cat'] as $cat_name)
- {
- if (!isset($categories[$cat_name]))
- {
- continue;
- }
- $module_data = array(
- 'module_basename' => $module_basename,
- 'module_enabled' => 1,
- 'module_display' => (isset($row['display'])) ? (int) $row['display'] : 1,
- 'parent_id' => (int) $categories[$cat_name]['id'],
- 'module_class' => $module_class,
- 'module_langname' => $row['title'],
- 'module_mode' => $module_mode,
- 'module_auth' => $row['auth'],
- );
- $_module->update_module_data($module_data, true);
- // Check for last sql error happened
- if ($db->sql_error_triggered)
- {
- $error = $db->sql_error($db->sql_error_sql);
- $this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__);
- }
- }
- }
- }
- // Move some of the modules around since the code above will put them in the wrong place
- if ($module_class == 'acp')
- {
- // Move main module 4 up...
- $sql = 'SELECT *
- FROM ' . MODULES_TABLE . "
- WHERE module_basename = 'main'
- AND module_class = 'acp'
- AND module_mode = 'main'";
- $result = $db->sql_query($sql);
- $row = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
- $_module->move_module_by($row, 'move_up', 4);
- // Move permissions intro screen module 4 up...
- $sql = 'SELECT *
- FROM ' . MODULES_TABLE . "
- WHERE module_basename = 'permissions'
- AND module_class = 'acp'
- AND module_mode = 'intro'";
- $result = $db->sql_query($sql);
- $row = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
- $_module->move_module_by($row, 'move_up', 4);
- // Move manage users screen module 5 up...
- $sql = 'SELECT *
- FROM ' . MODULES_TABLE . "
- WHERE module_basename =…
Large files files are truncated, but you can click here to view the full file