Пример #1
0
 /**
  * Writes the config file to disk, or if unable to do so offers alternative methods
  */
 function create_config_file($mode, $sub)
 {
     global $lang, $template, $phpbb_root_path, $phpEx;
     $this->page_title = $lang['STAGE_CONFIG_FILE'];
     // Obtain any submitted data
     $data = $this->get_submitted_data();
     if ($data['dbms'] == '') {
         // Someone's been silly and tried calling this page direct
         // So we send them back to the start to do it again properly
         $this->p_master->redirect("index.{$phpEx}?mode=install");
     }
     $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'] . '" />';
     $written = false;
     // Create a list of any PHP modules we wish to have loaded
     $load_extensions = array();
     $available_dbms = get_available_dbms($data['dbms']);
     $check_exts = array_merge(array($available_dbms[$data['dbms']]['MODULE']), $this->php_dlls_other);
     foreach ($check_exts as $dll) {
         if (!@extension_loaded($dll)) {
             if (!can_load_dll($dll)) {
                 continue;
             }
             $load_extensions[] = $dll . '.' . PHP_SHLIB_SUFFIX;
         }
     }
     // Create a lock file to indicate that there is an install in progress
     $fp = @fopen($phpbb_root_path . 'cache/install_lock', 'wb');
     if ($fp === false) {
         // We were unable to create the lock file - abort
         $this->p_master->error($lang['UNABLE_WRITE_LOCK'], __LINE__, __FILE__);
     }
     @fclose($fp);
     @chmod($phpbb_root_path . 'cache/install_lock', 0777);
     // Time to convert the data provided into a config file
     $config_data = phpbb_create_config_file_data($data, $available_dbms[$data['dbms']]['DRIVER'], $load_extensions);
     // Attempt to write out the config file directly. If it works, this is the easiest way to do it ...
     if (file_exists($phpbb_root_path . 'config.' . $phpEx) && phpbb_is_writable($phpbb_root_path . 'config.' . $phpEx) || phpbb_is_writable($phpbb_root_path)) {
         // Assume it will work ... if nothing goes wrong below
         $written = true;
         if (!($fp = @fopen($phpbb_root_path . 'config.' . $phpEx, 'w'))) {
             // Something went wrong ... so let's try another method
             $written = false;
         }
         if (!@fwrite($fp, $config_data)) {
             // Something went wrong ... so let's try another method
             $written = false;
         }
         @fclose($fp);
         if ($written) {
             // We may revert back to chmod() if we see problems with users not able to change their config.php file directly
             phpbb_chmod($phpbb_root_path . 'config.' . $phpEx, CHMOD_READ);
         }
     }
     if (isset($_POST['dldone'])) {
         // Do a basic check to make sure that the file has been uploaded
         // Note that all we check is that the file has _something_ in it
         // We don't compare the contents exactly - if they can't upload
         // a single file correctly, it's likely they will have other problems....
         if (filesize($phpbb_root_path . 'config.' . $phpEx) > 10) {
             $written = true;
         }
     }
     $config_options = array_merge($this->db_config_options, $this->admin_config_options);
     foreach ($config_options as $config_key => $vars) {
         if (!is_array($vars)) {
             continue;
         }
         $s_hidden_fields .= '<input type="hidden" name="' . $config_key . '" value="' . $data[$config_key] . '" />';
     }
     if (!$written) {
         // OK, so it didn't work let's try the alternatives
         if (isset($_POST['dlconfig'])) {
             // They want a copy of the file to download, so send the relevant headers and dump out the data
             header("Content-Type: text/x-delimtext; name=\"config.{$phpEx}\"");
             header("Content-disposition: attachment; filename=config.{$phpEx}");
             echo $config_data;
             exit;
         }
         // The option to download the config file is always available, so output it here
         $template->assign_vars(array('BODY' => $lang['CONFIG_FILE_UNABLE_WRITE'], 'L_DL_CONFIG' => $lang['DL_CONFIG'], 'L_DL_CONFIG_EXPLAIN' => $lang['DL_CONFIG_EXPLAIN'], 'L_DL_DONE' => $lang['DONE'], 'L_DL_DOWNLOAD' => $lang['DL_DOWNLOAD'], 'S_HIDDEN' => $s_hidden_fields, 'S_SHOW_DOWNLOAD' => true, 'U_ACTION' => $this->p_master->module_url . "?mode={$mode}&amp;sub=config_file"));
         return;
     } else {
         $template->assign_vars(array('BODY' => $lang['CONFIG_FILE_WRITTEN'], 'L_SUBMIT' => $lang['NEXT_STEP'], 'S_HIDDEN' => $s_hidden_fields, 'U_ACTION' => $this->p_master->module_url . "?mode={$mode}&amp;sub=advanced"));
         return;
     }
 }
