123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- <?php
- if (!defined('SMF'))
- die('Hacking attempt...');
- function DumpDatabase2()
- {
- global $db_name, $scripturl, $context, $modSettings, $crlf, $smcFunc, $db_prefix;
-
- if (!allowedTo('admin_forum'))
- fatal_lang_error('no_dump_database', 'critical');
-
- if (!isset($_REQUEST['struct']) && !isset($_REQUEST['data']))
- $_REQUEST['data'] = true;
- checkSession('post');
-
- db_extend();
-
- @set_time_limit(600);
- if (ini_get('memory_limit') < 256)
- @ini_set('memory_limit', '256M');
-
- if (isset($_REQUEST['compress']) && function_exists('gzencode'))
-
- {
-
- if (empty($modSettings['enableCompressedOutput']))
- @ob_start('ob_gzhandler', 65536);
-
- elseif (ob_get_length() != 0)
- {
- ob_end_clean();
- @ob_start('ob_gzhandler', 65536);
- }
-
- header('Content-Type: application/x-gzip');
- header('Accept-Ranges: bytes');
- header('Content-Encoding: none');
-
- if (!isBrowser('gecko'))
- header('Content-Transfer-Encoding: binary');
-
- $extension = '.sql.gz';
- }
- else
- {
-
- if (!empty($modSettings['enableCompressedOutput']))
- @ob_end_clean();
-
- elseif (function_exists('ob_clean') && ob_get_length() != 0)
- ob_clean();
-
- header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream'));
- header('Content-Encoding: none');
-
- $extension = '.sql';
- }
-
- $scripturl = '';
-
- if (!empty($smcFunc['db_get_backup']))
- {
- $smcFunc['db_get_backup']();
- exit;
- }
-
- header('Content-Disposition: filename="' . $db_name . '-' . (empty($_REQUEST['struct']) ? 'data' : (empty($_REQUEST['data']) ? 'structure' : 'complete')) . '_' . strftime('%Y-%m-%d') . $extension . '"');
- header('Cache-Control: private');
- header('Connection: close');
-
- $crlf = "\r\n";
-
- echo
- '-- ==========================================================', $crlf,
- '--', $crlf,
- '-- Database dump of tables in `', $db_name, '`', $crlf,
- '-- ', timeformat(time(), false), $crlf,
- '--', $crlf,
- '-- ==========================================================', $crlf,
- $crlf;
-
- if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) != 0)
- {
- $db = strtr($match[1], array('`' => ''));
- $dbp = str_replace('_', '\_', $match[2]);
- }
- else
- {
- $db = false;
- $dbp = $db_prefix;
- }
-
- $tables = $smcFunc['db_list_tables'](false, $db_prefix . '%');
- foreach ($tables as $tableName)
- {
- if (function_exists('apache_reset_timeout'))
- @apache_reset_timeout();
-
- if (isset($_REQUEST['struct']))
- {
- echo
- $crlf,
- '--', $crlf,
- '-- Table structure for table `', $tableName, '`', $crlf,
- '--', $crlf,
- $crlf,
- $smcFunc['db_table_sql']($tableName), ';', $crlf;
- }
-
- if (!isset($_REQUEST['data']) || substr($tableName, -10) == 'log_errors')
- continue;
-
- $get_rows = $smcFunc['db_insert_sql']($tableName);
-
- if (empty($get_rows))
- continue;
- echo
- $crlf,
- '--', $crlf,
- '-- Dumping data in `', $tableName, '`', $crlf,
- '--', $crlf,
- $crlf,
- $get_rows,
- '-- --------------------------------------------------------', $crlf;
- unset($get_rows);
- }
- echo
- $crlf,
- '-- Done', $crlf;
- exit;
- }
- ?>
|