PluginProbe
WP-DBManager / 2.71
WP-DBManager v2.71
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.71, at database-backup.php

207 lines 10.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 $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="'.intval($db_host[1]).'"';
37 } else {
38 $backup['sock'] = ' --socket="'.$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'] = $brace.$backup['mysqldumppath'].$brace.' --force --host="'.$backup['host'].'" --user="'.DB_USER.'" --password="'.$backup['password'].'"'.$backup['port'].$backup['sock'].$backup['charset'].' --add-drop-table --skip-lock-tables '.DB_NAME.' | gzip > '.$brace.$backup['filepath'].$brace;
46 } else {
47 $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
48 $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
49 $backup['command'] = $brace.$backup['mysqldumppath'].$brace.' --force --host="'.$backup['host'].'" --user="'.DB_USER.'" --password="'.$backup['password'].'"'.$backup['port'].$backup['sock'].$backup['charset'].' --add-drop-table --skip-lock-tables '.DB_NAME.' > '.$brace.$backup['filepath'].$brace;
50 }
51 $error = execute_backup($backup['command']);
52 if(!is_writable($backup['path'])) {
53 $text = '<font color="red">'.sprintf(__('Database Failed To Backup On \'%s\'. Backup Folder Not Writable.', 'wp-dbmanager'), $current_date).'</font>';
54 } elseif(filesize($backup['filepath']) == 0) {
55 unlink($backup['filepath']);
56 $text = '<font color="red">'.sprintf(__('Database Failed To Backup On \'%s\'. Backup File Size Is 0KB.', 'wp-dbmanager'), $current_date).'</font>';
57 } elseif(!is_file($backup['filepath'])) {
58 $text = '<font color="red">'.sprintf(__('Database Failed To Backup On \'%s\'. Invalid Backup File Path.', 'wp-dbmanager'), $current_date).'</font>';
59 } elseif($error) {
60 $text = '<font color="red">'.sprintf(__('Database Failed To Backup On \'%s\'.', 'wp-dbmanager'), $current_date).'</font>';
61 } else {
62 $text = '<font color="green">'.sprintf(__('Database Backed Up Successfully On \'%s\'.', 'wp-dbmanager'), $current_date).'</font>';
63 }
64 break;
65 }
66 }
67
68
69 ### Backup File Name
70 $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
71
72
73 ### MYSQL Base Dir
74 $status_count = 0;
75 $stats_function_disabled = 0;
76 ?>
77 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
78 <!-- Checking Backup Status -->
79 <div class="wrap">
80 <h2><?php _e('Backup Database', 'wp-dbmanager'); ?></h2>
81 <h3><?php _e('Checking Backup Status', 'wp-dbmanager'); ?></h3>
82 <p>
83 <?php _e('Checking Backup Folder', 'wp-dbmanager'); ?> <span dir="ltr">(<strong><?php echo stripslashes($backup['path']); ?></strong>)</span> ...<br />
84 <?php
85 if(@is_dir(stripslashes($backup['path']))) {
86 echo '<font color="green">'.__('Backup folder exists', 'wp-dbmanager').'</font><br />';
87 $status_count++;
88 } else {
89 echo '<font 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).'</font><br />';
90 }
91 if(@is_writable(stripslashes($backup['path']))) {
92 echo '<font color="green">'.__('Backup folder is writable', 'wp-dbmanager').'</font>';
93 $status_count++;
94 } else {
95 echo '<font color="red">'.__('Backup folder is NOT writable. Please CHMOD it to \'777\'.', 'wp-dbmanager').'</font>';
96 }
97 ?>
98 </p>
99 <p>
100 <?php
101 if(@file_exists(stripslashes($backup['mysqldumppath']))) {
102 echo __('Checking MYSQL Dump Path', 'wp-dbmanager').' <span dir="ltr">(<strong>'.stripslashes($backup['mysqldumppath']).'</strong>)</span> ...<br />';
103 echo '<font color="green">'.__('MYSQL dump path exists.', 'wp-dbmanager').'</font>';
104 $status_count++;
105 } else {
106 echo __('Checking MYSQL Dump Path', 'wp-dbmanager').' ...<br />';
107 echo '<font color="red">'.__('MYSQL dump path does NOT exist. Please check your mysqldump path under DB Options. If uncertain, contact your server administrator.', 'wp-dbmanager').'</font>';
108 }
109 ?>
110 </p>
111 <p>
112 <?php
113 if(@file_exists(stripslashes($backup['mysqlpath']))) {
114 echo __('Checking MYSQL Path', 'wp-dbmanager').' <span dir="ltr">(<strong>'.stripslashes($backup['mysqlpath']).'</strong>)</span> ...<br />';
115 echo '<font color="green">'.__('MYSQL path exists.', 'wp-dbmanager').'</font>';
116 $status_count++;
117 } else {
118 echo __('Checking MYSQL Path', 'wp-dbmanager').' ...<br />';
119 echo '<font color="red">'.__('MYSQL path does NOT exist. Please check your mysql path under DB Options. If uncertain, contact your server administrator.', 'wp-dbmanager').'</font>';
120 }
121 ?>
122 </p>
123 <p>
124 <?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 />
125 <?php
126 if(function_exists('passthru')) {
127 echo '<font color="green"><span dir="ltr">passthru()</span> '.__('enabled', 'wp-dbmanager').'.</font><br />';
128 $status_count++;
129 } else {
130 echo '<font color="red"><span dir="ltr">passthru()</span> '.__('disabled', 'wp-dbmanager').'.</font><br />';
131 $stats_function_disabled++;
132 }
133 if(function_exists('system')) {
134 echo '<font color="green"><span dir="ltr">system()</span> '.__('enabled', 'wp-dbmanager').'.</font><br />';
135 } else {
136 echo '<font color="red"><span dir="ltr">system()</span> '.__('disabled', 'wp-dbmanager').'.</font><br />';
137 $stats_function_disabled++;
138 }
139 if(function_exists('exec')) {
140 echo '<font color="green"><span dir="ltr">exec()</span> '.__('enabled', 'wp-dbmanager').'.</font>';
141 } else {
142 echo '<font color="red"><span dir="ltr">exec()</span> '.__('disabled', 'wp-dbmanager').'.</font>';
143 $stats_function_disabled++;
144 }
145 ?>
146 </p>
147 <p>
148 <?php
149 if($status_count == 5) {
150 echo '<strong><font color="green">'.__('Excellent. You Are Good To Go.', 'wp-dbmanager').'</font></strong>';
151 } else if($stats_function_disabled == 3) {
152 echo '<strong><font 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').'</font></strong>';
153 } else {
154 echo '<strong><font color="red">'.__('Please Rectify The Error Highlighted In Red Before Proceeding On.', 'wp-dbmanager').'</font></strong>';
155 }
156 ?>
157 </p>
158 <p><i><?php _e('Note: The checking of backup status is still undergoing testing, it may not be accurate.', 'wp-dbmanager'); ?></i></p>
159 </div>
160 <!-- Backup Database -->
161 <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
162 <?php wp_nonce_field('wp-dbmanager_backup'); ?>
163 <div class="wrap">
164 <h3><?php _e('Backup Database', 'wp-dbmanager'); ?></h3>
165 <br style="clear" />
166 <table class="widefat">
167 <thead>
168 <tr>
169 <th><?php _e('Option', 'wp-dbmanager'); ?></th>
170 <th><?php _e('Value', 'wp-dbmanager'); ?></th>
171 </tr>
172 </thead>
173 <tr>
174 <th><?php _e('Database Name:', 'wp-dbmanager'); ?></th>
175 <td><?php echo DB_NAME; ?></td>
176 </tr>
177 <tr style="background-color: #eee;">
178 <th><?php _e('Database Backup To:', 'wp-dbmanager'); ?></th>
179 <td><span dir="ltr"><?php echo stripslashes($backup['path']); ?></span></td>
180 </tr>
181 <tr>
182 <th><?php _e('Database Backup Date:', 'wp-dbmanager'); ?></th>
183 <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>
184 </tr>
185 <tr style="background-color: #eee;">
186 <th><?php _e('Database Backup File Name:', 'wp-dbmanager'); ?></th>
187 <td><span dir="ltr"><?php echo $backup['filename']; ?></span></td>
188 </tr>
189 <tr>
190 <th><?php _e('Database Backup Type:', 'wp-dbmanager'); ?></th>
191 <td><?php _e('Full (Structure and Data)', 'wp-dbmanager'); ?></td>
192 </tr>
193 <tr style="background-color: #eee;">
194 <th><?php _e('MYSQL Dump Location:', 'wp-dbmanager'); ?></th>
195 <td><span dir="ltr"><?php echo stripslashes($backup['mysqldumppath']); ?></span></td>
196 </tr>
197 <tr>
198 <th><?php _e('GZIP Database Backup File?', 'wp-dbmanager'); ?></th>
199 <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>
200 </tr>
201 <tr>
202 <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>
203 </tr>
204 </table>
205 </div>
206 </form>
207