home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Plugins / wp-dbmanager / dbmanager / database-backup.php next >
PHP Script  |  2008-02-19  |  10KB  |  200 lines

  1. <?php
  2. /*
  3. +----------------------------------------------------------------+
  4. |                                                                                            |
  5. |    WordPress 2.1 Plugin: WP-DBManager 2.20                                |
  6. |    Copyright (c) 2007 Lester "GaMerZ" Chan                                    |
  7. |                                                                                            |
  8. |    File Written By:                                                                    |
  9. |    - Lester "GaMerZ" Chan                                                            |
  10. |    - http://lesterchan.net                                                            |
  11. |                                                                                            |
  12. |    File Information:                                                                    |
  13. |    - Database Backup                                                                |
  14. |    - wp-content/plugins/dbmanager/database-backup.php                |
  15. |                                                                                            |
  16. +----------------------------------------------------------------+
  17. */
  18.  
  19.  
  20. ### Check Whether User Can Manage Database
  21. if(!current_user_can('manage_database')) {
  22.     die('Access Denied');
  23. }
  24.  
  25.  
  26. ### Variables Variables Variables
  27. $base_name = plugin_basename('dbmanager/database-manager.php');
  28. $base_page = 'admin.php?page='.$base_name;
  29. $current_date = gmdate(sprintf(__('%s @ %s', 'wp-dbmanager'), get_option('date_format'), get_option('time_format')), (time() + (get_option('gmt_offset') * 3600)));
  30. $backup = array();
  31. $backup_options = get_option('dbmanager_options');
  32. $backup['date'] = current_time('timestamp');
  33. $backup['mysqldumppath'] = $backup_options['mysqldumppath'];
  34. $backup['mysqlpath'] = $backup_options['mysqlpath'];
  35. $backup['path'] = $backup_options['path'];
  36.  
  37.  
  38. ### Form Processing 
  39. if($_POST['do']) {
  40.     // Decide What To Do
  41.     switch($_POST['do']) {
  42.         case __('Backup', 'wp-dbmanager'):
  43.             $gzip = intval($_POST['gzip']);
  44.             if($gzip == 1) {
  45.                 $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql.gz';
  46.                 $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
  47.                 $backup['command'] = $backup['mysqldumppath'].' --host="'.DB_HOST.'" --user="'.DB_USER.'" --password="'.DB_PASSWORD.'" --add-drop-table --skip-lock-tables '.DB_NAME.' | gzip > '.$backup['filepath'];
  48.             } else {
  49.                 $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
  50.                 $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
  51.                 $backup['command'] = $backup['mysqldumppath'].' --host="'.DB_HOST.'" --user="'.DB_USER.'" --password="'.DB_PASSWORD.'" --add-drop-table --skip-lock-tables '.DB_NAME.' > '.$backup['filepath'];
  52.             }
  53.             check_backup_files();
  54.             passthru($backup['command'], $error);
  55.             if(!is_writable($backup['path'])) {
  56.                 $text = '<font color="red">'.sprintf(__('Database Failed To Backup On \'%s\'. Backup Folder Not Writable.', 'wp-dbmanager'), $current_date).'</font>';
  57.             } elseif(filesize($backup['filepath']) == 0) {
  58.                 unlink($backup['filepath']);
  59.                 $text = '<font color="red">'.sprintf(__('Database Failed To Backup On \'%s\'. Backup File Size Is 0KB.', 'wp-dbmanager'), $current_date).'</font>';
  60.             } elseif(!is_file($backup['filepath'])) {
  61.                 $text = '<font color="red">'.sprintf(__('Database Failed To Backup On \'%s\'. Invalid Backup File Path.', 'wp-dbmanager'), $current_date).'</font>';
  62.             } elseif($error) {
  63.                 $text = '<font color="red">'.sprintf(__('Database Failed To Backup On \'%s\'.', 'wp-dbmanager'), $current_date).'</font>';
  64.             } else {
  65.                 $text = '<font color="green">'.sprintf(__('Database Backed Up Successfully On \'%s\'.', 'wp-dbmanager'), $current_date).'</font>';
  66.             }
  67.             break;
  68.     }
  69. }
  70.  
  71.  
  72. ### Backup File Name
  73. $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
  74.  
  75.  
  76. ### MYSQL Base Dir
  77. $status_count = 0;
  78. $stats_function_disabled = 0;
  79. ?>
  80. <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
  81. <!-- Checking Backup Status -->
  82. <div class="wrap">
  83.     <h2><?php _e('Checking Backup Status', 'wp-dbmanager'); ?></h2>
  84.     <p>
  85.         <?php _e('Checking Backup Folder', 'wp-dbmanager'); ?> (<strong><?php echo stripslashes($backup['path']); ?></strong>) ...<br />
  86.         <?php
  87.             if(is_dir(stripslashes($backup['path']))) {
  88.                 echo '<font color="green">'.__('Backup folder exists', 'wp-dbmanager').'</font><br />';
  89.                 $status_count++;
  90.             } else {
  91.                 echo '<font color="red">'.__('Backup folder does NOT exist. Please create \'backup-db\' folder in \'wp-content\' folder and CHMOD it to \'777\' or change the location of the backup folder under DB Option.', 'wp-dbmanager').'</font><br />';
  92.             }
  93.             if(is_writable(stripslashes($backup['path']))) {
  94.                 echo '<font color="green">'.__('Backup folder is writable', 'wp-dbmanager').'</font>';
  95.                 $status_count++;
  96.             } else {
  97.                 echo '<font color="red">'.__('Backup folder is NOT writable. Please CHMOD it to \'777\'.', 'wp-dbmanager').'</font>';
  98.             }
  99.         ?>
  100.     </p>
  101.     <p>        
  102.         <?php            
  103.             if(file_exists(stripslashes($backup['mysqldumppath']))) {
  104.                 echo __('Checking MYSQL Dump Path', 'wp-dbmanager').' (<strong>'.stripslashes($backup['mysqldumppath']).'</strong>) ...<br />';
  105.                 echo '<font color="green">'.__('MYSQL dump path exists.', 'wp-dbmanager').'</font>';
  106.                 $status_count++;
  107.             } else {
  108.                 echo __('Checking MYSQL Dump Path', 'wp-dbmanager').' ...<br />';
  109.                 echo '<font color="red">'.__('MYSQL dump path does NOT exist. Please check your mysqldump path under DB Options. If uncertain, contact your server administrator.', 'wp-dbmanager').'</font>';
  110.             }
  111.         ?>
  112.     </p>
  113.     <p>
  114.         <?php
  115.             if(file_exists(stripslashes($backup['mysqlpath']))) {
  116.                 echo __('Checking MYSQL Path', 'wp-dbmanager').' (<strong>'.stripslashes($backup['mysqlpath']).'</strong>) ...<br />';
  117.                 echo '<font color="green">'.__('MYSQL path exists.', 'wp-dbmanager').'</font>';
  118.                 $status_count++;
  119.             } else {
  120.                 echo __('Checking MYSQL Path', 'wp-dbmanager').' ...<br />';
  121.                 echo '<font color="red">'.__('MYSQL path does NOT exist. Please check your mysql path under DB Options. If uncertain, contact your server administrator.', 'wp-dbmanager').'</font>';
  122.             }
  123.         ?>
  124.     </p>
  125.     <p>
  126.         <?php _e('Checking PHP Functions', 'wp-dbmanager'); ?> (<strong>passthru()</strong>, <strong>system()</strong> <?php _e('and', 'wp-dbmanager'); ?> <strong>exec()</strong>) ...<br />
  127.         <?php
  128.             if(function_exists('passthru')) {
  129.                 echo '<font color="green">passthru() '.__('enabled', 'wp-dbmanager').'.</font><br />';
  130.                 $status_count++;
  131.             } else {
  132.                 echo '<font color="red">passthru() '.__('disabled', 'wp-dbmanager').'.</font><br />';
  133.                 $stats_function_disabled++;
  134.             }
  135.             if(function_exists('system')) {
  136.                 echo '<font color="green">system() '.__('enabled', 'wp-dbmanager').'.</font><br />';
  137.             } else {
  138.                 echo '<font color="red">system() '.__('disabled', 'wp-dbmanager').'.</font><br />';
  139.                 $stats_function_disabled++;
  140.             }
  141.             if(function_exists('exec')) {
  142.                 echo '<font color="green">exec() '.__('enabled', 'wp-dbmanager').'.</font>';
  143.             } else {
  144.                 echo '<font color="red">exec() '.__('disabled', 'wp-dbmanager').'.</font>';
  145.                 $stats_function_disabled++;
  146.             }
  147.         ?>    
  148.     </p>
  149.     <p>
  150.         <?php
  151.             if($status_count == 5) {
  152.                 echo '<strong><font color="green">'.__('Excellent. You Are Good To Go.', 'wp-dbmanager').'</font></strong>';
  153.             } else if($stats_function_disabled == 3) {
  154.                 echo '<strong><font color="red">'.__('I\'m sorry, your server administrator has disabled passthru(), system() and exec(), thus you cannot use this backup script. You may consider using the default WordPress database backup script instead.', 'wp-dbmanager').'</font></strong>';
  155.             } else {
  156.                 echo '<strong><font color="red">'.__('Please Rectify The Error Highlighted In Red Before Proceeding On.', 'wp-dbmanager').'</font></strong>';
  157.             }
  158.         ?>
  159.     </p>
  160.     <p><i><?php _e('Note: The checking of backup status is still undergoing testing, it may not be accurate.', 'wp-dbmanager'); ?></i></p>
  161. </div>
  162. <!-- Backup Database -->
  163. <div class="wrap">
  164.     <h2><?php _e('Backup Database', 'wp-dbmanager'); ?></h2>
  165.     <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
  166.     <table width="100%" cellspacing="3" cellpadding="3" border="0">
  167.         <tr>
  168.             <th align="left" scope="row"><?php _e('Database Name:', 'wp-dbmanager'); ?></th>
  169.             <td><?php echo DB_NAME; ?></td>
  170.         </tr>
  171.         <tr style="background-color: #eee;">
  172.             <th align="left" scope="row"><?php _e('Database Backup To:', 'wp-dbmanager'); ?></th>
  173.             <td><?php echo stripslashes($backup['path']); ?></td>
  174.         </tr>
  175.         <tr>
  176.             <th align="left" scope="row"><?php _e('Database Backup Date:', 'wp-dbmanager'); ?></th>
  177.             <td><?php echo gmdate(sprintf(__('%s @ %s', 'wp-dbmanager'), get_option('date_format'), get_option('time_format')), $backup['date']); ?></td>
  178.         </tr>
  179.         <tr style="background-color: #eee;">
  180.             <th align="left" scope="row"><?php _e('Database Backup File Name:', 'wp-dbmanager'); ?></th>
  181.             <td><?php echo $backup['filename']; ?></td>
  182.         </tr>
  183.         <tr>
  184.             <th align="left" scope="row"><?php _e('Database Backup Type:', 'wp-dbmanager'); ?></th>
  185.             <td><?php _e('Full (Structure and Data)', 'wp-dbmanager'); ?></td>
  186.         </tr>
  187.         <tr style="background-color: #eee;">
  188.             <th align="left" scope="row"><?php _e('MYSQL Dump Location:', 'wp-dbmanager'); ?></th>
  189.             <td><?php echo stripslashes($backup['mysqldumppath']); ?></td>
  190.         </tr>
  191.         <tr>
  192.             <th align="left" scope="row"><?php _e('GZIP Database Backup File?', 'wp-dbmanager'); ?></th>
  193.             <td><input type="radio" name="gzip" value="1" /><?php _e('Yes', 'wp-dbmanager'); ?>  <input type="radio" name="gzip" value="0" checked="checked" /><?php _e('No', 'wp-dbmanager'); ?></td>
  194.         </tr>
  195.         <tr>
  196.             <td colspan="2" align="center"><input type="submit" name="do" value="<?php _e('Backup', 'wp-dbmanager'); ?>" class="button" />  <input type="button" name="cancel" value="<?php _e('Cancel', 'wp-dbmanager'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
  197.         </tr>
  198.     </table>
  199.     </form>
  200. </div>