2006-03-18 06:39:47 +00:00
|
|
|
<?php
|
2007-10-05 14:36:34 +00:00
|
|
|
/**
|
2006-03-18 06:39:47 +00:00
|
|
|
*
|
2014-05-27 20:18:06 +02:00
|
|
|
* This file is part of the phpBB Forum Software package.
|
|
|
|
*
|
|
|
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
|
|
|
*
|
|
|
|
* For full copyright and license information, please see
|
|
|
|
* the docs/CREDITS.txt file.
|
2006-03-18 06:39:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-10-05 14:36:34 +00:00
|
|
|
/**
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
if (!defined('IN_PHPBB'))
|
|
|
|
{
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2006-03-18 06:39:47 +00:00
|
|
|
class acp_database
|
|
|
|
{
|
2012-05-30 13:38:41 +02:00
|
|
|
var $db_tools;
|
2006-03-18 06:39:47 +00:00
|
|
|
var $u_action;
|
|
|
|
|
|
|
|
function main($id, $mode)
|
|
|
|
{
|
2015-01-24 12:06:45 +01:00
|
|
|
global $cache, $db, $user, $template, $table_prefix, $request;
|
|
|
|
global $phpbb_root_path, $phpbb_container, $phpbb_log;
|
2009-03-30 13:32:57 +00:00
|
|
|
|
2015-01-24 12:06:45 +01:00
|
|
|
$this->db_tools = $phpbb_container->get('dbal.tools');
|
2012-05-30 13:38:41 +02:00
|
|
|
|
2006-03-18 06:39:47 +00:00
|
|
|
$user->add_lang('acp/database');
|
|
|
|
|
|
|
|
$this->tpl_name = 'acp_database';
|
2006-06-20 00:21:16 +00:00
|
|
|
$this->page_title = 'ACP_DATABASE';
|
2006-03-18 06:39:47 +00:00
|
|
|
|
2015-01-04 20:41:04 +01:00
|
|
|
$action = $request->variable('action', '');
|
2006-03-18 06:39:47 +00:00
|
|
|
$submit = (isset($_POST['submit'])) ? true : false;
|
|
|
|
|
|
|
|
$template->assign_vars(array(
|
|
|
|
'MODE' => $mode
|
|
|
|
));
|
|
|
|
|
|
|
|
switch ($mode)
|
|
|
|
{
|
|
|
|
case 'backup':
|
2006-03-19 11:17:47 +00:00
|
|
|
|
2006-12-02 13:19:40 +00:00
|
|
|
$this->page_title = 'ACP_BACKUP';
|
|
|
|
|
2006-03-18 06:39:47 +00:00
|
|
|
switch ($action)
|
|
|
|
{
|
|
|
|
case 'download':
|
2015-01-04 20:41:04 +01:00
|
|
|
$type = $request->variable('type', '');
|
|
|
|
$table = array_intersect($this->db_tools->sql_list_tables(), $request->variable('table', array('')));
|
|
|
|
$format = $request->variable('method', '');
|
|
|
|
$where = $request->variable('where', '');
|
2006-03-18 06:39:47 +00:00
|
|
|
|
2007-02-16 20:37:12 +00:00
|
|
|
if (!sizeof($table))
|
|
|
|
{
|
2007-07-16 01:06:34 +00:00
|
|
|
trigger_error($user->lang['TABLE_SELECT_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING);
|
2007-02-16 20:37:12 +00:00
|
|
|
}
|
|
|
|
|
2006-05-02 17:59:51 +00:00
|
|
|
$store = $download = $structure = $schema_data = false;
|
2006-04-16 17:31:02 +00:00
|
|
|
|
2006-06-20 00:21:16 +00:00
|
|
|
if ($where == 'store_and_download' || $where == 'store')
|
2006-04-16 17:31:02 +00:00
|
|
|
{
|
|
|
|
$store = true;
|
|
|
|
}
|
|
|
|
|
2006-06-20 00:21:16 +00:00
|
|
|
if ($where == 'store_and_download' || $where == 'download')
|
2006-04-16 17:31:02 +00:00
|
|
|
{
|
|
|
|
$download = true;
|
|
|
|
}
|
|
|
|
|
2006-05-02 17:59:51 +00:00
|
|
|
if ($type == 'full' || $type == 'structure')
|
|
|
|
{
|
|
|
|
$structure = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($type == 'full' || $type == 'data')
|
|
|
|
{
|
|
|
|
$schema_data = true;
|
|
|
|
}
|
|
|
|
|
2006-03-19 05:35:11 +00:00
|
|
|
@set_time_limit(1200);
|
2009-03-30 13:52:58 +00:00
|
|
|
@set_time_limit(0);
|
2006-03-19 05:35:11 +00:00
|
|
|
|
2006-08-17 01:47:14 +00:00
|
|
|
$time = time();
|
|
|
|
|
2006-12-15 03:06:57 +00:00
|
|
|
$filename = 'backup_' . $time . '_' . unique_id();
|
2007-02-15 20:30:41 +00:00
|
|
|
|
2015-02-22 16:22:10 +01:00
|
|
|
$extractor = $phpbb_container->get('dbal.extractor');
|
|
|
|
$extractor->init_extractor($format, $filename, $time, $download, $store);
|
2006-03-18 06:39:47 +00:00
|
|
|
|
2007-02-15 20:30:41 +00:00
|
|
|
$extractor->write_start($table_prefix);
|
|
|
|
|
2006-03-19 11:17:47 +00:00
|
|
|
foreach ($table as $table_name)
|
2006-03-18 06:39:47 +00:00
|
|
|
{
|
2006-03-19 11:17:47 +00:00
|
|
|
// Get the table structure
|
2006-05-02 17:59:51 +00:00
|
|
|
if ($structure)
|
2006-03-18 06:39:47 +00:00
|
|
|
{
|
2007-02-15 20:30:41 +00:00
|
|
|
$extractor->write_table($table_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We might wanna empty out all that junk :D
|
2014-06-26 17:17:35 +02:00
|
|
|
switch ($db->get_sql_layer())
|
2006-03-19 11:17:47 +00:00
|
|
|
{
|
2006-06-18 15:35:32 +00:00
|
|
|
case 'sqlite':
|
2013-11-03 21:58:05 -06:00
|
|
|
case 'sqlite3':
|
2007-02-15 20:30:41 +00:00
|
|
|
$extractor->flush('DELETE FROM ' . $table_name . ";\n");
|
2006-04-19 04:48:58 +00:00
|
|
|
break;
|
|
|
|
|
2006-04-18 02:41:59 +00:00
|
|
|
case 'mssql':
|
2006-04-18 15:21:15 +00:00
|
|
|
case 'mssql_odbc':
|
2010-02-11 00:02:51 +00:00
|
|
|
case 'mssqlnative':
|
2007-02-15 20:30:41 +00:00
|
|
|
$extractor->flush('TRUNCATE TABLE ' . $table_name . "GO\n");
|
2006-04-18 02:41:59 +00:00
|
|
|
break;
|
2007-02-15 20:30:41 +00:00
|
|
|
|
|
|
|
case 'oracle':
|
2009-09-21 17:59:39 +00:00
|
|
|
$extractor->flush('TRUNCATE TABLE ' . $table_name . "/\n");
|
2007-02-01 03:13:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-02-15 20:30:41 +00:00
|
|
|
$extractor->flush('TRUNCATE TABLE ' . $table_name . ";\n");
|
2007-02-01 03:13:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-03-25 01:03:17 +00:00
|
|
|
}
|
2006-03-18 06:39:47 +00:00
|
|
|
|
2006-03-19 11:17:47 +00:00
|
|
|
// Data
|
2006-05-02 17:59:51 +00:00
|
|
|
if ($schema_data)
|
2006-03-19 11:17:47 +00:00
|
|
|
{
|
2007-02-15 20:30:41 +00:00
|
|
|
$extractor->write_data($table_name);
|
2006-03-18 06:39:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-16 20:37:12 +00:00
|
|
|
$extractor->write_end();
|
2006-04-16 17:31:02 +00:00
|
|
|
|
2015-01-05 22:21:31 +01:00
|
|
|
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_DB_BACKUP');
|
2008-04-21 15:02:22 +00:00
|
|
|
|
2006-04-16 17:31:02 +00:00
|
|
|
if ($download == true)
|
2006-03-25 01:03:17 +00:00
|
|
|
{
|
|
|
|
exit;
|
|
|
|
}
|
2006-03-19 11:17:47 +00:00
|
|
|
|
2006-10-02 15:11:40 +00:00
|
|
|
trigger_error($user->lang['BACKUP_SUCCESS'] . adm_back_link($this->u_action));
|
2006-03-18 06:39:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-05-30 13:41:36 +02:00
|
|
|
$tables = $this->db_tools->sql_list_tables();
|
2008-04-20 06:29:00 +00:00
|
|
|
asort($tables);
|
2007-02-19 20:57:05 +00:00
|
|
|
foreach ($tables as $table_name)
|
2006-03-18 06:39:47 +00:00
|
|
|
{
|
2007-07-16 01:06:34 +00:00
|
|
|
if (strlen($table_prefix) === 0 || stripos($table_name, $table_prefix) === 0)
|
2007-02-19 20:57:05 +00:00
|
|
|
{
|
|
|
|
$template->assign_block_vars('tables', array(
|
|
|
|
'TABLE' => $table_name
|
|
|
|
));
|
|
|
|
}
|
2006-03-18 06:39:47 +00:00
|
|
|
}
|
2007-02-19 20:57:05 +00:00
|
|
|
unset($tables);
|
2006-03-18 06:39:47 +00:00
|
|
|
|
|
|
|
$template->assign_vars(array(
|
|
|
|
'U_ACTION' => $this->u_action . '&action=download'
|
|
|
|
));
|
2009-03-30 13:32:57 +00:00
|
|
|
|
2006-03-25 01:03:17 +00:00
|
|
|
$available_methods = array('gzip' => 'zlib', 'bzip2' => 'bz2');
|
|
|
|
|
|
|
|
foreach ($available_methods as $type => $module)
|
|
|
|
{
|
|
|
|
if (!@extension_loaded($module))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-03-18 06:39:47 +00:00
|
|
|
$template->assign_block_vars('methods', array(
|
|
|
|
'TYPE' => $type
|
|
|
|
));
|
|
|
|
}
|
2006-06-09 19:20:32 +00:00
|
|
|
|
|
|
|
$template->assign_block_vars('methods', array(
|
|
|
|
'TYPE' => 'text'
|
|
|
|
));
|
2006-03-18 06:39:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'restore':
|
2006-12-02 13:19:40 +00:00
|
|
|
|
|
|
|
$this->page_title = 'ACP_RESTORE';
|
|
|
|
|
2006-03-18 06:39:47 +00:00
|
|
|
switch ($action)
|
|
|
|
{
|
|
|
|
case 'submit':
|
2015-01-04 20:41:04 +01:00
|
|
|
$delete = $request->variable('delete', '');
|
|
|
|
$file = $request->variable('file', '');
|
|
|
|
$download = $request->variable('download', '');
|
2006-05-06 20:35:30 +00:00
|
|
|
|
2007-04-04 05:06:51 +00:00
|
|
|
if (!preg_match('#^backup_\d{10,}_[a-z\d]{16}\.(sql(?:\.(?:gz|bz2))?)$#', $file, $matches))
|
|
|
|
{
|
|
|
|
trigger_error($user->lang['BACKUP_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
|
}
|
|
|
|
|
2006-06-09 19:20:32 +00:00
|
|
|
$file_name = $phpbb_root_path . 'store/' . $matches[0];
|
|
|
|
|
2007-04-07 03:45:59 +00:00
|
|
|
if (!file_exists($file_name) || !is_readable($file_name))
|
2006-05-06 20:35:30 +00:00
|
|
|
{
|
2006-10-02 15:11:40 +00:00
|
|
|
trigger_error($user->lang['BACKUP_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
2006-05-06 20:35:30 +00:00
|
|
|
}
|
2006-04-16 17:31:02 +00:00
|
|
|
|
|
|
|
if ($delete)
|
|
|
|
{
|
2007-05-05 13:43:39 +00:00
|
|
|
if (confirm_box(true))
|
|
|
|
{
|
|
|
|
unlink($file_name);
|
2015-01-05 22:21:31 +01:00
|
|
|
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_DB_DELETE');
|
2007-05-05 13:43:39 +00:00
|
|
|
trigger_error($user->lang['BACKUP_DELETE'] . adm_back_link($this->u_action));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-05-05 21:47:16 +00:00
|
|
|
confirm_box(false, $user->lang['DELETE_SELECTED_BACKUP'], build_hidden_fields(array('delete' => $delete, 'file' => $file)));
|
2007-05-05 13:43:39 +00:00
|
|
|
}
|
2006-04-16 17:31:02 +00:00
|
|
|
}
|
2011-09-21 21:19:37 +01:00
|
|
|
else if ($download || confirm_box(true))
|
2006-04-16 17:31:02 +00:00
|
|
|
{
|
2007-05-05 21:47:16 +00:00
|
|
|
if ($download)
|
2006-04-16 17:31:02 +00:00
|
|
|
{
|
2007-05-05 21:47:16 +00:00
|
|
|
$name = $matches[0];
|
2006-04-16 17:31:02 +00:00
|
|
|
|
2007-05-05 21:47:16 +00:00
|
|
|
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;
|
|
|
|
}
|
2006-04-16 17:31:02 +00:00
|
|
|
|
2014-09-17 20:10:01 +02:00
|
|
|
header('Cache-Control: private, no-cache');
|
2007-05-05 21:47:16 +00:00
|
|
|
header("Content-Type: $mimetype; name=\"$name\"");
|
|
|
|
header("Content-disposition: attachment; filename=$name");
|
2006-06-12 21:55:30 +00:00
|
|
|
|
2007-05-05 21:47:16 +00:00
|
|
|
@set_time_limit(0);
|
2007-02-15 20:30:41 +00:00
|
|
|
|
2007-05-05 21:47:16 +00:00
|
|
|
$fp = @fopen($file_name, 'rb');
|
|
|
|
|
|
|
|
if ($fp !== false)
|
2006-07-04 03:54:41 +00:00
|
|
|
{
|
2007-05-05 21:47:16 +00:00
|
|
|
while (!feof($fp))
|
|
|
|
{
|
|
|
|
echo fread($fp, 8192);
|
|
|
|
}
|
|
|
|
fclose($fp);
|
2007-02-15 20:30:41 +00:00
|
|
|
}
|
2006-06-12 21:55:30 +00:00
|
|
|
|
2007-05-05 21:47:16 +00:00
|
|
|
flush();
|
|
|
|
exit;
|
|
|
|
}
|
2006-06-12 21:55:30 +00:00
|
|
|
|
2007-05-05 21:47:16 +00:00
|
|
|
switch ($matches[1])
|
|
|
|
{
|
|
|
|
case 'sql':
|
|
|
|
$fp = fopen($file_name, 'rb');
|
|
|
|
$read = 'fread';
|
|
|
|
$seek = 'fseek';
|
|
|
|
$eof = 'feof';
|
|
|
|
$close = 'fclose';
|
|
|
|
$fgetd = 'fgetd';
|
|
|
|
break;
|
2006-03-18 06:39:47 +00:00
|
|
|
|
2007-05-05 21:47:16 +00:00
|
|
|
case 'sql.bz2':
|
|
|
|
$fp = bzopen($file_name, 'r');
|
|
|
|
$read = 'bzread';
|
|
|
|
$seek = '';
|
|
|
|
$eof = 'feof';
|
|
|
|
$close = 'bzclose';
|
|
|
|
$fgetd = 'fgetd_seekless';
|
|
|
|
break;
|
2007-02-15 20:30:41 +00:00
|
|
|
|
2007-05-05 21:47:16 +00:00
|
|
|
case 'sql.gz':
|
|
|
|
$fp = gzopen($file_name, 'rb');
|
|
|
|
$read = 'gzread';
|
|
|
|
$seek = 'gzseek';
|
|
|
|
$eof = 'gzeof';
|
|
|
|
$close = 'gzclose';
|
|
|
|
$fgetd = 'fgetd';
|
|
|
|
break;
|
|
|
|
}
|
2007-02-15 20:30:41 +00:00
|
|
|
|
2014-06-26 17:17:35 +02:00
|
|
|
switch ($db->get_sql_layer())
|
2007-05-05 21:47:16 +00:00
|
|
|
{
|
|
|
|
case 'mysql':
|
|
|
|
case 'mysql4':
|
|
|
|
case 'mysqli':
|
|
|
|
case 'sqlite':
|
2013-11-03 21:58:05 -06:00
|
|
|
case 'sqlite3':
|
2007-05-05 21:47:16 +00:00
|
|
|
while (($sql = $fgetd($fp, ";\n", $read, $seek, $eof)) !== false)
|
|
|
|
{
|
|
|
|
$db->sql_query($sql);
|
|
|
|
}
|
|
|
|
break;
|
2006-03-18 06:39:47 +00:00
|
|
|
|
2007-05-05 21:47:16 +00:00
|
|
|
case 'postgres':
|
2008-03-26 17:27:34 +00:00
|
|
|
$delim = ";\n";
|
2007-05-05 21:47:16 +00:00
|
|
|
while (($sql = $fgetd($fp, $delim, $read, $seek, $eof)) !== false)
|
2006-07-04 03:54:41 +00:00
|
|
|
{
|
2007-05-05 21:47:16 +00:00
|
|
|
$query = trim($sql);
|
2008-04-20 06:29:00 +00:00
|
|
|
|
|
|
|
if (substr($query, 0, 13) == 'CREATE DOMAIN')
|
|
|
|
{
|
|
|
|
list(, , $domain) = explode(' ', $query);
|
|
|
|
$sql = "SELECT domain_name
|
|
|
|
FROM information_schema.domains
|
|
|
|
WHERE domain_name = '$domain';";
|
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
if (!$db->sql_fetchrow($result))
|
|
|
|
{
|
|
|
|
$db->sql_query($query);
|
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$db->sql_query($query);
|
|
|
|
}
|
|
|
|
|
2007-05-05 21:47:16 +00:00
|
|
|
if (substr($query, 0, 4) == 'COPY')
|
2007-02-15 20:30:41 +00:00
|
|
|
{
|
2007-05-05 21:47:16 +00:00
|
|
|
while (($sub = $fgetd($fp, "\n", $read, $seek, $eof)) !== '\.')
|
2007-02-19 20:57:05 +00:00
|
|
|
{
|
2007-05-05 21:47:16 +00:00
|
|
|
if ($sub === false)
|
|
|
|
{
|
2007-07-16 01:06:34 +00:00
|
|
|
trigger_error($user->lang['RESTORE_FAILURE'] . adm_back_link($this->u_action), E_USER_WARNING);
|
2007-05-05 21:47:16 +00:00
|
|
|
}
|
2014-06-26 17:17:35 +02:00
|
|
|
pg_put_line($db->get_db_connect_id(), $sub . "\n");
|
2007-02-19 20:57:05 +00:00
|
|
|
}
|
2014-06-26 17:17:35 +02:00
|
|
|
pg_put_line($db->get_db_connect_id(), "\\.\n");
|
|
|
|
pg_end_copy($db->get_db_connect_id());
|
2007-02-15 20:30:41 +00:00
|
|
|
}
|
2006-07-04 03:54:41 +00:00
|
|
|
}
|
2007-05-05 21:47:16 +00:00
|
|
|
break;
|
2006-03-18 06:39:47 +00:00
|
|
|
|
2007-05-05 21:47:16 +00:00
|
|
|
case 'oracle':
|
|
|
|
while (($sql = $fgetd($fp, "/\n", $read, $seek, $eof)) !== false)
|
|
|
|
{
|
|
|
|
$db->sql_query($sql);
|
|
|
|
}
|
|
|
|
break;
|
2007-02-15 20:30:41 +00:00
|
|
|
|
2007-05-05 21:47:16 +00:00
|
|
|
case 'mssql':
|
|
|
|
case 'mssql_odbc':
|
2010-05-01 02:15:58 +01:00
|
|
|
case 'mssqlnative':
|
2007-05-05 21:47:16 +00:00
|
|
|
while (($sql = $fgetd($fp, "GO\n", $read, $seek, $eof)) !== false)
|
|
|
|
{
|
|
|
|
$db->sql_query($sql);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-02-15 20:30:41 +00:00
|
|
|
|
2007-05-05 21:47:16 +00:00
|
|
|
$close($fp);
|
2007-02-15 20:30:41 +00:00
|
|
|
|
2008-04-21 15:02:22 +00:00
|
|
|
// Purge the cache due to updated data
|
|
|
|
$cache->purge();
|
|
|
|
|
2015-01-05 22:21:31 +01:00
|
|
|
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_DB_RESTORE');
|
2007-05-05 21:47:16 +00:00
|
|
|
trigger_error($user->lang['RESTORE_SUCCESS'] . adm_back_link($this->u_action));
|
|
|
|
break;
|
|
|
|
}
|
2011-09-21 21:19:37 +01:00
|
|
|
else if (!$download)
|
|
|
|
{
|
|
|
|
confirm_box(false, $user->lang['RESTORE_SELECTED_BACKUP'], build_hidden_fields(array('file' => $file)));
|
|
|
|
}
|
2007-02-15 20:30:41 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
$methods = array('sql');
|
2006-03-25 01:03:17 +00:00
|
|
|
$available_methods = array('sql.gz' => 'zlib', 'sql.bz2' => 'bz2');
|
|
|
|
|
|
|
|
foreach ($available_methods as $type => $module)
|
|
|
|
{
|
|
|
|
if (!@extension_loaded($module))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$methods[] = $type;
|
|
|
|
}
|
2006-03-18 06:39:47 +00:00
|
|
|
|
|
|
|
$dir = $phpbb_root_path . 'store/';
|
2007-01-20 17:58:27 +00:00
|
|
|
$dh = @opendir($dir);
|
|
|
|
|
2009-03-30 13:32:57 +00:00
|
|
|
$backup_files = array();
|
|
|
|
|
2007-01-20 17:58:27 +00:00
|
|
|
if ($dh)
|
2006-03-18 06:39:47 +00:00
|
|
|
{
|
2007-01-20 17:58:27 +00:00
|
|
|
while (($file = readdir($dh)) !== false)
|
2006-03-18 06:39:47 +00:00
|
|
|
{
|
2007-01-20 17:58:27 +00:00
|
|
|
if (preg_match('#^backup_(\d{10,})_[a-z\d]{16}\.(sql(?:\.(?:gz|bz2))?)$#', $file, $matches))
|
2006-03-18 06:39:47 +00:00
|
|
|
{
|
2009-03-30 13:32:57 +00:00
|
|
|
if (in_array($matches[2], $methods))
|
2007-01-20 17:58:27 +00:00
|
|
|
{
|
2010-02-06 21:19:40 +00:00
|
|
|
$backup_files[(int) $matches[1]] = $file;
|
2007-01-20 17:58:27 +00:00
|
|
|
}
|
2006-03-18 06:39:47 +00:00
|
|
|
}
|
|
|
|
}
|
2007-01-20 17:58:27 +00:00
|
|
|
closedir($dh);
|
2006-03-18 06:39:47 +00:00
|
|
|
}
|
|
|
|
|
2009-03-30 13:32:57 +00:00
|
|
|
if (!empty($backup_files))
|
|
|
|
{
|
|
|
|
krsort($backup_files);
|
|
|
|
|
|
|
|
foreach ($backup_files as $name => $file)
|
|
|
|
{
|
|
|
|
$template->assign_block_vars('files', array(
|
|
|
|
'FILE' => $file,
|
2010-02-06 21:19:40 +00:00
|
|
|
'NAME' => $user->format_date($name, 'd-m-Y H:i:s', true),
|
2009-03-30 13:32:57 +00:00
|
|
|
'SUPPORTED' => true,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-18 06:39:47 +00:00
|
|
|
$template->assign_vars(array(
|
|
|
|
'U_ACTION' => $this->u_action . '&action=submit'
|
|
|
|
));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-02-15 20:30:41 +00:00
|
|
|
}
|
2006-03-19 11:17:47 +00:00
|
|
|
|
2007-03-07 03:27:20 +00:00
|
|
|
// 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)
|
|
|
|
function get_usable_memory()
|
|
|
|
{
|
|
|
|
$val = trim(@ini_get('memory_limit'));
|
|
|
|
|
|
|
|
if (preg_match('/(\\d+)([mkg]?)/i', $val, $regs))
|
|
|
|
{
|
|
|
|
$memory_limit = (int) $regs[1];
|
|
|
|
switch ($regs[2])
|
|
|
|
{
|
|
|
|
|
|
|
|
case 'k':
|
|
|
|
case 'K':
|
|
|
|
$memory_limit *= 1024;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'm':
|
|
|
|
case 'M':
|
|
|
|
$memory_limit *= 1048576;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'g':
|
|
|
|
case 'G':
|
|
|
|
$memory_limit *= 1073741824;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// how much memory PHP requires at the start of export (it is really a little less)
|
|
|
|
if ($memory_limit > 6100000)
|
|
|
|
{
|
|
|
|
$memory_limit -= 6100000;
|
|
|
|
}
|
|
|
|
|
|
|
|
// allow us to consume half of the total memory available
|
|
|
|
$memory_limit /= 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// set the buffer to 1M if we have no clue how much memory PHP will give us :P
|
|
|
|
$memory_limit = 1048576;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $memory_limit;
|
|
|
|
}
|
|
|
|
|
2007-02-15 20:30:41 +00:00
|
|
|
function sanitize_data_mssql($text)
|
|
|
|
{
|
|
|
|
$data = preg_split('/[\n\t\r\b\f]/', $text);
|
|
|
|
preg_match_all('/[\n\t\r\b\f]/', $text, $matches);
|
2007-05-11 20:53:51 +00:00
|
|
|
|
2007-02-15 20:30:41 +00:00
|
|
|
$val = array();
|
2007-05-11 20:53:51 +00:00
|
|
|
|
2007-02-15 20:30:41 +00:00
|
|
|
foreach ($data as $value)
|
|
|
|
{
|
|
|
|
if (strlen($value))
|
|
|
|
{
|
2007-05-11 20:53:51 +00:00
|
|
|
$val[] = "'" . $value . "'";
|
2007-02-15 20:30:41 +00:00
|
|
|
}
|
|
|
|
if (sizeof($matches[0]))
|
|
|
|
{
|
|
|
|
$val[] = 'char(' . ord(array_shift($matches[0])) . ')';
|
|
|
|
}
|
|
|
|
}
|
2007-05-11 20:53:51 +00:00
|
|
|
|
2007-02-15 20:30:41 +00:00
|
|
|
return implode('+', $val);
|
|
|
|
}
|
|
|
|
|
|
|
|
function sanitize_data_oracle($text)
|
|
|
|
{
|
2009-09-21 17:59:39 +00:00
|
|
|
// $data = preg_split('/[\0\n\t\r\b\f\'"\/\\\]/', $text);
|
|
|
|
// preg_match_all('/[\0\n\t\r\b\f\'"\/\\\]/', $text, $matches);
|
|
|
|
$data = preg_split('/[\0\b\f\'\/]/', $text);
|
|
|
|
preg_match_all('/[\0\r\b\f\'\/]/', $text, $matches);
|
2007-05-11 20:53:51 +00:00
|
|
|
|
2007-02-15 20:30:41 +00:00
|
|
|
$val = array();
|
2007-05-11 20:53:51 +00:00
|
|
|
|
2007-02-15 20:30:41 +00:00
|
|
|
foreach ($data as $value)
|
|
|
|
{
|
|
|
|
if (strlen($value))
|
|
|
|
{
|
2007-05-11 20:53:51 +00:00
|
|
|
$val[] = "'" . $value . "'";
|
2007-02-15 20:30:41 +00:00
|
|
|
}
|
|
|
|
if (sizeof($matches[0]))
|
|
|
|
{
|
|
|
|
$val[] = 'chr(' . ord(array_shift($matches[0])) . ')';
|
|
|
|
}
|
|
|
|
}
|
2007-05-11 20:53:51 +00:00
|
|
|
|
2007-02-15 20:30:41 +00:00
|
|
|
return implode('||', $val);
|
|
|
|
}
|
|
|
|
|
|
|
|
function sanitize_data_generic($text)
|
|
|
|
{
|
|
|
|
$data = preg_split('/[\n\t\r\b\f]/', $text);
|
|
|
|
preg_match_all('/[\n\t\r\b\f]/', $text, $matches);
|
2007-05-11 20:53:51 +00:00
|
|
|
|
2007-02-15 20:30:41 +00:00
|
|
|
$val = array();
|
2007-05-11 20:53:51 +00:00
|
|
|
|
2007-02-15 20:30:41 +00:00
|
|
|
foreach ($data as $value)
|
|
|
|
{
|
|
|
|
if (strlen($value))
|
|
|
|
{
|
2007-05-11 20:53:51 +00:00
|
|
|
$val[] = "'" . $value . "'";
|
2007-02-15 20:30:41 +00:00
|
|
|
}
|
|
|
|
if (sizeof($matches[0]))
|
|
|
|
{
|
|
|
|
$val[] = "'" . array_shift($matches[0]) . "'";
|
|
|
|
}
|
|
|
|
}
|
2007-05-11 20:53:51 +00:00
|
|
|
|
2007-02-15 20:30:41 +00:00
|
|
|
return implode('||', $val);
|
|
|
|
}
|
|
|
|
|
|
|
|
// modified from PHP.net
|
|
|
|
function fgetd(&$fp, $delim, $read, $seek, $eof, $buffer = 8192)
|
|
|
|
{
|
|
|
|
$record = '';
|
|
|
|
$delim_len = strlen($delim);
|
2009-03-30 13:32:57 +00:00
|
|
|
|
2007-02-15 20:30:41 +00:00
|
|
|
while (!$eof($fp))
|
|
|
|
{
|
|
|
|
$pos = strpos($record, $delim);
|
|
|
|
if ($pos === false)
|
|
|
|
{
|
|
|
|
$record .= $read($fp, $buffer);
|
|
|
|
if ($eof($fp) && ($pos = strpos($record, $delim)) !== false)
|
|
|
|
{
|
|
|
|
$seek($fp, $pos + $delim_len - strlen($record), SEEK_CUR);
|
|
|
|
return substr($record, 0, $pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$seek($fp, $pos + $delim_len - strlen($record), SEEK_CUR);
|
|
|
|
return substr($record, 0, $pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-02-16 00:46:21 +00:00
|
|
|
function fgetd_seekless(&$fp, $delim, $read, $seek, $eof, $buffer = 8192)
|
|
|
|
{
|
|
|
|
static $array = array();
|
|
|
|
static $record = '';
|
|
|
|
|
|
|
|
if (!sizeof($array))
|
|
|
|
{
|
|
|
|
while (!$eof($fp))
|
|
|
|
{
|
|
|
|
if (strpos($record, $delim) !== false)
|
|
|
|
{
|
|
|
|
$array = explode($delim, $record);
|
|
|
|
$record = array_pop($array);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$record .= $read($fp, $buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($eof($fp) && strpos($record, $delim) !== false)
|
|
|
|
{
|
|
|
|
$array = explode($delim, $record);
|
|
|
|
$record = array_pop($array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sizeof($array))
|
|
|
|
{
|
|
|
|
return array_shift($array);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|