示例#1
0
function doStep1()
{
    global $txt, $ftp;
    // Remember if they agreed (even if they are only verifying.)
    if (isset($_POST['agree'])) {
        $_SESSION['webinstall_state']['agree'] = true;
    }
    if (!empty($_POST['verify']) || !empty($_POST['member_username']) && !empty($_POST['member_password'])) {
        $pass_data = 'web_user='******'member_username']) . '&check&web_pass='******'member_username']) . $_POST['member_password']) . 'w$--IN5~2a');
        $data = (int) fetch_web_data('http://download.simplemachines.org/index.php', $pass_data . '&verify=1');
        $_SESSION['webinstall_state']['is_logged_in'] = !empty($data);
        $_SESSION['webinstall_state']['is_charter'] = $data === 2;
        $_SESSION['webinstall_state']['is_beta_tester'] = $data === 3;
        $_SESSION['webinstall_state']['is_team'] = $data === 4;
        if ($_SESSION['webinstall_state']['is_team']) {
            $_SESSION['webinstall_state']['access'] = array(0, 1, 2);
        } elseif ($_SESSION['webinstall_state']['is_charter'] || $_SESSION['webinstall_state']['is_beta_tester']) {
            $_SESSION['webinstall_state']['access'] = array(0, 2);
        } else {
            $_SESSION['webinstall_state']['access'] = array(0);
        }
        $_SESSION['webinstall_state']['can_svn'] = $_SESSION['webinstall_state']['is_team'] || $_SESSION['webinstall_state']['is_beta_tester'];
        $_SESSION['webinstall_state']['user_data'] = $_SESSION['webinstall_state']['is_logged_in'] ? '?' . $pass_data : '';
        $_SESSION['webinstall_state']['member_info'] = $_SESSION['webinstall_state']['can_svn'] ? array($_POST['member_username'], $_POST['member_password']) : array();
        if (empty($data)) {
            echo '
						<br />
						<div class="error_message" style="margin: 0 1ex 2ex 1ex;">
							<div style="float: left; width: 2ex; font-size: 2em; color: red;">X</div>
							', $txt['error_not_member'], '
						</div>';
        }
        return doStep0();
    } elseif (isset($_GET['logout'])) {
        $_SESSION['webinstall_state']['is_logged_in'] = false;
        $_SESSION['webinstall_state']['is_charter'] = false;
        $_SESSION['webinstall_state']['is_beta_tester'] = false;
        $_SESSION['webinstall_state']['is_team'] = false;
        $_SESSION['webinstall_state']['access'] = array(0);
        $_SESSION['webinstall_state']['can_svn'] = false;
        $_SESSION['webinstall_state']['user_data'] = '';
        return doStep0();
    }
    // Perhaps they don't want to use a chmod of 777.
    if (isset($_REQUEST['chmod']) && is_numeric($_REQUEST['chmod'])) {
        // Make sure they passed us a valid mode.
        if (preg_match('~^([0]?[0-7]{3})$~', $_REQUEST['chmod']) !== 0) {
            $_SESSION['webinstall_state']['chmod'] = octdec($_REQUEST['chmod']);
        }
    }
    if (!isset($_SESSION['webinstall_state']['chmod'])) {
        $_SESSION['webinstall_state']['chmod'] = 0777;
    }
    if (empty($_SESSION['webinstall_state']['agree'])) {
        echo '
						<br />
						<div style="margin: 0 1ex 2ex 1ex; padding: 1.5ex; border: 2px dashed #cc5566; background-color: #ffd9df;">
							<div style="float: left; width: 2ex; font-size: 2em; color: red;">X</div>
							<div style="padding: 1ex;">', $txt['error_read_the_license'], '</div>
						</div>';
        return doStep0();
    }
    if (!empty($_POST['mirror'])) {
        // Verify mirror.
        $install_info = fetch_install_info();
        if (!isset($install_info['mirrors'][$_POST['mirror']])) {
            die('Security error.');
        }
        // Build file list ;).
        $files_to_download = array();
        if (function_exists('gzinflate')) {
            $ext = '.tar.gz';
        } else {
            $ext = '.tar';
        }
        if (file_exists(dirname(__FILE__) . '/Settings.php') && !file_exists(dirname(__FILE__) . '/install.php')) {
            $type = 'upgrade';
        } else {
            $type = 'install';
        }
        if (!empty($_SESSION['webinstall_state']['can_svn']) && !empty($_POST['use_svn'])) {
            // SVN files only have the branch numbers on them and not the actual version.
            preg_match('~(smf_[\\d]-[\\d])(.*)~', $_POST['filename'], $match);
            $_POST['filename_unmodified'] = $_POST['filename'];
            $_POST['filename'] = $match[1] . '-dev' . strftime('%Y%m%d') . '_';
            $_POST['mirror'] = 'https://devel.simplemachines.org/mkbuild/release/';
        }
        $files_to_download[] = $_POST['mirror'] . $_POST['filename'] . $type . $ext;
        if (isset($_POST['languages'])) {
            $version_selected = str_replace('SMF ', '', $_SESSION['webinstall_state']['install_info']['install'][isset($_POST['filename_unmodified']) ? $_POST['filename_unmodified'] : $_POST['filename']]);
            foreach ($_POST['languages'] as $lang) {
                if (isset($_SESSION['webinstall_state']['install_info']['languages'][$lang]) && in_array($version_selected, $_SESSION['webinstall_state']['install_info']['languages'][$lang]['versions'])) {
                    $files_to_download[] = $_POST['mirror'] . $_POST['filename'] . $lang . $ext;
                }
            }
        }
        $_SESSION['webinstall_state']['files_to_download'] = $files_to_download;
        $_SESSION['webinstall_state']['files_to_download_total'] = count($files_to_download);
    }
    // Windows isn't helped by chmod settings and FTP.
    if (strpos(__FILE__, ':\\') === 1) {
        return doStep2();
    }
    if (!isset($ftp)) {
        $ftp = new ftp_connection(null);
    } elseif ($ftp->error !== false) {
        $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
    }
    list($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
    if ($found_path || !isset($_POST['ftp_path'])) {
        $_POST['ftp_path'] = $detect_path;
    }
    if (!isset($_POST['ftp_username'])) {
        $_POST['ftp_username'] = $username;
    }
    echo '
				<form action="', $_SERVER['PHP_SELF'], '?step=2" method="post">
					<div class="panel">
						<h2>', $txt['ftp_login'], '</h2>
						<h3>', $txt['ftp_login_info'], '</h3>';
    if (isset($ftp_error)) {
        echo '
					<div class="error_message">
						<div>
							', $txt['error_ftp_no_connect'], '<br />
							<br />
							<code>', $ftp_error, '</code>
						</div>
					</div>
					<br />';
    }
    echo '
						<div style="margin: 0 1ex 2ex 1ex; padding: 1.5ex; border: 2px dashed #33cc44; background-color: #dfffe9;">
							<div style="float: left; width: 1.5ex; font-size: 2em; color: #33cc44;">!</div>
							', $txt['ftp_please_note'], '
						</div>

						<table width="520" cellspacing="0" cellpadding="0" border="0" align="center" style="margin-bottom: 1ex;">
							<tr>
								<td width="26%" valign="top" class="textbox"><label for="ftp_server">', $txt['ftp_server'], ':</label></td>
								<td>
									<div style="float: right; margin-right: 1px;"><label for="ftp_port" class="textbox"><strong>', $txt['ftp_port'], ':&nbsp;</strong></label> <input type="text" size="3" name="ftp_port" id="ftp_port" value="', isset($_POST['ftp_port']) ? $_POST['ftp_port'] : '21', '" /></div>
									<input type="text" size="30" name="ftp_server" id="ftp_server" value="', isset($_POST['ftp_server']) ? $_POST['ftp_server'] : 'localhost', '" style="width: 70%;" />
									<div style="font-size: smaller; margin-bottom: 2ex;">', $txt['ftp_server_info'], '</div>
								</td>
							</tr><tr>
								<td width="26%" valign="top" class="textbox"><label for="ftp_username">', $txt['ftp_username'], ':</label></td>
								<td>
									<input type="text" size="50" name="ftp_username" id="ftp_username" value="', isset($_POST['ftp_username']) ? $_POST['ftp_username'] : '', '" style="width: 99%;" />
									<div style="font-size: smaller; margin-bottom: 2ex;">', $txt['ftp_username_info'], '</div>
								</td>
							</tr><tr>
								<td width="26%" valign="top" class="textbox"><label for="ftp_password">', $txt['ftp_password'], ':</label></td>
								<td>
									<input type="password" size="50" name="ftp_password" id="ftp_password" style="width: 99%;" />
									<div style="font-size: smaller; margin-bottom: 3ex;">', $txt['ftp_password_info'], '</div>
								</td>
							</tr><tr>
								<td width="26%" valign="top" class="textbox"><label for="ftp_path">', $txt['ftp_path'], ':</label></td>
								<td style="padding-bottom: 1ex;">
									<input type="text" size="50" name="ftp_path" id="ftp_path" value="', $_POST['ftp_path'], '" style="width: 99%;" />
									<div style="font-size: smaller; margin-bottom: 2ex;">', !empty($found_path) ? $txt['ftp_path_found_info'] : $txt['ftp_path_info'], '</div>
								</td>
							</tr>
						</table>

						<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" /></div>
					</div>';
}
function loadSettings()
{
    global $convert_data, $from_prefix, $to_prefix, $convert_dbs, $command_line, $smcFunc;
    global $db_persist, $db_connection, $db_server, $db_user, $db_passwd, $modSettings;
    global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix;
    foreach ($convert_data['defines'] as $define) {
        $define = explode('=', $define);
        define($define[0], isset($define[1]) ? $define[1] : '1');
    }
    foreach ($convert_data['globals'] as $global) {
        global ${$global};
    }
    define('PATH_CACHE', 'PATH_CACHE');
    if (!empty($convert_data['eval'])) {
        eval($convert_data['eval']);
    }
    // Cannot find Settings.php?
    if (!$command_line && !file_exists($_POST['path_to'] . '/Settings.php')) {
        template_convert_above();
        return doStep0('This converter was unable to find SMF in the path you specified.<br /><br />Please double check the path, and that it is already installed there.');
    } elseif ($command_line && !file_exists($_POST['path_to'] . '/Settings.php')) {
        return print_error('This converter was unable to find SMF in the path you specified.<br /><br />Please double check the path, and that it is already installed there.', true);
    }
    $found = empty($convert_data['settings']);
    foreach ($convert_data['settings'] as $file) {
        $found |= file_exists($_POST['path_from'] . $file);
    }
    /*
    	Check if open_basedir is enabled.  If it's enabled and the converter file was not found then that means
    	that the user hasn't moved the files to the public html dir.  With this enabled and the file not found, we can't go anywhere from here.
    */
    if (!$command_line && @ini_get('open_basedir') != '' && !$found) {
        template_convert_above();
        return doStep0('The converter detected that your host has open_basedir enabled on this server.  Please ask your host to disable this setting or try moving the contents of your ' . $convert_data['name'] . ' to the public html folder of your site.');
    } elseif ($command_line && @ini_get('open_basedir') != '' && !$found) {
        return print_error('The converter detected that your host has open_basedir enabled on this server.  Please ask your host to disable this setting or try moving the contents of your ' . $convert_data['name'] . ' to the public html folder of your site.', true);
    }
    if (!$command_line && !$found) {
        template_convert_above();
        return doStep0('Unable to find the settings for ' . $convert_data['name'] . '.  Please double check the path and try again.');
    } elseif (!$command_line && !$found) {
        return print_error('Unable to find the settings for ' . $convert_data['name'] . '.  Please double check the path and try again.', true);
    }
    // Any parameters to speak of?
    if (!empty($convert_data['parameters']) && !empty($_SESSION['convert_parameters'])) {
        foreach ($convert_data['parameters'] as $param) {
            if (isset($_POST[$param['id']])) {
                $_SESSION['convert_parameters'][$param['id']] = $_POST[$param['id']];
            }
        }
        // Should already be global'd.
        foreach ($_SESSION['convert_parameters'] as $k => $v) {
            ${$k} = $v;
        }
    } elseif (!empty($convert_data['parameters'])) {
        $_SESSION['convert_parameters'] = array();
        foreach ($convert_data['parameters'] as $param) {
            if (isset($_POST[$param['id']])) {
                $_SESSION['convert_parameters'][$param['id']] = $_POST[$param['id']];
            } else {
                $_SESSION['convert_parameters'][$param['id']] = null;
            }
        }
        foreach ($_SESSION['convert_parameters'] as $k => $v) {
            ${$k} = $v;
        }
    }
    // Everything should be alright now... no cross server includes, we hope...
    require $_POST['path_to'] . '/Settings.php';
    require $sourcedir . '/QueryString.php';
    require $sourcedir . '/Subs.php';
    require $sourcedir . '/Errors.php';
    require $sourcedir . '/Load.php';
    require $sourcedir . '/Security.php';
    // PHP4 users compatibility
    if (@version_compare(PHP_VERSION, '5') == -1) {
        require_once $sourcedir . '/Subs-Compat.php';
    }
    $GLOBALS['boardurl'] = $boardurl;
    $modSettings['disableQueryCheck'] = true;
    // !!! Do we really need this?
    if (!$command_line && $_SESSION['convert_db_pass'] != $db_passwd) {
        template_convert_above();
        return doStep0('The database password you entered was incorrect.  Please make sure you are using the right password (for the SMF user!) and try it again.  If in doubt, use the password from Settings.php in the SMF installation.');
    } elseif ($command_line && $_SESSION['convert_db_pass'] != $db_passwd) {
        return print_error('The database password you entered was incorrect.  Please make sure you are using the right password (for the SMF user!) and try it again.  If in doubt, use the password from Settings.php in the SMF installation.', true);
    }
    // Check the steps that we have decided to go through.
    if (!$command_line && isset($_POST['do_steps']) && empty($_POST['do_steps'])) {
        template_convert_above();
        return doStep0('You must select at least one step to convert.');
    } elseif (!$command_line && isset($_POST['do_steps'])) {
        unset($_SESSION['do_steps']);
        foreach ($_POST['do_steps'] as $next_step_line => $step) {
            //$explode = explode(',', $step);
            //$_SESSION['do_steps'][$key] = array(
            //	'cur_step_line' => $explode[0],
            //	'prev_step_line' => $explode[1],
            //	'next_prev_line' => $explode[2],
            //);
            $_SESSION['do_steps'][$next_step_line] = $step;
        }
    }
    if (isset($_SESSION['convert_parameters']['database_type']) && !isset($convert_data['database_type'])) {
        $convert_data['database_type'] = $_SESSION['convert_parameters']['database_type'];
    }
    if (isset($convert_data['database_type']) && (function_exists($convert_data['database_type'] . '_query') || function_exists($convert_data['database_type'] . '_exec') || $convert_data['database_type'] == 'ado' && class_exists('com'))) {
        $convert_dbs = $convert_data['database_type'];
        if (isset($convert_data['connect_string'])) {
            $connect_string = eval('return "' . $convert_data['connect_string'] . '";');
        } elseif (isset($_SESSION['convert_parameters']['connect_string'])) {
            $connect_string = $_SESSION['convert_parameters']['connect_string'];
        }
        if ($convert_dbs == 'odbc') {
            $GLOBALS['odbc_connection'] = odbc_connect($connect_string, '', '');
        } elseif ($convert_dbs == 'ado') {
            $GLOBALS['ado_connection'] = new COM('ADODB.Connection');
            $GLOBALS['ado_connection']->Open($connect_string);
            register_shutdown_function(create_function('', '$GLOBALS[\'ado_connection\']->Close();'));
        }
    } elseif (!$command_line && isset($convert_data['database_type'])) {
        template_convert_above();
        return doStep0('PHP doesn\'t support the database type this converter was written for, \'' . $convert_data['database_type'] . '\'.');
    } elseif ($command_line && isset($convert_data['database_type'])) {
        return print_error('PHP doesn\'t support the database type this converter was written for, \'' . $convert_data['database_type'] . '\'.', true);
    } else {
        $convert_dbs = 'smf_db';
    }
    // Create a connection to the SMF database.
    loadDatabase();
    db_extend('packages');
    // Currently SQLite and PostgreSQL do not have support for cross database work.
    if ($command_line && in_array($smcFunc['db_title'], array('SQLite', 'PostgreSQL'))) {
        return print_error('The converter detected that you are using ' . $smcFunc['db_title'] . '. The SMF Converter does not currently support this database type.', true);
    } elseif (in_array($smcFunc['db_title'], array('SQLite', 'PostgreSQL'))) {
        template_convert_above();
        return doStep0('The converter detected that you are using ' . $smcFunc['db_title'] . '. The SMF Converter does not currently support this database type.');
    }
    // Does this converter support the current database type being used?
    if ($command_line && !in_array(strtolower($smcFunc['db_title']), $convert_data['database_support'])) {
        return print_error('The converter detected that you are using ' . $smcFunc['db_title'] . '. This converter only supports ' . explode(', ', $convert_data['database_support']) . '.', true);
    } elseif (!in_array(strtolower($smcFunc['db_title']), $convert_data['database_support'])) {
        template_convert_above();
        return print_error('The converter detected that you are using ' . $smcFunc['db_title'] . '. This converter only supports ' . explode(', ', $convert_data['database_support']) . '.', true);
    }
    // UTF8
    $charset = findSupportedCharsets();
    $charset = array_flip($charset);
    $charset = isset($_POST['charsets']) && isset($charset[$_POST['charsets']]) ? $_POST['charsets'] : '';
    $charset = !empty($charset) ? $charset : (isset($db_character_set) && preg_match('~^\\w+$~', $db_character_set) === 1 ? $db_character_set : '');
    if (!empty($charset)) {
        $smcFunc['db_query']('', "SET NAMES {$charset}", 'security_override');
    }
    if (strpos($db_prefix, '.') === false) {
        $to_prefix = is_numeric(substr($db_prefix, 0, 1)) ? $db_name . '.' . $db_prefix : '`' . $db_name . '`.' . $db_prefix;
    } else {
        $to_prefix = $db_prefix;
    }
    // Keep in mind our important variables, we don't want them swept away by the code we're running
    $smf_db_prefix = $db_prefix;
    $smf_db_type = $db_type;
    foreach ($convert_data['variable'] as $eval_me) {
        eval($eval_me);
    }
    foreach ($convert_data['settings'] as $file) {
        if (file_exists($_POST['path_from'] . $file) && empty($convert_data['flatfile'])) {
            require_once $_POST['path_from'] . $file;
        }
    }
    if (isset($convert_data['from_prefix'])) {
        $from_prefix = eval('return "' . fixDbPrefix($convert_data['from_prefix'], $smcFunc['db_title']) . '";');
    }
    if (preg_match('~^`[^`]+`.\\d~', $from_prefix) != 0) {
        $from_prefix = strtr($from_prefix, array('`' => ''));
    }
    // recall our variables in case the software we're converting from defines one itself...
    $db_prefix = $smf_db_prefix;
    $db_type = $smf_db_type;
    if ($_REQUEST['start'] == 0 && empty($_GET['substep']) && empty($_GET['cstep']) && ($_GET['step'] == 1 || $_GET['step'] == 2) && isset($convert_data['table_test'])) {
        $result = convert_query("\n\t\t\tSELECT COUNT(*)\n\t\t\tFROM " . eval('return "' . $convert_data['table_test'] . '";'), true);
        if (!$command_line && $result === false) {
            template_convert_above();
            doStep0('Sorry, the database connection information used in the specified installation of SMF cannot access the installation of ' . $convert_data['name'] . '.  This may either mean that the installation doesn\'t exist, or that the Database account used does not have permissions to access it.<br /><br />The error that was received from the Database was: ' . $smcFunc['db_error']());
        } elseif ($command_line && $result === false) {
            print_error("Sorry, the database connection information used in the specified installation of SMF cannot access the installation of " . $convert_data['name'] . ".  This may either mean that the installation doesn\\'t exist, or that the Database account used does not have permissions to access it.\n\nThe error that was received from the Database: " . $smcFunc['db_error'](), true);
        }
        convert_free_result($result);
    }
    // Attempt to allow big selects, only for mysql so far though.
    if ($smcFunc['db_title'] == 'MySQL') {
        $results = $smcFunc['db_query']('', "SELECT @@SQL_BIG_SELECTS, @@SQL_MAX_JOIN_SIZE", 'security_override');
        list($big_selects, $sql_max_join) = $smcFunc['db_fetch_row']($results);
        // Only waste a query if its worth it.
        if (empty($big_selects) || $big_selects != 1 && $big_selects != '1') {
            $smcFunc['db_query']('', "SET @@SQL_BIG_SELECTS = 1", 'security_override');
        }
        // Lets set MAX_JOIN_SIZE to something we should
        if (empty($sql_max_join) || $sql_max_join == '18446744073709551615' && $sql_max_join == '18446744073709551615') {
            $smcFunc['db_query']('', "SET @@SQL_MAX_JOIN_SIZE = 18446744073709551615", 'security_override');
        }
    }
    // Since we use now the attachment functions in Subs.php, we'll need this:
    $result = convert_query("\n\t\t\tSELECT value\n\t\t\tFROM {$to_prefix}settings\n\t\t\tWHERE variable = 'attachmentUploadDir'\n\t\t\tLIMIT 1");
    list($attachmentUploadDir) = $smcFunc['db_fetch_row']($result);
    $modSettings['attachmentUploadDir'] = $attachmentUploadDir;
    $smcFunc['db_free_result']($result);
}