diff -r 490d5cc509ed -r cf61fcea0001 wp/wp-content/plugins/wp-db-backup/wp-db-backup.php
--- a/wp/wp-content/plugins/wp-db-backup/wp-db-backup.php Tue Jun 09 11:14:17 2015 +0000
+++ b/wp/wp-content/plugins/wp-db-backup/wp-db-backup.php Mon Oct 14 17:39:30 2019 +0200
@@ -1,13 +1,13 @@
Tools → Backup to get started.
-Author: Austin Matzko
+Author: Austin Matzko
Author URI: http://austinmatzko.com/
-Version: 2.2.4
+Version: 2.3.3
-Copyright 2013 Austin Matzko (email : austin at pressedcode.com)
+Copyright 2018 Austin Matzko (email : austin at pressedcode.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,36 +24,22 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
*/
-/**
- * Change WP_BACKUP_DIR if you want to
- * use a different backup location
- */
-
if ( ! defined('ABSPATH') ) {
die('Please do not load this file directly.');
}
$rand = substr( md5( md5( DB_PASSWORD ) ), -5 );
-global $wpdbb_content_dir, $wpdbb_content_url, $wpdbb_plugin_dir;
+global $wpdbb_content_dir, $wpdbb_content_url;
$wpdbb_content_dir = ( defined('WP_CONTENT_DIR') ) ? WP_CONTENT_DIR : ABSPATH . 'wp-content';
$wpdbb_content_url = ( defined('WP_CONTENT_URL') ) ? WP_CONTENT_URL : get_option('siteurl') . '/wp-content';
-$wpdbb_plugin_dir = ( defined('WP_PLUGIN_DIR') ) ? WP_PLUGIN_DIR : $wpdbb_content_dir . '/plugins';
-
-if ( ! defined('WP_BACKUP_DIR') ) {
- define('WP_BACKUP_DIR', $wpdbb_content_dir . '/backup-' . $rand . '/');
-}
-
-if ( ! defined('WP_BACKUP_URL') ) {
- define('WP_BACKUP_URL', $wpdbb_content_url . '/backup-' . $rand . '/');
-}
if ( ! defined('ROWS_PER_SEGMENT') ) {
define('ROWS_PER_SEGMENT', 100);
}
-/**
- * Set MOD_EVASIVE_OVERRIDE to true
- * and increase MOD_EVASIVE_DELAY
+/**
+ * Set MOD_EVASIVE_OVERRIDE to true
+ * and increase MOD_EVASIVE_DELAY
* if the backup stops prematurely.
*/
// define('MOD_EVASIVE_OVERRIDE', false);
@@ -71,30 +57,30 @@
var $basename;
var $page_url;
var $referer_check_key;
- var $version = '2.1.5-alpha';
+ var $version = '2.3.3';
function module_check() {
$mod_evasive = false;
if ( defined( 'MOD_EVASIVE_OVERRIDE' ) && true === MOD_EVASIVE_OVERRIDE ) return true;
if ( ! defined( 'MOD_EVASIVE_OVERRIDE' ) || false === MOD_EVASIVE_OVERRIDE ) return false;
- if ( function_exists('apache_get_modules') )
- foreach( (array) apache_get_modules() as $mod )
+ if ( function_exists('apache_get_modules') )
+ foreach( (array) apache_get_modules() as $mod )
if ( false !== strpos($mod,'mod_evasive') || false !== strpos($mod,'mod_dosevasive') )
return true;
return false;
}
- function wpdbBackup() {
+ function __construct() {
global $table_prefix, $wpdb;
add_action('wp_ajax_save_backup_time', array(&$this, 'save_backup_time'));
add_action('init', array(&$this, 'init_textdomain'));
add_action('init', array(&$this, 'set_page_url'));
- add_action('load-update-core.php', array(&$this, 'update_notice_action'));
+ add_action('admin_init', array(&$this, 'update_notice_action'));
add_action('wp_db_backup_cron', array(&$this, 'cron_backup'));
add_action('wp_cron_daily', array(&$this, 'wp_cron_daily'));
add_filter('cron_schedules', array(&$this, 'add_sched_options'));
add_filter('wp_db_b_schedule_choices', array(&$this, 'schedule_choices'));
-
+
$table_prefix = ( isset( $table_prefix ) ) ? $table_prefix : $wpdb->prefix;
$datum = date("Ymd_B");
$this->backup_filename = DB_NAME . "_$table_prefix$datum.sql";
@@ -122,27 +108,29 @@
$this->core_table_names[] = $wpdb->{$name};
}
}
-
- $this->backup_dir = trailingslashit(apply_filters('wp_db_b_backup_dir', WP_BACKUP_DIR));
+
+ $requested_temp_dir = sanitize_text_field($_GET['wp_db_temp_dir']);
+ $this->backup_dir = trailingslashit(apply_filters('wp_db_b_backup_dir', (isset($requested_temp_dir) && is_writable($requested_temp_dir)) ? $requested_temp_dir : get_temp_dir()));
$this->basename = 'wp-db-backup';
-
+
$this->referer_check_key = $this->basename . '-download_' . DB_NAME;
if (isset($_POST['do_backup'])) {
$this->wp_secure('fatal');
check_admin_referer($this->referer_check_key);
$this->can_user_backup('main');
+
// save exclude prefs
-
- $exc_revisions = isset( $_POST['exclude-revisions'] ) ? (array) $_POST['exclude-revisions'] : array();
- $exc_spam = isset( $_POST['exclude-spam'] ) ? (array) $_POST['exclude-spam'] : array();
- update_option('wp_db_backup_excs', array('revisions' => $exc_revisions, 'spam' => $exc_spam));
+ update_option('wp_db_backup_excs', array(
+ 'revisions' => $this->get_revisions_to_exclude(),
+ 'spam' => $this->get_spam_to_exclude()
+ ));
switch($_POST['do_backup']) {
case 'backup':
add_action('init', array(&$this, 'perform_backup'));
break;
case 'fragments':
add_action('admin_menu', array(&$this, 'fragment_menu'));
- break;
+ break;
}
} elseif (isset($_GET['fragment'] )) {
$this->can_user_backup('frame');
@@ -154,19 +142,19 @@
add_action('admin_menu', array(&$this, 'admin_menu'));
}
}
-
+
function init() {
$this->can_user_backup();
if (isset($_GET['backup'])) {
- $via = isset($_GET['via']) ? $_GET['via'] : 'http';
-
- $this->backup_file = $_GET['backup'];
+ $via = isset($_GET['via']) ? sanitize_text_field($_GET['via']) : 'http';
+
+ $this->backup_file = sanitize_text_field($_GET['backup']);
$this->validate_file($this->backup_file);
switch($via) {
case 'smtp':
case 'email':
- $success = $this->deliver_backup($this->backup_file, 'smtp', $_GET['recipient'], 'frame');
+ $success = $this->deliver_backup($this->backup_file, 'smtp', sanitize_text_field($_GET['recipient']), 'frame');
$this->error_display( 'frame' );
if ( $success ) {
echo '
@@ -175,7 +163,7 @@
';
echo '
alert("' . __('Backup Complete!','wp-db-backup') . '");
- window.onbeforeunload = null;
+ window.onbeforeunload = null;
';
}
@@ -183,7 +171,7 @@
default:
$success = $this->deliver_backup($this->backup_file, $via);
echo $this->error_display( 'frame', false );
-
+
if ( $success ) {
echo '
" : '%1$s';
- $line = ( 'frame' == $loc ) ?
+ $line = ( 'frame' == $loc ) ?
"try{ window.parent.addError('%1\$s'); } catch(e) { msgList += ' %1\$s';}\n" :
"%1\$s
\n";
foreach( (array) $err_list as $err )
@@ -768,8 +763,8 @@
* Taken partially from phpMyAdmin and partially from
* Alain Wolf, Zurich - Switzerland
* Website: http://restkultur.ch/personal/wolf/scripts/db_backup/
-
- * Modified by Scott Merrill (http://www.skippy.net/)
+
+ * Modified by Scott Merrill (http://www.skippy.net/)
* to use the WordPress $wpdb object
* @param string $table
* @param string $segment
@@ -783,7 +778,7 @@
$this->error(__('Error getting table details','wp-db-backup') . ": $table");
return false;
}
-
+
if(($segment == 'none') || ($segment == 0)) {
// Add SQL statement to drop existing table
$this->stow("\n\n");
@@ -792,7 +787,7 @@
$this->stow("#\n");
$this->stow("\n");
$this->stow("DROP TABLE IF EXISTS " . $this->backquote($table) . ";\n");
-
+
// Table structure
// Comment in SQL-file
$this->stow("\n\n");
@@ -800,7 +795,7 @@
$this->stow("# " . sprintf(__('Table structure of table %s','wp-db-backup'),$this->backquote($table)) . "\n");
$this->stow("#\n");
$this->stow("\n");
-
+
$create_table = $wpdb->get_results("SHOW CREATE TABLE $table", ARRAY_N);
if (false === $create_table) {
$err_msg = sprintf(__('Error with SHOW CREATE TABLE for %s.','wp-db-backup'), $table);
@@ -808,20 +803,20 @@
$this->stow("#\n# $err_msg\n#\n");
}
$this->stow($create_table[0][1] . ' ;');
-
+
if (false === $table_structure) {
$err_msg = sprintf(__('Error getting table structure of %s','wp-db-backup'), $table);
$this->error($err_msg);
$this->stow("#\n# $err_msg\n#\n");
}
-
+
// Comment in SQL-file
$this->stow("\n\n");
$this->stow("#\n");
$this->stow('# ' . sprintf(__('Data contents of table %s','wp-db-backup'),$this->backquote($table)) . "\n");
$this->stow("#\n");
}
-
+
if(($segment == 'none') || ($segment >= 0)) {
$defs = array();
$ints = array();
@@ -835,10 +830,10 @@
$ints[strtolower($struct->Field)] = "1";
}
}
-
-
+
+
// Batch by $row_inc
-
+
if($segment == 'none') {
$row_start = 0;
$row_inc = ROWS_PER_SEGMENT;
@@ -846,8 +841,8 @@
$row_start = $segment * ROWS_PER_SEGMENT;
$row_inc = ROWS_PER_SEGMENT;
}
-
- do {
+
+ do {
// don't include extra stuff, if so requested
$excs = (array) get_option('wp_db_backup_excs');
$where = '';
@@ -856,11 +851,11 @@
} elseif ( is_array($excs['revisions'] ) && in_array($table, $excs['revisions']) ) {
$where = ' WHERE post_type != "revision"';
}
-
+
if ( !ini_get('safe_mode')) @set_time_limit(15*60);
$table_data = $wpdb->get_results("SELECT * FROM $table $where LIMIT {$row_start}, {$row_inc}", ARRAY_A);
- $entries = 'INSERT INTO ' . $this->backquote($table) . ' VALUES (';
+ $entries = 'INSERT INTO ' . $this->backquote($table) . ' VALUES (';
// \x08\\x09, not required
$search = array("\x00", "\x0a", "\x0d", "\x1a");
$replace = array('\0', '\n', '\r', '\Z');
@@ -868,7 +863,7 @@
foreach ($table_data as $row) {
$values = array();
foreach ($row as $key => $value) {
- if ($ints[strtolower($key)]) {
+ if ( !empty($ints[strtolower($key)]) ) {
// make sure there are no blank spots in the insert syntax,
// yet try to avoid quotation marks around integers
$value = ( null === $value || '' === $value) ? $defs[strtolower($key)] : $value;
@@ -883,7 +878,7 @@
}
} while((count($table_data) > 0) and ($segment=='none'));
}
-
+
if(($segment == 'none') || ($segment < 0)) {
// Create footer/closing comment in SQL-file
$this->stow("\n");
@@ -893,10 +888,10 @@
$this->stow("\n");
}
} // end backup_table()
-
+
function db_backup($core_tables, $other_tables) {
global $table_prefix, $wpdb;
-
+
if (is_writable($this->backup_dir)) {
$this->fp = $this->open($this->backup_dir . $this->backup_filename);
if(!$this->fp) {
@@ -907,7 +902,7 @@
$this->error(__('The backup directory is not writeable!','wp-db-backup'));
return false;
}
-
+
//Begin new backup of MySql
$this->stow("# " . __('WordPress MySQL database backup','wp-db-backup') . "\n");
$this->stow("#\n");
@@ -915,12 +910,12 @@
$this->stow("# " . sprintf(__('Hostname: %s','wp-db-backup'),DB_HOST) . "\n");
$this->stow("# " . sprintf(__('Database: %s','wp-db-backup'),$this->backquote(DB_NAME)) . "\n");
$this->stow("# --------------------------------------------------------\n");
-
+
if ( (is_array($other_tables)) && (count($other_tables) > 0) )
$tables = array_merge($core_tables, $other_tables);
else
$tables = $core_tables;
-
+
foreach ($tables as $table) {
// Increase script execution time-limit to 15 min for every table.
if ( !ini_get('safe_mode')) @set_time_limit(15*60);
@@ -930,15 +925,15 @@
$this->stow("# --------------------------------------------------------\n");
$this->backup_table($table);
}
-
+
$this->close($this->fp);
-
+
if (count($this->errors)) {
return false;
} else {
return $this->backup_filename;
}
-
+
} //wp_db_backup
/**
@@ -966,12 +961,9 @@
// try to use phpmailer directly (WP 2.2+)
if ( is_object( $phpmailer ) && ( strtolower(get_class( $phpmailer )) == 'phpmailer' ) ) {
-
+
// Get the site domain and get rid of www.
- $sitename = strtolower( $_SERVER['SERVER_NAME'] );
- if ( substr( $sitename, 0, 4 ) == 'www.' ) {
- $sitename = substr( $sitename, 4 );
- }
+ $sitename = $this->get_sitename();
$from_email = 'wordpress@' . $sitename;
$from_name = 'WordPress';
@@ -994,7 +986,7 @@
$phpmailer->Subject = $subject;
do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
-
+
$result = @$phpmailer->Send();
// old-style: build the headers directly
@@ -1002,18 +994,18 @@
$randomish = md5(time());
$boundary = "==WPBACKUP-$randomish";
$fp = fopen($diskfile,"rb");
- $file = fread($fp,filesize($diskfile));
+ $file = fread($fp,filesize($diskfile));
$this->close($fp);
-
+
$data = chunk_split(base64_encode($file));
-
+
$headers .= "MIME-Version: 1.0\n";
- $headers = 'From: wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])) . "\n";
+ $headers = 'From: wordpress@' . preg_replace('#^www\.#', '', sanitize_text_field(strtolower($_SERVER['SERVER_NAME']))) . "\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
-
+
// Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
- "--{$boundary}\n" .
+ "--{$boundary}\n" .
"Content-Type: text/plain; charset=\"" . get_bloginfo('charset') . "\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
@@ -1027,7 +1019,7 @@
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$boundary}--\n";
-
+
$result = @wp_mail($to, $subject, $message, $headers);
}
return $result;
@@ -1036,7 +1028,7 @@
function deliver_backup($filename = '', $delivery = 'http', $recipient = '', $location = 'main') {
if ('' == $filename) { return false; }
-
+
$diskfile = $this->backup_dir . $filename;
$gz_diskfile = "{$diskfile}.gz";
@@ -1061,9 +1053,9 @@
}
$diskfile = $gz_diskfile;
$filename = "{$filename}.gz";
-
+
/**
- * Try to compress to gzip, if available
+ * Try to compress to gzip, if available
*/
} else {
if ( function_exists('gzencode') ) {
@@ -1083,7 +1075,7 @@
}
}
/*
- *
+ *
*/
} elseif ( file_exists( $gz_diskfile ) && empty( $_GET['download-retry'] ) ) {
$diskfile = $gz_diskfile;
@@ -1092,7 +1084,7 @@
if ('http' == $delivery) {
if ( ! file_exists( $diskfile ) ) {
- if ( empty( $_GET['download-retry'] ) ) {
+ if ( empty( $_GET['download-retry'] ) ) {
$this->error(array('kind' => 'fatal', 'msg' => sprintf(__('File not found:%s','wp-db-backup'), " $filename
") . '
' . __('Return to Backup','wp-db-backup') . ''));
} else {
return true;
@@ -1125,7 +1117,7 @@
$err = error_get_last();
$msg .= $err['message'];
} else {
- $msg .= __('ERROR: The mail application has failed to deliver the backup.','wp-db-backup');
+ $msg .= __('ERROR: The mail application has failed to deliver the backup.','wp-db-backup');
}
$this->error(array('kind' => 'fatal', 'loc' => $location, 'msg' => $msg));
} else {
@@ -1136,37 +1128,35 @@
}
return $success;
}
-
+
function backup_menu() {
global $table_prefix, $wpdb;
$feedback = '';
$whoops = false;
-
+
// did we just do a backup? If so, let's report the status
if ( $this->backup_complete ) {
$feedback = '
' . __('Backup Successful','wp-db-backup') . '!';
$file = $this->backup_file;
switch($_POST['deliver']) {
case 'http':
- $feedback .= '
' . sprintf(__('Your backup file: %2s should begin downloading shortly.','wp-db-backup'), WP_BACKUP_URL . "{$this->backup_file}", $this->backup_file);
+ $feedback .= '
' . sprintf(__('Your backup file: %2s should begin downloading shortly.','wp-db-backup'), "{$this->backup_file}", $this->backup_file);
break;
case 'smtp':
- if (! is_email($_POST['backup_recipient'])) {
+ $email = sanitize_text_field(wp_unslash($_POST['backup_recipient']));
+ if (! is_email($email)) {
$feedback .= get_option('admin_email');
} else {
- $feedback .= $_POST['backup_recipient'];
+ $feedback .= $email;
}
$feedback = '
' . sprintf(__('Your backup has been emailed to %s','wp-db-backup'), $feedback);
break;
- case 'none':
- $feedback .= '
' . __('Your backup file has been saved on the server. If you would like to download it now, right click and select "Save As"','wp-db-backup');
- $feedback .= ':
$file : " . sprintf(__('%s bytes','wp-db-backup'), filesize($this->backup_dir . $file));
}
$feedback .= '
' . __('The following errors were reported:','wp-db-backup') . '
'; @@ -1175,14 +1165,14 @@ } // did we just save options for wp-cron? - if ( (function_exists('wp_schedule_event') || function_exists('wp_cron_init')) + if ( (function_exists('wp_schedule_event') || function_exists('wp_cron_init')) && isset($_POST['wp_cron_backup_options']) ) : do_action('wp_db_b_update_cron_options'); if ( function_exists('wp_schedule_event') ) { wp_clear_scheduled_hook( 'wp_db_backup_cron' ); // unschedule previous $scheds = (array) wp_get_schedules(); - $name = strval($_POST['wp_cron_schedule']); - $interval = ( isset($scheds[$name]['interval']) ) ? + $name = sanitize_text_field(strval($_POST['wp_cron_schedule'])); + $interval = ( isset($scheds[$name]['interval']) ) ? (int) $scheds[$name]['interval'] : 0; update_option('wp_cron_backup_schedule', $name, false); if ( 0 !== $interval ) { @@ -1192,28 +1182,28 @@ else { update_option('wp_cron_backup_schedule', intval($_POST['cron_schedule']), false); } - update_option('wp_cron_backup_tables', isset( $_POST['wp_cron_backup_tables'] ) ? $_POST['wp_cron_backup_tables'] : array() ); + update_option('wp_cron_backup_tables', $this->get_submitted_tables_to_backup_in_cron()); if (is_email($_POST['cron_backup_recipient'])) { - update_option('wp_cron_backup_recipient', $_POST['cron_backup_recipient'], false); + update_option('wp_cron_backup_recipient', sanitize_text_field($_POST['cron_backup_recipient']), false); } $feedback .= '' . __('Scheduled Backup Options Saved!','wp-db-backup') . '
NOT writable! We cannot create the backup files.','wp-db-backup'); ?>
777', 'a+w
', '' . $this->backup_dir . '
'); ?>
-
NOT writable! We cannot create the backup files.','wp-db-backup'); ?>
NOT writable! We cannot create the backup files.','wp-db-backup'); ?>
safe_mode file ownership restrictions, which limit what files web applications like WordPress can create.', 'wp-db-backup'); ?>
safe_mode file ownership restrictions, which limit what files web applications like WordPress can create.', 'wp-db-backup'); ?>
' . $this->backup_dir . ''); - ?>