Пример #2
0
 public static function install_board()
 {
     global $phpbb_root_path, $phpEx;
     self::recreate_database(self::$config);
     $config_file = $phpbb_root_path . "config.{$phpEx}";
     $config_file_dev = $phpbb_root_path . "config_dev.{$phpEx}";
     $config_file_test = $phpbb_root_path . "config_test.{$phpEx}";
     if (file_exists($config_file)) {
         if (!file_exists($config_file_dev)) {
             rename($config_file, $config_file_dev);
         } else {
             unlink($config_file);
         }
     }
     $parseURL = parse_url(self::$config['phpbb_functional_url']);
     self::visit('install/index.php?mode=install&language=en');
     self::assertContains('Welcome to Installation', self::find_element('id', 'main')->getText());
     // install/index.php?mode=install&sub=requirements
     self::submit();
     self::assertContains('Installation compatibility', self::find_element('id', 'main')->getText());
     // install/index.php?mode=install&sub=database
     self::submit();
     self::assertContains('Database configuration', self::find_element('id', 'main')->getText());
     self::find_element('id', 'dbms')->sendKeys(str_replace('phpbb\\db\\driver\\', '', self::$config['dbms']));
     self::find_element('id', 'dbhost')->sendKeys(self::$config['dbhost']);
     self::find_element('id', 'dbport')->sendKeys(self::$config['dbport']);
     self::find_element('id', 'dbname')->sendKeys(self::$config['dbname']);
     self::find_element('id', 'dbuser')->sendKeys(self::$config['dbuser']);
     self::find_element('id', 'dbpasswd')->sendKeys(self::$config['dbpasswd']);
     // Need to clear default phpbb_ prefix
     self::find_element('id', 'table_prefix')->clear();
     self::find_element('id', 'table_prefix')->sendKeys(self::$config['table_prefix']);
     // install/index.php?mode=install&sub=database
     self::submit();
     self::assertContains('Successful connection', self::find_element('id', 'main')->getText());
     // install/index.php?mode=install&sub=administrator
     self::submit();
     self::assertContains('Administrator configuration', self::find_element('id', 'main')->getText());
     self::find_element('id', 'admin_name')->sendKeys('admin');
     self::find_element('id', 'admin_pass1')->sendKeys('adminadmin');
     self::find_element('id', 'admin_pass2')->sendKeys('adminadmin');
     self::find_element('id', 'board_email')->sendKeys('*****@*****.**');
     // install/index.php?mode=install&sub=administrator
     self::submit();
     self::assertContains('Tests passed', self::find_element('id', 'main')->getText());
     // install/index.php?mode=install&sub=config_file
     self::submit();
     // Installer has created a config.php file, we will overwrite it with a
     // config file of our own in order to get the DEBUG constants defined
     $config_php_data = phpbb_create_config_file_data(self::$config, self::$config['dbms'], true, false, true);
     $config_created = file_put_contents($config_file, $config_php_data) !== false;
     if (!$config_created) {
         self::markTestSkipped("Could not write {$config_file} file.");
     }
     if (strpos(self::find_element('id', 'main')->getText(), 'The configuration file has been written') === false) {
         self::submit('id', 'dldone');
     }
     self::assertContains('The configuration file has been written', self::find_element('id', 'main')->getText());
     // install/index.php?mode=install&sub=advanced
     self::submit();
     self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', self::find_element('id', 'main')->getText());
     self::find_element('id', 'smtp_delivery')->sendKeys('1');
     self::find_element('id', 'smtp_host')->sendKeys('nxdomain.phpbb.com');
     self::find_element('id', 'smtp_user')->sendKeys('nxuser');
     self::find_element('id', 'smtp_pass')->sendKeys('nxpass');
     self::find_element('id', 'server_protocol')->sendKeys($parseURL['scheme'] . '://');
     self::find_element('id', 'server_name')->sendKeys('localhost');
     self::find_element('id', 'server_port')->sendKeys(isset($parseURL['port']) ? $parseURL['port'] : 80);
     self::find_element('id', 'script_path')->sendKeys($parseURL['path']);
     // install/index.php?mode=install&sub=create_table
     self::submit();
     self::assertContains('The database tables used by phpBB', self::find_element('id', 'main')->getText());
     self::assertContains('have been created and populated with some initial data.', self::find_element('id', 'main')->getText());
     // install/index.php?mode=install&sub=final
     self::submit();
     self::assertContains('You have successfully installed', self::find_element('id', 'main')->getText());
     copy($config_file, $config_file_test);
 }
