phpBB

Code Changes

File: includes/acp/acp_database.php

  Unmodified   Added   Modified   Removed
Line 23Line 23
{
var $db_tools;
var $u_action;

{
var $db_tools;
var $u_action;

 
	public $page_title;


function main($id, $mode)
{


function main($id, $mode)
{

Line 69Line 70
							trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
}


							trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
}


						$store = $download = $structure = $schema_data = false;

						$store = $structure = $schema_data = false;





						if ($where == 'store_and_download' || $where == 'store')

						if ($where == 'store')

						{
$store = true;

						{
$store = true;

						}

if ($where == 'store_and_download' || $where == 'download')
{
$download = true;

 
						}

if ($type == 'full' || $type == 'structure')

						}

if ($type == 'full' || $type == 'structure')

Line 98Line 94

$filename = 'backup_' . $time . '_' . unique_id();



$filename = 'backup_' . $time . '_' . unique_id();


 
						/** @var phpbb\db\extractor\extractor_interface $extractor Database extractor */

						$extractor = $phpbb_container->get('dbal.extractor');

						$extractor = $phpbb_container->get('dbal.extractor');

						$extractor->init_extractor($format, $filename, $time, $download, $store);

						$extractor->init_extractor($format, $filename, $time, false, $store);


$extractor->write_start($table_prefix);



$extractor->write_start($table_prefix);


Line 144Line 141
						$extractor->write_end();

$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_DB_BACKUP');

						$extractor->write_end();

$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_DB_BACKUP');


if ($download == true)
{
exit;
}

 

trigger_error($user->lang['BACKUP_SUCCESS'] . adm_back_link($this->u_action));
break;


trigger_error($user->lang['BACKUP_SUCCESS'] . adm_back_link($this->u_action));
break;

Line 201Line 193
					case 'submit':
$delete = $request->variable('delete', '');
$file = $request->variable('file', '');

					case 'submit':
$delete = $request->variable('delete', '');
$file = $request->variable('file', '');

						$download = $request->variable('download', '');

 




						if (!preg_match('#^backup_\d{10,}_(?:[a-z\d]{16}|[a-z\d]{32})\.(sql(?:\.(?:gz|bz2))?)$#i', $file, $matches))
{
trigger_error($user->lang['BACKUP_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
}

						$backup_info = $this->get_backup_file($phpbb_root_path . 'store/', $file);








						$file_name = $phpbb_root_path . 'store/' . $matches[0];

if (!file_exists($file_name) || !is_readable($file_name))

						if (empty($backup_info) || !is_readable($backup_info['file_name']))



						{
trigger_error($user->lang['BACKUP_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
}

						{
trigger_error($user->lang['BACKUP_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
}

Line 219Line 205
						{
if (confirm_box(true))
{

						{
if (confirm_box(true))
{

								unlink($file_name);

								unlink($backup_info['file_name']);

								$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_DB_DELETE');
trigger_error($user->lang['BACKUP_DELETE'] . adm_back_link($this->u_action));
}

								$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_DB_DELETE');
trigger_error($user->lang['BACKUP_DELETE'] . adm_back_link($this->u_action));
}

Line 228Line 214
								confirm_box(false, $user->lang['DELETE_SELECTED_BACKUP'], build_hidden_fields(array('delete' => $delete, 'file' => $file)));
}
}

								confirm_box(false, $user->lang['DELETE_SELECTED_BACKUP'], build_hidden_fields(array('delete' => $delete, 'file' => $file)));
}
}

						else if ($download || confirm_box(true))

						else if (confirm_box(true))

						{

						{

							if ($download)
{
$name = $matches[0];

switch ($matches[1])
{
case 'sql':
$mimetype = 'text/x-sql';
break;
case 'sql.bz2':
$mimetype = 'application/x-bzip2';
break;
case 'sql.gz':
$mimetype = 'application/x-gzip';
break;
}

header('Cache-Control: private, no-cache');
header("Content-Type: $mimetype; name=\"$name\"");
header("Content-disposition: attachment; filename=$name");

@set_time_limit(0);

$fp = @fopen($file_name, 'rb');

if ($fp !== false)
{
while (!feof($fp))
{
echo fread($fp, 8192);
}
fclose($fp);
}

flush();
exit;
}

switch ($matches[1])

							switch ($backup_info['extension'])







































							{
case 'sql':

							{
case 'sql':

									$fp = fopen($file_name, 'rb');

									$fp = fopen($backup_info['file_name'], 'rb');

									$read = 'fread';
$seek = 'fseek';
$eof = 'feof';

									$read = 'fread';
$seek = 'fseek';
$eof = 'feof';

Line 280Line 228
								break;

case 'sql.bz2':

								break;

case 'sql.bz2':

									$fp = bzopen($file_name, 'r');

									$fp = bzopen($backup_info['file_name'], 'r');

									$read = 'bzread';
$seek = '';
$eof = 'feof';

									$read = 'bzread';
$seek = '';
$eof = 'feof';

Line 289Line 237
								break;

case 'sql.gz':

								break;

case 'sql.gz':

									$fp = gzopen($file_name, 'rb');

									$fp = gzopen($backup_info['file_name'], 'rb');

									$read = 'gzread';
$seek = 'gzseek';
$eof = 'gzeof';
$close = 'gzclose';
$fgetd = 'fgetd';
break;

									$read = 'gzread';
$seek = 'gzseek';
$eof = 'gzeof';
$close = 'gzclose';
$fgetd = 'fgetd';
break;

 

default:
trigger_error($user->lang['BACKUP_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
return;

							}

switch ($db->get_sql_layer())

							}

switch ($db->get_sql_layer())

Line 375Line 327
							trigger_error($user->lang['RESTORE_SUCCESS'] . adm_back_link($this->u_action));
break;
}

							trigger_error($user->lang['RESTORE_SUCCESS'] . adm_back_link($this->u_action));
break;
}

						else if (!$download)

						else

						{
confirm_box(false, $user->lang['RESTORE_SELECTED_BACKUP'], build_hidden_fields(array('file' => $file)));
}

default:

						{
confirm_box(false, $user->lang['RESTORE_SELECTED_BACKUP'], build_hidden_fields(array('file' => $file)));
}

default:

						$methods = array('sql');
$available_methods = array('sql.gz' => 'zlib', 'sql.bz2' => 'bz2');

						$backup_files = $this->get_file_list($phpbb_root_path . 'store/');






						foreach ($available_methods as $type => $module)

						if (!empty($backup_files))

						{

						{

							if (!@extension_loaded($module))



							krsort($backup_files);

foreach ($backup_files as $name => $file)

							{

							{

								continue;





								$template->assign_block_vars('files', array(
'FILE' => sha1($file),
'NAME' => $user->format_date($name, 'd-m-Y H:i', true),
'SUPPORTED' => true,
));

							}

							}

							$methods[] = $type;

 
						}


						}


						$dir = $phpbb_root_path . 'store/';
$dh = @opendir($dir);



















						$template->assign_vars(array(
'U_ACTION' => $this->u_action . '&action=submit'
));
break;
}
break;
}
}

/**
* Get backup file from file hash
*
* @param string $directory Relative path to directory
* @param string $file_hash Hash of selected file
*
* @return array Backup file data or empty array if unable to find file
*/
protected function get_backup_file($directory, $file_hash)
{
$backup_data = [];





						$backup_files = array();

































		$file_list = $this->get_file_list($directory);
$supported_extensions = $this->get_supported_extensions();

foreach ($file_list as $file)
{
preg_match('#^backup_(\d{10,})_(?:[a-z\d]{16}|[a-z\d]{32})\.(sql(?:\.(?:gz|bz2))?)$#i', $file, $matches);
if (sha1($file) === $file_hash && in_array($matches[2], $supported_extensions))
{
$backup_data = [
'file_name' => $directory . $file,
'extension' => $matches[2],
];
break;
}
}

return $backup_data;
}

/**
* Get backup file list for directory
*
* @param string $directory Relative path to backup directory
*
* @return array List of backup files in specified directory
*/
protected function get_file_list($directory)
{
$supported_extensions = $this->get_supported_extensions();

$dh = @opendir($directory);

$backup_files = [];


if ($dh)
{


if ($dh)
{

Line 404Line 410
							{
if (preg_match('#^backup_(\d{10,})_(?:[a-z\d]{16}|[a-z\d]{32})\.(sql(?:\.(?:gz|bz2))?)$#i', $file, $matches))
{

							{
if (preg_match('#^backup_(\d{10,})_(?:[a-z\d]{16}|[a-z\d]{32})\.(sql(?:\.(?:gz|bz2))?)$#i', $file, $matches))
{

									if (in_array($matches[2], $methods))

					if (in_array($matches[2], $supported_extensions))

									{
$backup_files[(int) $matches[1]] = $file;
}

									{
$backup_files[(int) $matches[1]] = $file;
}

Line 413Line 419
							closedir($dh);
}


							closedir($dh);
}


						if (!empty($backup_files))









		return $backup_files;
}

/**
* Get supported extensions for backup
*
* @return array List of supported extensions
*/
protected function get_supported_extensions()

						{

						{

							krsort($backup_files);


		$extensions = ['sql'];
$available_methods = ['sql.gz' => 'zlib', 'sql.bz2' => 'bz2'];





							foreach ($backup_files as $name => $file)

		foreach ($available_methods as $type => $module)

							{

							{

								$template->assign_block_vars('files', array(
'FILE' => $file,
'NAME' => $user->format_date($name, 'd-m-Y H:i:s', true),
'SUPPORTED' => true,
));

			if (!@extension_loaded($module))
{
continue;



							}

							}

 
			$extensions[] = $type;

						}


						}


						$template->assign_vars(array(
'U_ACTION' => $this->u_action . '&action=submit'
));
break;
}
break;
}

		return $extensions;







	}
}


	}
}