PluginProbe
WP-DBManager / 2.76
WP-DBManager v2.76
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.76, at database-manage.php

179 lines 9.0 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 do_action( 'wp_dbmanager_before_escapeshellcmd' );
47 $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;
48 } else {
49 do_action( 'wp_dbmanager_before_escapeshellcmd' );
50 $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 );
51 }
52 if( realpath( $backup['path'] ) === false ) {
53 $text = '<p style="color: red;">' . sprintf(__('%s is not a valid backup path', 'wp-dbmanager'), stripslashes( $backup['path'] ) ) . '</p>';
54 } else if( dbmanager_is_valid_path( $backup['mysqlpath'] ) === 0 ) {
55 $text = '<p style="color: red;">' . sprintf(__('%s is not a valid mysql path', 'wp-dbmanager'), stripslashes( $backup['mysqlpath'] ) ) . '</p>';
56 } else {
57 passthru( $backup['command'], $error );
58 }
59 if($error) {
60 $text = '<p style="color: red;">'.sprintf(__('Database On \'%s\' Failed To Restore', 'wp-dbmanager'), $nice_file_date).'</p>';
61 } else {
62 $text = '<p style="color: green;">'.sprintf(__('Database On \'%s\' Restored Successfully', 'wp-dbmanager'), $nice_file_date).'</p>';
63 }
64 } else {
65 $text = '<p style="color: red;">'.__('No Backup Database File Selected', 'wp-dbmanager').'</p>';
66 }
67 break;
68 case __('E-Mail', 'wp-dbmanager'):
69 if(!empty($database_file)) {
70 $to = ( !empty( $_POST['email_to'] ) ? sanitize_email( $_POST['email_to'] ) : get_option( 'admin_email' ) );
71
72 if( dbmanager_email_backup( $to, $backup['path'].'/'.$database_file ) ) {
73 $text .= '<p style="color: green;">'.sprintf(__('Database Backup File For \'%s\' Successfully E-Mailed To \'%s\'', 'wp-dbmanager'), $nice_file_date, $to).'</p>';
74 } else {
75 $text = '<p style="color: red;">'.sprintf(__('Unable To E-Mail Database Backup File For \'%s\' To \'%s\'', 'wp-dbmanager'), $nice_file_date, $to).'</p>';
76 }
77 } else {
78 $text = '<p style="color: red;">'.__('No Backup Database File Selected', 'wp-dbmanager').'</p>';
79 }
80 break;
81 case __('Download', 'wp-dbmanager'):
82 if(empty($database_file)) {
83 $text = '<p style="color: red;">'.__('No Backup Database File Selected', 'wp-dbmanager').'</p>';
84 }
85 break;
86 case __('Delete', 'wp-dbmanager'):
87 if(!empty($database_file)) {
88 if(is_file($backup['path'].'/'.$database_file)) {
89 if(!unlink($backup['path'].'/'.$database_file)) {
90 $text .= '<p style="color: red;">'.sprintf(__('Unable To Delete Database Backup File On \'%s\'', 'wp-dbmanager'), $nice_file_date).'</p>';
91 } else {
92 $text .= '<p style="color: green;">'.sprintf(__('Database Backup File On \'%s\' Deleted Successfully', 'wp-dbmanager'), $nice_file_date).'</p>';
93 }
94 } else {
95 $text = '<p style="color: red;">'.sprintf(__('Invalid Database Backup File On \'%s\'', 'wp-dbmanager'), $nice_file_date).'</p>';
96 }
97 } else {
98 $text = '<p style="color: red;">'.__('No Backup Database File Selected', 'wp-dbmanager').'</p>';
99 }
100 break;
101 }
102 }
103 ?>
104 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated">'.$text.'</div>'; } ?>
105 <!-- Manage Backup Database -->
106 <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
107 <?php wp_nonce_field('wp-dbmanager_manage'); ?>
108 <div class="wrap">
109 <h2><?php _e('Manage Backup Database', 'wp-dbmanager'); ?></h2>
110 <p><?php _e('Choose A Backup Date To E-Mail, Restore, Download Or Delete', 'wp-dbmanager'); ?></p>
111 <table class="widefat">
112 <thead>
113 <tr>
114 <th><?php _e('No.', 'wp-dbmanager'); ?></th>
115 <th><?php _e('Database File', 'wp-dbmanager'); ?></th>
116 <th><?php _e('Date/Time', 'wp-dbmanager'); ?></th>
117 <th><?php _e('Size', 'wp-dbmanager'); ?></th>
118 <th><?php _e('Select', 'wp-dbmanager'); ?></th>
119 </tr>
120 </thead>
121 <?php
122 $no = 0;
123 $totalsize = 0;
124 if(!is_emtpy_folder($backup['path'])) {
125 if ($handle = opendir($backup['path'])) {
126 $database_files = array();
127 while (false !== ($file = readdir($handle))) {
128 if ($file != '.' && $file != '..' && $file != '.htaccess' && (file_ext($file) == 'sql' || file_ext($file) == 'gz')) {
129 $database_files[] = $file;
130 }
131 }
132 closedir($handle);
133 sort($database_files);
134 for($i = (sizeof($database_files)-1); $i > -1; $i--) {
135 if($no%2 == 0) {
136 $style = '';
137 } else {
138 $style = ' class="alternate"';
139 }
140 $no++;
141 $database_text = substr($database_files[$i], 13);
142 $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)));
143 $size_text = filesize($backup['path'].'/'.$database_files[$i]);
144 echo "<tr$style>\n";
145 echo '<td>'.number_format_i18n($no).'</td>';
146 echo "<td>$database_text</td>";
147 echo "<td>$date_text</td>";
148 echo '<td>'.format_size($size_text).'</td>';
149 echo "<td><input type=\"radio\" name=\"database_file\" value=\"$database_files[$i]\" /></td>\n</tr>\n";
150 $totalsize += $size_text;
151 }
152 } else {
153 echo '<tr><td align="center" colspan="5">'.__('There Are No Database Backup Files Available.', 'wp-dbmanager').'</td></tr>';
154 }
155 } else {
156 echo '<tr><td align="center" colspan="5">'.__('There Are No Database Backup Files Available.', 'wp-dbmanager').'</td></tr>';
157 }
158 ?>
159 <tr class="thead">
160 <th colspan="3"><?php printf(_n('%s Backup File', '%s Backup Files', $no, 'wp-dbmanager'), number_format_i18n($no)); ?></th>
161 <th><?php echo format_size($totalsize); ?></th>
162 <th>&nbsp;</th>
163 </tr>
164 </table>
165 <table class="form-table">
166 <tr>
167 <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>
168 </tr>
169 <tr>
170 <td colspan="5" align="center">
171 <input type="submit" name="do" value="<?php _e('Download', 'wp-dbmanager'); ?>" class="button" />&nbsp;&nbsp;
172 <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;
173 <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;
174 <input type="button" name="cancel" value="<?php _e('Cancel', 'wp-dbmanager'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
175 </tr>
176 </table>
177 </div>
178 </form>
179