* @version 1.0pre */ $GLOBALS['current_smf_version'] = '1.0pre'; $GLOBALS['db_script_version'] = '2-0'; $GLOBALS['required_php_version'] = '5.3.1'; global $installurl, $incontext, $databases, $txt; $incontext = array(); // Don't have PHP support, do you? // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;"> // Database info. $databases = array('mysql' => array('name' => 'MySQL', 'version' => '4.1.0', 'version_check' => 'return min(mysql_get_server_info(), mysql_get_client_info());', 'supported' => function_exists('mysql_connect'), 'default_user' => 'mysql.default_user', 'default_password' => 'mysql.default_password', 'default_host' => 'mysql.default_host', 'default_port' => 'mysql.default_port', 'utf8_support' => true, 'utf8_version' => '4.1.0', 'utf8_version_check' => 'return mysql_get_server_info();', 'utf8_default' => true, 'utf8_required' => true, 'alter_support' => true, 'validate_prefix' => create_function('&$value', ' $value = preg_replace(\'~[^A-Za-z0-9_\\$]~\', \'\', $value); return true; '))); // Initialize everything and load the language files. initialize_inputs(); load_lang_file(); // This is what we are. $installurl = $_SERVER['PHP_SELF']; // All the steps in detail. // Number,Name,Function,Progress Weight. $incontext['steps'] = array(0 => array(1, $txt['install_step_welcome'], 'Welcome', 0), 1 => array(2, $txt['install_step_writable'], 'CheckFilesWritable', 10), 2 => array(3, $txt['install_step_databaseset'], 'DatabaseSettings', 15), 3 => array(4, $txt['install_step_forum'], 'ForumSettings', 40), 4 => array(5, $txt['install_step_databasechange'], 'DatabasePopulation', 15), 5 => array(6, $txt['install_step_admin'], 'AdminAccount', 20), 6 => array(7, $txt['install_step_delete'], 'DeleteInstall', 0)); // Default title... $incontext['page_title'] = $txt['smf_installer']; // What step are we on? $incontext['current_step'] = isset($_GET['step']) ? (int) $_GET['step'] : 0; // Loop through all the steps doing each one as required. $incontext['overall_percent'] = 0; foreach ($incontext['steps'] as $num => $step) { if ($num >= $incontext['current_step']) { // The current weight of this step in terms of overall progress.
/** * Load all essential data and connect to the DB as this is pre SSI.php */ function loadEssentialData() { global $db_server, $db_user, $db_passwd, $db_name, $db_connection, $db_prefix, $db_character_set, $db_type, $db_port, $modSettings; // Do the non-SSI stuff... @set_magic_quotes_runtime(0); error_reporting(E_ALL); if (!defined('ELK')) { define('ELK', 1); } // Start the session. if (ini_get('session.save_handler') == 'user') { @ini_set('session.save_handler', 'files'); } @session_start(); // Initialize everything... initialize_inputs(); // Get the database going! if (empty($db_type)) { $db_type = 'mysql'; } if (file_exists(SOURCEDIR . '/database/Database.subs.php')) { require_once SOURCEDIR . '/database/Database.subs.php'; // Make the connection... $db_connection = elk_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true, 'port' => $db_port), $db_type); // Oh dear god!! if ($db_connection === null) { die('Unable to connect to database - please check username and password are correct in Settings.php'); } $db = database(); if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\\w+$~', $db_character_set) === 1) { $db->query('', ' SET NAMES ' . $db_character_set, array('db_error_skip' => true)); } // Load the modSettings data... $request = $db->query('', ' SELECT variable, value FROM {db_prefix}settings', array('db_error_skip' => true)); $modSettings = array(); while ($row = $db->fetch_assoc($request)) { $modSettings[$row['variable']] = $row['value']; } $db->free_result($request); } else { return throw_error('Cannot find ' . SOURCEDIR . '/database/Database.subs.php. Please check you have uploaded all source files and have the correct paths set.'); } // If they don't have the file, they're going to get a warning anyway so we won't need to clean request vars. if (file_exists(SOURCEDIR . '/QueryString.php')) { require_once SUBSDIR . '/Util.class.php'; require_once SOURCEDIR . '/Subs.php'; require_once SOURCEDIR . '/QueryString.php'; cleanRequest(); } // Set a session life limit for the admin if (isset($modSettings['admin_session_lifetime'])) { $modSettings['admin_session_lifetime'] = 5; } if (!isset($_GET['substep'])) { $_GET['substep'] = 0; } }
function set_settings() { global $smcFunc, $context, $db_connection, $db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_type; $db_updates = isset($_POST['dbsettings']) ? $_POST['dbsettings'] : array(); $theme_updates = isset($_POST['themesettings']) ? $_POST['themesettings'] : array(); $file_updates = isset($_POST['flatsettings']) ? $_POST['flatsettings'] : array(); $attach_dirs = array(); if (empty($db_updates['theme_default'])) { unset($db_updates['theme_default']); } else { $db_updates['theme_guests'] = 1; $smcFunc['db_query'](true, ' UPDATE {db_prefix}members SET {raw:theme_column} = 0', array('theme_column' => $context['is_legacy'] ? 'ID_THEME' : 'id_theme')); } $settingsArray = file(dirname(__FILE__) . '/Settings.php'); $settings = array(); for ($i = 0, $n = count($settingsArray); $i < $n; $i++) { $settingsArray[$i] = rtrim($settingsArray[$i]); // Remove the redirect... if ($settingsArray[$i] == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))') { $settingsArray[$i] = ''; $settingsArray[$i++] = ''; $settingsArray[$i++] = ''; $settingsArray[$i++] = ''; $settingsArray[$i++] = ''; $settingsArray[$i++] = ''; continue; } if (isset($settingsArray[$i][0]) && $settingsArray[$i][0] != '.' && preg_match('~^[$]([a-zA-Z_]+)\\s*=\\s*(?:(["\'])(.*?["\'])(?:\\2)?|(.*?)(?:\\2)?);~', $settingsArray[$i], $match) == 1) { $settings[$match[1]] = stripslashes($match[3]); } foreach ($file_updates as $var => $val) { if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) { $comment = strstr($settingsArray[$i], '#'); $settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : ''); } } } // Blank out the file - done to fix a oddity with some servers. $fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w'); fclose($fp); $fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+'); $lines = count($settingsArray); for ($i = 0; $i < $lines - 1; $i++) { // Don't just write a bunch of blank lines. if ($settingsArray[$i] != '' || $settingsArray[$i - 1] != '') { fwrite($fp, $settingsArray[$i] . "\n"); } } fwrite($fp, $settingsArray[$i]); fclose($fp); // Make sure it works. require dirname(__FILE__) . '/Settings.php'; //We need to re-try the database settings, right? $context['settings_test'] = 1; initialize_inputs(); //if database settings are wrong, we will not try anything else! if ($db_connection != true) { return; } $setString = array(); foreach ($db_updates as $var => $val) { $setString[] = array($var, stripslashes($val)); } // Attachments dirs if ($context['is_legacy']) { foreach ($setString as $key => $value) { if (strpos($value[0], 'attachmentUploadDir') == 0 && strpos($value[0], 'attachmentUploadDir') !== false) { $attach_dirs[0] = $value[1]; unset($setString[$key]); } } } else { $attach_count = 1; foreach ($setString as $key => $value) { if (strpos($value[0], 'attachmentUploadDir') == 0 && strpos($value[0], 'attachmentUploadDir') !== false) { $attach_dirs[$attach_count++] = $value[1]; unset($setString[$key]); } } } // Only one dir...or maybe nothing at all if (count($attach_dirs) > 1) { $setString[] = array('attachmentUploadDir', @serialize($attach_dirs)); // If we want to (re)set currentAttachmentUploadDir here is a good place // foreach ($attach_dirs as $id => $attach_dir) // if (is_dir($attach_dir) && is_writable($attach_dir)) // $setString[] = array('currentAttachmentUploadDir', $id + 1); } elseif (!$context['is_legacy'] && isset($attach_dirs[1])) { $setString[] = array('attachmentUploadDir', $attach_dirs[1]); $setString[] = array('currentAttachmentUploadDir', 0); } elseif ($context['is_legacy'] && isset($attach_dirs[0])) { $setString[] = array('attachmentUploadDir', $attach_dirs[0]); } else { $setString[] = array('attachmentUploadDir', ''); $setString[] = array('currentAttachmentUploadDir', 0); } if (!empty($setString)) { $smcFunc['db_insert']('replace', '{db_prefix}settings', array('variable' => 'string', 'value' => 'string-65534'), $setString, array('variable')); } $setString = array(); foreach ($theme_updates as $var => $val) { // Extract the data preg_match('~theme_([\\d]+)_(.+)~', $var, $match); if (empty($match[0])) { continue; } $setString[] = array($match[1], 0, $match[2], stripslashes($val)); } if (!empty($setString)) { $smcFunc['db_insert']('replace', '{db_prefix}themes', array('id_theme' => 'int', 'id_member' => 'int', 'variable' => 'string', 'value' => 'string-65534'), $setString, array('id_theme', 'id_member', 'variable')); } //If we got here, all is good :) $context['settings_saved'] = 1; }
function loadEssentialData() { global $db_server, $db_user, $db_passwd, $db_name, $db_connection, $db_prefix, $db_character_set, $db_type; global $modSettings, $sourcedir, $smcFunc, $upcontext; // Do the non-SSI stuff... @set_magic_quotes_runtime(0); error_reporting(E_ALL); define('SMF', 1); // Start the session. if (@ini_get('session.save_handler') == 'user') { @ini_set('session.save_handler', 'files'); } @session_start(); if (empty($smcFunc)) { $smcFunc = array(); } // Initialize everything... initialize_inputs(); // Get the database going! if (empty($db_type)) { $db_type = 'mysql'; } if (file_exists($sourcedir . '/lib/Subs-Db-' . $db_type . '.php')) { require_once $sourcedir . '/lib/Subs-Db-' . $db_type . '.php'; // Make the connection... $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, array('non_fatal' => true)); // Oh dear god!! if ($db_connection === null) { die('Unable to connect to database - please check username and password are correct in Settings.php'); } if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\\w+$~', $db_character_set) === 1) { $smcFunc['db_query']('', ' SET NAMES ' . $db_character_set, array('db_error_skip' => true)); } // Load the modSettings data... $request = $smcFunc['db_query']('', ' SELECT variable, value FROM {db_prefix}settings', array('db_error_skip' => true)); $modSettings = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { $modSettings[$row['variable']] = $row['value']; } $smcFunc['db_free_result']($request); } else { return throw_error('Cannot find ' . $sourcedir . '/lib/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.'); } // If they don't have the file, they're going to get a warning anyway so we won't need to clean request vars. if (file_exists($sourcedir . '/QueryString.php')) { require_once $sourcedir . '/QueryString.php'; cleanRequest(); } if (!isset($_GET['substep'])) { $_GET['substep'] = 0; } }
function cmdStep0() { global $time_start; $time_start = time(); @ob_end_clean(); ob_implicit_flush(true); @set_time_limit(600); if (!isset($_SERVER['argv'])) { $_SERVER['argv'] = array(); } // If its empty, force help. if (empty($_SERVER['argv'][1])) { $_SERVER['argv'][1] = '--help'; } // Lets get the path_to and path_from foreach ($_SERVER['argv'] as $i => $arg) { // Trim spaces. $arg = trim($arg); if (preg_match('~^--path_to=(.+)$~', $arg, $match) != 0) { $_POST['path_to'] = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1]; } elseif (preg_match('~^--path_from=(.+)$~', $arg, $match) != 0) { $_POST['path_from'] = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1]; } elseif (preg_match('~^--db_pass=(.+)?$~', $arg, $match) != 0) { $_POST['db_pass'] = isset($match[1]) ? $match[1] : ''; } elseif ($arg == '--debug') { $_GET['debug'] = 1; } elseif (preg_match('~^--convert_script=(.+)$~', $arg, $match) != 0) { $_REQUEST['convert_script'] = $match[1]; } elseif ($arg == '--help' || ($i = 0)) { print_error('SMF Command-line Converter Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]... --path_to Path to SMF (' . dirname(__FILE__) . '). --path_from Path to the software that you are converting from. --convert_script The name of the script. (old_forum_to_smf.sql) --db_pass SMF database password. "The Database password (for verification only.)" --debug Output debugging information.', true); } // We have extra params. if (preg_match('~^--(.+)=(.+)$~', $arg, $match) != 0 && !array_key_exists($match[1], $_POST)) { $_POST[$match[1]] = $match[2]; } } // Do we have the paths and passwords? if (!isset($_POST['path_to'])) { print_error('ERROR: You must enter the path_to in order to convert.', true); } elseif (!isset($_POST['path_from'])) { print_error('ERROR: You must enter the path_from in order to convert.', true); } elseif (!isset($_POST['db_pass'])) { print_error('ERROR: You must enter SMF\'s database password in order to convert.', true); } else { $_GET['step'] = 1; initialize_inputs(); doStep1(); } exit; }