Пример #3
0
 protected static function install_board()
 {
     global $phpbb_root_path, $phpEx;
     self::recreate_database(self::$config);
     $config_file = $phpbb_root_path . "config.{$phpEx}";
     $config_file_dev = $phpbb_root_path . "config_dev.{$phpEx}";
     $config_file_test = $phpbb_root_path . "config_test.{$phpEx}";
     if (file_exists($config_file)) {
         if (!file_exists($config_file_dev)) {
             rename($config_file, $config_file_dev);
         } else {
             unlink($config_file);
         }
     }
     self::$cookieJar = new CookieJar();
     self::$client = new Goutte\Client(array(), null, self::$cookieJar);
     // Set client manually so we can increase the cURL timeout
     self::$client->setClient(new Guzzle\Http\Client('', array(Guzzle\Http\Client::DISABLE_REDIRECTS => true, 'curl.options' => array(CURLOPT_TIMEOUT => 120))));
     // Reset the curl handle because it is 0 at this point and not a valid
     // resource
     self::$client->getClient()->getCurlMulti()->reset(true);
     $parseURL = parse_url(self::$config['phpbb_functional_url']);
     $crawler = self::request('GET', 'install/index.php?mode=install&language=en');
     self::assertContains('Welcome to Installation', $crawler->filter('#main')->text());
     $form = $crawler->selectButton('submit')->form();
     // install/index.php?mode=install&sub=requirements
     $crawler = self::submit($form);
     self::assertContains('Installation compatibility', $crawler->filter('#main')->text());
     $form = $crawler->selectButton('submit')->form();
     // install/index.php?mode=install&sub=database
     $crawler = self::submit($form);
     self::assertContains('Database configuration', $crawler->filter('#main')->text());
     $form = $crawler->selectButton('submit')->form(array('dbms' => str_replace('phpbb\\db\\driver\\', '', self::$config['dbms']), 'dbhost' => self::$config['dbhost'], 'dbport' => self::$config['dbport'], 'dbname' => self::$config['dbname'], 'dbuser' => self::$config['dbuser'], 'dbpasswd' => self::$config['dbpasswd'], 'table_prefix' => self::$config['table_prefix']));
     // install/index.php?mode=install&sub=database
     $crawler = self::submit($form);
     self::assertContains('Successful connection', $crawler->filter('#main')->text());
     $form = $crawler->selectButton('submit')->form();
     // install/index.php?mode=install&sub=administrator
     $crawler = self::submit($form);
     self::assertContains('Administrator configuration', $crawler->filter('#main')->text());
     $form = $crawler->selectButton('submit')->form(array('default_lang' => 'en', 'admin_name' => 'admin', 'admin_pass1' => 'adminadmin', 'admin_pass2' => 'adminadmin', 'board_email' => '*****@*****.**'));
     // install/index.php?mode=install&sub=administrator
     $crawler = self::submit($form);
     self::assertContains('Tests passed', $crawler->filter('#main')->text());
     $form = $crawler->selectButton('submit')->form();
     // We have to skip install/index.php?mode=install&sub=config_file
     // because that step will create a config.php file if phpBB has the
     // permission to do so. We have to create the config file on our own
     // in order to get the DEBUG constants defined.
     $config_php_data = phpbb_create_config_file_data(self::$config, self::$config['dbms'], true, false, true);
     $config_created = file_put_contents($config_file, $config_php_data) !== false;
     if (!$config_created) {
         self::markTestSkipped("Could not write {$config_file} file.");
     }
     // We also have to create a install lock that is normally created by
     // the installer. The file will be removed by the final step of the
     // installer.
     $install_lock_file = $phpbb_root_path . 'cache/install_lock';
     $lock_created = file_put_contents($install_lock_file, '') !== false;
     if (!$lock_created) {
         self::markTestSkipped("Could not create {$lock_created} file.");
     }
     @chmod($install_lock_file, 0666);
     // install/index.php?mode=install&sub=advanced
     $form_data = $form->getValues();
     unset($form_data['submit']);
     $crawler = self::request('POST', 'install/index.php?mode=install&sub=advanced', $form_data);
     self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', $crawler->filter('#main')->text());
     $form = $crawler->selectButton('submit')->form(array('email_enable' => true, 'smtp_delivery' => true, 'smtp_host' => 'nxdomain.phpbb.com', 'smtp_auth' => 'PLAIN', 'smtp_user' => 'nxuser', 'smtp_pass' => 'nxpass', 'cookie_secure' => false, 'force_server_vars' => false, 'server_protocol' => $parseURL['scheme'] . '://', 'server_name' => 'localhost', 'server_port' => isset($parseURL['port']) ? (int) $parseURL['port'] : 80, 'script_path' => $parseURL['path']));
     // install/index.php?mode=install&sub=create_table
     $crawler = self::submit($form);
     self::assertContains('The database tables used by phpBB', $crawler->filter('#main')->text());
     self::assertContains('have been created and populated with some initial data.', $crawler->filter('#main')->text());
     $form = $crawler->selectButton('submit')->form();
     // install/index.php?mode=install&sub=final
     $crawler = self::submit($form);
     self::assertContains('You have successfully installed', $crawler->text());
     copy($config_file, $config_file_test);
 }
