/** */ function get_convert_settings($sub) { global $lang, $language, $template, $db, $phpbb_root_path, $phpEx, $config, $cache; require($phpbb_root_path . 'config.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); $db = new $sql_db(); $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true); unset($dbpasswd); $this->page_title = $lang['STAGE_SETTINGS']; // We need to fill the config to let internal functions correctly work $sql = 'SELECT * FROM ' . CONFIG_TABLE; $result = $db->sql_query($sql); $config = array(); while ($row = $db->sql_fetchrow($result)) { $config[$row['config_name']] = $row['config_value']; } $db->sql_freeresult($result); $convertor_tag = request_var('tag', ''); if (empty($convertor_tag)) { $this->p_master->error($lang['NO_CONVERT_SPECIFIED'], __LINE__, __FILE__); } $get_info = true; // check security implications of direct inclusion $convertor_tag = basename($convertor_tag); if (!file_exists('./convertors/convert_' . $convertor_tag . '.' . $phpEx)) { $this->p_master->error($lang['CONVERT_NOT_EXIST'], __LINE__, __FILE__); } include('./convertors/convert_' . $convertor_tag . '.' . $phpEx); // The test_file is a file that should be present in the location of the old board. if (!isset($test_file)) { $this->p_master->error($lang['DEV_NO_TEST_FILE'], __LINE__, __FILE__); } $submit = (isset($_POST['submit'])) ? true : false; $src_dbms = request_var('src_dbms', $convertor_data['dbms']); $src_dbhost = request_var('src_dbhost', $convertor_data['dbhost']); $src_dbport = request_var('src_dbport', $convertor_data['dbport']); $src_dbuser = request_var('src_dbuser', $convertor_data['dbuser']); $src_dbpasswd = request_var('src_dbpasswd', $convertor_data['dbpasswd']); $src_dbname = request_var('src_dbname', $convertor_data['dbname']); $src_table_prefix = request_var('src_table_prefix', $convertor_data['table_prefix']); $forum_path = request_var('forum_path', $convertor_data['forum_path']); $refresh = request_var('refresh', 1); // Default URL of the old board // @todo Are we going to use this for attempting to convert URL references in posts, or should we remove it? // -> We should convert old urls to the new relative urls format // $src_url = request_var('src_url', 'Not in use at the moment'); // strip trailing slash from old forum path $forum_path = (strlen($forum_path) && $forum_path[strlen($forum_path) - 1] == '/') ? substr($forum_path, 0, -1) : $forum_path; $error = array(); if ($submit) { if (!@file_exists('./../' . $forum_path . '/' . $test_file)) { $error[] = sprintf($lang['COULD_NOT_FIND_PATH'], $forum_path); } $connect_test = false; $available_dbms = get_available_dbms(false, true, true); if (!isset($available_dbms[$src_dbms]) || !$available_dbms[$src_dbms]['AVAILABLE']) { $error['db'][] = $lang['INST_ERR_NO_DB']; $connect_test = false; } else { $connect_test = connect_check_db(true, $error, $available_dbms[$src_dbms], $src_table_prefix, $src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, true, ($src_dbms == $dbms) ? false : true, false); } // The forum prefix of the old and the new forum can only be the same if two different databases are used. if ($src_table_prefix == $table_prefix && $src_dbms == $dbms && $src_dbhost == $dbhost && $src_dbport == $dbport && $src_dbname == $dbname) { $error[] = sprintf($lang['TABLE_PREFIX_SAME'], $src_table_prefix); } // Check table prefix if (!sizeof($error)) { // initiate database connection to old db if old and new db differ global $src_db, $same_db; $src_db = $same_db = false; if ($src_dbms != $dbms || $src_dbhost != $dbhost || $src_dbport != $dbport || $src_dbname != $dbname || $src_dbuser != $dbuser) { $sql_db = 'dbal_' . $src_dbms; $src_db = new $sql_db(); $src_db->sql_connect($src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, false, true); $same_db = false; } else { $src_db = $db; $same_db = true; } $src_db->sql_return_on_error(true); $db->sql_return_on_error(true); // Try to select one row from the first table to see if the prefix is OK $result = $src_db->sql_query_limit('SELECT * FROM ' . $src_table_prefix . $tables[0], 1); if (!$result) { $prefixes = array(); $tables_existing = get_tables($src_db); $tables_existing = array_map('strtolower', $tables_existing); foreach ($tables_existing as $table_name) { compare_table($tables, $table_name, $prefixes); } unset($tables_existing); foreach ($prefixes as $prefix => $count) { if ($count >= sizeof($tables)) { $possible_prefix = $prefix; break; } } $msg = ''; if (!empty($convertor_data['table_prefix'])) { $msg .= sprintf($lang['DEFAULT_PREFIX_IS'], $convertor_data['forum_name'], $convertor_data['table_prefix']); } if (!empty($possible_prefix)) { $msg .= '<br />'; $msg .= ($possible_prefix == '*') ? $lang['BLANK_PREFIX_FOUND'] : sprintf($lang['PREFIX_FOUND'], $possible_prefix); $src_table_prefix = ($possible_prefix == '*') ? '' : $possible_prefix; } $error[] = $msg; } $src_db->sql_freeresult($result); $src_db->sql_return_on_error(false); } if (!sizeof($error)) { // Save convertor Status set_config('convert_progress', serialize(array( 'step' => '', 'table_prefix' => $src_table_prefix, 'tag' => $convertor_tag, )), true); set_config('convert_db_server', serialize(array( 'dbms' => $src_dbms, 'dbhost' => $src_dbhost, 'dbport' => $src_dbport, 'dbname' => $src_dbname, )), true); set_config('convert_db_user', serialize(array( 'dbuser' => $src_dbuser, 'dbpasswd' => $src_dbpasswd, )), true); // Save options set_config('convert_options', serialize(array('forum_path' => './../' . $forum_path, 'refresh' => $refresh)), true); $template->assign_block_vars('checks', array( 'TITLE' => $lang['VERIFY_OPTIONS'], 'RESULT' => $lang['CONVERT_SETTINGS_VERIFIED'], )); $template->assign_vars(array( 'L_SUBMIT' => $lang['BEGIN_CONVERT'], // 'S_HIDDEN' => $s_hidden_fields, 'U_ACTION' => $this->p_master->module_url . "?mode={$this->mode}&sub=in_progress&tag=$convertor_tag&language=$language", )); return; } else { $template->assign_block_vars('checks', array( 'TITLE' => $lang['VERIFY_OPTIONS'], 'RESULT' => '<b style="color:red">' . implode('<br />', $error) . '</b>', )); } } // end submit foreach ($this->convert_options as $config_key => $vars) { if (!is_array($vars) && strpos($config_key, 'legend') === false) { continue; } if (strpos($config_key, 'legend') !== false) { $template->assign_block_vars('options', array( 'S_LEGEND' => true, 'LEGEND' => $lang[$vars]) ); continue; } $options = isset($vars['options']) ? $vars['options'] : ''; $template->assign_block_vars('options', array( 'KEY' => $config_key, 'TITLE' => $lang[$vars['lang']], 'S_EXPLAIN' => $vars['explain'], 'S_LEGEND' => false, 'TITLE_EXPLAIN' => ($vars['explain']) ? $lang[$vars['lang'] . '_EXPLAIN'] : '', 'CONTENT' => $this->p_master->input_field($config_key, $vars['type'], $$config_key, $options), ) ); } $template->assign_vars(array( 'TITLE' => $lang['STAGE_SETTINGS'], 'BODY' => $lang['CONV_OPTIONS_BODY'], 'L_SUBMIT' => $lang['BEGIN_CONVERT'], 'U_ACTION' => $this->p_master->module_url . "?mode={$this->mode}&sub=settings&tag=$convertor_tag&language=$language", )); }
/** * Obtain the information required to connect to the database */ function obtain_database_settings($mode, $sub) { global $lang, $template, $phpEx; $this->page_title = $lang['STAGE_DATABASE']; // Obtain any submitted data $data = $this->get_submitted_data(); $connect_test = false; $error = array(); $available_dbms = get_available_dbms(false, true); // Has the user opted to test the connection? if (isset($_POST['testdb'])) { if (!isset($available_dbms[$data['dbms']]) || !$available_dbms[$data['dbms']]['AVAILABLE']) { $error[] = $lang['INST_ERR_NO_DB']; $connect_test = false; } else { $connect_test = connect_check_db(true, $error, $available_dbms[$data['dbms']], $data['table_prefix'], $data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport']); } $template->assign_block_vars('checks', array( 'S_LEGEND' => true, 'LEGEND' => $lang['DB_CONNECTION'], 'LEGEND_EXPLAIN' => false, )); if ($connect_test) { $template->assign_block_vars('checks', array( 'TITLE' => $lang['DB_TEST'], 'RESULT' => '<strong style="color:green">' . $lang['SUCCESSFUL_CONNECT'] . '</strong>', 'S_EXPLAIN' => false, 'S_LEGEND' => false, )); } else { $template->assign_block_vars('checks', array( 'TITLE' => $lang['DB_TEST'], 'RESULT' => '<strong style="color:red">' . implode('<br />', $error) . '</strong>', 'S_EXPLAIN' => false, 'S_LEGEND' => false, )); } } if (!$connect_test) { // Update the list of available DBMS modules to only contain those which can be used $available_dbms_temp = array(); foreach ($available_dbms as $type => $dbms_ary) { if (!$dbms_ary['AVAILABLE']) { continue; } $available_dbms_temp[$type] = $dbms_ary; } $available_dbms = &$available_dbms_temp; // And now for the main part of this page $data['table_prefix'] = (!empty($data['table_prefix']) ? $data['table_prefix'] : 'phpbb_'); foreach ($this->db_config_options as $config_key => $vars) { if (!is_array($vars) && strpos($config_key, 'legend') === false) { continue; } if (strpos($config_key, 'legend') !== false) { $template->assign_block_vars('options', array( 'S_LEGEND' => true, 'LEGEND' => $lang[$vars]) ); continue; } $options = isset($vars['options']) ? $vars['options'] : ''; $template->assign_block_vars('options', array( 'KEY' => $config_key, 'TITLE' => $lang[$vars['lang']], 'S_EXPLAIN' => $vars['explain'], 'S_LEGEND' => false, 'TITLE_EXPLAIN' => ($vars['explain']) ? $lang[$vars['lang'] . '_EXPLAIN'] : '', 'CONTENT' => $this->p_master->input_field($config_key, $vars['type'], $data[$config_key], $options), ) ); } } // And finally where do we want to go next (well today is taken isn't it :P) $s_hidden_fields = ($data['img_imagick']) ? '<input type="hidden" name="img_imagick" value="' . addslashes($data['img_imagick']) . '" />' : ''; $s_hidden_fields .= '<input type="hidden" name="language" value="' . $data['language'] . '" />'; if ($connect_test) { foreach ($this->db_config_options as $config_key => $vars) { if (!is_array($vars)) { continue; } $s_hidden_fields .= '<input type="hidden" name="' . $config_key . '" value="' . $data[$config_key] . '" />'; } } $url = ($connect_test) ? $this->p_master->module_url . "?mode=$mode&sub=administrator" : $this->p_master->module_url . "?mode=$mode&sub=database"; $s_hidden_fields .= ($connect_test) ? '' : '<input type="hidden" name="testdb" value="true" />'; $submit = $lang['NEXT_STEP']; $template->assign_vars(array( 'L_SUBMIT' => $submit, 'S_HIDDEN' => $s_hidden_fields, 'U_ACTION' => $url, )); }
/** * Confirm Upgrade Options */ function confirm_upgrade_options($name, &$error) { global $cache, $sql_db, $user, $old_db; if (!isset($this->available_upgrades[$name])) { trigger_error('NO_MODE'); } $options = $this->get_options($name); $default_options = array(); foreach ($options as $config_key => $vars) { $default_options[$config_key] = isset($vars['default']) ? $vars['default'] : ''; } $this->selected_options = array_merge($default_options, $this->selected_options); $this->selected_options['limit'] = intval($this->selected_options['limit']); if ($this->selected_options['limit'] < 1) { $error[] = $user->lang['LIMIT_INCORRECT']; } connect_check_db(true, $error, array('DRIVER' => substr($sql_db, 5)), $this->selected_options['db_prefix'], $this->selected_options['db_host'], $this->selected_options['db_user'], $this->selected_options['db_password'], $this->selected_options['db_name'], $this->selected_options['db_port'], false, false); if (sizeof($error) == 1 && $error[0] == '') { $error = array(); } if (!sizeof($error)) { $this->old_db_connect(); $old_db->sql_return_on_error(true); foreach ($this->available_upgrades[$name]['requred_tables'] as $table) { $sql = 'SELECT * FROM ' . $this->selected_options['db_prefix'] . $table . ' LIMIT 1'; if (!$old_db->sql_query($sql)) { $error[] = sprintf($user->lang['DB_TABLE_NOT_EXIST'], $this->selected_options['db_prefix'] . $table); } } } if (!sizeof($error)) { // put the options in the cache for the upgrade $cache->put('_blog_upgrade', $this->selected_options); return true; } return false; }