| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
if(!current_user_can('manage_database')) { |
|---|
| 22 |
die('Access Denied'); |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
$base_name = plugin_basename('wp-dbmanager/database-manager.php'); |
|---|
| 28 |
$base_page = 'admin.php?page='.$base_name; |
|---|
| 29 |
$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'))); |
|---|
| 30 |
$backup = array(); |
|---|
| 31 |
$backup_options = get_option('dbmanager_options'); |
|---|
| 32 |
$backup['date'] = current_time('timestamp'); |
|---|
| 33 |
$backup['mysqldumppath'] = $backup_options['mysqldumppath']; |
|---|
| 34 |
$backup['mysqlpath'] = $backup_options['mysqlpath']; |
|---|
| 35 |
$backup['path'] = $backup_options['path']; |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
if($_POST['do']) { |
|---|
| 40 |
|
|---|
| 41 |
switch($_POST['do']) { |
|---|
| 42 |
case __('Backup', 'wp-dbmanager'): |
|---|
| 43 |
$gzip = intval($_POST['gzip']); |
|---|
| 44 |
if($gzip == 1) { |
|---|
| 45 |
$backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql.gz'; |
|---|
| 46 |
$backup['filepath'] = $backup['path'].'/'.$backup['filename']; |
|---|
| 47 |
$backup['command'] = $backup['mysqldumppath'].' --host="'.DB_HOST.'" --user="'.DB_USER.'" --password="'.DB_PASSWORD.'" --add-drop-table --skip-lock-tables '.DB_NAME.' | gzip > '.$backup['filepath']; |
|---|
| 48 |
} else { |
|---|
| 49 |
$backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql'; |
|---|
| 50 |
$backup['filepath'] = $backup['path'].'/'.$backup['filename']; |
|---|
| 51 |
$backup['command'] = $backup['mysqldumppath'].' --host="'.DB_HOST.'" --user="'.DB_USER.'" --password="'.DB_PASSWORD.'" --add-drop-table --skip-lock-tables '.DB_NAME.' > '.$backup['filepath']; |
|---|
| 52 |
} |
|---|
| 53 |
$error = execute_backup($backup['command']); |
|---|
| 54 |
if(!is_writable($backup['path'])) { |
|---|
| 55 |
$text = '<font color="red">'.sprintf(__('Database Failed To Backup On \'%s\'. Backup Folder Not Writable.', 'wp-dbmanager'), $current_date).'</font>'; |
|---|
| 56 |
} elseif(filesize($backup['filepath']) == 0) { |
|---|
| 57 |
unlink($backup['filepath']); |
|---|
| 58 |
$text = '<font color="red">'.sprintf(__('Database Failed To Backup On \'%s\'. Backup File Size Is 0KB.', 'wp-dbmanager'), $current_date).'</font>'; |
|---|
| 59 |
} elseif(!is_file($backup['filepath'])) { |
|---|
| 60 |
$text = '<font color="red">'.sprintf(__('Database Failed To Backup On \'%s\'. Invalid Backup File Path.', 'wp-dbmanager'), $current_date).'</font>'; |
|---|
| 61 |
} elseif($error) { |
|---|
| 62 |
$text = '<font color="red">'.sprintf(__('Database Failed To Backup On \'%s\'.', 'wp-dbmanager'), $current_date).'</font>'; |
|---|
| 63 |
} else { |
|---|
| 64 |
$text = '<font color="green">'.sprintf(__('Database Backed Up Successfully On \'%s\'.', 'wp-dbmanager'), $current_date).'</font>'; |
|---|
| 65 |
} |
|---|
| 66 |
break; |
|---|
| 67 |
} |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
$backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql'; |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
$status_count = 0; |
|---|
| 77 |
$stats_function_disabled = 0; |
|---|
| 78 |
?> |
|---|
| 79 |
<?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> |
|---|
| 80 |
<!-- Checking Backup Status --> |
|---|
| 81 |
<div class="wrap"> |
|---|
| 82 |
<h2><?php _e('Checking Backup Status', 'wp-dbmanager'); ?></h2> |
|---|
| 83 |
<p> |
|---|
| 84 |
<?php _e('Checking Backup Folder', 'wp-dbmanager'); ?> (<strong><?php echo stripslashes($backup['path']); ?></strong>) ...<br /> |
|---|
| 85 |
<?php |
|---|
| 86 |
if(@is_dir(stripslashes($backup['path']))) { |
|---|
| 87 |
echo '<font color="green">'.__('Backup folder exists', 'wp-dbmanager').'</font><br />'; |
|---|
| 88 |
$status_count++; |
|---|
| 89 |
} else { |
|---|
| 90 |
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 />'; |
|---|
| 91 |
} |
|---|
| 92 |
if(@is_writable(stripslashes($backup['path']))) { |
|---|
| 93 |
echo '<font color="green">'.__('Backup folder is writable', 'wp-dbmanager').'</font>'; |
|---|
| 94 |
$status_count++; |
|---|
| 95 |
} else { |
|---|
| 96 |
echo '<font color="red">'.__('Backup folder is NOT writable. Please CHMOD it to \'777\'.', 'wp-dbmanager').'</font>'; |
|---|
| 97 |
} |
|---|
| 98 |
?> |
|---|
| 99 |
</p> |
|---|
| 100 |
<p> |
|---|
| 101 |
<?php |
|---|
| 102 |
if(@file_exists(stripslashes($backup['mysqldumppath']))) { |
|---|
| 103 |
echo __('Checking MYSQL Dump Path', 'wp-dbmanager').' (<strong>'.stripslashes($backup['mysqldumppath']).'</strong>) ...<br />'; |
|---|
| 104 |
echo '<font color="green">'.__('MYSQL dump path exists.', 'wp-dbmanager').'</font>'; |
|---|
| 105 |
$status_count++; |
|---|
| 106 |
} else { |
|---|
| 107 |
echo __('Checking MYSQL Dump Path', 'wp-dbmanager').' ...<br />'; |
|---|
| 108 |
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>'; |
|---|
| 109 |
} |
|---|
| 110 |
?> |
|---|
| 111 |
</p> |
|---|
| 112 |
<p> |
|---|
| 113 |
<?php |
|---|
| 114 |
if(@file_exists(stripslashes($backup['mysqlpath']))) { |
|---|
| 115 |
echo __('Checking MYSQL Path', 'wp-dbmanager').' (<strong>'.stripslashes($backup['mysqlpath']).'</strong>) ...<br />'; |
|---|
| 116 |
echo '<font color="green">'.__('MYSQL path exists.', 'wp-dbmanager').'</font>'; |
|---|
| 117 |
$status_count++; |
|---|
| 118 |
} else { |
|---|
| 119 |
echo __('Checking MYSQL Path', 'wp-dbmanager').' ...<br />'; |
|---|
| 120 |
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>'; |
|---|
| 121 |
} |
|---|
| 122 |
?> |
|---|
| 123 |
</p> |
|---|
| 124 |
<p> |
|---|
| 125 |
<?php _e('Checking PHP Functions', 'wp-dbmanager'); ?> (<strong>passthru()</strong>, <strong>system()</strong> <?php _e('and', 'wp-dbmanager'); ?> <strong>exec()</strong>) ...<br /> |
|---|
| 126 |
<?php |
|---|
| 127 |
if(function_exists('passthru')) { |
|---|
| 128 |
echo '<font color="green">passthru() '.__('enabled', 'wp-dbmanager').'.</font><br />'; |
|---|
| 129 |
$status_count++; |
|---|
| 130 |
} else { |
|---|
| 131 |
echo '<font color="red">passthru() '.__('disabled', 'wp-dbmanager').'.</font><br />'; |
|---|
| 132 |
$stats_function_disabled++; |
|---|
| 133 |
} |
|---|
| 134 |
if(function_exists('system')) { |
|---|
| 135 |
echo '<font color="green">system() '.__('enabled', 'wp-dbmanager').'.</font><br />'; |
|---|
| 136 |
} else { |
|---|
| 137 |
echo '<font color="red">system() '.__('disabled', 'wp-dbmanager').'.</font><br />'; |
|---|
| 138 |
$stats_function_disabled++; |
|---|
| 139 |
} |
|---|
| 140 |
if(function_exists('exec')) { |
|---|
| 141 |
echo '<font color="green">exec() '.__('enabled', 'wp-dbmanager').'.</font>'; |
|---|
| 142 |
} else { |
|---|
| 143 |
echo '<font color="red">exec() '.__('disabled', 'wp-dbmanager').'.</font>'; |
|---|
| 144 |
$stats_function_disabled++; |
|---|
| 145 |
} |
|---|
| 146 |
?> |
|---|
| 147 |
</p> |
|---|
| 148 |
<p> |
|---|
| 149 |
<?php |
|---|
| 150 |
if($status_count == 5) { |
|---|
| 151 |
echo '<strong><font color="green">'.__('Excellent. You Are Good To Go.', 'wp-dbmanager').'</font></strong>'; |
|---|
| 152 |
} else if($stats_function_disabled == 3) { |
|---|
| 153 |
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>'; |
|---|
| 154 |
} else { |
|---|
| 155 |
echo '<strong><font color="red">'.__('Please Rectify The Error Highlighted In Red Before Proceeding On.', 'wp-dbmanager').'</font></strong>'; |
|---|
| 156 |
} |
|---|
| 157 |
?> |
|---|
| 158 |
</p> |
|---|
| 159 |
<p><i><?php _e('Note: The checking of backup status is still undergoing testing, it may not be accurate.', 'wp-dbmanager'); ?></i></p> |
|---|
| 160 |
</div> |
|---|
| 161 |
<!-- Backup Database --> |
|---|
| 162 |
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post"> |
|---|
| 163 |
<div class="wrap"> |
|---|
| 164 |
<h2><?php _e('Backup Database', 'wp-dbmanager'); ?></h2> |
|---|
| 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><?php echo stripslashes($backup['path']); ?></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><?php echo $backup['filename']; ?></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><?php echo stripslashes($backup['mysqldumppath']); ?></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" /> <label for="gzip-yes"><?php _e('Yes', 'wp-dbmanager'); ?></label> <input type="radio" id="gzip-no" name="gzip" value="0" checked="checked" /> <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" /> <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> |
|---|