Пример #4
0
	protected function install_board()
	{
		global $phpbb_root_path, $phpEx;

		self::$config = phpbb_test_case_helpers::get_test_config();

		if (!isset(self::$config['phpbb_functional_url']))
		{
			return;
		}

		self::$config['table_prefix'] = 'phpbb_';
		$this->recreate_database(self::$config);

		if (file_exists($phpbb_root_path . "config.$phpEx"))
		{
			if (!file_exists($phpbb_root_path . "config_dev.$phpEx"))
			{
				rename($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_dev.$phpEx");
			}
			else
			{
				unlink($phpbb_root_path . "config.$phpEx");
			}
		}

		// begin data
		$data = array();

		$data = array_merge($data, self::$config);

		$data = array_merge($data, array(
			'default_lang'	=> 'en',
			'admin_name'	=> 'admin',
			'admin_pass1'	=> 'admin',
			'admin_pass2'	=> 'admin',
			'board_email'	=> '*****@*****.**',
		));

		$parseURL = parse_url(self::$config['phpbb_functional_url']);

		$data = array_merge($data, array(
			'email_enable'		=> false,
			'smtp_delivery'		=> false,
			'smtp_host'		=> '',
			'smtp_auth'		=> '',
			'smtp_user'		=> '',
			'smtp_pass'		=> '',
			'cookie_secure'		=> false,
			'force_server_vars'	=> false,
			'server_protocol'	=> $parseURL['scheme'] . '://',
			'server_name'		=> 'localhost',
			'server_port'		=> isset($parseURL['port']) ? (int) $parseURL['port'] : 80,
			'script_path'		=> $parseURL['path'],
		));
		// end data

		$content = $this->do_request('install');
		$this->assertContains('Welcome to Installation', $content);

		$this->do_request('create_table', $data);

		file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true));

		$this->do_request('config_file', $data);

		copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx");

		$this->do_request('final', $data);
	}