Exemplo n.º 1
0
function Welcome()
{
    global $incontext, $txt, $databases, $installurl;
    $incontext['page_title'] = $txt['install_welcome'];
    $incontext['sub_template'] = 'welcome_message';
    // Done the submission?
    if (isset($_POST['contbutt'])) {
        return true;
    }
    // Check the PHP version.
    if (!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION) > 0) {
        $incontext['warning'] = $txt['error_php_too_low'];
    }
    // See if we think they have already installed it?
    if (is_readable(dirname(__FILE__) . '/Settings.php')) {
        $probably_installed = 0;
        foreach (file(dirname(__FILE__) . '/Settings.php') as $line) {
            if (preg_match('~^\\$db_passwd\\s=\\s\'([^\']+)\';$~', $line)) {
                $probably_installed++;
            }
            if (preg_match('~^\\$boardurl\\s=\\s\'([^\']+)\';~', $line) && !preg_match('~^\\$boardurl\\s=\\s\'http://127\\.0\\.0\\.1/smf\';~', $line)) {
                $probably_installed++;
            }
        }
        if ($probably_installed == 2) {
            $incontext['warning'] = $txt['error_already_installed'];
        }
    }
    // Is some database support even compiled in?
    $incontext['supported_databases'] = array();
    foreach ($databases as $key => $db) {
        if ($db['supported']) {
            if (!file_exists(dirname(__FILE__) . '/install_' . $GLOBALS['db_script_version'] . '_' . $key . '.sql')) {
                $databases[$key]['supported'] = false;
                $notFoundSQLFile = true;
                $txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $key . '.sql');
            } else {
                $incontext['supported_databases'][] = $db;
            }
        }
    }
    if (empty($incontext['supported_databases'])) {
        $error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
    } elseif (!function_exists('session_start')) {
        $error = 'error_session_missing';
    } elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
        $error = 'error_missing_files';
    } elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
        $error = 'error_session_save_path';
    }
    // Since each of the three messages would look the same, anyway...
    if (isset($error)) {
        $incontext['error'] = $txt[$error];
    }
    // Mod_security blocks everything that smells funny. Let SMF handle security.
    if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
        $incontext['error'] = $txt['error_mod_security'] . '<br /><br /><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
    }
    return false;
}
Exemplo n.º 2
0
function doStep0()
{
    global $txt;
    // Just so people using older versions of PHP aren't left in the cold.
    if (!isset($_SERVER['PHP_SELF'])) {
        $_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
    }
    // Show a language selection...
    if (count($GLOBALS['detected_languages']) > 1) {
        echo '
				<div style="padding-bottom: 2ex; text-align: ', empty($txt['lang_rtl']) ? 'right' : 'left', ';">
					<form action="', $_SERVER['PHP_SELF'], '" method="get">
						<label for="installer_language">', $txt['installer_language'], ':</label> <select id="installer_language" name="lang_file" onchange="location.href = \'', $_SERVER['PHP_SELF'], '?lang_file=\' + this.options[this.selectedIndex].value;">';
        foreach ($GLOBALS['detected_languages'] as $lang => $name) {
            echo '
							<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected="selected"' : '', ' value="', $lang, '">', $name, '</option>';
        }
        echo '
						</select>

						<noscript><input type="submit" value="', $txt['installer_language_set'], '" /></noscript>
					</form>
				</div>';
    }
    // Check the PHP version.
    if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION) > 0) && !isset($_GET['overphp'])) {
        echo '
				<div class="error_message">
					<div style="color: red;">', $txt['error_php_too_low'], '</div>
					<br />
					<a href="', $_SERVER['PHP_SELF'], '?step=0&amp;overphp=true">', $txt['error_message_click'], '</a> ', $txt['error_message_bad_try_again'], '
				</div>';
        return false;
    }
    // Is MySQL even compiled in?
    if (!function_exists('mysql_connect')) {
        $error = 'error_mysql_missing';
    } elseif (!function_exists('session_start')) {
        $error = 'error_session_missing';
    } elseif (!file_exists(dirname(__FILE__) . '/index.php') || !file_exists(dirname(__FILE__) . '/install_1-1.sql')) {
        $error = 'error_missing_files';
    } elseif (session_save_path() == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
        $error = 'error_session_save_path';
    }
    // Since each of the three messages would look the same, anyway...
    if (isset($error)) {
        echo '
				<div class="error_message">
					<div style="color: red;">', $txt[$error], '</div>
					<br />
					<a href="', $_SERVER['PHP_SELF'], '?step=0&amp;overphp=true">', $txt['error_message_click'], '</a> ', $txt['error_message_try_again'], '
				</div>';
        return false;
    }
    // Make sure all the files are properly writable (has its own messages...)
    if (!make_files_writable()) {
        return false;
    }
    // Mod_security blocks everything that smells funny. Let SMF handle security.
    if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
        echo '
				<div class="error_message">
					<div style="color: red;">', $txt['error_mod_security'], '</div>
					<br />
					<a href="', $_SERVER['PHP_SELF'], '?step=0&amp;overphp=true&amp;overmodsecurity=true">', $txt['error_message_click'], '</a> ', $txt['error_message_bad_try_again'], '
				</div>';
        return false;
    }
    // Set up the defaults.
    $db_server = @ini_get('mysql.default_host') or $db_server = 'localhost';
    $db_user = isset($_POST['ftp_username']) ? $_POST['ftp_username'] : @ini_get('mysql.default_user');
    $db_name = isset($_POST['ftp_username']) ? $_POST['ftp_username'] : @ini_get('mysql.default_user');
    $db_passwd = @ini_get('mysql.default_password');
    // This is just because it makes it easier for people on Lycos/Tripod UK :P.
    if (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] == 'members.lycos.co.uk' && defined('LOGIN')) {
        $db_user = LOGIN;
        $db_name = LOGIN . '_uk_db';
    }
    // Should we use a non standard port?
    $db_port = @ini_get('mysql.default_port');
    if (!empty($db_port)) {
        $db_server .= ':' . $db_port;
    }
    // What host and port are we on?
    $host = empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
    // Now, to put what we've learned together... and add a path.
    $url = 'http://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
    // Check if the database sessions will even work.
    $test_dbsession = @ini_get('session.auto_start') != 1 && @version_compare(PHP_VERSION, '4.2.0') != -1;
    echo '
				<div class="panel">
					<form action="' . $_SERVER['PHP_SELF'] . '?step=1" method="post">
						<h2>', $txt['install_settings'], '</h2>
						<h3>', $txt['install_settings_info'], '</h3>

						<table width="100%" cellpadding="0" cellspacing="0" border="0" style="margin-bottom: 2ex;">
							<tr>
								<td width="20%" valign="top" class="textbox"><label for="mbname_input">', $txt['install_settings_name'], ':</label></td>
								<td>
									<input type="text" name="mbname" id="mbname_input" value="', $txt['install_settings_name_default'], '" size="65" />
									<div style="font-size: smaller; margin-bottom: 2ex;">', $txt['install_settings_name_info'], '</div>
								</td>
							</tr><tr>
								<td valign="top" class="textbox"><label for="boardurl_input">', $txt['install_settings_url'], ':</label></td>
								<td>
									<input type="text" name="boardurl" id="boardurl_input" value="', $url, '" size="65" /><br />
									<div style="font-size: smaller; margin-bottom: 2ex;">', $txt['install_settings_url_info'], '</div>
								</td>
							</tr><tr>
								<td valign="top" class="textbox">', $txt['install_settings_compress'], ':</td>
								<td>
									<input type="checkbox" name="compress" id="compress_check" checked="checked" /> <label for="compress_check">', $txt['install_settings_compress_title'], '</label><br />
									<div style="font-size: smaller; margin-bottom: 2ex;">', $txt['install_settings_compress_info'], '</div>
								</td>
							</tr><tr>
								<td valign="top" class="textbox">', $txt['install_settings_dbsession'], ':</td>
								<td>
									<input type="checkbox" name="dbsession" id="dbsession_check" checked="checked" /> <label for="dbsession_check">', $txt['install_settings_dbsession_title'], '</label><br />
									<div style="font-size: smaller; margin-bottom: 2ex;">', $test_dbsession ? $txt['install_settings_dbsession_info1'] : $txt['install_settings_dbsession_info2'], '</div>
								</td>
							</tr>';
    if (strpos(strtolower(PHP_OS), 'win') === false || @version_compare(PHP_VERSION, '4.2.3') != -1) {
        echo '
							<tr>
								<td valign="top" class="textbox">', $txt['install_settings_utf8'], ':</td>
								<td>
									<input type="checkbox" name="utf8" id="utf8_check" /> <label for="utf8_check">', $txt['install_settings_utf8_title'], '</label><br />
									<div style="font-size: smaller; margin-bottom: 2ex;">', $txt['install_settings_utf8_info'], '</div>
								</td>
							</tr>';
    }
    echo '
							<tr>
								<td valign="top" class="textbox">', $txt['install_settings_stats'], ':</td>
								<td>
									<input type="checkbox" name="stats" id="stats_check" /> <label for="stats_check">', $txt['install_settings_stats_title'], '</label><br />
									<div style="font-size: smaller; margin-bottom: 2ex;">', $txt['install_settings_stats_info'], '</div>
								</td>
							</tr>
						</table>

						<h2>', $txt['mysql_settings'], '</h2>
						<h3>', $txt['mysql_settings_info'], '</h3>

						<table width="100%" cellpadding="0" cellspacing="0" border="0" style="margin-bottom: 2ex;">
							<tr>
								<td width="20%" valign="top" class="textbox"><label for="db_server_input">', $txt['mysql_settings_server'], ':</label></td>
								<td>
									<input type="text" name="db_server" id="db_server_input" value="', $db_server, '" size="30" /><br />
									<div style="font-size: smaller; margin-bottom: 2ex;">', $txt['mysql_settings_server_info'], '</div>
								</td>
							</tr><tr>
								<td valign="top" class="textbox"><label for="db_user_input">', $txt['mysql_settings_username'], ':</label></td>
								<td>
									<input type="text" name="db_user" id="db_user_input" value="', $db_user, '" size="30" /><br />
									<div style="font-size: smaller; margin-bottom: 2ex;">', $txt['mysql_settings_username_info'], '</div>
								</td>
							</tr><tr>
								<td valign="top" class="textbox"><label for="db_passwd_input">', $txt['mysql_settings_password'], ':</label></td>
								<td>
									<input type="password" name="db_passwd" id="db_passwd_input" value="', $db_passwd, '" size="30" /><br />
									<div style="font-size: smaller; margin-bottom: 2ex;">', $txt['mysql_settings_password_info'], '</div>
								</td>
							</tr><tr>
								<td valign="top" class="textbox"><label for="db_name_input">', $txt['mysql_settings_database'], ':</label></td>
								<td>
									<input type="text" name="db_name" id="db_name_input" value="', empty($db_name) ? 'smf' : $db_name, '" size="30" /><br />
									<div style="font-size: smaller; margin-bottom: 2ex;">', $txt['mysql_settings_database_info'], '</div>
								</td>
							</tr><tr>
								<td valign="top" class="textbox"><label for="db_prefix_input">', $txt['mysql_settings_prefix'], ':</label></td>
								<td>
									<input type="text" name="db_prefix" id="db_prefix_input" value="smf_" size="30" /><br />
									<div style="font-size: smaller; margin-bottom: 2ex;">', $txt['mysql_settings_prefix_info'], '</div>
								</td>
							</tr>
						</table>

						<div style="margin: 1ex; text-align: ', empty($txt['lang_rtl']) ? 'right' : 'left', ';"><input type="submit" value="', $txt['install_settings_proceed'], '" /></div>
					</form>
				</div>';
    return true;
}