Esempio n. 1
0
/**
 * Fifth installation step.
 *
 * @return tempcode		Progress report / UI
 */
function step_5()
{
    if (count($_POST) == 0) {
        exit(do_lang('INST_POST_ERROR'));
    }
    if (function_exists('set_time_limit')) {
        @set_time_limit(180);
    }
    $url = 'install.php?step=6';
    $use_msn = post_param_integer('use_msn', 0);
    if ($use_msn == 0) {
        $use_msn = post_param_integer('use_multi_db', 0);
    }
    if ($use_msn == 0) {
        $_POST['db_forums'] = $_POST['db_site'];
        $_POST['db_forums_host'] = $_POST['db_site_host'];
        $_POST['db_forums_user'] = $_POST['db_site_user'];
        $_POST['db_forums_password'] = $_POST['db_site_password'];
        $_POST['ocf_table_prefix'] = array_key_exists('table_prefix', $_POST) ? $_POST['table_prefix'] : 'ocp_';
    }
    // Check cookie settings. IF THIS CODE IS CHANGED ALSO CHANGE COPY&PASTED CODE IN CONFIG_EDITOR.PHP
    $cookie_path = post_param('cookie_path');
    $cookie_domain = trim(post_param('cookie_domain'));
    $base_url = post_param('base_url');
    if (substr($base_url, -1) == '/') {
        $base_url = substr($base_url, 0, strlen($base_url) - 1);
    }
    $url_parts = parse_url($base_url);
    if (!array_key_exists('host', $url_parts)) {
        $url_parts['host'] = 'localhost';
    }
    if (!array_key_exists('path', $url_parts)) {
        $url_parts['path'] = '';
    }
    if (substr($url_parts['path'], -1) != '/') {
        $url_parts['path'] .= '/';
    }
    if (substr($cookie_path, -1) == '/') {
        $cookie_path = substr($cookie_path, 0, strlen($cookie_path) - 1);
    }
    if ($cookie_path != '' && substr($url_parts['path'], 0, strlen($cookie_path) + 1) != $cookie_path . '/') {
        warn_exit(do_lang_tempcode('COOKIE_PATH_MUST_MATCH', escape_html($url_parts['path'])));
    }
    if ($cookie_domain != '') {
        if (strpos($url_parts['host'], '.') === false) {
            warn_exit(do_lang_tempcode('COOKIE_DOMAIN_CANT_USE'));
        }
        if (substr($cookie_domain, 0, 1) != '.') {
            warn_exit(do_lang_tempcode('COOKIE_DOMAIN_MUST_START_DOT'));
        } elseif (substr($url_parts['host'], 1 - strlen($cookie_domain)) != substr($cookie_domain, 1)) {
            warn_exit(do_lang_tempcode('COOKIE_DOMAIN_MUST_MATCH', escape_html($url_parts['host'])));
        }
    }
    $table_prefix = post_param('table_prefix');
    if ($table_prefix == '') {
        warn_exit(do_lang_tempcode('NO_BLANK_TABLE_PREFIX'));
    }
    // Give warning if database contains data
    global $SITE_INFO;
    foreach ($_POST as $key => $val) {
        if ($key == 'ftp_password' || $key == 'ftp_password_confirm' || $key == 'admin_password_confirm' || $key == 'ocf_admin_password' || $key == 'ocf_admin_password_confirm') {
            continue;
        }
        if (get_magic_quotes_gpc()) {
            $val = stripslashes($val);
        }
        if ($key == 'admin_password') {
            $val = '!' . md5($val . 'ocp');
        }
        $SITE_INFO[$key] = trim($val);
    }
    require_code('database');
    if (post_param_integer('confirm', 0) == 0) {
        $tmp = new database_driver(trim(post_param('db_site')), trim(post_param('db_site_host')), trim(post_param('db_site_user')), trim(post_param('db_site_password')), $table_prefix);
        $test = $tmp->query_value_null_ok('config', 'the_type', array('the_name' => 'is_on_gd'), '', true);
        unset($tmp);
        if (!is_null($test)) {
            global $LANG;
            $sections = build_keep_post_fields(array('forum_type', 'db_type', 'board_path', 'default_lang'));
            $sections->attach(form_input_hidden('confirm', '1'));
            return do_template('INSTALLER_STEP_4', array('_GUID' => 'aaf0386966dd4b75c8027a6b1f7454c6', 'MESSAGE' => do_lang_tempcode('WARNING_DB_OVERWRITE'), 'LANG' => $LANG, 'DB_TYPE' => post_param('db_type'), 'FORUM_TYPE' => post_param('forum_type'), 'BOARD_PATH' => post_param('board_path'), 'SECTIONS' => $sections));
        }
    }
    if ($_POST['db_forums'] != $_POST['db_site'] && get_forum_type() == 'ocf') {
        $tmp = new database_driver(trim(post_param('db_forums')), trim(post_param('db_forums_host')), trim(post_param('db_forums_user')), trim(post_param('db_forums_password')), $table_prefix);
        if (is_null($tmp->query_value_null_ok('db_meta', 'COUNT(*)', NULL, '', true))) {
            warn_exit(do_lang_tempcode('MSN_FORUM_DB_NOT_OCF_ALREADY'));
        }
    }
    global $FILE_ARRAY;
    $still_ftp = false;
    $log = new ocp_tempcode();
    if (@is_array($FILE_ARRAY)) {
        $ftp_status = step_5_ftp();
        $log->attach($ftp_status[0]);
        if ($ftp_status[1] != -1) {
            $url = 'install.php?step=5&start_from=' . strval($ftp_status[1]);
            $still_ftp = true;
        }
    }
    if (!$still_ftp) {
        require_code('zones');
        require_code('comcode');
        require_code('themes');
        $log->attach(step_5_checks());
        $log->attach(step_5_write_config());
        $log->attach(step_5_uninstall());
        $log->attach(step_5_core());
        include_ocf();
        $log->attach(step_5_core_2());
    }
    return do_template('INSTALLER_STEP_LOG', array('_GUID' => '83ed0405bc32fdf2cc499662bfa51bc9', 'PREVIOUS_STEP' => '4', 'URL' => $url, 'LOG' => $log, 'HIDDEN' => build_keep_post_fields()));
}