| 1 |
<?php |
| 2 |
/* |
| 3 |
+----------------------------------------------------------------+ |
| 4 |
| | |
| 5 |
| WordPress 2.7 Plugin: WP-DBManager 2.40 | |
| 6 |
| Copyright (c) 2008 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/wp-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('wp-dbmanager/database-manager.php'); |
| 28 |
$base_page = 'admin.php?page='.$base_name; |
| 29 |
$current_date = mysql2date(sprintf(__('%s @ %s', 'wp-dbmanager'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', current_time('timestamp'))); |
| 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 |
$brace = (substr(PHP_OS, 0, 3) == 'WIN') ? '"' : ''; |
| 44 |
$gzip = intval($_POST['gzip']); |
| 45 |
if($gzip == 1) { |
| 46 |
$backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql.gz'; |
| 47 |
$backup['filepath'] = $backup['path'].'/'.$backup['filename']; |
| 48 |
$backup['command'] = $brace.$backup['mysqldumppath'].$brace.' --host="'.DB_HOST.'" --user="'.DB_USER.'" --password="'.DB_PASSWORD.'" --add-drop-table --skip-lock-tables '.DB_NAME.' | gzip > '.$brace.$backup['filepath'].$brace; |
| 49 |
} else { |
| 50 |
$backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql'; |
| 51 |
$backup['filepath'] = $backup['path'].'/'.$backup['filename']; |
| 52 |
$backup['command'] = $brace.$backup['mysqldumppath'].$brace.' --host="'.DB_HOST.'" --user="'.DB_USER.'" --password="'.DB_PASSWORD.'" --add-drop-table --skip-lock-tables '.DB_NAME.' > '.$brace.$backup['filepath'].$brace; |
| 53 |
} |
| 54 |
$error = execute_backup($backup['command']); |
| 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 |
<div id="icon-wp-dbmanager" class="icon32"><br /></div> |
| 84 |
<h2><?php _e('Backup Database', 'wp-dbmanager'); ?></h2> |
| 85 |
<h3><?php _e('Checking Backup Status', 'wp-dbmanager'); ?></h3> |
| 86 |
<p> |
| 87 |
<?php _e('Checking Backup Folder', 'wp-dbmanager'); ?> <span dir="ltr">(<strong><?php echo stripslashes($backup['path']); ?></strong>)</span> ...<br /> |
| 88 |
<?php |
| 89 |
if(@is_dir(stripslashes($backup['path']))) { |
| 90 |
echo '<font color="green">'.__('Backup folder exists', 'wp-dbmanager').'</font><br />'; |
| 91 |
$status_count++; |
| 92 |
} else { |
| 93 |
echo '<font color="red">'.sprintf(__('Backup folder does NOT exist. Please create \'backup-db\' folder in \'%s\' folder and CHMOD it to \'777\' or change the location of the backup folder under DB Option.', 'wp-dbmanager'), WP_CONTENT_DIR).'</font><br />'; |
| 94 |
} |
| 95 |
if(@is_writable(stripslashes($backup['path']))) { |
| 96 |
echo '<font color="green">'.__('Backup folder is writable', 'wp-dbmanager').'</font>'; |
| 97 |
$status_count++; |
| 98 |
} else { |
| 99 |
echo '<font color="red">'.__('Backup folder is NOT writable. Please CHMOD it to \'777\'.', 'wp-dbmanager').'</font>'; |
| 100 |
} |
| 101 |
?> |
| 102 |
</p> |
| 103 |
<p> |
| 104 |
<?php |
| 105 |
if(@file_exists(stripslashes($backup['mysqldumppath']))) { |
| 106 |
echo __('Checking MYSQL Dump Path', 'wp-dbmanager').' <span dir="ltr">(<strong>'.stripslashes($backup['mysqldumppath']).'</strong>)</span> ...<br />'; |
| 107 |
echo '<font color="green">'.__('MYSQL dump path exists.', 'wp-dbmanager').'</font>'; |
| 108 |
$status_count++; |
| 109 |
} else { |
| 110 |
echo __('Checking MYSQL Dump Path', 'wp-dbmanager').' ...<br />'; |
| 111 |
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>'; |
| 112 |
} |
| 113 |
?> |
| 114 |
</p> |
| 115 |
<p> |
| 116 |
<?php |
| 117 |
if(@file_exists(stripslashes($backup['mysqlpath']))) { |
| 118 |
echo __('Checking MYSQL Path', 'wp-dbmanager').' <span dir="ltr">(<strong>'.stripslashes($backup['mysqlpath']).'</strong>)</span> ...<br />'; |
| 119 |
echo '<font color="green">'.__('MYSQL path exists.', 'wp-dbmanager').'</font>'; |
| 120 |
$status_count++; |
| 121 |
} else { |
| 122 |
echo __('Checking MYSQL Path', 'wp-dbmanager').' ...<br />'; |
| 123 |
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>'; |
| 124 |
} |
| 125 |
?> |
| 126 |
</p> |
| 127 |
<p> |
| 128 |
<?php _e('Checking PHP Functions', 'wp-dbmanager'); ?> <span dir="ltr">(<strong>passthru()</strong>, <strong>system()</strong> <?php _e('and', 'wp-dbmanager'); ?> <strong>exec()</strong>)</span> ...<br /> |
| 129 |
<?php |
| 130 |
if(function_exists('passthru')) { |
| 131 |
echo '<font color="green"><span dir="ltr">passthru()</span> '.__('enabled', 'wp-dbmanager').'.</font><br />'; |
| 132 |
$status_count++; |
| 133 |
} else { |
| 134 |
echo '<font color="red"><span dir="ltr">passthru()</span> '.__('disabled', 'wp-dbmanager').'.</font><br />'; |
| 135 |
$stats_function_disabled++; |
| 136 |
} |
| 137 |
if(function_exists('system')) { |
| 138 |
echo '<font color="green"><span dir="ltr">system()</span> '.__('enabled', 'wp-dbmanager').'.</font><br />'; |
| 139 |
} else { |
| 140 |
echo '<font color="red"><span dir="ltr">system()</span> '.__('disabled', 'wp-dbmanager').'.</font><br />'; |
| 141 |
$stats_function_disabled++; |
| 142 |
} |
| 143 |
if(function_exists('exec')) { |
| 144 |
echo '<font color="green"><span dir="ltr">exec()</span> '.__('enabled', 'wp-dbmanager').'.</font>'; |
| 145 |
} else { |
| 146 |
echo '<font color="red"><span dir="ltr">exec()</span> '.__('disabled', 'wp-dbmanager').'.</font>'; |
| 147 |
$stats_function_disabled++; |
| 148 |
} |
| 149 |
?> |
| 150 |
</p> |
| 151 |
<p> |
| 152 |
<?php |
| 153 |
if($status_count == 5) { |
| 154 |
echo '<strong><font color="green">'.__('Excellent. You Are Good To Go.', 'wp-dbmanager').'</font></strong>'; |
| 155 |
} else if($stats_function_disabled == 3) { |
| 156 |
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>'; |
| 157 |
} else { |
| 158 |
echo '<strong><font color="red">'.__('Please Rectify The Error Highlighted In Red Before Proceeding On.', 'wp-dbmanager').'</font></strong>'; |
| 159 |
} |
| 160 |
?> |
| 161 |
</p> |
| 162 |
<p><i><?php _e('Note: The checking of backup status is still undergoing testing, it may not be accurate.', 'wp-dbmanager'); ?></i></p> |
| 163 |
</div> |
| 164 |
<!-- Backup Database --> |
| 165 |
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post"> |
| 166 |
<div class="wrap"> |
| 167 |
<h3><?php _e('Backup Database', 'wp-dbmanager'); ?></h3> |
| 168 |
<br style="clear" /> |
| 169 |
<table class="widefat"> |
| 170 |
<thead> |
| 171 |
<tr> |
| 172 |
<th><?php _e('Option', 'wp-dbmanager'); ?></th> |
| 173 |
<th><?php _e('Value', 'wp-dbmanager'); ?></th> |
| 174 |
</tr> |
| 175 |
</thead> |
| 176 |
<tr> |
| 177 |
<th><?php _e('Database Name:', 'wp-dbmanager'); ?></th> |
| 178 |
<td><?php echo DB_NAME; ?></td> |
| 179 |
</tr> |
| 180 |
<tr style="background-color: #eee;"> |
| 181 |
<th><?php _e('Database Backup To:', 'wp-dbmanager'); ?></th> |
| 182 |
<td><span dir="ltr"><?php echo stripslashes($backup['path']); ?></span></td> |
| 183 |
</tr> |
| 184 |
<tr> |
| 185 |
<th><?php _e('Database Backup Date:', 'wp-dbmanager'); ?></th> |
| 186 |
<td><?php echo mysql2date(sprintf(__('%s @ %s', 'wp-dbmanager'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $backup['date'])); ?></td> |
| 187 |
</tr> |
| 188 |
<tr style="background-color: #eee;"> |
| 189 |
<th><?php _e('Database Backup File Name:', 'wp-dbmanager'); ?></th> |
| 190 |
<td><span dir="ltr"><?php echo $backup['filename']; ?></span></td> |
| 191 |
</tr> |
| 192 |
<tr> |
| 193 |
<th><?php _e('Database Backup Type:', 'wp-dbmanager'); ?></th> |
| 194 |
<td><?php _e('Full (Structure and Data)', 'wp-dbmanager'); ?></td> |
| 195 |
</tr> |
| 196 |
<tr style="background-color: #eee;"> |
| 197 |
<th><?php _e('MYSQL Dump Location:', 'wp-dbmanager'); ?></th> |
| 198 |
<td><span dir="ltr"><?php echo stripslashes($backup['mysqldumppath']); ?></span></td> |
| 199 |
</tr> |
| 200 |
<tr> |
| 201 |
<th><?php _e('GZIP Database Backup File?', 'wp-dbmanager'); ?></th> |
| 202 |
<td><input type="radio" id="gzip-yes" name="gzip" value="1" /> <label for="gzip-yes"><?php _e('Yes', 'wp-dbmanager'); ?></label> <input type="radio" id="gzip-no" name="gzip" value="0" checked="checked" /> <label for="gzip-no"><?php _e('No', 'wp-dbmanager'); ?></label></td> |
| 203 |
</tr> |
| 204 |
<tr> |
| 205 |
<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> |
| 206 |
</tr> |
| 207 |
</table> |
| 208 |
</div> |
| 209 |
</form> |