コード例 #1
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;
}
コード例 #2
0
ファイル: webinstall.php プロジェクト: norv/smf-tools
function doStep2()
{
    global $txt, $ftp;
    $chmod =& $_SESSION['webinstall_state']['chmod'];
    if (isset($_POST['ftp_username'])) {
        $ftp = new ftp_connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']);
        if ($ftp->error === false) {
            // Try it without /home/abc just in case they messed up.
            if (!$ftp->chdir($_POST['ftp_path'])) {
                $ftp->chdir(preg_replace('~^/home[2]?/[^/]+?~', '', $_POST['ftp_path']));
            }
        }
        if ($ftp->error === false) {
            foreach ($_SESSION['webinstall_state']['files_to_download'] as $i => $file) {
                $ftp->create_file('smf_install' . $i . '.tmp');
                $ftp->chmod('smf_install' . $i . '.tmp', $chmod);
            }
            if (!file_exists(dirname(__FILE__) . '/smf_install0.tmp')) {
                $ftp->error = true;
            }
        }
        if ($ftp->error === false) {
            $_SESSION['installer_temp_ftp'] = array('server' => $_POST['ftp_server'], 'port' => $_POST['ftp_port'], 'username' => $_POST['ftp_username'], 'password' => $_POST['ftp_password'], 'path' => $_POST['ftp_path']);
            run_chmod_test($ftp, $chmod);
        } elseif ($_POST['ftp_username'] != '') {
            echo '
					<div class="error_message">
						<div>', $txt['error_not_right_path'], '</div>
					</div>';
            return doStep1();
        }
    }
    if (ini_get('memory_limit') < 64) {
        ini_set('memory_limit', '64M');
    }
    foreach ($_SESSION['webinstall_state']['files_to_download'] as $i => $file) {
        if ($i < $_GET['substep']) {
            continue;
        }
        $data = fetch_web_data($file, isset($_SESSION['webinstall_state']['user_data']) ? $_SESSION['webinstall_state']['user_data'] : '');
        if (function_exists('gzinflate')) {
            $data = extract_gzip($data);
        }
        if ($data === false) {
            echo '
					<div class="error_message">
						<div>', sprintf($txt['error_unable_download'], $file), '</div>
						<br />
						<a href="', $_SERVER['PHP_SELF'], '?step=1&substep=', $i, '">', $txt['error_message_click'], '</a> ', $txt['error_message_try_again'], '
					</div>';
            return false;
        }
        file_put_contents(dirname(__FILE__) . '/smf_install' . $i . '.tmp', $data);
        if ($i < $_SESSION['webinstall_state']['files_to_download_total'] - 1) {
            $query_string = '?step=2&substep=' . ($i + 1);
            $percent_done_total = round(($i + 1) / $_SESSION['webinstall_state']['files_to_download_total'] * 100, 2);
            // Pausing time!
            echo '
				<div class="panel">
					<h2 style="margin-top: 2ex;">', $txt['not_done_yet'], '</h2>
					<h3>', $txt['download_paused'], '</h3>

					<div style="padding-left: 20%; padding-right: 20%; margin-top: 1ex;">
						<strong>', $txt['download_progress'], ':</strong>
						<div style="font-size: 8pt; height: 12pt; border: 1px solid black; background-color: white; padding: 1px; position: relative;">
							<div style="padding-top: 1pt; width: 100%; z-index: 2; color: black; position: absolute; text-align: center; font-weight: bold;">', $percent_done_total, '%</div>
							<div style="width: ', $percent_done_total, '%; height: 12pt; z-index: 1; background-color: red;">&nbsp;</div>
						</div>
					</div>
					<form action="', $_SERVER['PHP_SELF'], $query_string, '" method="post" name="autoSubmit">
						<div class="righttext" style="margin: 1ex;"><input name="b" type="submit" value="', $txt['continue'], '" /></div>
					</form>
					<script type="text/javascript"><!-- // --><![CDATA[
						window.onload = doAutoSubmit;
						var countdown = 3;

						function doAutoSubmit()
						{
							if (countdown == 0)
								document.autoSubmit.submit();
							else if (countdown == -1)
								return;

							document.autoSubmit.b.value = "', $txt['continue'], ' (" + countdown + ")";
							countdown--;

							setTimeout(doAutoSubmit, 1000);
						}
					// ]]></script>
				</div>';
            return true;
        }
    }
    $_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'] = '';
    $_SESSION['webinstall_state']['member_info'] = array();
    echo '
				<div class="panel">
					<h2>', $txt['download_successful'], '</h2>
					<h3>', $txt['download_successful_info'], '</h3>

					<form action="', $_SERVER['PHP_SELF'], '?step=3" method="post" name="autoSubmit">
						<div class="righttext" style="margin: 1ex;"><input type="submit" name="b" value="', $txt['continue'], '" /></div>
					</form>
					<script type="text/javascript"><!-- // --><![CDATA[
						window.onload = doAutoSubmit;
						var countdown = 3;

						function doAutoSubmit()
						{
							if (countdown == 0)
								document.autoSubmit.submit();
							else if (countdown == -1)
								return;

							document.autoSubmit.b.value = "', $txt['continue'], ' (" + countdown + ")";
							countdown--;

							setTimeout(doAutoSubmit, 1000);
						}
					// ]]></script>
				</div>';
    return true;
}
コード例 #3
0
ファイル: upgrade.php プロジェクト: alencarmo/OCF
function cmdStep0()
{
    global $boarddir, $sourcedir, $db_prefix, $language, $modSettings, $start_time;
    $start_time = time();
    ob_end_clean();
    ob_implicit_flush(true);
    @set_time_limit(0);
    if (!isset($_SERVER['argv'])) {
        $_SERVER['argv'] = array();
    }
    $_GET['maint'] = 1;
    foreach ($_SERVER['argv'] as $i => $arg) {
        if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
            $_GET['lang'] = $match[1];
        } elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
            continue;
        } elseif ($arg == '--no-maintenance') {
            $_GET['maint'] = 0;
        } elseif ($arg == '--debug') {
            $_GET['debug'] = 1;
        } elseif ($arg == '--backup') {
            $_GET['backup'] = 1;
        } elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($boarddir . '/Themes/converted'))) {
            $_GET['conv'] = 1;
        } elseif ($i != 0) {
            echo 'SMF Command-line Upgrader
Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...

    --language=LANG         Reset the forum\'s language to LANG.
    --no-maintenance        Don\'t put the forum into maintenance mode.
    --debug                 Output debugging information.
    --backup                Create backups of tables with "backup_" prefix.';
            if (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($boarddir . '/Themes/converted')) {
                echo '
    --template              Convert the YaBB SE template file.';
            }
            echo "\n";
            exit;
        }
    }
    if (!php_version_check()) {
        print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
    }
    if (!mysql_version_check()) {
        print_error('Error: MySQL ' . min(mysql_get_server_info(), mysql_get_client_info()) . ' does not match minimum requirements.', true);
    }
    if (mysql_query("ALTER TABLE {$db_prefix}boards ORDER BY ID_BOARD") === false) {
        print_error('Error: The MySQL account in Settings.php does not have sufficient privileges.', true);
    }
    $check = @file_exists($boarddir . '/Themes/default/index.template.php') && @file_exists($sourcedir . '/QueryString.php') && @file_exists($sourcedir . '/ManageBoards.php');
    if (!$check && !isset($modSettings['smfVersion'])) {
        print_error('Error: Some files are missing or out-of-date.', true);
    }
    // Do a quick version spot check.
    $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
    preg_match('~\\*\\s*Software\\s+Version:\\s+SMF\\s+(.+?)[\\s]{2}~i', $temp, $match);
    if (empty($match[1]) || $match[1] != SMF_VERSION) {
        print_error('Error: Some files have not yet been updated properly.');
    }
    // Make sure Settings.php is writable.
    if (!is_writable($boarddir . '/Settings.php')) {
        @chmod($boarddir . '/Settings.php', 0777);
    }
    if (!is_writable($boarddir . '/Settings.php')) {
        print_error('Error: Unable to obtain write access to "Settings.php".');
    }
    // Make sure Settings.php is writable.
    if (!is_writable($boarddir . '/Settings_bak.php')) {
        @chmod($boarddir . '/Settings_bak.php', 0777);
    }
    if (!is_writable($boarddir . '/Settings_bak.php')) {
        print_error('Error: Unable to obtain write access to "Settings_bak.php".');
    }
    if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
        print_error('Error: Unable to obtain write access to "agreement.txt".');
    } elseif (isset($modSettings['agreement'])) {
        $fp = fopen($boarddir . '/agreement.txt', 'w');
        fwrite($fp, $modSettings['agreement']);
        fclose($fp);
    }
    // Make sure Themes is writable.
    if (!is_writable($boarddir . '/Themes')) {
        @chmod($boarddir . '/Themes', 0777);
    }
    if (!is_writable($boarddir . '/Themes') && !isset($modSettings['smfVersion'])) {
        print_error('Error: Unable to obtain write access to "Themes".');
    }
    if (!file_exists($boarddir . '/Themes/default/languages/index.' . basename($language, '.lng') . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
        print_error('Error: Unable to find language files!');
    } else {
        $temp = substr(@implode('', @file($boarddir . '/Themes/default/languages/index.' . (isset($_GET['lang']) ? $_GET['lang'] : basename($language, '.lng')) . '.php')), 0, 4096);
        preg_match('~(?://|/\\*)\\s*Version:\\s+(.+?);\\s*index(?:[\\s]{2}|\\*/)~i', $temp, $match);
        if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
            print_error('Error: Language files out of date.');
        }
    }
    return doStep1();
}