1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-14 04:42:04 +02:00

Merge pull request #5501 from marc1706/ticket/15928

[ticket/15928] Remove support for downloading backups
This commit is contained in:
Marc Alexander 2019-04-07 10:45:08 +02:00
commit 21791971aa
No known key found for this signature in database
GPG Key ID: 50E0D2423696F995
3 changed files with 114 additions and 107 deletions

View File

@ -20,7 +20,6 @@
<p class="submit-buttons">
<input class="button1" type="submit" id="submit" name="submit" value="{L_START_RESTORE}" />&nbsp;
<input class="button2" type="submit" id="delete" name="delete" value="{L_DELETE_BACKUP}" />&nbsp;
<input class="button2" type="submit" id="download" name="download" value="{L_DOWNLOAD_BACKUP}" />
</p>
{S_FORM_TOKEN}
</fieldset>
@ -72,7 +71,6 @@
<dt><label for="where">{L_ACTION}{L_COLON}</label></dt>
<dd>
<label><input id="where" type="radio" class="radio" name="where" value="store" checked="checked" /> {L_STORE_LOCAL}</label>
<label><input type="radio" class="radio" name="where" value="download" /> {L_DOWNLOAD}</label>
</dd>
</dl>
<dl>

View File

@ -23,6 +23,7 @@ class acp_database
{
var $db_tools;
var $u_action;
public $page_title;
function main($id, $mode)
{
@ -69,18 +70,13 @@ class acp_database
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;
}
if ($where == 'store_and_download' || $where == 'download')
{
$download = true;
}
if ($type == 'full' || $type == 'structure')
{
$structure = true;
@ -98,8 +94,9 @@ class acp_database
$filename = 'backup_' . $time . '_' . unique_id();
/** @var phpbb\db\extractor\extractor_interface $extractor Database 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);
@ -145,11 +142,6 @@ class acp_database
$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;
@ -201,16 +193,10 @@ class acp_database
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);
}
@ -219,7 +205,7 @@ class acp_database
{
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));
}
@ -228,50 +214,12 @@ class acp_database
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['extensions'])
{
case 'sql':
$fp = fopen($file_name, 'rb');
$fp = fopen($backup_info['file_name'], 'rb');
$read = 'fread';
$seek = 'fseek';
$eof = 'feof';
@ -280,7 +228,7 @@ class acp_database
break;
case 'sql.bz2':
$fp = bzopen($file_name, 'r');
$fp = bzopen($backup_info['file_name'], 'r');
$read = 'bzread';
$seek = '';
$eof = 'feof';
@ -289,13 +237,17 @@ class acp_database
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;
default:
trigger_error($user->lang['BACKUP_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
return;
}
switch ($db->get_sql_layer())
@ -375,43 +327,13 @@ class acp_database
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:
$methods = array('sql');
$available_methods = array('sql.gz' => 'zlib', 'sql.bz2' => 'bz2');
foreach ($available_methods as $type => $module)
{
if (!@extension_loaded($module))
{
continue;
}
$methods[] = $type;
}
$dir = $phpbb_root_path . 'store/';
$dh = @opendir($dir);
$backup_files = array();
if ($dh)
{
while (($file = readdir($dh)) !== false)
{
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))
{
$backup_files[(int) $matches[1]] = $file;
}
}
}
closedir($dh);
}
$backup_files = $this->get_file_list($phpbb_root_path . 'store/');
if (!empty($backup_files))
{
@ -420,8 +342,8 @@ class acp_database
foreach ($backup_files as $name => $file)
{
$template->assign_block_vars('files', array(
'FILE' => $file,
'NAME' => $user->format_date($name, 'd-m-Y H:i:s', true),
'FILE' => sha1($file),
'NAME' => $user->format_date($name, 'd-m-Y H:i', true),
'SUPPORTED' => true,
));
}
@ -435,6 +357,92 @@ class acp_database
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 = [];
$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)
{
while (($file = readdir($dh)) !== false)
{
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], $supported_extensions))
{
$backup_files[(int) $matches[1]] = $file;
}
}
}
closedir($dh);
}
return $backup_files;
}
/**
* Get supported extensions for backup
*
* @return array List of supported extensions
*/
protected function get_supported_extensions()
{
$extensions = ['sql'];
$available_methods = ['sql.gz' => 'zlib', 'sql.bz2' => 'bz2'];
foreach ($available_methods as $type => $module)
{
if (!@extension_loaded($module))
{
continue;
}
$extensions[] = $type;
}
return $extensions;
}
}
// get how much space we allow for a chunk of data, very similar to phpMyAdmin's way of doing things ;-) (hey, we only do this for MySQL anyway :P)

View File

@ -38,14 +38,15 @@ if (empty($lang) || !is_array($lang))
// Database Backup/Restore
$lang = array_merge($lang, array(
'ACP_BACKUP_EXPLAIN' => 'Here you can backup all your phpBB related data. You may store the resulting archive in your <samp>store/</samp> folder or download it directly. Depending on your server configuration you may be able to compress the file in a number of formats.',
'ACP_BACKUP_EXPLAIN' => 'Here you can backup all your phpBB related data. The resulting archive will be stored in your <samp>store/</samp> folder. Depending on your server configuration you may be able to compress the file in a number of formats.',
'ACP_RESTORE_EXPLAIN' => 'This will perform a full restore of all phpBB tables from a saved file. If your server supports it you may use a gzip or bzip2 compressed text file and it will automatically be decompressed. <strong>WARNING</strong> This will overwrite any existing data. The restore may take a long time to process please do not move from this page till it is complete. Backups are stored in the <samp>store/</samp> folder and are assumed to be generated by phpBBs backup functionality. Restoring backups that were not created by the built in system may or may not work.',
'BACKUP_DELETE' => 'The backup file has been deleted successfully.',
'BACKUP_INVALID' => 'The selected file to backup is invalid.',
'BACKUP_OPTIONS' => 'Backup options',
'BACKUP_SUCCESS' => 'The backup file has been created successfully.',
'BACKUP_TYPE' => 'Backup type',
'BACKUP_DELETE' => 'The backup file has been deleted successfully.',
'BACKUP_INVALID' => 'The selected file to backup is invalid.',
'BACKUP_NOT_SUPPORTED' => 'The selected backup is not supported',
'BACKUP_OPTIONS' => 'Backup options',
'BACKUP_SUCCESS' => 'The backup file has been created successfully.',
'BACKUP_TYPE' => 'Backup type',
'DATABASE' => 'Database utilities',
'DATA_ONLY' => 'Data only',