PluginProbe
WP-DBManager / 2.04
WP-DBManager v2.04
4.0.0 trunk 1.00 2.00 2.01 2.02 2.03 2.04 2.05 2.10 2.11 2.20 2.30 2.31 2.40 2.50 2.65 2.70 2.71 2.72 2.73 2.74 2.75 2.76 2.78 All 40 releases
wp-dbmanager / dbmanager / database-manage.php

database-manage.php in WP-DBManager 2.04, at dbmanager/database-manage.php

204 lines 9.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 +----------------------------------------------------------------+
4 | |
5 | WordPress 2.0 Plugin: WP-DBManager 2.04 |
6 | Copyright (c) 2005 Lester "GaMerZ" Chan |
7 | |
8 | File Written By: |
9 | - Lester "GaMerZ" Chan |
10 | - http://www.lesterchan.net |
11 | |
12 | File Information: |
13 | - Database Restore |
14 | - wp-content/plugins/dbmanager/database-restore.php |
15 | |
16 +----------------------------------------------------------------+
17 */
18
19
20 ### Download Database
21 if(!empty($_GET['file'])) {
22 require_once('../../../wp-config.php');
23 auth_redirect();
24 if(strpos($_SERVER['HTTP_REFERER'], get_settings('siteurl').'/wp-admin/admin.php?page=dbmanager/database-manage.php') !== false) {
25 $backup_options = get_settings('dbmanager_options');
26 $file_path = $backup_options['path'].'/'.$_GET['file'];
27 header("Pragma: public");
28 header("Expires: 0");
29 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
30 header("Content-Type: application/force-download");
31 header("Content-Type: application/octet-stream");
32 header("Content-Type: application/download");
33 header("Content-Disposition: attachment; filename=".basename($file_path).";");
34 header("Content-Transfer-Encoding: binary");
35 header("Content-Length: ".filesize($file_path));
36 @readfile($file_path);
37 }
38 exit();
39 }
40
41
42 ### Require Database Config
43 require('database-config.php');
44
45
46 ### Form Processing
47 if($_POST['do']) {
48 // Lets Prepare The Variables
49 $database_file = trim($_POST['database_file']);
50 $nice_file_date = gmdate('l, jS F Y @ H:i', substr($database_file, 0, 10));
51
52 // Decide What To Do
53 switch($_POST['do']) {
54 case 'Restore':
55 if(!empty($database_file)) {
56 if(stristr($database_file, '.gz')) {
57 $backup['command'] = 'gunzip < '.$backup['path'].'/'.$database_file.' | '.$backup['mysqlpath'].' --host='.DB_HOST.' --user='.DB_USER.' --password='.DB_PASSWORD.' '.DB_NAME;
58 } else {
59 $backup['command'] = $backup['mysqlpath'].' --host='.DB_HOST.' --user='.DB_USER.' --password='.DB_PASSWORD.' '.DB_NAME.' < '.$backup['path'].'/'.$database_file;
60 }
61 passthru($backup['command'], $error);
62 if($error) {
63 $text = "<font color=\"red\">Database On '$nice_file_date' Failed To Restore</font>";
64 } else {
65 $text = "<font color=\"green\">Database On '$nice_file_date' Restored Successfully</font>";
66 }
67 } else {
68 $text = '<font color="red">No Backup Database File Selected</font>';
69 }
70 break;
71 case 'E-Mail':
72 if(!empty($database_file)) {
73 // Get And Read The Database Backup File
74 $file_path = $backup['path'].'/'.$database_file;
75 $file_size = format_size(filesize($file_path));
76 $file_date = gmdate('l, jS F Y @ H:i', substr($database_file, 0, 10));
77 $file = fopen($file_path,'rb');
78 $file_data = fread($file,filesize($file_path));
79 fclose($file);
80 $file_data = chunk_split(base64_encode($file_data));
81 // Create Mail To, Mail Subject And Mail Header
82 if(!empty($_POST['email_to'])) {
83 $mail_to = trim($_POST['email_to']);
84 } else {
85 $mail_to = get_settings('admin_email');
86 }
87 $mail_subject = get_bloginfo('name').' Database Backup File For '.$file_date;
88 $mail_header = 'From: '.get_bloginfo('name').' Administrator <'.get_settings('admin_email').'>';
89 // MIME Boundary
90 $random_time = md5(time());
91 $mime_boundary = "==WP-DBManager- $random_time";
92 // Create Mail Header And Mail Message
93 $mail_header .= "\nMIME-Version: 1.0\n" .
94 "Content-Type: multipart/mixed;\n" .
95 " boundary=\"{$mime_boundary}\"";
96 $mail_message = "Website Name: ".get_bloginfo('name')."\nWebsite URL: ".get_bloginfo('siteurl')."\nBackup File Name: $database_file\nBackup File Date: $file_date\nBackup File Size: $file_size\n\nWith Regards,\n".get_bloginfo('name')." Administrator\n".get_bloginfo('siteurl');
97 $mail_message = "This is a multi-part message in MIME format.\n\n" .
98 "--{$mime_boundary}\n" .
99 "Content-Type: text/plain; charset=\"utf-8\"\n" .
100 "Content-Transfer-Encoding: 7bit\n\n".$mail_message."\n\n";
101 $mail_message .= "--{$mime_boundary}\n" .
102 "Content-Type: application/octet-stream;\n" .
103 " name=\"$database_file\"\n" .
104 "Content-Disposition: attachment;\n" .
105 " filename=\"$database_file\"\n" .
106 "Content-Transfer-Encoding: base64\n\n" .
107 $file_data."\n\n--{$mime_boundary}--\n";
108 if(mail($mail_to, $mail_subject, $mail_message, $mail_header)) {
109 $text .= "<font color=\"green\">Database Backup File For '$file_date' Successfully E-Mailed To '$mail_to'</font><br />";
110 } else {
111 $text = "<font color=\"red\">Unable To E-Mail Database Backup File For '$file_date' To '$mail_to'</font>";
112 }
113 } else {
114 $text = '<font color="red">No Backup Database File Selected</font>';
115 }
116 break;
117 case 'Download':
118 if(empty($database_file)) {
119 $text = '<font color="red">No Backup Database File Selected</font>';
120 }
121 break;
122 case 'Delete':
123 if(!empty($database_file)) {
124 $nice_file_date = gmdate('l, jS F Y @ H:i', substr($database_file, 0, 10));
125 if(is_file($backup['path'].'/'.$database_file)) {
126 if(!unlink($backup['path'].'/'.$database_file)) {
127 $text .= "<font color=\"red\">Unable To Delete Database Backup File On '$nice_file_date'</font><br />";
128 } else {
129 $text .= "<font color=\"green\">Database Backup File On '$nice_file_date' Deleted Successfully</font><br />";
130 }
131 } else {
132 $text = "<font color=\"red\">Invalid Database Backup File On '$nice_file_date'</font>";
133 }
134 } else {
135 $text = '<font color="red">No Backup Database File Selected</font>';
136 }
137 break;
138 }
139 }
140 ?>
141 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
142 <!-- Manage Backup Database -->
143 <div class="wrap">
144 <h2>Manage Backup Database</h2>
145 <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
146 <table width="100%" cellspacing="3" cellpadding="3" border="0">
147 <tr>
148 <th align="left" scope="row" colspan="5">Choose A Backup Date To E-Mail, Restore, Download Or Delete</th>
149 </tr>
150 <tr>
151 <th align="left" scope="col">No.</th>
152 <th align="left" scope="col">Database File</th>
153 <th align="left" scope="col">Date/Time</th>
154 <th align="left" scope="col">Size</th>
155 <th align="left" scope="col">Select</th>
156 </tr>
157 <?php
158 if(!is_emtpy_folder($backup['path'])) {
159 if ($handle = opendir($backup['path'])) {
160 $database_files = array();
161 while (false !== ($file = readdir($handle))) {
162 if ($file != '.' && $file != '..' && (file_ext($file) == 'sql' || file_ext($file) == 'gz')) {
163 $database_files[] = $file;
164 }
165 }
166 closedir($handle);
167 for($i = (sizeof($database_files)-1); $i > -1; $i--) {
168 if($no%2 == 0) {
169 $style = 'style=\'background-color: #eee\'';
170 } else {
171 $style = 'style=\'background-color: none\'';
172 }
173 $no++;
174 $database_text = substr($database_files[$i], 13);
175 $date_text = gmdate('l, jS F Y @ H:i', substr($database_files[$i], 0, 10));
176 $size_text = filesize($backup['path'].'/'.$database_files[$i]);
177 echo "<tr $style>\n<td>$no</td>";
178 echo "<td>$database_text</td>";
179 echo "<td>$date_text</td>";
180 echo '<td>'.format_size($size_text).'</td>';
181 echo "<td><input type=\"radio\" name=\"database_file\" value=\"$database_files[$i]\" /></td>\n</tr>\n";
182 $totalsize += $size_text;
183 }
184 } else {
185 echo '<tr><td align="center" colspan="5">There Are No Database Backup Files Available</td></tr>';
186 }
187 } else {
188 echo '<tr><td align="center" colspan="5">There Are No Database Backup Files Available</td></tr>';
189 }
190 ?>
191 <tr>
192 <th align="left" colspan="3"><?php echo $no; ?> Backup File(s)</th>
193 <th align="left"><?php echo format_size($totalsize); ?></th>
194 <td>&nbsp;</td>
195 </tr>
196 <tr>
197 <td colspan="5">E-mail database backup file to: <input type="text" name="email_to" size="30" maxlength="50" value="<?php echo get_settings('admin_email'); ?>" />&nbsp;&nbsp;<input type="submit" name="do" value="E-Mail" class="button" /></td>
198 </tr>
199 <tr>
200 <td colspan="5" align="center"><input type="submit" name="do" value="Download" class="button" />&nbsp;&nbsp;<input type="submit" name="do" value="Restore" onclick="return confirm('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.')" class="button" />&nbsp;&nbsp;<input type="submit" class="button" name="do" value="Delete" onclick="return confirm('You Are About To Delete The Selected Database Backup Files.\nThis Action Is Not Reversible.\n\n Choose \'Cancel\' to stop, \'OK\' to delete.')" />&nbsp;&nbsp;<input type="button" name="cancel" Value="<?php _e('Cancel'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
201 </tr>
202 </table>
203 </form>
204 </div>