コード例 #1
0
ファイル: install_convert.php プロジェクト: steveh/phpbb
	/**
	*/
	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}&amp;sub=in_progress&amp;tag=$convertor_tag&amp;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}&amp;sub=settings&amp;tag=$convertor_tag&amp;language=$language",
		));
	}
コード例 #2
0
ファイル: convertor.php プロジェクト: 007durgesh219/phpbb
 /**
  * Validates settings form
  *
  * @param string	$convertor
  */
 public function proccess_settings_form($convertor)
 {
     global $phpbb_root_path, $phpEx, $get_info;
     $phpbb_root_path = $this->phpbb_root_path;
     $phpEx = $this->php_ext;
     $get_info = true;
     require_once $this->phpbb_root_path . 'includes/constants.' . $this->php_ext;
     require_once $this->phpbb_root_path . 'includes/functions_convert.' . $this->php_ext;
     // Include convertor if available
     $convertor_file_path = $this->phpbb_root_path . 'install/convertors/convert_' . $convertor . '.' . $this->php_ext;
     include $convertor_file_path;
     // We expect to have an AJAX request here
     $src_dbms = $this->request->variable('src_dbms', $convertor_data['dbms']);
     $src_dbhost = $this->request->variable('src_dbhost', $convertor_data['dbhost']);
     $src_dbport = $this->request->variable('src_dbport', $convertor_data['dbport']);
     $src_dbuser = $this->request->variable('src_dbuser', $convertor_data['dbuser']);
     $src_dbpasswd = $this->request->variable('src_dbpasswd', $convertor_data['dbpasswd']);
     $src_dbname = $this->request->variable('src_dbname', $convertor_data['dbname']);
     $src_table_prefix = $this->request->variable('src_table_prefix', $convertor_data['table_prefix']);
     $forum_path = $this->request->variable('forum_path', $convertor_data['forum_path']);
     $refresh = $this->request->variable('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->variable('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 (!file_exists($this->phpbb_root_path . $forum_path . '/' . $test_file)) {
         $error[] = $this->language->lang('COULD_NOT_FIND_PATH', $forum_path);
     }
     $connect_test = false;
     $available_dbms = $this->db_helper->get_available_dbms(false, true, true);
     if (!isset($available_dbms[$src_dbms]) || !$available_dbms[$src_dbms]['AVAILABLE']) {
         $error[] = $this->language->lang('INST_ERR_NO_DB');
     } else {
         $connect_test = $this->db_helper->check_database_connection($src_dbms, $src_dbhost, $src_dbport, $src_dbuser, $src_dbpasswd, $src_dbname, $src_table_prefix);
     }
     extract($this->config_php_file->get_all());
     // 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[] = $this->language->lang('TABLE_PREFIX_SAME', $src_table_prefix);
     }
     if (!$connect_test) {
         $error[] = $this->language->lang('INST_ERR_DB_CONNECT');
     }
     $src_dbms = $this->config_php_file->convert_30_dbms_to_31($src_dbms);
     // Check table prefix
     if (empty($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) {
             /** @var \phpbb\db\driver\driver_interface $src_db */
             $src_db = new $src_dbms();
             $src_db->sql_connect($src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, false, true);
             $same_db = false;
         } else {
             $src_db = $this->db;
             $same_db = true;
         }
         $src_db->sql_return_on_error(true);
         $this->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();
             $db_tools_factory = new \phpbb\db\tools\factory();
             $db_tools = $db_tools_factory->get($src_db);
             $tables_existing = $db_tools->sql_list_tables();
             $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 .= $this->language->lang_array('DEFAULT_PREFIX_IS', array($convertor_data['forum_name'], $convertor_data['table_prefix']));
             }
             if (!empty($possible_prefix)) {
                 $msg .= '<br />';
                 $msg .= $possible_prefix == '*' ? $this->language->lang('BLANK_PREFIX_FOUND') : $this->language->lang_array('PREFIX_FOUND', array($possible_prefix));
                 $src_table_prefix = $possible_prefix == '*' ? '' : $possible_prefix;
             }
             $error[] = $msg;
         }
         $src_db->sql_freeresult($result);
         $src_db->sql_return_on_error(false);
     }
     if (empty($error)) {
         // Save convertor Status
         $this->config->set('convert_progress', serialize(array('step' => '', 'table_prefix' => $src_table_prefix, 'tag' => $convertor)), false);
         $this->config->set('convert_db_server', serialize(array('dbms' => $src_dbms, 'dbhost' => $src_dbhost, 'dbport' => $src_dbport, 'dbname' => $src_dbname)), false);
         $this->config->set('convert_db_user', serialize(array('dbuser' => $src_dbuser, 'dbpasswd' => $src_dbpasswd)), false);
         // Save options
         $this->config->set('convert_options', serialize(array('forum_path' => $this->phpbb_root_path . $forum_path, 'refresh' => $refresh)), false);
         $url = $this->controller_helper->route('phpbb_convert_convert', array('converter' => $convertor));
         $this->iohandler->redirect($url);
         $this->iohandler->send_response(true);
     } else {
         $this->render_settings_form($error);
     }
 }