version() > '4.1' ? 'Engine' : 'Type'; $tablepre = $_G['config']['db'][1]['tablepre']; $dbcharset = $_G['config']['db'][1]['dbcharset']; $backupdir = C::t('setting') -> fetch('backupdir'); if (!$backupdir) { $backupdir = random(6); @mkdir('./data/backup_' . $backupdir, 0777); C::t('setting') -> update('backupdir', $backupdir); } $backupdir = 'backup_' . $backupdir; if (!is_dir('./data/' . $backupdir)) { mkdir('./data/' . $backupdir, 0777); } $operation = $_GET['operation'] ? $_GET['operation'] : 'export'; $op = $_GET['op']; if ($operation == 'export') { $navtitle = lang('database_export') . ' - ' . lang('appname'); if (!submitcheck('exportsubmit', 1)) { $shelldisabled = function_exists('shell_exec') ? '' : 'disabled'; $tables = ''; $dztables = array(); $tables = C::t('setting') -> fetch('custombackup', true); $dzz_tables = fetchtablelist($tablepre); foreach ($dzz_tables as $table) { $dztables[$table['Name']] = $table['Name']; } $defaultfilename = date('ymd') . '_' . random(8); } else { $submit = true; DB::query('SET SQL_QUOTE_SHOW_CREATE=0', 'SILENT'); if (!$_GET['filename'] || preg_match("/(\.)(exe|jsp|asp|aspx|cgi|fcgi|pl)(\.|$)/i", $_GET['filename'])) { showmessage('database_export_filename_invalid'); } if(!preg_match("/^[a-zA-Z0-9_]+$/i",$_GET['filename'])){ showmessage('database_export_filename_invalid'); } $time = dgmdate(TIMESTAMP); if ($_GET['type'] == 'dzz') { $tables = arraykeys2(fetchtablelist($tablepre), 'Name'); } elseif ($_GET['type'] == 'custom') { $tables = array(); $alltables= arraykeys2(fetchtablelist($tablepre), 'Name'); if (empty($_GET['setup'])) { $tables = C::t('setting') -> fetch('custombackup', true); } else { C::t('setting') -> update('custombackup', empty($_GET['customtables']) ? '' : $_GET['customtables']); $tables = $_GET['customtables']; } //验证表名是否正确 foreach($tables as $key => $table){ if(!in_array($table,$alltables)) unset($tables[$key]); } if (!is_array($tables) || empty($tables)) { showmessage('database_export_custom_invalid'); } } $memberexist = array_search(DB::table('user'), $tables); if ($memberexist !== FALSE) { unset($tables[$memberexist]); array_unshift($tables, DB::table('user')); } $volume = intval($_GET['volume']) + 1; $idstring = '# Identify: ' . base64_encode($_G['timestamp']."," . $_G['setting']['version'] . "," .$_GET['type']."," .$_GET['method']."," .$volume."," .$tablepre."," .$dbcharset) . "\n"; $dumpcharset = $_GET['sqlcharset'] ? $_GET['sqlcharset'] : str_replace('-', '', $_G['charset']); $setnames = ($_GET['sqlcharset'] && $db -> version() > '4.1' && (!$_GET['sqlcompat'] || $_GET['sqlcompat'] == 'MYSQL41')) ? "SET NAMES '$dumpcharset';\n\n" : ''; if ($db -> version() > '4.1') { if ($_GET['sqlcharset']) { DB::query('SET NAMES %s', array($_GET['sqlcharset'])); } if ($_GET['sqlcompat'] == 'MYSQL40') { DB::query("SET SQL_MODE='MYSQL40'"); } elseif ($_GET['sqlcompat'] == 'MYSQL41') { DB::query("SET SQL_MODE=''"); } } $backupfilename = './data/' . $backupdir . '/' . str_replace(array('/', '\\', '.', "'"), '', $_GET['filename']); if ($_GET['usezip']) { require_once './core/class/class_zip.php'; } if ($_GET['method'] == 'multivol') { $sqldump = ''; $tableid = intval($_GET['tableid']); $startfrom = intval($_GET['startfrom']); if (!$tableid && $volume == 1) { foreach ($tables as $table) { $sqldump .= sqldumptablestruct($table); } } $complete = TRUE; for (; $complete && $tableid < count($tables) && strlen($sqldump) + 500 < $_GET['sizelimit'] * 1000; $tableid++) { $sqldump .= sqldumptable($tables[$tableid], $startfrom, strlen($sqldump)); if ($complete) { $startfrom = 0; } } $dumpfile = $backupfilename . "-%s" . '.sql'; !$complete && $tableid--; if (trim($sqldump)) { $sqldump = "$idstring" . "# \n" . "# DzzOffice Multi-Volume Data Dump Vol.$volume\n" . "# Version: DzzOffice! " . $_G['setting']['version'] . "\n" . "# Time: $time\n" . "# Type: {$_GET['type']}\n" . "# Table Prefix: $tablepre\n" . "#\n" . "# Dzz! Home: http://www.dzzoffice.com\n" . "# Please visit our website for newest infomation about DzzOffice\n" . "# --------------------------------------------------------\n\n\n" . "$setnames" . $sqldump; $dumpfilename = sprintf($dumpfile, $volume); @$fp = fopen($dumpfilename, 'wb'); @flock($fp, 2); if (@!fwrite($fp, $sqldump)) { @fclose($fp); showmessage('database_export_file_invalid', '', 'error'); } else { fclose($fp); if ($_GET['usezip'] == 2) { $fp = fopen($dumpfilename, "r"); $content = @fread($fp, filesize($dumpfilename)); fclose($fp); $zip = new zipfile(); $zip -> addFile($content, basename($dumpfilename)); $fp = fopen(sprintf($backupfilename . "-%s" . '.zip', $volume), 'w'); if (@fwrite($fp, $zip -> file()) !== FALSE) { @unlink($dumpfilename); } fclose($fp); } unset($sqldump, $zip, $content); $redirecturl = BASESCRIPT . "?mod=system&op=database&operation=export&type=" . rawurlencode($_GET['type']) . "&saveto=server&filename=" . rawurlencode($_GET['filename']) . "&method=multivol&sizelimit=" . rawurlencode($_GET['sizelimit']) . "&volume=" . rawurlencode($volume) . "&tableid=" . rawurlencode($tableid) . "&startfrom=" . rawurlencode($startrow) . "&extendins=" . rawurlencode($_GET['extendins']) . "&sqlcharset=" . rawurlencode($_GET['sqlcharset']) . "&sqlcompat=" . rawurlencode($_GET['sqlcompat']) . "&exportsubmit=yes&usehex={$_GET['usehex']}&usezip={$_GET['usezip']}"; $msg = lang('database_export_multivol_redirect', array('volume' => $volume)); $msg_type = 'text-success'; } } else { $msg = ''; $volume--; $filelist = '