PluginProbe
WP-DBManager / 2.73
WP-DBManager v2.73
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-backup.php

database-backup.php in WP-DBManager 2.73, at database-backup.php

223 lines 11.1 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 $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')));
12 $backup = array();
13 $backup_options = get_option('dbmanager_options');
14 $backup['date'] = current_time('timestamp');
15 $backup['mysqldumppath'] = $backup_options['mysqldumppath'];
16 $backup['mysqlpath'] = $backup_options['mysqlpath'];
17 $backup['path'] = $backup_options['path'];
18 $backup['password'] = str_replace('$', '\$', DB_PASSWORD);
19 $backup['charset'] = ' --default-character-set="utf8"';
20
21 ### Form Processing
22 if(!empty($_POST['do'])) {
23 $text = '';
24 // Decide What To Do
25 switch($_POST['do']) {
26 case __('Backup', 'wp-dbmanager'):
27 check_admin_referer('wp-dbmanager_backup');
28 $brace = (substr(PHP_OS, 0, 3) == 'WIN') ? '"' : '';
29 $backup['host'] = DB_HOST;
30 $backup['port'] = '';
31 $backup['sock'] = '';
32 if(strpos(DB_HOST, ':') !== false) {
33 $db_host = explode(':', DB_HOST);
34 $backup['host'] = $db_host[0];
35 if(intval($db_host[1]) != 0) {
36 $backup['port'] = ' --port=' . escapeshellarg( intval( $db_host[1] ) );
37 } else {
38 $backup['sock'] = ' --socket=' . escapeshellarg( $db_host[1] );
39 }
40 }
41 $gzip = intval($_POST['gzip']);
42 if($gzip == 1) {
43 $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql.gz';
44 $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
45 $backup['command'] = escapeshellcmd( $brace . $backup['mysqldumppath'] . $brace ) . ' --force --host=' . escapeshellarg( $backup['host'] ) . ' --user=' . escapeshellarg( DB_USER ) . ' --password=' . escapeshellarg( $backup['password'] ) . $backup['port'] . $backup['sock'] . $backup['charset'] . ' --add-drop-table --skip-lock-tables ' . DB_NAME . ' | gzip > ' . escapeshellcmd( $brace . $backup['filepath'] . $brace );
46 } else {
47 $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
48 $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
49 $backup['command'] = escapeshellcmd( $brace . $backup['mysqldumppath'] . $brace ) . ' --force --host=' . escapeshellarg( $backup['host'] ) . ' --user=' . escapeshellarg( DB_USER ) . ' --password=' . escapeshellarg( $backup['password'] ) . $backup['port'] . $backup['sock'] . $backup['charset'] . ' --add-drop-table --skip-lock-tables ' . DB_NAME . ' > ' . escapeshellcmd( $brace . $backup['filepath'] . $brace );
50 }
51
52 $error = execute_backup($backup['command']);
53 if(!is_writable($backup['path'])) {
54 $text = '<p style="color: red;">'.sprintf(__('Database Failed To Backup On \'%s\'. Backup Folder Not Writable.', 'wp-dbmanager'), $current_date).'</p>';
55 } elseif(filesize($backup['filepath']) == 0) {
56 unlink($backup['filepath']);
57 $text = '<p style="color: red;">'.sprintf(__('Database Failed To Backup On \'%s\'. Backup File Size Is 0KB.', 'wp-dbmanager'), $current_date).'</p>';
58 } elseif(!is_file($backup['filepath'])) {
59 $text = '<p style="color: red;">'.sprintf(__('Database Failed To Backup On \'%s\'. Invalid Backup File Path.', 'wp-dbmanager'), $current_date).'</p>';
60 } elseif($error) {
61 $text = '<p style="color: red;">'.sprintf(__('Database Failed To Backup On \'%s\'.', 'wp-dbmanager'), $current_date).'</p>';
62 } else {
63 $text = '<p style="color: green;">'.sprintf(__('Database Backed Up Successfully On \'%s\'.', 'wp-dbmanager'), $current_date).'</p>';
64 }
65 break;
66 }
67 }
68
69
70 ### Backup File Name
71 $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
72
73
74 ### MYSQL Base Dir
75 $status_count = 0;
76 $stats_function_disabled = 0;
77 ?>
78 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
79 <!-- Checking Backup Status -->
80 <div class="wrap">
81 <h2><?php _e('Backup Database', 'wp-dbmanager'); ?></h2>
82 <h3><?php _e('Checking Backup Status', 'wp-dbmanager'); ?></h3>
83 <p>
84 <?php _e('Checking Backup Folder', 'wp-dbmanager'); ?> <span dir="ltr">(<strong><?php echo stripslashes($backup['path']); ?></strong>)</span> ...<br />
85 <?php
86 if( realpath( $backup['path'] ) === false ) {
87 echo '<p style="color: red;">' . sprintf( __( '%s is not a valid backup path', 'wp-dbmanager' ), stripslashes( $backup['path'] ) ) . '</p>';
88 $status_count++;
89 } else {
90 if (@is_dir(stripslashes($backup['path']))) {
91 echo '<p style="color: green;">' . __('Backup folder exists', 'wp-dbmanager') . '</p>';
92 $status_count++;
93 } else {
94 echo '<p style="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) . '</p>';
95 }
96 if (@is_writable(stripslashes($backup['path']))) {
97 echo '<p style="color: green;">' . __('Backup folder is writable', 'wp-dbmanager') . '</p>';
98 $status_count++;
99 } else {
100 echo '<p style="color: red;">' . __('Backup folder is NOT writable. Please CHMOD it to \'777\'.', 'wp-dbmanager') . '</p>';
101 }
102 }
103 ?>
104 </p>
105 <p>
106 <?php
107 if( dbmanager_is_valid_path( $backup['mysqldumppath'] ) === 0 ) {
108 echo '<p style="color: red;">' . sprintf( __( '%s is not a valid backup mysqldump path', 'wp-dbmanager' ), stripslashes( $backup['mysqldumppath'] ) ) . '</p>';
109 $status_count++;
110 } else {
111 if (@file_exists(stripslashes($backup['mysqldumppath']))) {
112 echo __('Checking MYSQL Dump Path', 'wp-dbmanager') . ' <span dir="ltr">(<strong>' . stripslashes($backup['mysqldumppath']) . '</strong>)</span> ...<br />';
113 echo '<p style="color: green;">' . __('MYSQL dump path exists.', 'wp-dbmanager') . '</p>';
114 $status_count++;
115 } else {
116 echo __('Checking MYSQL Dump Path', 'wp-dbmanager') . ' ...<br />';
117 echo '<p style="color: red;">' . __('MYSQL dump path does NOT exist. Please check your mysqldump path under DB Options. If uncertain, contact your server administrator.', 'wp-dbmanager') . '</p>';
118 }
119 }
120 ?>
121 </p>
122 <p>
123 <?php
124 if( dbmanager_is_valid_path( $backup['mysqlpath'] ) === 0 ) {
125 echo '<p style="color: red;">' . sprintf( __( '%s is not a valid backup mysql path', 'wp-dbmanager' ), stripslashes( $backup['mysqlpath'] ) ) . '</p>';
126 $status_count++;
127 } else {
128 if (@file_exists(stripslashes($backup['mysqlpath']))) {
129 echo __('Checking MYSQL Path', 'wp-dbmanager') . ' <span dir="ltr">(<strong>' . stripslashes($backup['mysqlpath']) . '</strong>)</span> ...<br />';
130 echo '<p style="color: green;">' . __('MYSQL path exists.', 'wp-dbmanager') . '</p>';
131 $status_count++;
132 } else {
133 echo __('Checking MYSQL Path', 'wp-dbmanager') . ' ...<br />';
134 echo '<p style="color: red;">' . __('MYSQL path does NOT exist. Please check your mysql path under DB Options. If uncertain, contact your server administrator.', 'wp-dbmanager') . '</p>';
135 }
136 }
137 ?>
138 </p>
139 <p>
140 <?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 />
141 <?php
142 if(function_exists('passthru')) {
143 echo '<p style="color: green;"><span dir="ltr">passthru()</span> '.__('enabled', 'wp-dbmanager').'.</p>';
144 $status_count++;
145 } else {
146 echo '<p style="color: red;"><span dir="ltr">passthru()</span> '.__('disabled', 'wp-dbmanager').'.</p>';
147 $stats_function_disabled++;
148 }
149 if(function_exists('system')) {
150 echo '<p style="color: green;"><span dir="ltr">system()</span> '.__('enabled', 'wp-dbmanager').'.</p>';
151 } else {
152 echo '<p style="color: red;"><span dir="ltr">system()</span> '.__('disabled', 'wp-dbmanager').'.</p>';
153 $stats_function_disabled++;
154 }
155 if(function_exists('exec')) {
156 echo '<p style="color: green;"><span dir="ltr">exec()</span> '.__('enabled', 'wp-dbmanager').'.</p>';
157 } else {
158 echo '<p style="color: red;"><span dir="ltr">exec()</span> '.__('disabled', 'wp-dbmanager').'.</p>';
159 $stats_function_disabled++;
160 }
161 ?>
162 </p>
163 <p>
164 <?php
165 if($status_count == 5) {
166 echo '<strong><p style="color: green;">'.__('Excellent. You Are Good To Go.', 'wp-dbmanager').'</p></strong>';
167 } else if($stats_function_disabled == 3) {
168 echo '<strong><p style="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').'</p></strong>';
169 } else {
170 echo '<strong><p style="color: red;">'.__('Please Rectify The Error Highlighted In Red Before Proceeding On.', 'wp-dbmanager').'</p></strong>';
171 }
172 ?>
173 </p>
174 <p><i><?php _e('Note: The checking of backup status is still undergoing testing, it may not be accurate.', 'wp-dbmanager'); ?></i></p>
175 </div>
176 <!-- Backup Database -->
177 <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
178 <?php wp_nonce_field('wp-dbmanager_backup'); ?>
179 <div class="wrap">
180 <h3><?php _e('Backup Database', 'wp-dbmanager'); ?></h3>
181 <br style="clear" />
182 <table class="widefat">
183 <thead>
184 <tr>
185 <th><?php _e('Option', 'wp-dbmanager'); ?></th>
186 <th><?php _e('Value', 'wp-dbmanager'); ?></th>
187 </tr>
188 </thead>
189 <tr>
190 <th><?php _e('Database Name:', 'wp-dbmanager'); ?></th>
191 <td><?php echo DB_NAME; ?></td>
192 </tr>
193 <tr style="background-color: #eee;">
194 <th><?php _e('Database Backup To:', 'wp-dbmanager'); ?></th>
195 <td><span dir="ltr"><?php echo stripslashes($backup['path']); ?></span></td>
196 </tr>
197 <tr>
198 <th><?php _e('Database Backup Date:', 'wp-dbmanager'); ?></th>
199 <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>
200 </tr>
201 <tr style="background-color: #eee;">
202 <th><?php _e('Database Backup File Name:', 'wp-dbmanager'); ?></th>
203 <td><span dir="ltr"><?php echo $backup['filename']; ?></span></td>
204 </tr>
205 <tr>
206 <th><?php _e('Database Backup Type:', 'wp-dbmanager'); ?></th>
207 <td><?php _e('Full (Structure and Data)', 'wp-dbmanager'); ?></td>
208 </tr>
209 <tr style="background-color: #eee;">
210 <th><?php _e('MYSQL Dump Location:', 'wp-dbmanager'); ?></th>
211 <td><span dir="ltr"><?php echo stripslashes($backup['mysqldumppath']); ?></span></td>
212 </tr>
213 <tr>
214 <th><?php _e('GZIP Database Backup File?', 'wp-dbmanager'); ?></th>
215 <td><input type="radio" id="gzip-yes" name="gzip" value="1" />&nbsp;<label for="gzip-yes"><?php _e('Yes', 'wp-dbmanager'); ?></label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" id="gzip-no" name="gzip" value="0" checked="checked" />&nbsp;<label for="gzip-no"><?php _e('No', 'wp-dbmanager'); ?></label></td>
216 </tr>
217 <tr>
218 <td colspan="2" align="center"><input type="submit" name="do" value="<?php _e('Backup', 'wp-dbmanager'); ?>" class="button" />&nbsp;&nbsp;<input type="button" name="cancel" value="<?php _e('Cancel', 'wp-dbmanager'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
219 </tr>
220 </table>
221 </div>
222 </form>
223