3
+----------------------------------------------------------------+
5
| WordPress 2.8 Plugin: WP-DBManager 2.63 |
6
| Copyright (c) 2009 Lester "GaMerZ" Chan |
9
| - Lester "GaMerZ" Chan |
10
| - http://lesterchan.net |
13
| - Database Restore |
14
| - wp-content/plugins/wp-dbmanager/database-restore.php |
16
+----------------------------------------------------------------+
20
### Check Whether User Can Manage Database
21
if(!current_user_can('manage_database')) {
26
### Variables Variables Variables
27
$base_name = plugin_basename('wp-dbmanager/database-manager.php');
28
$base_page = 'admin.php?page='.$base_name;
30
$backup_options = get_option('dbmanager_options');
31
$backup['date'] = current_time('timestamp');
32
$backup['mysqldumppath'] = $backup_options['mysqldumppath'];
33
$backup['mysqlpath'] = $backup_options['mysqlpath'];
34
$backup['path'] = $backup_options['path'];
35
$backup['password'] = str_replace('$', '\$', DB_PASSWORD);
40
check_admin_referer('wp-dbmanager_manage');
41
// Lets Prepare The Variables
42
$database_file = trim($_POST['database_file']);
43
$nice_file_date = mysql2date(sprintf(__('%s @ %s', 'wp-dbmanager'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', substr($database_file, 0, 10)));
46
switch($_POST['do']) {
47
case __('Restore', 'wp-dbmanager'):
48
if(!empty($database_file)) {
49
$brace = (substr(PHP_OS, 0, 3) == 'WIN') ? '"' : '';
50
$backup['host'] = DB_HOST;
53
if(strpos(DB_HOST, ':') !== false) {
54
$db_host = explode(':', DB_HOST);
55
$backup['host'] = $db_host[0];
56
if(is_int($db_host[1])) {
57
$backup['port'] = ' --port="'.intval($db_host[1]).'"';
59
$backup['sock'] = ' --socket="'.$db_host[1].'"';
62
if(stristr($database_file, '.gz')) {
63
$backup['command'] = 'gunzip < '.$brace.$backup['path'].'/'.$database_file.$brace.' | '.$brace.$backup['mysqlpath'].$brace.' --host="'.$backup['host'].'" --user="'.DB_USER.'" --password="'.$backup['password'].'"'.$backup['port'].$backup['sock'].' '.DB_NAME;
65
$backup['command'] = $brace.$backup['mysqlpath'].$brace.' --host="'.$backup['host'].'" --user="'.DB_USER.'" --password="'.$backup['password'].'"'.$backup['port'].$backup['sock'].' '.DB_NAME.' < '.$brace.$backup['path'].'/'.$database_file.$brace;
67
passthru($backup['command'], $error);
69
$text = '<font color="red">'.sprintf(__('Database On \'%s\' Failed To Restore', 'wp-dbmanager'), $nice_file_date).'</font>';
71
$text = '<font color="green">'.sprintf(__('Database On \'%s\' Restored Successfully', 'wp-dbmanager'), $nice_file_date).'</font>';
74
$text = '<font color="red">'.__('No Backup Database File Selected', 'wp-dbmanager').'</font>';
77
case __('E-Mail', 'wp-dbmanager'):
78
if(!empty($database_file)) {
79
// Get And Read The Database Backup File
80
$file_path = $backup['path'].'/'.$database_file;
81
$file_size = format_size(filesize($file_path));
82
$file_date = $nice_file_date;
83
$file = fopen($file_path,'rb');
84
$file_data = fread($file,filesize($file_path));
86
$file_data = chunk_split(base64_encode($file_data));
87
// Create Mail To, Mail Subject And Mail Header
88
if(!empty($_POST['email_to'])) {
89
$mail_to = trim($_POST['email_to']);
91
$mail_to = get_option('admin_email');
93
$mail_subject = sprintf(__('%s Database Backup File For %s', 'wp-dbmanager'), wp_specialchars_decode(get_option('blogname')), $file_date);
94
$mail_header = 'From: '.wp_specialchars_decode(get_option('blogname')).' Administrator <'.get_option('admin_email').'>';
96
$random_time = md5(time());
97
$mime_boundary = "==WP-DBManager- $random_time";
98
// Create Mail Header And Mail Message
99
$mail_header .= "\nMIME-Version: 1.0\n" .
100
"Content-Type: multipart/mixed;\n" .
101
" boundary=\"{$mime_boundary}\"";
102
$mail_message = __('Website Name:', 'wp-dbmanager').' '.wp_specialchars_decode(get_option('blogname'))."\n".
103
__('Website URL:', 'wp-dbmanager').' '.get_bloginfo('siteurl')."\n".
104
__('Backup File Name:', 'wp-dbmanager').' '.$database_file."\n".
105
__('Backup File Date:', 'wp-dbmanager').' '.$file_date."\n".
106
__('Backup File Size:', 'wp-dbmanager').' '.$file_size."\n\n".
107
__('With Regards,', 'wp-dbmanager')."\n".
108
wp_specialchars_decode(get_option('blogname')).' '. __('Administrator', 'wp-dbmanager')."\n".
109
get_bloginfo('siteurl');
110
$mail_message = "This is a multi-part message in MIME format.\n\n" .
111
"--{$mime_boundary}\n" .
112
"Content-Type: text/plain; charset=\"utf-8\"\n" .
113
"Content-Transfer-Encoding: 7bit\n\n".$mail_message."\n\n";
114
$mail_message .= "--{$mime_boundary}\n" .
115
"Content-Type: application/octet-stream;\n" .
116
" name=\"$database_file\"\n" .
117
"Content-Disposition: attachment;\n" .
118
" filename=\"$database_file\"\n" .
119
"Content-Transfer-Encoding: base64\n\n" .
120
$file_data."\n\n--{$mime_boundary}--\n";
121
if(mail($mail_to, $mail_subject, $mail_message, $mail_header)) {
122
$text .= '<font color="green">'.sprintf(__('Database Backup File For \'%s\' Successfully E-Mailed To \'%s\'', 'wp-dbmanager'), $file_date, $mail_to).'</font><br />';
124
$text = '<font color="red">'.sprintf(__('Unable To E-Mail Database Backup File For \'%s\' To \'%s\'', 'wp-dbmanager'), $file_date, $mail_to).'</font>';
127
$text = '<font color="red">'.__('No Backup Database File Selected', 'wp-dbmanager').'</font>';
130
case __('Download', 'wp-dbmanager'):
131
if(empty($database_file)) {
132
$text = '<font color="red">'.__('No Backup Database File Selected', 'wp-dbmanager').'</font>';
135
case __('Delete', 'wp-dbmanager'):
136
if(!empty($database_file)) {
137
if(is_file($backup['path'].'/'.$database_file)) {
138
if(!unlink($backup['path'].'/'.$database_file)) {
139
$text .= '<font color="red">'.sprintf(__('Unable To Delete Database Backup File On \'%s\'', 'wp-dbmanager'), $nice_file_date).'</font><br />';
141
$text .= '<font color="green">'.sprintf(__('Database Backup File On \'%s\' Deleted Successfully', 'wp-dbmanager'), $nice_file_date).'</font><br />';
144
$text = '<font color="red">'.sprintf(__('Invalid Database Backup File On \'%s\'', 'wp-dbmanager'), $nice_file_date).'</font>';
147
$text = '<font color="red">'.__('No Backup Database File Selected', 'wp-dbmanager').'</font>';
153
<?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
154
<!-- Manage Backup Database -->
155
<form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
156
<?php wp_nonce_field('wp-dbmanager_manage'); ?>
158
<div id="icon-wp-dbmanager" class="icon32"><br /></div>
159
<h2><?php _e('Manage Backup Database', 'wp-dbmanager'); ?></h2>
160
<p><?php _e('Choose A Backup Date To E-Mail, Restore, Download Or Delete', 'wp-dbmanager'); ?></p>
161
<table class="widefat">
164
<th><?php _e('No.', 'wp-dbmanager'); ?></th>
165
<th><?php _e('Database File', 'wp-dbmanager'); ?></th>
166
<th><?php _e('Date/Time', 'wp-dbmanager'); ?></th>
167
<th><?php _e('Size', 'wp-dbmanager'); ?></th>
168
<th><?php _e('Select', 'wp-dbmanager'); ?></th>
172
if(!is_emtpy_folder($backup['path'])) {
173
if ($handle = opendir($backup['path'])) {
174
$database_files = array();
175
while (false !== ($file = readdir($handle))) {
176
if ($file != '.' && $file != '..' && $file != '.htaccess' && (file_ext($file) == 'sql' || file_ext($file) == 'gz')) {
177
$database_files[] = $file;
181
sort($database_files);
182
for($i = (sizeof($database_files)-1); $i > -1; $i--) {
186
$style = ' class="alternate"';
189
$database_text = substr($database_files[$i], 13);
190
$date_text = mysql2date(sprintf(__('%s @ %s', 'wp-dbmanager'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', substr($database_files[$i], 0, 10)));
191
$size_text = filesize($backup['path'].'/'.$database_files[$i]);
193
echo '<td>'.number_format_i18n($no).'</td>';
194
echo "<td>$database_text</td>";
195
echo "<td>$date_text</td>";
196
echo '<td>'.format_size($size_text).'</td>';
197
echo "<td><input type=\"radio\" name=\"database_file\" value=\"$database_files[$i]\" /></td>\n</tr>\n";
198
$totalsize += $size_text;
201
echo '<tr><td align="center" colspan="5">'.__('There Are No Database Backup Files Available.', 'wp-dbmanager').'</td></tr>';
204
echo '<tr><td align="center" colspan="5">'.__('There Are No Database Backup Files Available.', 'wp-dbmanager').'</td></tr>';
208
<th colspan="3"><?php printf(_n('%s Backup File', '%s Backup Files', $no, 'wp-dbmanager'), number_format_i18n($no)); ?></th>
209
<th><?php echo format_size($totalsize); ?></th>
213
<table class="form-table">
215
<td colspan="5" align="center"><label for="email_to"><?php _e('E-mail database backup file to:', 'wp-dbmanager'); ?></label> <input type="text" id="email_to" name="email_to" size="30" maxlength="50" value="<?php echo get_option('admin_email'); ?>" dir="ltr" /> <input type="submit" name="do" value="<?php _e('E-Mail', 'wp-dbmanager'); ?>" class="button" /></td>
218
<td colspan="5" align="center">
219
<input type="submit" name="do" value="<?php _e('Download', 'wp-dbmanager'); ?>" class="button" />
220
<input type="submit" name="do" value="<?php _e('Restore', 'wp-dbmanager'); ?>" onclick="return confirm('<?php _e('You Are About To Restore A Database.\nThis Action Is Not Reversible.\nAny Data Inserted After The Backup Date Will Be Gone.\n\n Choose [Cancel] to stop, [Ok] to restore.', 'wp-dbmanager'); ?>')" class="button" />
221
<input type="submit" class="button" name="do" value="<?php _e('Delete', 'wp-dbmanager'); ?>" onclick="return confirm('<?php _e('You Are About To Delete The Selected Database Backup Files.\nThis Action Is Not Reversible.\n\n Choose [Cancel] to stop, [Ok] to delete.', 'wp-dbmanager'); ?>')" />
222
<input type="button" name="cancel" value="<?php _e('Cancel', 'wp-dbmanager'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
b'\\ No newline at end of file'