PluginProbe
WP-DBManager / 2.74
WP-DBManager v2.74
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 / database-manage.php

database-manage.php in WP-DBManager 2.74, at database-manage.php

177 lines 8.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 ### Check Whether User Can Manage Database
3 if(!current_user_can('manage_database')) {
4 die('Access Denied');
5 }
6
7
8 ### Variables Variables Variables
9 $base_name = plugin_basename('wp-dbmanager/database-manager.php');
10 $base_page = 'admin.php?page='.$base_name;
11 $backup = array();
12 $backup_options = get_option('dbmanager_options');
13 $backup['date'] = current_time('timestamp');
14 $backup['mysqldumppath'] = $backup_options['mysqldumppath'];
15 $backup['mysqlpath'] = $backup_options['mysqlpath'];
16 $backup['path'] = $backup_options['path'];
17 $backup['charset'] = ' --default-character-set="utf8"';
18
19
20 ### Form Processing
21 if( !empty( $_POST['do'] ) ) {
22 check_admin_referer('wp-dbmanager_manage');
23 // Lets Prepare The Variables
24 $database_file = trim($_POST['database_file']);
25 $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)));
26 $text = '';
27
28 // Decide What To Do
29 switch($_POST['do']) {
30 case __('Restore', 'wp-dbmanager'):
31 if(!empty($database_file)) {
32 $brace = (substr(PHP_OS, 0, 3) == 'WIN') ? '"' : '';
33 $backup['host'] = DB_HOST;
34 $backup['port'] = '';
35 $backup['sock'] = '';
36 if(strpos(DB_HOST, ':') !== false) {
37 $db_host = explode(':', DB_HOST);
38 $backup['host'] = $db_host[0];
39 if(intval($db_host[1]) != 0) {
40 $backup['port'] = ' --port=' . escapeshellarg( intval( $db_host[1] ) );
41 } else {
42 $backup['sock'] = ' --socket=' . escapeshellarg( $db_host[1] );
43 }
44 }
45 if(stristr($database_file, '.gz')) {
46 $backup['command'] = 'gunzip < ' . escapeshellcmd( $brace . $backup['path'] . '/' . $database_file . $brace ) .' | '. escapeshellcmd( $brace . $backup['mysqlpath'] . $brace ) . ' --host=' . escapeshellarg( $backup['host'] ) . ' --user=' . escapeshellarg( DB_USER ) . ' --password=' . escapeshellarg( DB_PASSWORD ) . $backup['port'] . $backup['sock'] . $backup['charset'] . ' ' . DB_NAME;
47 } else {
48 $backup['command'] = escapeshellcmd( $brace . $backup['mysqlpath'] . $brace ) . ' --host=' . escapeshellarg( $backup['host'] ) . ' --user=' . escapeshellarg( DB_USER ) . ' --password=' . escapeshellarg( DB_PASSWORD ) . $backup['port'] . $backup['sock'] . $backup['charset'] . ' ' . DB_NAME . ' < '.escapeshellcmd( $brace . $backup['path'] . '/' . $database_file . $brace );
49 }
50 if( realpath( $backup['path'] ) === false ) {
51 $text = '<p style="color: red;">' . sprintf(__('%s is not a valid backup path', 'wp-dbmanager'), stripslashes( $backup['path'] ) ) . '</p>';
52 } else if( dbmanager_is_valid_path( $backup['mysqlpath'] ) === 0 ) {
53 $text = '<p style="color: red;">' . sprintf(__('%s is not a valid mysql path', 'wp-dbmanager'), stripslashes( $backup['mysqlpath'] ) ) . '</p>';
54 } else {
55 passthru( $backup['command'], $error );
56 }
57 if($error) {
58 $text = '<p style="color: red;">'.sprintf(__('Database On \'%s\' Failed To Restore', 'wp-dbmanager'), $nice_file_date).'</p>';
59 } else {
60 $text = '<p style="color: green;">'.sprintf(__('Database On \'%s\' Restored Successfully', 'wp-dbmanager'), $nice_file_date).'</p>';
61 }
62 } else {
63 $text = '<p style="color: red;">'.__('No Backup Database File Selected', 'wp-dbmanager').'</p>';
64 }
65 break;
66 case __('E-Mail', 'wp-dbmanager'):
67 if(!empty($database_file)) {
68 $to = ( !empty( $_POST['email_to'] ) ? sanitize_email( $_POST['email_to'] ) : get_option( 'admin_email' ) );
69
70 if( dbmanager_email_backup( $to, $backup['path'].'/'.$database_file ) ) {
71 $text .= '<p style="color: green;">'.sprintf(__('Database Backup File For \'%s\' Successfully E-Mailed To \'%s\'', 'wp-dbmanager'), $nice_file_date, $to).'</p>';
72 } else {
73 $text = '<p style="color: red;">'.sprintf(__('Unable To E-Mail Database Backup File For \'%s\' To \'%s\'', 'wp-dbmanager'), $nice_file_date, $to).'</p>';
74 }
75 } else {
76 $text = '<p style="color: red;">'.__('No Backup Database File Selected', 'wp-dbmanager').'</p>';
77 }
78 break;
79 case __('Download', 'wp-dbmanager'):
80 if(empty($database_file)) {
81 $text = '<p style="color: red;">'.__('No Backup Database File Selected', 'wp-dbmanager').'</p>';
82 }
83 break;
84 case __('Delete', 'wp-dbmanager'):
85 if(!empty($database_file)) {
86 if(is_file($backup['path'].'/'.$database_file)) {
87 if(!unlink($backup['path'].'/'.$database_file)) {
88 $text .= '<p style="color: red;">'.sprintf(__('Unable To Delete Database Backup File On \'%s\'', 'wp-dbmanager'), $nice_file_date).'</p>';
89 } else {
90 $text .= '<p style="color: green;">'.sprintf(__('Database Backup File On \'%s\' Deleted Successfully', 'wp-dbmanager'), $nice_file_date).'</p>';
91 }
92 } else {
93 $text = '<p style="color: red;">'.sprintf(__('Invalid Database Backup File On \'%s\'', 'wp-dbmanager'), $nice_file_date).'</p>';
94 }
95 } else {
96 $text = '<p style="color: red;">'.__('No Backup Database File Selected', 'wp-dbmanager').'</p>';
97 }
98 break;
99 }
100 }
101 ?>
102 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated">'.$text.'</div>'; } ?>
103 <!-- Manage Backup Database -->
104 <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
105 <?php wp_nonce_field('wp-dbmanager_manage'); ?>
106 <div class="wrap">
107 <h2><?php _e('Manage Backup Database', 'wp-dbmanager'); ?></h2>
108 <p><?php _e('Choose A Backup Date To E-Mail, Restore, Download Or Delete', 'wp-dbmanager'); ?></p>
109 <table class="widefat">
110 <thead>
111 <tr>
112 <th><?php _e('No.', 'wp-dbmanager'); ?></th>
113 <th><?php _e('Database File', 'wp-dbmanager'); ?></th>
114 <th><?php _e('Date/Time', 'wp-dbmanager'); ?></th>
115 <th><?php _e('Size', 'wp-dbmanager'); ?></th>
116 <th><?php _e('Select', 'wp-dbmanager'); ?></th>
117 </tr>
118 </thead>
119 <?php
120 $no = 0;
121 $totalsize = 0;
122 if(!is_emtpy_folder($backup['path'])) {
123 if ($handle = opendir($backup['path'])) {
124 $database_files = array();
125 while (false !== ($file = readdir($handle))) {
126 if ($file != '.' && $file != '..' && $file != '.htaccess' && (file_ext($file) == 'sql' || file_ext($file) == 'gz')) {
127 $database_files[] = $file;
128 }
129 }
130 closedir($handle);
131 sort($database_files);
132 for($i = (sizeof($database_files)-1); $i > -1; $i--) {
133 if($no%2 == 0) {
134 $style = '';
135 } else {
136 $style = ' class="alternate"';
137 }
138 $no++;
139 $database_text = substr($database_files[$i], 13);
140 $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)));
141 $size_text = filesize($backup['path'].'/'.$database_files[$i]);
142 echo "<tr$style>\n";
143 echo '<td>'.number_format_i18n($no).'</td>';
144 echo "<td>$database_text</td>";
145 echo "<td>$date_text</td>";
146 echo '<td>'.format_size($size_text).'</td>';
147 echo "<td><input type=\"radio\" name=\"database_file\" value=\"$database_files[$i]\" /></td>\n</tr>\n";
148 $totalsize += $size_text;
149 }
150 } else {
151 echo '<tr><td align="center" colspan="5">'.__('There Are No Database Backup Files Available.', 'wp-dbmanager').'</td></tr>';
152 }
153 } else {
154 echo '<tr><td align="center" colspan="5">'.__('There Are No Database Backup Files Available.', 'wp-dbmanager').'</td></tr>';
155 }
156 ?>
157 <tr class="thead">
158 <th colspan="3"><?php printf(_n('%s Backup File', '%s Backup Files', $no, 'wp-dbmanager'), number_format_i18n($no)); ?></th>
159 <th><?php echo format_size($totalsize); ?></th>
160 <th>&nbsp;</th>
161 </tr>
162 </table>
163 <table class="form-table">
164 <tr>
165 <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" />&nbsp;&nbsp;<input type="submit" name="do" value="<?php _e('E-Mail', 'wp-dbmanager'); ?>" class="button" /></td>
166 </tr>
167 <tr>
168 <td colspan="5" align="center">
169 <input type="submit" name="do" value="<?php _e('Download', 'wp-dbmanager'); ?>" class="button" />&nbsp;&nbsp;
170 <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" />&nbsp;&nbsp;
171 <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'); ?>')" />&nbsp;&nbsp;
172 <input type="button" name="cancel" value="<?php _e('Cancel', 'wp-dbmanager'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
173 </tr>
174 </table>
175 </div>
176 </form>
177