function run_php_converter()
{
    global $from_prefix, $to_prefix, $convert_data, $smcFunc;
    foreach ($convert_data['globals'] as $global) {
        global ${$global};
    }
    $_GET['substep'] = (int) @$_GET['substep'];
    $_GET['cstep'] = (int) @$_GET['cstep'];
    require dirname(__FILE__) . '/' . $_SESSION['convert_script'];
    if (function_exists('load_converter_settings')) {
        load_converter_settings();
    }
    for ($_GET['cstep'] = max(1, $_GET['cstep']); function_exists('convertStep' . $_GET['cstep']); $_GET['cstep']++) {
        call_user_func('convertStep' . $_GET['cstep']);
        $_GET['substep'] = 0;
        pastTime(0);
        print_line(' Successful.');
        flush();
    }
    $_GET['substep'] = 0;
    $_REQUEST['start'] = 0;
    return doStep2();
}
Example #2
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>';
}
Example #3
0
function doStep1()
{
    global $db_prefix, $command_line, $modSettings;
    global $boarddir, $boardurl, $sourcedir, $maintenance;
    // Firstly, if they're enabling SM stat collection just do it.
    if (!empty($_REQUEST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats'])) {
        // Attempt to register the site etc.
        $fp = @fsockopen("www.simplemachines.org", 80, $errno, $errstr);
        if ($fp) {
            $out = "GET /smf/stats/register_stats.php?site=" . base64_encode($boardurl) . " HTTP/1.1\r\n";
            $out .= "Host: www.simplemachines.org\r\n";
            $out .= "Connection: Close\r\n\r\n";
            fwrite($fp, $out);
            $return_data = '';
            while (!feof($fp)) {
                $return_data .= fgets($fp, 128);
            }
            fclose($fp);
            // Get the unique site ID.
            preg_match('~SITE-ID:\\s(\\w{10})~', $return_data, $ID);
            if (!empty($ID[1])) {
                upgrade_query("\n\t\t\t\t\tREPLACE INTO {$db_prefix}settings\n\t\t\t\t\t\t(variable, value)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t('allow_sm_stats', '{$ID['1']}')");
            }
        }
    } else {
        upgrade_query("\n\t\t\tDELETE FROM {$db_prefix}settings\n\t\t\tWHERE variable = 'allow_sm_stats'");
    }
    $endl = $command_line ? "\n" : '<br />' . "\n";
    $changes = array();
    if (isset($_GET['lang'])) {
        $changes['language'] = '\'english\'';
    }
    if (!empty($_GET['maint'])) {
        $changes['maintenance'] = '2';
        $changes['mtitle'] = '\'Upgrading the forum...\'';
        $changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
    }
    echo $command_line ? ' * ' : '', 'Updating Settings.php...';
    copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
    if (substr($boarddir, 0, 1) == '.') {
        $changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
    }
    if (substr($sourcedir, 0, 1) == '.') {
        $changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
    }
    // !!! Maybe change the cookie name if going to 1.1, too?
    // Update Settings.php with the new settings.
    changeSettings($changes);
    echo ' Successful.', $endl;
    if (!empty($_GET['backup']) || isset($_GET['t'])) {
        echo $command_line ? ' * ' : 'Backing up old table data...';
        if (preg_match('~^`(.+?)`\\.(.+?)$~', $db_prefix, $match) != 0) {
            $result = upgrade_query("\n\t\t\t\tSHOW TABLES\n\t\t\t\tFROM `" . strtr($match[1], array('`' => '')) . "`\n\t\t\t\tLIKE '" . str_replace('_', '\\_', $match[2]) . "%'");
        } else {
            $result = upgrade_query("\n\t\t\t\tSHOW TABLES\n\t\t\t\tLIKE '" . str_replace('_', '\\_', $db_prefix) . "%'");
        }
        $table_names = array();
        while ($row = mysql_fetch_row($result)) {
            if (substr($row[0], 0, 7) !== 'backup_') {
                $table_names[] = $row[0];
            }
        }
        mysql_free_result($result);
        for ($substep = $_GET['substep'], $n = count($table_names); $substep < $n; $substep++) {
            nextSubstep($substep);
            if (!empty($_GET['debug'])) {
                if ($command_line) {
                    echo $endl, ' +++ Backing up "' . str_replace($db_prefix, '', $table_names[$substep]) . '"...';
                } else {
                    echo '<br />
				&nbsp;&nbsp;&nbsp;', 'Backing up &quot;' . str_replace($db_prefix, '', $table_names[$substep]) . '&quot;...';
                }
                flush();
            }
            $result = upgrade_query("\n\t\t\t\tSHOW CREATE TABLE " . $table_names[$substep]);
            list(, $create) = mysql_fetch_row($result);
            mysql_free_result($result);
            $create = preg_split('/[\\n\\r]/', $create);
            $auto_inc = '';
            // Default engine type.
            $engine = 'MyISAM';
            $charset = '';
            $collate = '';
            foreach ($create as $k => $l) {
                // Get the name of the auto_increment column.
                if (strpos($l, 'auto_increment')) {
                    $auto_inc = trim($l);
                }
                // For the engine type, see if we can work out what it is.
                if (strpos($l, 'ENGINE') !== false || strpos($l, 'TYPE') !== false) {
                    // Extract the engine type.
                    preg_match('~(ENGINE|TYPE)=(\\w+)(\\sDEFAULT)?(\\sCHARSET=(\\w+))?(\\sCOLLATE=(\\w+))?~', $l, $match);
                    if (!empty($match[2])) {
                        $engine = $match[2];
                    }
                    if (!empty($match[5])) {
                        $charset = $match[5];
                    }
                    if (!empty($match[7])) {
                        $collate = $match[7];
                    }
                }
                // Skip everything but keys...
                if (strpos($l, 'KEY') === false) {
                    unset($create[$k]);
                }
            }
            if (!empty($create)) {
                $create = '(
					' . implode('
					', $create) . ')';
            } else {
                $create = '';
            }
            upgrade_query("\n\t\t\t\tDROP TABLE IF EXISTS backup_" . $table_names[$substep]);
            upgrade_query("\n\t\t\t\tCREATE TABLE backup_" . $table_names[$substep] . " {$create}\n\t\t\t\tTYPE={$engine}" . (empty($charset) ? '' : " CHARACTER SET {$charset}" . (empty($collate) ? '' : " COLLATE {$collate}")) . "\n\t\t\t\tSELECT *\n\t\t\t\tFROM " . $table_names[$substep]);
            if ($auto_inc != '') {
                if (preg_match('~\\`(.+?)\\`\\s~', $auto_inc, $match) != 0 && substr($auto_inc, -1, 1) == ',') {
                    $auto_inc = substr($auto_inc, 0, -1);
                }
                upgrade_query("\n\t\t\t\t\tALTER TABLE backup_" . $table_names[$substep] . "\n\t\t\t\t\tCHANGE COLUMN {$match['1']} {$auto_inc}");
            }
            if (!empty($_GET['debug'])) {
                echo ' done.';
            }
        }
        if (!empty($_GET['debug'])) {
            echo $endl;
            flush();
        }
        echo ' Successful.', $endl;
    }
    $_GET['substep'] = 0;
    return doStep2();
}