[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 backup_mysql.php

Zen Cart 源代码 backup_mysql.php




下载文件

文件名: backup_mysql.php
文件类型: PHP文件
文件大小: 32.41 KiB
MD5: 0dcc64d4f5367593daedec840d0af78b

backup_mysql.php - 关闭高亮
  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // |zen-cart Open Source E-commerce                                       |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 2003 The zen-cart developers                           |
  7. // |                                                                      |
  8. // | http://www.zen-cart.com/index.php                                    |
  9. // |                                                                      |
  10. // | Portions Copyright (c) 2003 osCommerce                               |
  11. // +----------------------------------------------------------------------+
  12. // | This source file is subject to version 2.0 of the GPL license,       |
  13. // | that is bundled with this package in the file LICENSE, and is        |
  14. // | available through the world-wide-web at the following url:           |
  15. // | http://www.zen-cart.com/license/2_0.txt.                             |
  16. // | If you did not receive a copy of the zen-cart license and are unable |
  17. // | to obtain it through the world-wide-web, please send a note to       |
  18. // | license@zen-cart.com so we can mail you a copy immediately.          |
  19. // +----------------------------------------------------------------------+
  20. // $Id: backup_mysql.php revised 2012-07-07  $
  21. //
  22.  
  23.   define('OS_DELIM', '');
  24.  
  25.   require('includes/application_top.php');
  26.   $debug = '';
  27.   $dump_params = '';
  28.   $tables_to_export = (isset($_GET['tables']) && $_GET['tables'] !='') ? str_replace(',',' ',$_GET['tables']) : '';
  29.   $redirect= (isset($_GET['returnto']) && $_GET['returnto'] !='') ? $_GET['returnto'] : '';
  30.   $resultcodes = '';
  31.   $_POST['compress'] = (isset($_REQUEST['compress'])) ? $_REQUEST['compress'] : false;
  32.   $strA = '';
  33.   $strB = '';
  34.   $compress_override = ((isset($_GET['comp']) && $_GET['comp']>0) || COMPRESS_OVERRIDE=='true') ? true : false;
  35.   if (isset($_GET['debug']) && ($_GET['debug']=='ON' || $_GET['debug']>0)) $debug='ON';
  36.   $skip_locks_requested = (isset($_REQUEST['skiplocks']) && $_REQUEST['skiplocks'] == 'yes');
  37.  
  38.  
  39. // check to see if open_basedir restrictions in effect -- if so, likely won't be able to use this tool.
  40.   $flag_basedir = false;
  41.   $open_basedir=@ini_get('open_basedir');
  42.   if ($open_basedir !='') {
  43.     $basedir_check_array = explode(':',$open_basedir);
  44.     foreach($basedir_check_array as $basedir_check) {
  45.       if (!strstr(DIR_FS_ADMIN,$basedir_check)) $flag_basedir=true;
  46.     }
  47.     if ($flag_basedir) $messageStack->add(ERROR_CANT_BACKUP_IN_SAFE_MODE, 'error');
  48.   }
  49. // check to see if "exec()" is disabled in PHP -- if so, won't be able to use this tool.
  50.   $exec_disabled = false;
  51.   $php_disabled_functions = @ini_get("disable_functions");
  52.   if ($php_disabled_functions != '') {
  53.     if ($debug=='ON') $messageStack->add('PHP-Disabled-functions: ' . $php_disabled_functions,'error');
  54.     if (in_array('exec', preg_split('/,/', str_replace(' ', '', $php_disabled_functions)))) {
  55.       $messageStack->add(ERROR_EXEC_DISABLED, 'error');
  56.       $exec_disabled = true;
  57.     }
  58.   }
  59.  
  60.  
  61. // Note that LOCAL_EXE_MYSQL and LOCAL_EXE_MYSQL_DUMP are defined in the /admin/includes/languages/backup_mysql.php file
  62. // These can occasionally be overridden in the URL by specifying &tool=/path/to/foo/bar/plus/utilname, depending on server support
  63. // Do not change them here ... edit the LANGUAGES file instead.
  64. // the following lines check to be sure that they've been entered correctly in the language file
  65.   $pathsearch=array(str_replace('mysql','',LOCAL_EXE_MYSQL).'/',str_replace('mysql.exe','',LOCAL_EXE_MYSQL).'/','/usr/bin/','/usr/local/bin/','/usr/local/mysql/bin/','c:/mysql/bin/','d:/mysql/bin/','e:/mysql/bin/', 'c:/apache2triad/mysql/bin/', 'd:/apache2triad/mysql/bin/', 'e:/apache2triad/mysql/bin/', 'c:/server/mysql/bin/', '\'c:/Program Files/MySQL/MySQL Server 5.0/bin/\'', '\'d:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\\\'', '\'c:/Program Files/MySQL/MySQL Server 4.1/bin/\'');
  66.   $pathsearch=array_merge($pathsearch,explode(':',$open_basedir));
  67.   $mysql_exe = 'unknown';
  68.   $mysqldump_exe = 'unknown';
  69.   foreach($pathsearch as $path){
  70. //      $path = str_replace('\\','/',$path); // convert backslashes
  71.     $path = str_replace('//','/',$path); // convert double slashes to singles
  72.     $path = str_replace("'","",$path); // remove ' marks if any
  73.     $path = (substr($path,-1)!='/' && substr($path,-1)!='\\') ? $path . '/' : $path; // add a '/' to the end if missing
  74.  
  75.     if ($mysql_exe == 'unknown') {
  76.       if (@file_exists($path.'mysql'))     $mysql_exe = $path.'mysql';
  77.       if (@file_exists($path.'mysql.exe')) $mysql_exe = $path.'mysql.exe';
  78.     }
  79.     if ($mysqldump_exe == 'unknown') {
  80.       if (@file_exists($path.'mysqldump'))     $mysqldump_exe = $path.'mysqldump';
  81.       if (@file_exists($path.'mysqldump.exe')) $mysqldump_exe = $path.'mysqldump.exe';
  82.     }
  83.     if ($debug=='ON') $messageStack->add_session('Checking Path: '.$path.'<br />','caution');
  84.     if ($mysql_exe != 'unknown' && $mysqldump_exe != 'unknown') break;
  85.   }
  86.  
  87.   if (!$mysqldump_exe){
  88.     $messageStack->add_session('警告: 没找到"mysqldump"库。不能执行数据库备份。<br />请在langauges/backup_mysql.php中设置MYSQLDUMP库的路径','error');
  89.     $mysqldump_exe = ((@file_exists($mysqldump_exe) ? $mysqldump_exe : 'mysqldump' ) );
  90.   }
  91.   if (!$mysql_exe){
  92.     $messageStack->add_session('警告: 没找"mysql"库。不能执行数据库恢复。<br />请在langauges/backup_mysql.php中设置MYSQL库的路径','error');
  93.     $mysql_exe =     ((@file_exists($mysql_exe) ? $mysql_exe : 'mysql' ) );
  94.   }
  95.   if ($mysql_exe == 'unknown') {
  96.     $mysql_exe = 'mysql';
  97.   }
  98.   if ($mysqldump_exe == 'unknown') {
  99.     $mysqldump_exe = 'mysqldump';
  100.   }
  101.  
  102.   $mysql_exe = '"'.$mysql_exe.'"';
  103.   $mysqldump_exe = '"'.$mysqldump_exe.'"';
  104.   if ($debug=='ON') $messageStack->add_session('<br />','caution');
  105.   if ($debug=='ON') $messageStack->add_session('COMMAND FILES SELECTED:','caution');
  106.   if ($debug=='ON') $messageStack->add_session('mysqlexe='.$mysql_exe.'<br />','caution');
  107.   if ($debug=='ON') $messageStack->add_session('mysqldumpexe='.$mysqldump_exe.'<br /><br />','caution');
  108.  
  109.   $action = (isset($_GET['action']) ? $_GET['action'] : '');
  110.  
  111.   if (zen_not_null($action)) {
  112.     switch ($action) {
  113.       case 'forget':
  114.         $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key = 'DB_LAST_RESTORE'");
  115.         $messageStack->add_session(SUCCESS_LAST_RESTORE_CLEARED, 'success');
  116.         zen_redirect(zen_href_link(FILENAME_BACKUP_MYSQL));
  117.         break;
  118.       case 'backupnow':
  119.         zen_set_time_limit(250);  // not sure if this is needed anymore?
  120.  
  121.         $backup_file = 'db_' . DB_DATABASE . '-' . ($tables_to_export != '' ? 'limited-' : '' ) . date('YmdHis') . '.sql';
  122.  
  123.         $dump_params .= ' "--host=' . DB_SERVER . '"';
  124.         $dump_params .= ' "--user=' . DB_SERVER_USERNAME . '"';
  125.         $dump_params .= ' "--password=' . DB_SERVER_PASSWORD . '"';
  126.         $dump_params .= ' --opt';   //"optimized" -- turns on all "fast" and optimized export methods
  127.         $dump_params .= ' --complete-insert';  // undo optimization slightly and do "complete inserts"--lists all column names for benefit of restore of diff systems
  128.         if ($skip_locks_requested) {
  129.           $dump_params .= ' --skip-lock-tables --skip-add-locks';     //use this if your host prevents you from locking tables for backup
  130.         }
  131. //        $dump_params .= ' --skip-comments'; // mysqldump inserts '--' as comment delimiters, which is invalid on import (only for mysql v4.01+)
  132. //        $dump_params .= ' --skip-quote-names';
  133. //        $dump_params .= ' --force';  // ignore SQL errors if they occur
  134. //        $dump_params .= ' --compatible=postgresql'; // other options are: ,mysql323, mysql40
  135.         $dump_params .= ' "--result-file=' . DIR_FS_BACKUP . $backup_file . '"';
  136.         $dump_params .= ' ' . DB_DATABASE;
  137.  
  138.         // if using the "--tables" parameter, this should be the last parameter, and tables should be space-delimited
  139.         // fill $tables_to_export with list of tables, separated by spaces, if wanna just export certain tables
  140.         $dump_params .= (($tables_to_export=='') ? '' : ' --tables ' . $tables_to_export);
  141.         $dump_params .= " 2>&1";
  142.  
  143.         $toolfilename = (isset($_GET['tool']) && $_GET['tool'] != '') ? $_GET['tool'] : $mysqldump_exe;
  144.  
  145.         // remove " marks in parameters for friendlier IIS support
  146. //REQUIRES TESTING:        if (strstr($toolfilename,'.exe')) $dump_params = str_replace('"','',$dump_params);
  147.  
  148.         if ($debug=='ON') $messageStack->add_session('COMMAND: '.OS_DELIM.$toolfilename . ' ' . $dump_params.OS_DELIM, 'caution');
  149.  
  150.  
  151.         $resultcodes = @exec(OS_DELIM . $toolfilename . $dump_params . OS_DELIM, $output, $dump_results );
  152.         @exec("exit(0)");
  153.         if ($dump_results == -1) $messageStack->add_session(FAILURE_BACKUP_FAILED_CHECK_PERMISSIONS . '<br />The command being run is: ' . $toolfilename . str_replace('--password='.DB_SERVER_PASSWORD,'--password=*****', str_replace('2>&1','',$dump_params)), 'error');
  154.         if ($debug=='ON' || (zen_not_null($dump_results) && $dump_results!='0')) $messageStack->add_session('Result code: '.$dump_results, 'caution');
  155.  
  156.         #parse the value that comes back from the script
  157.         if (zen_not_null($resultcodes)) list($strA, $strB) = preg_split ('/[|]/', $resultcodes);
  158.         if ($debug=='ON') $messageStack->add_session("valueA: " . $strA,'error');
  159.         if ($debug=='ON') $messageStack->add_session("valueB: " . $strB,'error');
  160.  
  161.         //$output contains response strings from execution. This displays if needed.
  162.         foreach($output as $key=>$value) {$messageStack->add_session("$key => $value<br />",'caution'); }
  163.  
  164.         if (file_exists(DIR_FS_BACKUP . $backup_file) && ($dump_results == '0' || $dump_results=='')) { // display success message noting that MYSQLDUMP was used
  165.           $messageStack->add_session('<a href="' . ((ENABLE_SSL_ADMIN == 'true') ? DIR_WS_HTTPS_ADMIN : DIR_WS_ADMIN) . 'backups/' . $backup_file . '">' . SUCCESS_DATABASE_SAVED . '</a>', 'success');
  166.         } elseif ($dump_results=='127') {
  167.           $messageStack->add_session(FAILURE_DATABASE_NOT_SAVED_UTIL_NOT_FOUND, 'error');
  168.         } elseif (stristr($strA, 'Access denied') && stristr($strA, 'LOCK TABLES') ) {
  169.           unlink(DIR_FS_BACKUP . $backup_file);
  170.           zen_redirect(zen_href_link(FILENAME_BACKUP_MYSQL, 'action=backupnow'.(($debug=='ON')?'&debug=ON':'') . (($_POST['compress']!=false)?'&compress='.$_POST['compress']:'') . (($tables_to_export!='')?'&tables='.str_replace(' ',',',$tables_to_export):'') . '&skiplocks=yes'));
  171.         } else {
  172.           $messageStack->add_session(FAILURE_DATABASE_NOT_SAVED, 'error');
  173.         }
  174.  
  175.         //compress the file as requested & optionally download
  176.         if (isset($_POST['download']) && ($_POST['download'] == 'yes') && file_exists(DIR_FS_BACKUP . $backup_file) ) {
  177.           switch ($_POST['compress']) {
  178.             case 'gzip':
  179.               @exec(LOCAL_EXE_GZIP . ' ' . DIR_FS_BACKUP . $backup_file);
  180.               $backup_file .= '.gz';
  181.               break;
  182.             case 'zip':
  183.               @exec(LOCAL_EXE_ZIP . ' -j ' . DIR_FS_BACKUP . $backup_file . '.zip ' . DIR_FS_BACKUP . $backup_file);
  184.               if (file_exists(DIR_FS_BACKUP . $backup_file) && file_exists(DIR_FS_BACKUP . $backup_file . 'zip')) unlink(DIR_FS_BACKUP . $backup_file);
  185.               $backup_file .= '.zip';
  186.           }
  187.       if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) {
  188.             header('Content-Type: application/octetstream');
  189. //            header('Content-Disposition: inline; filename="' . $backup_file . '"');
  190.             header('Content-Disposition: attachment; filename=' . $backup_file);
  191.             header("Expires: Mon, 26 Jul 2001 05:00:00 GMT");
  192.             header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  193.             header("Cache-Control: must_revalidate, post-check=0, pre-check=0");
  194.             header("Pragma: public");
  195.             header("Cache-control: private");
  196.       } else {
  197.             header('Content-Type: application/x-octet-stream');
  198.             header('Content-Disposition: attachment; filename=' . $backup_file);
  199.             header("Expires: Mon, 26 Jul 2001 05:00:00 GMT");
  200.             header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  201.             header("Pragma: no-cache");
  202.       }
  203.  
  204.           readfile(DIR_FS_BACKUP . $backup_file);
  205.           unlink(DIR_FS_BACKUP . $backup_file);
  206.  
  207.           exit;
  208.         } else {
  209.           switch ($_POST['compress'] && file_exists(DIR_FS_BACKUP . $backup_file)) {
  210.             case 'gzip':
  211.               @exec(LOCAL_EXE_GZIP . ' ' . DIR_FS_BACKUP . $backup_file);
  212.               if (file_exists(DIR_FS_BACKUP . $backup_file)) @exec('gzip ' . DIR_FS_BACKUP . $backup_file);
  213.               break;
  214.             case 'zip':
  215.               @exec(LOCAL_EXE_ZIP . ' -j ' . DIR_FS_BACKUP . $backup_file . '.zip ' . DIR_FS_BACKUP . $backup_file);
  216.               if (file_exists(DIR_FS_BACKUP . $backup_file) && file_exists(DIR_FS_BACKUP . $backup_file . 'zip')) unlink(DIR_FS_BACKUP . $backup_file);
  217.           }
  218.         }
  219.         zen_redirect(zen_href_link(FILENAME_BACKUP_MYSQL));
  220.         break;
  221.       case 'restorenow':
  222.       case 'restorelocalnow':
  223.         zen_set_time_limit(300);
  224.           $specified_restore_file = (isset($_GET['file'])) ? $_GET['file'] : '';
  225.  
  226.           if ($specified_restore_file !='' && file_exists(DIR_FS_BACKUP . $specified_restore_file)) {
  227.             $restore_file = DIR_FS_BACKUP . $specified_restore_file;
  228.             $extension = substr($specified_restore_file, -3);
  229.  
  230.             //determine file format and unzip if needed
  231.             if ( ($extension == 'sql') || ($extension == '.gz') || ($extension == 'zip') ) {
  232.               switch ($extension) {
  233.                 case 'sql':
  234.                   $restore_from = $restore_file;
  235.                   $remove_raw = false;
  236.                   break;
  237.                 case '.gz':
  238.                   $restore_from = substr($restore_file, 0, -3);
  239.                   exec(LOCAL_EXE_GUNZIP . ' ' . $restore_file . ' -c > ' . $restore_from);
  240.                   $remove_raw = true;
  241.                   break;
  242.                 case 'zip':
  243.                   $restore_from = substr($restore_file, 0, -4);
  244.                   exec(LOCAL_EXE_UNZIP . ' ' . $restore_file . ' -d ' . DIR_FS_BACKUP);
  245.                   $remove_raw = true;
  246.               }
  247.             }
  248.         } elseif ($action == 'restorelocalnow') {
  249.             $sql_file = new upload('sql_file', DIR_FS_BACKUP);
  250.             $specified_restore_file = $sql_file->filename;
  251.             $restore_from = DIR_FS_BACKUP . $specified_restore_file;
  252.         }
  253.  
  254.         //Restore using "mysql"
  255.         $load_params  = ' "--database=' . DB_DATABASE . '"';
  256.         $load_params .= ' "--host=' . DB_SERVER . '"';
  257.         $load_params .= ' "--user=' . DB_SERVER_USERNAME . '"';
  258.         $load_params .= ((DB_SERVER_PASSWORD =='') ? '' : ' "--password=' . DB_SERVER_PASSWORD . '"');
  259.         $load_params .= ' ' . DB_DATABASE; // this needs to be the 2nd-last parameter
  260.         $load_params .= ' < "' . $restore_from . '"'; // this needs to be the LAST parameter
  261.         $load_params .= " 2>&1";
  262.         //DEBUG echo $mysql_exe . ' ' . $load_params;
  263.  
  264.         if (file_exists($restore_from) && $specified_restore_file != '') {
  265.           $toolfilename = (isset($_GET['tool']) && $_GET['tool'] != '') ? $_GET['tool'] : $mysql_exe;
  266.  
  267.           // remove " marks in parameters for friendlier IIS support
  268. //REQUIRES TESTING:          if (strstr($toolfilename,'.exe')) $load_params = str_replace('"','',$load_params);
  269.  
  270.           if ($debug=='ON') $messageStack->add_session('COMMAND: '.OS_DELIM.$toolfilename . ' ' . $load_params.OS_DELIM, 'caution');
  271.  
  272.           $resultcodes=exec(OS_DELIM . $toolfilename . $load_params . OS_DELIM, $output, $load_results );
  273.           exec("exit(0)");
  274.           #parse the value that comes back from the script
  275.           list($strA, $strB) = preg_split ('/[|]/', $resultcodes);
  276.           if ($debug=='ON') $messageStack->add_session("valueA: " . $strA,'error');
  277.           if ($debug=='ON') $messageStack->add_session("valueB: " . $strB,'error');
  278.           if ($debug=='ON' || (zen_not_null($load_results) && $load_results!='0')) $messageStack->add_session('Result code: '.$load_results, 'caution');
  279.  
  280.           if ($load_results == '0') {
  281.             // store the last-restore-date, if successful
  282.             $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key = 'DB_LAST_RESTORE'");
  283.             $db->Execute("insert into " . TABLE_CONFIGURATION . " values ('', 'Last Database Restore', 'DB_LAST_RESTORE', '" . $specified_restore_file . "', 'Last database restore file', '6', '', '', now(), '', '')");
  284.             $messageStack->add_session('<a href="' . ((ENABLE_SSL_ADMIN == 'true') ? DIR_WS_HTTPS_ADMIN : DIR_WS_ADMIN) . 'backups/' . $specified_restore_file . '">' . SUCCESS_DATABASE_RESTORED . '</a>', 'success');
  285.             } elseif ($load_results == '127') {
  286.             $messageStack->add_session(FAILURE_DATABASE_NOT_RESTORED_UTIL_NOT_FOUND, 'error');
  287.             } else {
  288.             $messageStack->add_session(FAILURE_DATABASE_NOT_RESTORED, 'error');
  289.             } // endif $load_results
  290.           } else {
  291.           $messageStack->add_session(sprintf(FAILURE_DATABASE_NOT_RESTORED_FILE_NOT_FOUND, '[' . $restore_from .']'), 'error');
  292.           } // endif file_exists
  293.  
  294.         zen_redirect(zen_href_link(FILENAME_BACKUP_MYSQL));
  295.         break;
  296.       case 'download':
  297.         $extension = substr($_GET['file'], -3);
  298.  
  299.         if ( ($extension == 'zip') || ($extension == '.gz') || ($extension == 'sql') ) {
  300.           if ($fp = fopen(DIR_FS_BACKUP . $_GET['file'], 'rb')) {
  301.             $buffer = fread($fp, filesize(DIR_FS_BACKUP . $_GET['file']));
  302.             fclose($fp);
  303.  
  304.             header('Content-type: application/x-octet-stream');
  305.             header('Content-disposition: attachment; filename=' . $_GET['file']);
  306.  
  307.             echo $buffer;
  308.  
  309.             exit;
  310.           }
  311.         } else {
  312.           $messageStack->add(ERROR_DOWNLOAD_LINK_NOT_ACCEPTABLE, 'error');
  313.         }
  314.         break;
  315.       case 'deleteconfirm':
  316.         if (strstr($_GET['file'], '..')) zen_redirect(zen_href_link(FILENAME_BACKUP_MYSQL));
  317.  
  318.         $zremove_error = zen_remove(DIR_FS_BACKUP . '/' . $_GET['file']);
  319.         // backwards compatibility:
  320.         if (isset($zen_remove_error) && $zen_remove_error == true) $zremove_error = $zen_remove_error;
  321.  
  322.         if (!$zremove_error) {
  323.           $messageStack->add_session(SUCCESS_BACKUP_DELETED, 'success');
  324.  
  325.           zen_redirect(zen_href_link(FILENAME_BACKUP_MYSQL));
  326.         }
  327.         break;
  328.     }
  329.   }
  330.  
  331. // check if the backup directory exists
  332.   $dir_ok = false;
  333.   if (is_dir(DIR_FS_BACKUP)) {
  334.     if (is_writable(DIR_FS_BACKUP)) {
  335.       $dir_ok = true;
  336.     } else {
  337.       $messageStack->add(ERROR_BACKUP_DIRECTORY_NOT_WRITEABLE, 'error');
  338.     }
  339.   } else {
  340.     $messageStack->add(ERROR_BACKUP_DIRECTORY_DOES_NOT_EXIST, 'error');
  341.   }
  342.  
  343.  
  344. ?>
  345. <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
  346. <html <?php echo HTML_PARAMS; ?>>
  347. <head>
  348. <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
  349. <title><?php echo TITLE; ?></title>
  350. <link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
  351. <link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS">
  352. <script language="javascript" src="includes/menu.js"></script>
  353. <script language="javascript" src="includes/general.js"></script>
  354. <script type="text/javascript">
  355.   <!--
  356.   function init()
  357.   {
  358.     cssjsmenu('navbar');
  359.     if (document.getElementById)
  360.     {
  361.       var kill = document.getElementById('hoverJS');
  362.       kill.disabled = true;
  363.     }
  364.   }
  365.   // -->
  366. </script>
  367. </head>
  368. <body onLoad="init()">
  369. <!-- header //-->
  370. <?php require(DIR_WS_INCLUDES . 'header.php'); ?>
  371. <!-- header_eof //-->
  372.  
  373. <!-- body //-->
  374. <table border="0" width="100%" cellspacing="2" cellpadding="2">
  375.   <tr>
  376. <!-- body_text //-->
  377.     <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
  378.       <tr>
  379.         <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
  380.           <tr>
  381.             <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
  382.             <td class="pageHeading" align="right"><?php echo zen_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
  383.           </tr>
  384. <?php if (substr(HTTP_SERVER, 0, 5) != 'https') {  // display security warning about downloads if not SSL ?>
  385.           <tr>
  386.             <td class="main"><?php echo WARNING_NOT_SECURE_FOR_DOWNLOADS; ?></td>
  387.             <td class="main" align="right"><?php echo zen_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
  388.           </tr>
  389. <?php } ?>
  390.         </table></td>
  391.       </tr>
  392.       <tr>
  393.         <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
  394.           <tr>
  395.             <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
  396.               <tr class="dataTableHeadingRow">
  397.                 <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_TITLE; ?></td>
  398.                 <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_FILE_DATE; ?></td>
  399.                 <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_FILE_SIZE; ?></td>
  400.                 <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
  401.               </tr>
  402. <?php
  403. //  if (!get_cfg_var('safe_mode') && $dir_ok == true) {
  404.     $dir = dir(DIR_FS_BACKUP);
  405.     $contents = array();
  406.     while ($file = $dir->read()) {
  407.       if (!is_dir(DIR_FS_BACKUP . $file)) {
  408.         if (substr($file,0,1) != '.' && !in_array($file, array('empty.txt', 'index.php', 'index.htm', 'index.html'))) {
  409.           $contents[] = $file;
  410.         }
  411.       }
  412.     }
  413.     sort($contents);
  414.     for ($i=0, $n=sizeof($contents); $i<$n; $i++) {
  415.       $entry = $contents[$i];
  416.       $check = 0;
  417.  
  418.       if ((!isset($_GET['file']) || (isset($_GET['file']) && ($_GET['file'] == $entry))) && !isset($buInfo) && ($action != 'backup') && ($action != 'restorelocal')) {
  419.         $file_array['file'] = $entry;
  420.         $file_array['date'] = date(PHP_DATE_TIME_FORMAT, filemtime(DIR_FS_BACKUP . $entry));
  421.         $file_array['size'] = number_format(filesize(DIR_FS_BACKUP . $entry)) . ' bytes';
  422.         switch (substr($entry, -3)) {
  423.           case 'zip': $file_array['compression'] = 'ZIP'; break;
  424.           case '.gz': $file_array['compression'] = 'GZIP'; break;
  425.           default: $file_array['compression'] = TEXT_NO_EXTENSION; break;
  426.         }
  427.  
  428.         $buInfo = new objectInfo($file_array);
  429.       }
  430.  
  431.       if (isset($buInfo) && is_object($buInfo) && ($entry == $buInfo->file)) {
  432.         echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)">' . "\n";
  433.         $onclick_link = 'file=' . $buInfo->file . '&action=restore';
  434.       } else {
  435.         echo '              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)">' . "\n";
  436.         $onclick_link = 'file=' . $entry;
  437.       }
  438. ?>
  439. <!--                 <td class="dataTableContent" onclick="document.location.href='<?php echo zen_href_link(FILENAME_BACKUP_MYSQL, $onclick_link); ?>'"><?php echo '<a href="' . zen_href_link(FILENAME_BACKUP_MYSQL, 'action=download&file=' . $entry) . '">' . zen_image(DIR_WS_ICONS . 'file_download.gif', ICON_FILE_DOWNLOAD) . '</a>&nbsp;' . $entry; ?></td> -->
  440.                 <td class="dataTableContent" onClick="document.location.href='<?php echo zen_href_link(FILENAME_BACKUP_MYSQL, $onclick_link); ?>'"><?php echo '<a href="' . ((ENABLE_SSL_ADMIN == 'true') ? DIR_WS_HTTPS_ADMIN : DIR_WS_ADMIN) . 'backups/' . $entry . '">' . zen_image(DIR_WS_ICONS . 'file_download.gif', ICON_FILE_DOWNLOAD) . '</a>&nbsp;' . $entry; ?></td>
  441.                 <td class="dataTableContent" align="center" onClick="document.location.href='<?php echo zen_href_link(FILENAME_BACKUP_MYSQL, $onclick_link); ?>'"><?php echo date(PHP_DATE_TIME_FORMAT, filemtime(DIR_FS_BACKUP . $entry)); ?></td>
  442.                 <td class="dataTableContent" align="right" onClick="document.location.href='<?php echo zen_href_link(FILENAME_BACKUP_MYSQL, $onclick_link); ?>'"><?php echo number_format(filesize(DIR_FS_BACKUP . $entry)); ?> bytes</td>
  443.                 <td class="dataTableContent" align="right"><?php if (isset($buInfo) && is_object($buInfo) && ($entry == $buInfo->file)) { echo zen_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . zen_href_link(FILENAME_BACKUP_MYSQL, 'file=' . $entry) . '">' . zen_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
  444.               </tr>
  445. <?php
  446.     }
  447.     $dir->close();
  448. //  } // endif safe-mode & dir_ok
  449.  
  450. // now let's display the backup/restore buttons below filelist
  451. ?>
  452.               <tr>
  453.                 <td class="smallText" colspan="3"><?php echo TEXT_BACKUP_DIRECTORY . ' ' . DIR_FS_BACKUP; ?></td>
  454.                 <td align="right" class="smallText">
  455.                     <?php if ( ($action != 'backup') && (isset($dir)) && !ini_get('safe_mode') && $dir_ok == true ) {
  456.                              echo '<a href="' . zen_href_link(FILENAME_BACKUP_MYSQL, 'action=backup'.(($debug=='ON')?'&debug=ON':'')) . (($tables_to_export!='')?'&tables='.str_replace(' ',',',$tables_to_export):'') . '">' .
  457.                                    zen_image_button('button_backup.gif', IMAGE_BACKUP) . '</a>&nbsp;&nbsp;';
  458.                           }
  459.                           if ( ($action != 'restorelocal') && isset($dir) ) {
  460.                              echo '<a href="' . zen_href_link(FILENAME_BACKUP_MYSQL, 'action=restorelocal'.(($debug=='ON')?'&debug=ON':'')) . '">' .
  461.                                    zen_image_button('button_restore.gif', IMAGE_RESTORE) . '</a>';
  462.                           } ?>
  463.                 </td>
  464.               </tr>
  465. <?php
  466.   if (defined('DB_LAST_RESTORE')) {
  467. ?>
  468.               <tr>
  469.                 <td class="smallText" colspan="4"><?php echo TEXT_LAST_RESTORATION . ' ' . DB_LAST_RESTORE . ' <a href="' . zen_href_link(FILENAME_BACKUP_MYSQL, 'action=forget') . '">' . TEXT_FORGET . '</a>'; ?></td>
  470.               </tr>
  471. <?php
  472.   }
  473. ?>
  474.             </table></td>
  475. <?php
  476.   $heading = array();
  477.   $contents = array();
  478.  
  479.   switch ($action) {
  480.     case 'backup':
  481.       $heading[] = array('text' => '<strong>' . TEXT_INFO_HEADING_NEW_BACKUP . '</strong>');
  482.  
  483.       $contents = array('form' => zen_draw_form('backup', FILENAME_BACKUP_MYSQL, 'action=backupnow'.(($debug=='ON')?'&debug=ON':''). (($tables_to_export!='')?'&tables='.str_replace(' ',',',$tables_to_export):'')));
  484.       $contents[] = array('text' => TEXT_INFO_NEW_BACKUP);
  485.  
  486.       $contents[] = array('text' => '<br />' . zen_draw_radio_field('compress', 'no', (!@file_exists(LOCAL_EXE_GZIP) && !$compress_override ? true : false)) . ' ' . TEXT_INFO_USE_NO_COMPRESSION);
  487.       if (@file_exists(LOCAL_EXE_GZIP) || $compress_override) $contents[] = array('text' => '<br />' . zen_draw_radio_field('compress', 'gzip', true) . ' ' . TEXT_INFO_USE_GZIP);
  488.       if (@file_exists(LOCAL_EXE_ZIP)) $contents[] = array('text' => zen_draw_radio_field('compress', 'zip',(!@file_exists(LOCAL_EXE_GZIP) ? true : false)) . ' ' . TEXT_INFO_USE_ZIP);
  489.       $contents[] = array('text' => '<br />' . zen_draw_radio_field('skiplocks', 'yes', false) . ' ' . TEXT_INFO_SKIP_LOCKS);
  490.  
  491.  
  492.       // Download to file --- Should only be done if SSL is active, otherwise database is exposed as clear text
  493.       if ($dir_ok == true) {
  494.         $contents[] = array('text' => '<br />' . zen_draw_checkbox_field('download', 'yes') . ' ' . TEXT_INFO_DOWNLOAD_ONLY . '*<br /><span class="errorText">*' . TEXT_INFO_BEST_THROUGH_HTTPS . '</span>');
  495.       } else {
  496.         $contents[] = array('text' => '<br />' . zen_draw_radio_field('download', 'yes', true) . ' ' . TEXT_INFO_DOWNLOAD_ONLY . '*<br /><span class="errorText">*' . TEXT_INFO_BEST_THROUGH_HTTPS . '</span>');
  497.       }
  498.  
  499.       // display backup button
  500.       $contents[] = array('align' => 'center', 'text' => '<br />' . zen_image_submit('button_backup.gif', IMAGE_BACKUP) . '&nbsp;<a href="' . zen_href_link(FILENAME_BACKUP_MYSQL,(($debug=='ON')?'debug=ON':'')) . (($tables_to_export!='')?'&tables='.str_replace(' ',',',$tables_to_export):''). '">' . zen_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
  501.       break;
  502.     case 'restore':
  503.       $heading[] = array('text' => '<strong>' . $buInfo->date . '</strong>');
  504.  
  505.       $contents[] = array('text' => zen_break_string(sprintf(TEXT_INFO_RESTORE, DIR_FS_BACKUP . (($buInfo->compression != TEXT_NO_EXTENSION) ? substr($buInfo->file, 0, strrpos($buInfo->file, '.')) : $buInfo->file), ($buInfo->compression != TEXT_NO_EXTENSION) ? TEXT_INFO_UNPACK : ''), 35, ' '));
  506.       $contents[] = array('align' => 'center', 'text' => '<br /><a href="' . zen_href_link(FILENAME_BACKUP_MYSQL, 'file=' . $buInfo->file . '&action=restorenow'.(($debug=='ON')?'&debug=ON':'')) . '">' . zen_image_button('button_restore.gif', IMAGE_RESTORE) . '</a>&nbsp;<a href="' . zen_href_link(FILENAME_BACKUP_MYSQL, 'file=' . $buInfo->file.(($debug=='ON')?'&debug=ON':'')) . '">' . zen_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
  507.       break;
  508.     case 'restorelocal':
  509.       $heading[] = array('text' => '<strong>' . TEXT_INFO_HEADING_RESTORE_LOCAL . '</strong>');
  510.  
  511.       $contents = array('form' => zen_draw_form('restore', FILENAME_BACKUP_MYSQL, 'action=restorelocalnow'.(($debug=='ON')?'&debug=ON':''), 'post', 'enctype="multipart/form-data"'));
  512.       $contents[] = array('text' => TEXT_INFO_RESTORE_LOCAL . '<br /><br />' . TEXT_INFO_BEST_THROUGH_HTTPS);
  513.       $contents[] = array('text' => '<br />' . zen_draw_file_field('sql_file'));
  514.       $contents[] = array('text' => TEXT_INFO_RESTORE_LOCAL_RAW_FILE);
  515.       $contents[] = array('align' => 'center', 'text' => '<br />' . zen_image_submit('button_restore.gif', IMAGE_RESTORE) . '&nbsp;<a href="' . zen_href_link(FILENAME_BACKUP_MYSQL,(($debug=='ON')?'debug=ON':'')) . '">' . zen_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
  516.       break;
  517.     case 'delete':
  518.       if ($dir_ok == false) continue;
  519.       $heading[] = array('text' => '<strong>' . $buInfo->date . '</strong>');
  520.  
  521.       $contents = array('form' => zen_draw_form('delete', FILENAME_BACKUP_MYSQL, 'file=' . $buInfo->file . '&action=deleteconfirm'));
  522.       $contents[] = array('text' => TEXT_DELETE_INTRO);
  523.       $contents[] = array('text' => '<br /><strong>' . $buInfo->file . '</strong>');
  524.       $contents[] = array('align' => 'center', 'text' => '<br />' . zen_image_submit('button_delete.gif', IMAGE_DELETE) . ' <a href="' . zen_href_link(FILENAME_BACKUP_MYSQL, 'file=' . $buInfo->file) . '">' . zen_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
  525.       break;
  526.     default:
  527.       if (isset($buInfo) && is_object($buInfo)) {
  528.         $heading[] = array('text' => '<strong>' . $buInfo->date . '</strong>');
  529.  
  530.         $contents[] = array('align' => 'center',
  531.                             'text' => '<a href="' . zen_href_link(FILENAME_BACKUP_MYSQL, 'file=' . $buInfo->file . '&action=restore'.(($debug=='ON')?'&debug=ON':'')) . '">' .
  532.                                                     zen_image_button('button_restore.gif', IMAGE_RESTORE) . '</a> ' .
  533.                                       (($dir_ok==true && $exec_disabled==false) ? '<a href="' . zen_href_link(FILENAME_BACKUP_MYSQL, 'file=' . $buInfo->file . '&action=delete') . '">' .
  534.                                                     zen_image_button('button_delete.gif', IMAGE_DELETE) . '</a>' : '' ) );
  535.         $contents[] = array('text' => '<br />' . TEXT_INFO_DATE . ' ' . $buInfo->date);
  536.         $contents[] = array('text' => TEXT_INFO_SIZE . ' ' . $buInfo->size);
  537.         $contents[] = array('text' => '<br />' . TEXT_INFO_COMPRESSION . ' ' . $buInfo->compression);
  538.       }
  539.       break;
  540.   }
  541.  
  542.   if ( (zen_not_null($heading)) && (zen_not_null($contents)) ) {
  543.     echo '            <td width="25%" valign="top">' . "\n";
  544.  
  545.     $box = new box;
  546.     echo $box->infoBox($heading, $contents);
  547.  
  548.     echo '            </td>' . "\n";
  549.   }
  550. ?>
  551.           </tr>
  552.         </table></td>
  553.       </tr>
  554.     </table></td>
  555. <!-- body_text_eof //-->
  556.   </tr>
  557. </table>
  558. <!-- body_eof //-->
  559.  
  560. <!-- footer //-->
  561. <?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
  562. <!-- footer_eof //-->
  563. <br />
  564. </body>
  565. </html>
  566. <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>


cron