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-backup.php

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

245 lines 12.2 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['charset'] = ' --default-character-set="utf8"';
19
20 ### Form Processing
21 if(!empty($_POST['do'])) {
22 $text = '';
23 // Decide What To Do
24 switch($_POST['do']) {
25 case __('Backup', 'wp-dbmanager'):
26 check_admin_referer('wp-dbmanager_backup');
27 $brace = (substr(PHP_OS, 0, 3) == 'WIN') ? '"' : '';
28 $backup['host'] = DB_HOST;
29 $backup['port'] = '';
30 $backup['sock'] = '';
31 if(strpos(DB_HOST, ':') !== false) {
32 $db_host = explode(':', DB_HOST);
33 $backup['host'] = $db_host[0];
34 if(intval($db_host[1]) != 0) {
35 $backup['port'] = ' --port=' . escapeshellarg( intval( $db_host[1] ) );
36 } else {
37 $backup['sock'] = ' --socket=' . escapeshellarg( $db_host[1] );
38 }
39 }
40 $gzip = intval($_POST['gzip']);
41
42 if($gzip == 1) {
43 $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql.gz';
44 $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
45 do_action( 'wp_dbmanager_before_escapeshellcmd' );
46 $backup['command'] = escapeshellcmd( $brace . $backup['mysqldumppath'] . $brace ) . ' --force --host=' . escapeshellarg( $backup['host'] ) . ' --user=' . escapeshellarg( DB_USER ) . ' --password=' . escapeshellarg( DB_PASSWORD ) . $backup['port'] . $backup['sock'] . $backup['charset'] . ' --add-drop-table --skip-lock-tables ' . DB_NAME . ' | gzip > ' . escapeshellcmd( $brace . $backup['filepath'] . $brace );
47 } else {
48 $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
49 $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
50 do_action( 'wp_dbmanager_before_escapeshellcmd' );
51 $backup['command'] = escapeshellcmd( $brace . $backup['mysqldumppath'] . $brace ) . ' --force --host=' . escapeshellarg( $backup['host'] ) . ' --user=' . escapeshellarg( DB_USER ) . ' --password=' . escapeshellarg( DB_PASSWORD ) . $backup['port'] . $backup['sock'] . $backup['charset'] . ' --add-drop-table --skip-lock-tables ' . DB_NAME . ' > ' . escapeshellcmd( $brace . $backup['filepath'] . $brace );
52 }
53 $error = execute_backup( $backup['command'] );
54 if(!is_writable( $backup['path'] ) ) {
55 $text = '<p style="color: red;">'.sprintf(__('Database Failed To Backup On \'%s\'. Backup Folder Not Writable.', 'wp-dbmanager'), $current_date).'</p>';
56 } elseif( is_file( $backup['filepath'] ) && filesize( $backup['filepath'] ) === 0 ) {
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 ### Backup File Name
70 $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
71 $backup_path = stripslashes( $backup['path'] );
72
73 ### MYSQL Base Dir
74 $status_count = 0;
75 $stats_function_disabled = 0;
76 ?>
77 <?php if( ! empty( $text ) ) { echo '<div id="message" class="updated">'.$text.'</div>'; } ?>
78 <!-- Checking Backup Status -->
79 <div class="wrap">
80 <h2><?php _e('Backup Database', 'wp-dbmanager'); ?></h2>
81 <h3><?php _e('Checking Security Status', 'wp-dbmanager'); ?></h3>
82 <p>
83 <?php
84 if( is_iis() ) {
85 if ( ! is_file( $backup_path . '/Web.config' ) ) {
86 echo '<p style="color: red;">' . sprintf( __( 'Web.config is missing from %s', 'wp-dbmanager' ), $backup_path ) . '</p>';
87 } else {
88 echo '<p style="color: green;">' . sprintf( __( 'Web.config is present in %s', 'wp-dbmanager' ), $backup_path ) . '</p>';
89 }
90 } else {
91 if( ! is_file( $backup_path . '/.htaccess' ) ) {
92 echo '<p style="color: red;">' . sprintf( __( '.htaccess is missing from %s', 'wp-dbmanager' ), $backup_path ) . '</p>';
93 } else {
94 echo '<p style="color: green;">' . sprintf( __( '.htaccess is present in %s', 'wp-dbmanager' ), $backup_path ) . '</p>';
95 }
96 }
97 if( ! is_file( $backup_path . '/index.php' ) ) {
98 echo '<p style="color: red;">' . sprintf( __( 'index.php is missing from %s', 'wp-dbmanager' ), $backup_path ) . '</p>';
99 } else {
100 echo '<p style="color: green;">' . sprintf( __( 'index.php is present in %s', 'wp-dbmanager' ), $backup_path ) . '</p>';
101 }
102 ?>
103 </p>
104 <h3><?php _e('Checking Backup Status', 'wp-dbmanager'); ?></h3>
105 <p>
106 <?php _e('Checking Backup Folder', 'wp-dbmanager'); ?> <span dir="ltr">(<strong><?php echo $backup_path; ?></strong>)</span> ...<br />
107 <?php
108 if( realpath( $backup_path ) === false ) {
109 echo '<p style="color: red;">' . sprintf( __( '%s is not a valid backup path', 'wp-dbmanager' ), $backup_path ) . '</p>';
110 $status_count++;
111 } else {
112 if ( @is_dir( $backup_path ) ) {
113 echo '<p style="color: green;">' . __('Backup folder exists', 'wp-dbmanager') . '</p>';
114 $status_count++;
115 } else {
116 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>';
117 }
118 if ( @is_writable( $backup_path ) ) {
119 echo '<p style="color: green;">' . __('Backup folder is writable', 'wp-dbmanager') . '</p>';
120 $status_count++;
121 } else {
122 echo '<p style="color: red;">' . __('Backup folder is NOT writable. Please CHMOD it to \'777\'.', 'wp-dbmanager') . '</p>';
123 }
124 }
125 ?>
126 </p>
127 <p>
128 <?php
129 if( dbmanager_is_valid_path( $backup['mysqldumppath'] ) === 0 ) {
130 echo '<p style="color: red;">' . sprintf( __( '%s is not a valid backup mysqldump path', 'wp-dbmanager' ), stripslashes( $backup['mysqldumppath'] ) ) . '</p>';
131 $status_count++;
132 } else {
133 if ( @file_exists( stripslashes( $backup['mysqldumppath'] ) ) ) {
134 echo __('Checking MYSQL Dump Path', 'wp-dbmanager') . ' <span dir="ltr">(<strong>' . stripslashes( $backup['mysqldumppath'] ) . '</strong>)</span> ...<br />';
135 echo '<p style="color: green;">' . __('MYSQL dump path exists.', 'wp-dbmanager') . '</p>';
136 $status_count++;
137 } else {
138 echo __('Checking MYSQL Dump Path', 'wp-dbmanager') . ' ...<br />';
139 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>';
140 }
141 }
142 ?>
143 </p>
144 <p>
145 <?php
146 if( dbmanager_is_valid_path( $backup['mysqlpath'] ) === 0 ) {
147 echo '<p style="color: red;">' . sprintf( __( '%s is not a valid backup mysql path', 'wp-dbmanager' ), stripslashes( $backup['mysqlpath'] ) ) . '</p>';
148 $status_count++;
149 } else {
150 if ( @file_exists( stripslashes($backup['mysqlpath'] ) ) ) {
151 echo __('Checking MYSQL Path', 'wp-dbmanager') . ' <span dir="ltr">(<strong>' . stripslashes($backup['mysqlpath']) . '</strong>)</span> ...<br />';
152 echo '<p style="color: green;">' . __('MYSQL path exists.', 'wp-dbmanager') . '</p>';
153 $status_count++;
154 } else {
155 echo __('Checking MYSQL Path', 'wp-dbmanager') . ' ...<br />';
156 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>';
157 }
158 }
159 ?>
160 </p>
161 <p>
162 <?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 />
163 <?php
164 if( function_exists( 'passthru' ) ) {
165 echo '<p style="color: green;"><span dir="ltr">passthru()</span> '.__('enabled', 'wp-dbmanager').'.</p>';
166 $status_count++;
167 } else {
168 echo '<p style="color: red;"><span dir="ltr">passthru()</span> '.__('disabled', 'wp-dbmanager').'.</p>';
169 $stats_function_disabled++;
170 }
171 if( function_exists( 'system' ) ) {
172 echo '<p style="color: green;"><span dir="ltr">system()</span> '.__('enabled', 'wp-dbmanager').'.</p>';
173 } else {
174 echo '<p style="color: red;"><span dir="ltr">system()</span> '.__('disabled', 'wp-dbmanager').'.</p>';
175 $stats_function_disabled++;
176 }
177 if( function_exists( 'exec' ) ) {
178 echo '<p style="color: green;"><span dir="ltr">exec()</span> '.__('enabled', 'wp-dbmanager').'.</p>';
179 } else {
180 echo '<p style="color: red;"><span dir="ltr">exec()</span> '.__('disabled', 'wp-dbmanager').'.</p>';
181 $stats_function_disabled++;
182 }
183 ?>
184 </p>
185 <p>
186 <?php
187 if( $status_count === 5 ) {
188 echo '<strong><p style="color: green;">'.__('Excellent. You Are Good To Go.', 'wp-dbmanager').'</p></strong>';
189 } else if( $stats_function_disabled === 3 ) {
190 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>';
191 } else {
192 echo '<strong><p style="color: red;">'.__('Please Rectify The Error Highlighted In Red Before Proceeding On.', 'wp-dbmanager').'</p></strong>';
193 }
194 ?>
195 </p>
196 <p><i><?php _e('Note: The checking of backup status is still undergoing testing, it may not be accurate.', 'wp-dbmanager'); ?></i></p>
197 </div>
198 <!-- Backup Database -->
199 <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
200 <?php wp_nonce_field('wp-dbmanager_backup'); ?>
201 <div class="wrap">
202 <h3><?php _e('Backup Database', 'wp-dbmanager'); ?></h3>
203 <br style="clear" />
204 <table class="widefat">
205 <thead>
206 <tr>
207 <th><?php _e('Option', 'wp-dbmanager'); ?></th>
208 <th><?php _e('Value', 'wp-dbmanager'); ?></th>
209 </tr>
210 </thead>
211 <tr>
212 <th><?php _e('Database Name:', 'wp-dbmanager'); ?></th>
213 <td><?php echo DB_NAME; ?></td>
214 </tr>
215 <tr style="background-color: #eee;">
216 <th><?php _e('Database Backup To:', 'wp-dbmanager'); ?></th>
217 <td><span dir="ltr"><?php echo $backup_path; ?></span></td>
218 </tr>
219 <tr>
220 <th><?php _e('Database Backup Date:', 'wp-dbmanager'); ?></th>
221 <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>
222 </tr>
223 <tr style="background-color: #eee;">
224 <th><?php _e('Database Backup File Name:', 'wp-dbmanager'); ?></th>
225 <td><span dir="ltr"><?php echo $backup['filename']; ?></span></td>
226 </tr>
227 <tr>
228 <th><?php _e('Database Backup Type:', 'wp-dbmanager'); ?></th>
229 <td><?php _e('Full (Structure and Data)', 'wp-dbmanager'); ?></td>
230 </tr>
231 <tr style="background-color: #eee;">
232 <th><?php _e('MYSQL Dump Location:', 'wp-dbmanager'); ?></th>
233 <td><span dir="ltr"><?php echo stripslashes($backup['mysqldumppath']); ?></span></td>
234 </tr>
235 <tr>
236 <th><?php _e('GZIP Database Backup File?', 'wp-dbmanager'); ?></th>
237 <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>
238 </tr>
239 <tr>
240 <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>
241 </tr>
242 </table>
243 </div>
244 </form>
245