version() > '4.1' ? 'Engine' : 'Type'; $tablepre = $_G['config']['db'][1]['tablepre']; $dbcharset = $_G['config']['db'][1]['dbcharset']; require_once libfile('function/attachment'); cpheader(); if(!isfounder()) cpmsg('noaccess_isfounder', '', 'error'); $excepttables = array($tablepre.'common_admincp_session', $tablepre.'common_syscache', $tablepre.'common_failedlogin', $tablepre.'forum_rsscache', $tablepre.'common_searchindex', $tablepre.'forum_spacecache', $tablepre.'common_session'); $backupdir = C::t('common_setting')->fetch('backupdir'); if(!$backupdir) { $backupdir = random(6); @mkdir('./data/backup_'.$backupdir, 0777); C::t('common_setting')->update('backupdir',$backupdir); } $backupdir = 'backup_'.$backupdir; if(!is_dir('./data/'.$backupdir)) { mkdir('./data/'.$backupdir, 0777); } if($operation == 'export') { $_SERVER['REQUEST_METHOD'] = 'POST'; if(!submitcheck('exportsubmit')) { $shelldisabled = function_exists('shell_exec') ? '' : 'disabled'; $tables = ''; $dztables = array(); $tables = C::t('common_setting')->fetch('custombackup', true); $discuz_tables = fetchtablelist($tablepre); foreach($discuz_tables as $table) { $dztables[$table['Name']] = $table['Name']; } $defaultfilename = date('ymd').'_'.random(8); include DISCUZ_ROOT.'./config/config_ucenter.php'; $uc_tablepre = explode('.', UC_DBTABLEPRE); $uc_tablepre = $uc_tablepre[1] ? $uc_tablepre[1] : $uc_tablepre[0]; $uc_tablepre = substr($uc_tablepre, '0', '-8'); if(UC_CONNECT == 'mysql' && UC_DBHOST == $_G['config']['db'][1]['dbhost'] && UC_DBNAME == $_G['config']['db'][1]['dbname'] && $uc_tablepre == $tablepre) { $db_export = 'db_export_discuz_uc'; $db_export_key = 'discuz_uc'; $db_export_tips = cplang('db_export_tips_uc', array('uc_backup_url' => $uc_backup_url)).cplang('db_export_tips'); $db_export_discuz_table = cplang('db_export_discuz_table_uc'); } else { $db_export = 'db_export_discuz'; $db_export_key = 'discuz'; $uc_backup_url = UC_API.'/admin.php?m=db&a=ls&iframe=1'; $db_export_tips = cplang('db_export_tips_nouc', array('uc_backup_url' => $uc_backup_url)).cplang('db_export_tips'); $db_export_discuz_table = cplang('db_export_discuz_table'); } shownav('founder', 'nav_db', 'nav_db_export'); showsubmenu('nav_db', array( array('nav_db_export', 'db&operation=export', 1), array('nav_db_import', 'db&operation=import', 0), array('nav_db_runquery', 'db&operation=runquery', 0), array('nav_db_optimize', 'db&operation=optimize', 0), array('nav_db_dbcheck', 'db&operation=dbcheck', 0) )); showtips($db_export_tips); showformheader('db&operation=export&setup=1'); showtableheader(); showsetting('db_export_type', array('type', array( array($db_export_key, $lang[$db_export], array('showtables' => 'none')), array('custom', $lang['db_export_custom'], array('showtables' => '')) )), $db_export_key, 'mradio'); showtagheader('tbody', 'showtables'); showtablerow('', '', ''; showtablerow('', 'colspan="2"', mcheckbox('customtables', $dztables)); showtagfooter('tbody'); showtagheader('tbody', 'advanceoption'); showsetting('db_export_method', '', '', ''); showtitle('db_export_options'); showsetting('db_export_options_extended_insert', 'extendins', 0, 'radio'); showsetting('db_export_options_sql_compatible', array('sqlcompat', array( array('', $lang['default']), array('MYSQL40', 'MySQL 3.23/4.0.x'), array('MYSQL41', 'MySQL 4.1.x/5.x') )), '', 'mradio'); showsetting('db_export_options_charset', array('sqlcharset', array( array('', cplang('default')), $dbcharset ? array($dbcharset, strtoupper($dbcharset)) : array(), $db->version() > '4.1' && $dbcharset != 'utf8' ? array('utf8', 'UTF-8') : array() ), TRUE), 0, 'mradio'); showsetting('db_export_usehex', 'usehex', 1, 'radio'); if(function_exists('gzcompress')) { showsetting('db_export_usezip', array('usezip', array( array('1', $lang['db_export_zip_1']), array('2', $lang['db_export_zip_2']), array('0', $lang['db_export_zip_3']) )), 0, 'mradio'); } showsetting('db_export_filename', '', '', '.sql'); showtagfooter('tbody'); showsubmit('exportsubmit', 'submit', '', 'more_options'); showtablefooter(); showformfooter(); } else { DB::query('SET SQL_QUOTE_SHOW_CREATE=0', 'SILENT'); if(!$_GET['filename'] || !preg_match('/^[\w\_]+$/', $_GET['filename'])) { cpmsg('database_export_filename_invalid', '', 'error'); } $time = dgmdate(TIMESTAMP); if($_GET['type'] == 'discuz' || $_GET['type'] == 'discuz_uc') { $tables = arraykeys2(fetchtablelist($tablepre), 'Name'); } elseif($_GET['type'] == 'custom') { $tables = array(); if(empty($_GET['setup'])) { $tables = C::t('common_setting')->fetch('custombackup', true); } else { C::t('common_setting')->update('custombackup', empty($_GET['customtables'])? '' : $_GET['customtables']); $tables = & $_GET['customtables']; } if( !is_array($tables) || empty($tables)) { cpmsg('database_export_custom_invalid', '', 'error'); } } $memberexist = array_search(DB::table('common_member'), $tables); if($memberexist !== FALSE) { unset($tables[$memberexist]); array_unshift($tables, DB::table('common_member')); } $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 './source/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". "# Discuz! Multi-Volume Data Dump Vol.$volume\n". "# Version: Discuz! {$_G[setting][version]}\n". "# Time: $time\n". "# Type: {$_GET['type']}\n". "# Table Prefix: $tablepre\n". "#\n". "# Discuz! Home: http://www.discuz.com\n". "# Please visit our website for newest infomation about Discuz!\n". "# --------------------------------------------------------\n\n\n". "$setnames". $sqldump; $dumpfilename = sprintf($dumpfile, $volume); @$fp = fopen($dumpfilename, 'wb'); @flock($fp, 2); if(@!fwrite($fp, $sqldump)) { @fclose($fp); cpmsg('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); cpmsg('database_export_multivol_redirect', "action=db&operation=export&formhash=".formhash()."&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']}", 'loading', array('volume' => $volume)); } } else { $volume--; $filelist = '