array(), 'onedrive' => array(), 'googledrive' => array(), 'googlecloud' => array()); public function __construct() { $this->admin_init(); } private function wp_normalize_path($path) { // wp_normalize_path is not present before WP 3.9 if (function_exists('wp_normalize_path')) return wp_normalize_path($path); // Taken from WP 4.6 $path = str_replace('\\', '/', $path); $path = preg_replace('|(?<=.)/+|', '/', $path); if (':' === substr($path, 1, 1)) { $path = ucfirst($path); } return $path; } /** * Get the path to the UI templates directory * * @return String - a filesystem directory path */ public function get_templates_dir() { return apply_filters('updraftplus_templates_dir', $this->wp_normalize_path(UPDRAFTPLUS_DIR.'/templates')); } private function register_template_directories() { $template_directories = array(); $templates_dir = $this->get_templates_dir(); if ($dh = opendir($templates_dir)) { while (($file = readdir($dh)) !== false) { if ('.' == $file || '..' == $file) continue; if (is_dir($templates_dir.'/'.$file)) { $template_directories[$file] = $templates_dir.'/'.$file; } } closedir($dh); } // This is the optimal hook for most extensions to hook into $this->template_directories = apply_filters('updraftplus_template_directories', $template_directories); } public function include_template($path, $return_instead_of_echo = false, $extract_these = array()) { if ($return_instead_of_echo) ob_start(); if (preg_match('#^([^/]+)/(.*)$#', $path, $matches)) { $prefix = $matches[1]; $suffix = $matches[2]; if (isset($this->template_directories[$prefix])) { $template_file = $this->template_directories[$prefix].'/'.$suffix; } } if (!isset($template_file)) { $template_file = UPDRAFTPLUS_DIR.'/templates/'.$path; } $template_file = apply_filters('updraftplus_template', $template_file, $path); do_action('updraftplus_before_template', $path, $template_file, $return_instead_of_echo, $extract_these); if (!file_exists($template_file)) { error_log("UpdraftPlus: template not found: $template_file"); echo __('Error:', 'updraftplus').' '.__('template not found', 'updraftplus')." ($path)"; } else { extract($extract_these); global $updraftplus, $wpdb; $updraftplus_admin = $this; include $template_file; } do_action('updraftplus_after_template', $path, $template_file, $return_instead_of_echo, $extract_these); if ($return_instead_of_echo) return ob_get_clean(); } /** * Add actions for any needed dashboard notices for remote storage services * * @param String|Array $services - a list of services, or single service */ private function setup_all_admin_notices_global($services) { global $updraftplus; if ('googledrive' === $services || (is_array($services) && in_array('googledrive', $services))) { $settings = $updraftplus->update_remote_storage_options_format('googledrive'); if (is_wp_error($settings)) { if (!isset($this->storage_module_option_errors)) $this->storage_module_option_errors = ''; $this->storage_module_option_errors .= "Google Drive (".$settings->get_error_code()."): ".$settings->get_error_message(); add_action('all_admin_notices', array($this, 'show_admin_warning_multiple_storage_options')); $updraftplus->log_wp_error($settings, true, true); } elseif (!empty($settings['settings'])) { foreach ($settings['settings'] as $instance_id => $storage_options) { if ((defined('UPDRAFTPLUS_CUSTOM_GOOGLEDRIVE_APP') && UPDRAFTPLUS_CUSTOM_GOOGLEDRIVE_APP) || !empty($storage_options['clientid'])) { if (!empty($storage_options['clientid'])) { $clientid = $storage_options['clientid']; $token = empty($storage_options['token']) ? '' : $storage_options['token']; } if (!empty($clientid) && '' == $token) { if (!in_array($instance_id, $this->auth_instance_ids['googledrive'])) $this->auth_instance_ids['googledrive'][] = $instance_id; if (false === has_action('all_admin_notices', array($this, 'show_admin_warning_googledrive'))) add_action('all_admin_notices', array($this, 'show_admin_warning_googledrive')); } unset($clientid); unset($token); } else { if (empty($storage_options['user_id'])) { if (!in_array($instance_id, $this->auth_instance_ids['googledrive'])) $this->auth_instance_ids['googledrive'][] = $instance_id; if (false === has_action('all_admin_notices', array($this, 'show_admin_warning_googledrive'))) add_action('all_admin_notices', array($this, 'show_admin_warning_googledrive')); } } } } } if ('googlecloud' === $services || (is_array($services) && in_array('googlecloud', $services))) { $settings = $updraftplus->update_remote_storage_options_format('googlecloud'); if (is_wp_error($settings)) { if (!isset($this->storage_module_option_errors)) $this->storage_module_option_errors = ''; $this->storage_module_option_errors .= "Google Cloud (".$settings->get_error_code()."): ".$settings->get_error_message(); add_action('all_admin_notices', array($this, 'show_admin_warning_multiple_storage_options')); $updraftplus->log_wp_error($settings, true, true); } elseif (!empty($settings['settings'])) { foreach ($settings['settings'] as $instance_id => $storage_options) { $clientid = $storage_options['clientid']; $token = (empty($storage_options['token'])) ? '' : $storage_options['token']; if (!empty($clientid) && empty($token)) { if (!in_array($instance_id, $this->auth_instance_ids['googlecloud'])) $this->auth_instance_ids['googlecloud'][] = $instance_id; if (false === has_action('all_admin_notices', array($this, 'show_admin_warning_googlecloud'))) add_action('all_admin_notices', array($this, 'show_admin_warning_googlecloud')); } } } } if ('dropbox' === $services || (is_array($services) && in_array('dropbox', $services))) { $settings = $updraftplus->update_remote_storage_options_format('dropbox'); if (is_wp_error($settings)) { if (!isset($this->storage_module_option_errors)) $this->storage_module_option_errors = ''; $this->storage_module_option_errors .= "Dropbox (".$settings->get_error_code()."): ".$settings->get_error_message(); add_action('all_admin_notices', array($this, 'show_admin_warning_multiple_storage_options')); $updraftplus->log_wp_error($settings, true, true); } elseif (!empty($settings['settings'])) { foreach ($settings['settings'] as $instance_id => $storage_options) { if (empty($storage_options['tk_access_token'])) { if (!in_array($instance_id, $this->auth_instance_ids['dropbox'])) $this->auth_instance_ids['dropbox'][] = $instance_id; if (false === has_action('all_admin_notices', array($this, 'show_admin_warning_dropbox'))) add_action('all_admin_notices', array($this, 'show_admin_warning_dropbox')); } } } } if ('onedrive' === $services || (is_array($services) && in_array('onedrive', $services))) { $settings = $updraftplus->update_remote_storage_options_format('onedrive'); if (is_wp_error($settings)) { if (!isset($this->storage_module_option_errors)) $this->storage_module_option_errors = ''; $this->storage_module_option_errors .= "OneDrive (".$settings->get_error_code()."): ".$settings->get_error_message(); add_action('all_admin_notices', array($this, 'show_admin_warning_multiple_storage_options')); $updraftplus->log_wp_error($settings, true, true); } elseif (!empty($settings['settings'])) { foreach ($settings['settings'] as $instance_id => $storage_options) { if ((defined('UPDRAFTPLUS_CUSTOM_ONEDRIVE_APP') && UPDRAFTPLUS_CUSTOM_ONEDRIVE_APP)) { if (!empty($storage_options['clientid']) && !empty($storage_options['secret']) && empty($storage_options['refresh_token'])) { if (!in_array($instance_id, $this->auth_instance_ids['onedrive'])) $this->auth_instance_ids['onedrive'][] = $instance_id; if (false === has_action('all_admin_notices', array($this, 'show_admin_warning_onedrive'))) add_action('all_admin_notices', array($this, 'show_admin_warning_onedrive')); } elseif (empty($storage_options['refresh_token'])) { if (!in_array($instance_id, $this->auth_instance_ids['onedrive'])) $this->auth_instance_ids['onedrive'][] = $instance_id; if (false === has_action('all_admin_notices', array($this, 'show_admin_warning_onedrive'))) add_action('all_admin_notices', array($this, 'show_admin_warning_onedrive')); } } else { if (empty($storage_options['refresh_token'])) { if (!in_array($instance_id, $this->auth_instance_ids['onedrive'])) $this->auth_instance_ids['onedrive'][] = $instance_id; if (false === has_action('all_admin_notices', array($this, 'show_admin_warning_onedrive'))) add_action('all_admin_notices', array($this, 'show_admin_warning_onedrive')); } } } } } if ('updraftvault' === $services || (is_array($services) && in_array('updraftvault', $services))) { $settings = $updraftplus->update_remote_storage_options_format('updraftvault'); if (is_wp_error($settings)) { if (!isset($this->storage_module_option_errors)) $this->storage_module_option_errors = ''; $this->storage_module_option_errors .= "UpdraftVault (".$settings->get_error_code()."): ".$settings->get_error_message(); add_action('all_admin_notices', array($this, 'show_admin_warning_multiple_storage_options')); $updraftplus->log_wp_error($settings, true, true); } elseif (!empty($settings['settings'])) { foreach ($settings['settings'] as $instance_id => $storage_options) { if (empty($storage_options['token']) && empty($storage_options['email'])) { add_action('all_admin_notices', array($this, 'show_admin_warning_updraftvault')); } } } } if ($this->disk_space_check(1048576*35) === false) add_action('all_admin_notices', array($this, 'show_admin_warning_diskspace')); } private function setup_all_admin_notices_udonly($service, $override = false) { global $wp_version; if (UpdraftPlus_Options::user_can_manage() && defined('DISABLE_WP_CRON') && DISABLE_WP_CRON && (!defined('UPDRAFTPLUS_DISABLE_WP_CRON_NOTICE') || !UPDRAFTPLUS_DISABLE_WP_CRON_NOTICE)) { add_action('all_admin_notices', array($this, 'show_admin_warning_disabledcron')); } if (UpdraftPlus_Options::get_updraft_option('updraft_debug_mode')) { @ini_set('display_errors', 1); // @codingStandardsIgnoreLine if (defined('E_DEPRECATED')) { // @codingStandardsIgnoreLine @error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED); } else { @error_reporting(E_ALL & ~E_NOTICE); } add_action('all_admin_notices', array($this, 'show_admin_debug_warning')); } if (null === UpdraftPlus_Options::get_updraft_option('updraft_interval')) { add_action('all_admin_notices', array($this, 'show_admin_nosettings_warning')); $this->no_settings_warning = true; } // Avoid false positives, by attempting to raise the limit (as happens when we actually do a backup) @set_time_limit(UPDRAFTPLUS_SET_TIME_LIMIT); $max_execution_time = (int) @ini_get('max_execution_time'); if ($max_execution_time>0 && $max_execution_time<20) { add_action('all_admin_notices', array($this, 'show_admin_warning_execution_time')); } // LiteSpeed has a generic problem with terminating cron jobs if (isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false) { if (!is_file(ABSPATH.'.htaccess') || !preg_match('/noabort/i', file_get_contents(ABSPATH.'.htaccess'))) { add_action('all_admin_notices', array($this, 'show_admin_warning_litespeed')); } } if (version_compare($wp_version, '3.2', '<')) add_action('all_admin_notices', array($this, 'show_admin_warning_wordpressversion')); } /** * Used to output the information for the next scheduled backup. * moved to function for the ajax saves */ public function next_scheduled_backups_output() { // UNIX timestamp $next_scheduled_backup = wp_next_scheduled('updraft_backup'); if ($next_scheduled_backup) { // Convert to GMT $next_scheduled_backup_gmt = gmdate('Y-m-d H:i:s', $next_scheduled_backup); // Convert to blog time zone $next_scheduled_backup = get_date_from_gmt($next_scheduled_backup_gmt, 'D, F j, Y H:i'); // $next_scheduled_backup = date_i18n('D, F j, Y H:i', $next_scheduled_backup); } else { $next_scheduled_backup = __('Nothing currently scheduled', 'updraftplus'); $files_not_scheduled = true; } $next_scheduled_backup_database = wp_next_scheduled('updraft_backup_database'); if (UpdraftPlus_Options::get_updraft_option('updraft_interval_database', UpdraftPlus_Options::get_updraft_option('updraft_interval')) == UpdraftPlus_Options::get_updraft_option('updraft_interval')) { if (isset($files_not_scheduled)) { $next_scheduled_backup_database = $next_scheduled_backup; $database_not_scheduled = true; } else { $next_scheduled_backup_database = __("At the same time as the files backup", 'updraftplus'); $next_scheduled_backup_database_same_time = true; } } else { if ($next_scheduled_backup_database) { // Convert to GMT $next_scheduled_backup_database_gmt = gmdate('Y-m-d H:i:s', $next_scheduled_backup_database); // Convert to blog time zone $next_scheduled_backup_database = get_date_from_gmt($next_scheduled_backup_database_gmt, 'D, F j, Y H:i'); // $next_scheduled_backup_database = date_i18n('D, F j, Y H:i', $next_scheduled_backup_database); } else { $next_scheduled_backup_database = __('Nothing currently scheduled', 'updraftplus'); $database_not_scheduled = true; } } ?>
'.__('This file does not appear to be an UpdraftPlus backup archive (such files are .zip or .gz files which have a name like: backup_(time)_(site name)_(code)_(type).(zip|gz)).', 'updraftplus').'
'.apply_filters('updraftplus_if_foreign_then_premium_message', ''), 'makesure' => __('(make sure that you were trying to upload a zip file previously created by UpdraftPlus)', 'updraftplus'), 'uploaderror' => __('Upload error:', 'updraftplus'), 'notdba' => __('This file does not appear to be an UpdraftPlus encrypted database archive (such files are .gz.crypt files which have a name like: backup_(time)_(site name)_(code)_db.crypt.gz).', 'updraftplus'), 'uploaderr' => __('Upload error', 'updraftplus'), 'followlink' => __('Follow this link to attempt decryption and download the database file to your computer.', 'updraftplus'), 'thiskey' => __('This decryption key will be attempted:', 'updraftplus'), 'unknownresp' => __('Unknown server response:', 'updraftplus'), 'ukrespstatus' => __('Unknown server response status:', 'updraftplus'), 'uploaded' => __('The file was uploaded.', 'updraftplus'), 'backupnow' => __('Backup Now', 'updraftplus'), 'cancel' => __('Cancel', 'updraftplus'), 'deletebutton' => __('Delete', 'updraftplus'), 'createbutton' => __('Create', 'updraftplus'), 'youdidnotselectany' => __('You did not select any components to restore. Please select at least one, and then try again.', 'updraftplus'), 'proceedwithupdate' => __('Proceed with update', 'updraftplus'), 'close' => __('Close', 'updraftplus'), 'restore' => __('Restore', 'updraftplus'), 'downloadlogfile' => __('Download log file', 'updraftplus'), 'automaticbackupbeforeupdate' => __('Automatic backup before update', 'updraftplus'), 'unsavedsettings' => __('You have made changes to your settings, and not saved.', 'updraftplus'), 'saving' => __('Saving...', 'updraftplus'), 'connect' => __('Connect', 'updraftplus'), 'connecting' => __('Connecting...', 'updraftplus'), 'disconnect' => __('Disconnect', 'updraftplus'), 'disconnecting' => __('Disconnecting...', 'updraftplus'), 'counting' => __('Counting...', 'updraftplus'), 'updatequotacount' => __('Update quota count', 'updraftplus'), 'addingsite' => __('Adding...', 'updraftplus'), 'addsite' => __('Add site', 'updraftplus'), // 'resetting' => __('Resetting...', 'updraftplus'), 'creating_please_allow' => __('Creating...', 'updraftplus').(function_exists('openssl_encrypt') ? '' : ' ('.__('your PHP install lacks the openssl module; as a result, this can take minutes; if nothing has happened by then, then you should either try a smaller key size, or ask your web hosting company how to enable this PHP module on your setup.', 'updraftplus').')'), 'sendtosite' => __('Send to site:', 'updraftplus'), 'checkrpcsetup' => sprintf(__('You should check that the remote site is online, not firewalled, does not have security modules that may be blocking access, has UpdraftPlus version %s or later active and that the keys have been entered correctly.', 'updraftplus'), '2.10.3'), 'pleasenamekey' => __('Please give this key a name (e.g. indicate the site it is for):', 'updraftplus'), 'key' => __('Key', 'updraftplus'), 'nokeynamegiven' => sprintf(__("Failure: No %s was given.", 'updraftplus'), __('key name', 'updraftplus')), 'deleting' => __('Deleting...', 'updraftplus'), 'enter_mothership_url' => __('Please enter a valid URL', 'updraftplus'), 'delete_response_not_understood' => __("We requested to delete the file, but could not understand the server's response", 'updraftplus'), 'testingconnection' => __('Testing connection...', 'updraftplus'), 'send' => __('Send', 'updraftplus'), 'migratemodalheight' => class_exists('UpdraftPlus_Addons_Migrator') ? 555 : 300, 'migratemodalwidth' => class_exists('UpdraftPlus_Addons_Migrator') ? 770 : 500, 'download' => _x('Download', '(verb)', 'updraftplus'), 'browse_download_link' => apply_filters('updraftplus_browse_download_link', ''.__("With UpdraftPlus Premium, you can directly download individual files from here.", "updraftplus").''), 'unsavedsettingsbackup' => __('You have made changes to your settings, and not saved.', 'updraftplus')."\n".__('You should save your changes to ensure that they are used for making your backup.', 'updraftplus'), 'unsaved_settings_export' => __('You have made changes to your settings, and not saved.', 'updraftplus')."\n".__('Your export file will be of your displayed settings, not your saved ones.', 'updraftplus'), 'dayselector' => $day_selector, 'mdayselector' => $mday_selector, 'day' => __('day', 'updraftplus'), 'inthemonth' => __('in the month', 'updraftplus'), 'days' => __('day(s)', 'updraftplus'), 'hours' => __('hour(s)', 'updraftplus'), 'weeks' => __('week(s)', 'updraftplus'), 'forbackupsolderthan' => __('For backups older than', 'updraftplus'), 'ud_url' => UPDRAFTPLUS_URL, 'processing' => __('Processing...', 'updraftplus'), 'pleasefillinrequired' => __('Please fill in the required information.', 'updraftplus'), 'test_settings' => __('Test %s Settings', 'updraftplus'), 'testing_settings' => __('Testing %s Settings...', 'updraftplus'), 'settings_test_result' => __('%s settings test result:', 'updraftplus'), 'nothing_yet_logged' => __('Nothing yet logged', 'updraftplus'), 'import_select_file' => __('You have not yet selected a file to import.', 'updraftplus'), 'import_invalid_json_file' => __('Error: The chosen file is corrupt. Please choose a valid UpdraftPlus export file.', 'updraftplus'), 'updraft_settings_url' => UpdraftPlus_Options::admin_page_url().'?page=updraftplus', 'network_site_url' => network_site_url(), 'importing' => __('Importing...', 'updraftplus'), 'importing_data_from' => __('This will import data from:', 'updraftplus'), 'exported_on' => __('Which was exported on:', 'updraftplus'), 'continue_import' => __('Do you want to carry out the import?', 'updraftplus'), 'complete' => __('Complete', 'updraftplus'), 'remote_delete_limit' => defined('UPDRAFTPLUS_REMOTE_DELETE_LIMIT') ? UPDRAFTPLUS_REMOTE_DELETE_LIMIT : 15, 'remote_files_deleted' => __('remote files deleted', 'updraftplus'), 'http_code' => __('HTTP code:', 'updraftplus'), 'makesure2' => __('The file failed to upload. Please check the following:', 'updraftplus')."\n\n - ".__('Any settings in your .htaccess or web.config file that affects the maximum upload or post size.', 'updraftplus')."\n - ".__('The available memory on the server.', 'updraftplus')."\n - ".__('That you are attempting to upload a zip file previously created by UpdraftPlus.', 'updraftplus')."\n\n".__('Further information may be found in the browser JavaScript console, and the server PHP error logs.', 'updraftplus'), 'zip_file_contents' => __('Browsing zip file', 'updraftplus'), 'zip_file_contents_info' => __('Select a file to view information about it', 'updraftplus'), 'search' => __('Search', 'updraftplus'), 'download_timeout' => __('Unable to download file. This could be caused by a timeout. It would be best to download the zip to your computer.', 'updraftplus'), 'loading_log_file' => __('Loading log file', 'updraftplus'), 'updraftplus_version' => $updraftplus->version, 'updraftcentral_wizard_empty_url' => __('Please enter the URL where your UpdraftCentral dashboard is hosted.'), 'updraftcentral_wizard_invalid_url' => __('Please enter a valid URL e.g http://example.com', 'updraftplus'), 'export_settings_file_name' => 'updraftplus-settings-'.sanitize_title(get_bloginfo('name')).'.json', // For remote storage handlebarsjs template 'remote_storage_options' => $remote_storage_options_and_templates['options'], 'remote_storage_templates' => $remote_storage_options_and_templates['templates'], 'instance_enabled' => __('Currently enabled', 'updraftplus'), 'instance_disabled' => __('Currently disabled', 'updraftplus'), )); } /** * Despite the name, this fires irrespective of what capabilities the user has (even none - so be careful) */ public function core_upgrade_preamble() { // They need to be able to perform backups, and to perform updates if (!UpdraftPlus_Options::user_can_manage() || (!current_user_can('update_core') && !current_user_can('update_plugins') && !current_user_can('update_themes'))) return; if (!class_exists('UpdraftPlus_Addon_Autobackup')) { if (defined('UPDRAFTPLUS_NOADS_B')) return; } ?> do_notice('autobackup', 'autobackup', true)); } else { echo ' '; } ?> 'html5,flash,silverlight,html4', 'browse_button' => 'plupload-browse-button', 'container' => 'plupload-upload-ui', 'drop_element' => 'drag-drop-area', 'file_data_name' => 'async-upload', 'multiple_queues' => true, 'max_file_size' => '100Gb', 'chunk_size' => $chunk_size.'b', 'url' => admin_url('admin-ajax.php', 'relative'), 'multipart' => true, 'multi_selection' => true, 'urlstream_upload' => true, // additional post data to send to our ajax hook 'multipart_params' => array( '_ajax_nonce' => wp_create_nonce('updraft-uploader'), 'action' => 'plupload_action' ) ); // WP 3.9 updated to plupload 2.0 - https://core.trac.wordpress.org/ticket/25663 if (is_file(ABSPATH.WPINC.'/js/plupload/Moxie.swf')) { $plupload_init['flash_swf_url'] = includes_url('js/plupload/Moxie.swf'); } else { $plupload_init['flash_swf_url'] = includes_url('js/plupload/plupload.flash.swf'); } if (is_file(ABSPATH.WPINC.'/js/plupload/Moxie.xap')) { $plupload_init['silverlight_xap_url'] = includes_url('js/plupload/Moxie.xap'); } else { $plupload_init['silverlight_xap_url'] = includes_url('js/plupload/plupload.silverlight.swf'); } ?> backups_dir_location(); $disk_free_space = @disk_free_space($updraft_dir); if (false == $disk_free_space) return -1; return ($disk_free_space > $space) ? true : false; } /** * Adds the settings link under the plugin on the plugin screen. * * @param Array $links Set of links for the plugin, before being filtered * @param String $file File name (relative to the plugin directory) * @return Array filtered results */ public function plugin_action_links($links, $file) { if (is_array($links) && 'updraftplus/updraftplus.php' == $file) { $settings_link = ''.__("Settings", "updraftplus").''; array_unshift($links, $settings_link); $settings_link = ''.__("Add-Ons / Pro Support", "updraftplus").''; array_unshift($links, $settings_link); } return $links; } public function admin_action_upgrade_pluginortheme() { if (isset($_GET['action']) && ('upgrade-plugin' == $_GET['action'] || 'upgrade-theme' == $_GET['action']) && !class_exists('UpdraftPlus_Addon_Autobackup') && !defined('UPDRAFTPLUS_NOADS_B')) { if ('upgrade-plugin' == $_GET['action']) { if (!current_user_can('update_plugins')) return; } else { if (!current_user_can('update_themes')) return; } $dismissed_until = UpdraftPlus_Options::get_updraft_option('updraftplus_dismissedautobackup', 0); if ($dismissed_until > time()) return; if ('upgrade-plugin' == $_GET['action']) { $title = __('Update Plugin'); $parent_file = 'plugins.php'; $submenu_file = 'plugins.php'; } else { $title = __('Update Theme'); $parent_file = 'themes.php'; $submenu_file = 'themes.php'; } include_once(ABSPATH.'wp-admin/admin-header.php'); if (!class_exists('UpdraftPlus_Notices')) include_once(UPDRAFTPLUS_DIR.'/includes/updraftplus-notices.php'); global $updraftplus_notices; $updraftplus_notices->do_notice('autobackup', 'autobackup'); } } public function show_admin_warning($message, $class = 'updated') { echo ' "; } public function show_admin_warning_multiple_storage_options() { $this->show_admin_warning('UpdraftPlus: '.__('An error occurred when fetching storage module options: ', 'updraftplus').htmlspecialchars($this->storage_module_option_errors), 'error'); } public function show_admin_warning_unwritable() { $unwritable_mess = htmlspecialchars(__("The 'Backup Now' button is disabled as your backup directory is not writable (go to the 'Settings' tab and find the relevant option).", 'updraftplus')); $this->show_admin_warning($unwritable_mess, "error"); } public function show_admin_nosettings_warning() { $this->show_admin_warning(''.__('Welcome to UpdraftPlus!', 'updraftplus').' '.__('To make a backup, just press the Backup Now button.', 'updraftplus').' '.__('To change any of the default settings of what is backed up, to configure scheduled backups, to send your backups to remote storage (recommended), and more, go to the settings tab.', 'updraftplus').'', 'updated notice is-dismissible'); } public function show_admin_warning_execution_time() { $this->show_admin_warning(''.__('Warning', 'updraftplus').': '.sprintf(__('The amount of time allowed for WordPress plugins to run is very low (%s seconds) - you should increase it to avoid backup failures due to time-outs (consult your web hosting company for more help - it is the max_execution_time PHP setting; the recommended value is %s seconds or more)', 'updraftplus'), (int) @ini_get('max_execution_time'), 90)); } public function show_admin_warning_disabledcron() { $this->show_admin_warning(''.__('Warning', 'updraftplus').': '.__('The scheduler is disabled in your WordPress install, via the DISABLE_WP_CRON setting. No backups can run (even "Backup Now") unless either you have set up a facility to call the scheduler manually, or until it is enabled.', 'updraftplus').' '.__('Go here for more information.', 'updraftplus').'', 'updated updraftplus-disable-wp-cron-warning'); } public function show_admin_warning_diskspace() { $this->show_admin_warning(''.__('Warning', 'updraftplus').': '.sprintf(__('You have less than %s of free disk space on the disk which UpdraftPlus is configured to use to create backups. UpdraftPlus could well run out of space. Contact your the operator of your server (e.g. your web hosting company) to resolve this issue.', 'updraftplus'), '35 MB')); } public function show_admin_warning_wordpressversion() { $this->show_admin_warning(''.__('Warning', 'updraftplus').': '.sprintf(__('UpdraftPlus does not officially support versions of WordPress before %s. It may work for you, but if it does not, then please be aware that no support is available until you upgrade WordPress.', 'updraftplus'), '3.2')); } public function show_admin_warning_litespeed() { $this->show_admin_warning(''.__('Warning', 'updraftplus').': '.sprintf(__('Your website is hosted using the %s web server.', 'updraftplus'), 'LiteSpeed').' '.__('Please consult this FAQ if you have problems backing up.', 'updraftplus').''); } public function show_admin_debug_warning() { $this->show_admin_warning(''.__('Notice', 'updraftplus').': '.__('UpdraftPlus\'s debug mode is on. You may see debugging notices on this page not just from UpdraftPlus, but from any other plugin installed. Please try to make sure that the notice you are seeing is from UpdraftPlus before you raise a support request.', 'updraftplus').''); } public function show_admin_warning_overdue_crons($howmany) { $ret = ' '; return $ret; } /** * Output authorisation links for any un-authorised Dropbox settings instances */ public function show_admin_warning_dropbox() { $this->get_method_auth_link('dropbox'); } /** * Output authorisation links for any un-authorised OneDrive settings instances */ public function show_admin_warning_onedrive() { $this->get_method_auth_link('onedrive'); } public function show_admin_warning_updraftvault() { $this->show_admin_warning(''.__('UpdraftPlus notice:', 'updraftplus').' '.sprintf(__('%s has been chosen for remote storage, but you are not currently connected.', 'updraftplus'), 'UpdraftPlus Vault').' '.__('Go to the remote storage settings in order to connect.', 'updraftplus'), 'updated'); } /** * Output authorisation links for any un-authorised Google Drive settings instances */ public function show_admin_warning_googledrive() { $this->get_method_auth_link('googledrive'); } /** * Output authorisation links for any un-authorised Google Cloud settings instances */ public function show_admin_warning_googlecloud() { $this->get_method_auth_link('googlecloud'); } /** * This method will setup the storage object and get the authentication link ready to be output with the notice * * @param String $method - the remote storage method */ public function get_method_auth_link($method) { global $updraftplus; $storage_objects_and_ids = $updraftplus->get_storage_objects_and_ids(array($method)); $object = $storage_objects_and_ids[$method]['object']; foreach ($this->auth_instance_ids[$method] as $instance_id) { $object->set_instance_id($instance_id); $this->show_admin_warning(''.__('UpdraftPlus notice:', 'updraftplus').' '.$object->get_authentication_link(false, false), 'updated updraft_authenticate_'.$method); } } /** * This options filter removes ABSPATH off the front of updraft_dir, if it is given absolutely and contained within it * * @param string $updraft_dir Directory * @return string */ public function prune_updraft_dir_prefix($updraft_dir) { if ('/' == substr($updraft_dir, 0, 1) || "\\" == substr($updraft_dir, 0, 1) || preg_match('/^[a-zA-Z]:/', $updraft_dir)) { $wcd = trailingslashit(WP_CONTENT_DIR); if (strpos($updraft_dir, $wcd) === 0) { $updraft_dir = substr($updraft_dir, strlen($wcd)); } } return $updraft_dir; } /** * Start a download of a backup. This method is called via the AJAX action updraft_download_backup. May die instead of returning depending upon the mode in which it is called. */ public function updraft_download_backup() { if (empty($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'], 'updraftplus_download')) die; if (empty($_REQUEST['timestamp']) || !is_numeric($_REQUEST['timestamp']) || empty($_REQUEST['type'])) exit; $findex = empty($_REQUEST['findex']) ? 0 : (int) $_REQUEST['findex']; $stage = empty($_REQUEST['stage']) ? '' : $_REQUEST['stage']; $file_path = empty($_REQUEST['filepath']) ? '' : $_REQUEST['filepath']; // This call may not actually return, depending upon what mode it is called in $result = $this->do_updraft_download_backup($findex, $_REQUEST['type'], $_REQUEST['timestamp'], $stage, false, $file_path); // In theory, if a response was already sent, then Connection: close has been issued, and a Content-Length. However, in https://updraftplus.com/forums/topic/pclzip_err_bad_format-10-invalid-archive-structure/ a browser ignores both of these, and then picks up the second output and complains. if (empty($result['already_closed'])) echo json_encode($result); die(); } /** * Ensure that a specified backup is present, downloading if necessary (or delete it, if the parameters so indicate). N.B. This function may die(), depending on the request being made in $stage * * @param Integer $findex - the index number of the backup archive requested * @param String $type - the entity type (e.g. 'plugins') being requested * @param Integer $timestamp - identifier for the backup being requested (UNIX epoch time) * @param Mixed $stage - the stage; valid values include (have not audited for other possibilities) at least 'delete' and 2. * @param Callable|Boolean $close_connection_callable - function used to close the connection to the caller; an array of data to return is passed. If false, then UpdraftPlus::close_browser_connection is called with a JSON version of the data. * @param String $file_path - an over-ride for where to download the file to (basename only) * * @return Array - sumary of the results. May also just die. */ public function do_updraft_download_backup($findex, $type, $timestamp, $stage, $close_connection_callable = false, $file_path = '') { @set_time_limit(UPDRAFTPLUS_SET_TIME_LIMIT); global $updraftplus; // This is a bit ugly; these variables get placed back into $_POST (where they may possibly have come from), so that UpdraftPlus::log() can detect exactly where to log the download status. $_POST['findex'] = $findex; $_POST['type'] = $type; $_POST['timestamp'] = $timestamp; // Check that it is a known entity type; if not, die if ('db' != substr($type, 0, 2)) { $backupable_entities = $updraftplus->get_backupable_file_entities(true); foreach ($backupable_entities as $t => $info) { if ($type == $t) $type_match = true; } if (empty($type_match)) return array('result' => 'error', 'code' => 'no_such_type'); } // We already know that no possible entities have an MD5 clash (even after 2 characters) // Also, there's nothing enforcing a requirement that nonces are hexadecimal $job_nonce = dechex($timestamp).$findex.substr(md5($type), 0, 3); // You need a nonce before you can set job data. And we certainly don't yet have one. $updraftplus->backup_time_nonce($job_nonce); $debug_mode = UpdraftPlus_Options::get_updraft_option('updraft_debug_mode'); // Set the job type before logging, as there can be different logging destinations $updraftplus->jobdata_set('job_type', 'download'); $updraftplus->jobdata_set('job_time_ms', $updraftplus->job_time_ms); // Retrieve the information from our backup history $backup_history = UpdraftPlus_Backup_History::get_history(); // Base name $file = $backup_history[$timestamp][$type]; // Deal with multi-archive sets if (is_array($file)) $file = $file[$findex]; if (false !== strpos($file_path, '..')) { error_log("UpdraftPlus_Admin::do_updraft_download_backup : invalid file_path: $file_path"); return array('result' => __('Error: invalid path', 'updraftplus')); } if (!empty($file_path)) $file = $file_path; // Where it should end up being downloaded to $fullpath = $updraftplus->backups_dir_location().'/'.$file; if (!empty($file_path) && strpos(realpath($fullpath), realpath($updraftplus->backups_dir_location())) === false) { error_log("UpdraftPlus_Admin::do_updraft_download_backup : invalid fullpath: $fullpath"); return array('result' => __('Error: invalid path', 'updraftplus')); } if (2 == $stage) { $updraftplus->spool_file($fullpath); // We only want to remove if it was a temp file from the zip browser if (!empty($file_path)) @unlink($fullpath); // Do not return - we do not want the caller to add any output die; } if ('delete' == $stage) { @unlink($fullpath); $updraftplus->log("The file has been deleted ($file)"); return array('result' => 'deleted'); } // TODO: FIXME: Failed downloads may leave log files forever (though they are small) if ($debug_mode) $updraftplus->logfile_open($updraftplus->nonce); set_error_handler(array($updraftplus, 'php_error'), E_ALL & ~E_STRICT); $updraftplus->log("Requested to obtain file: timestamp=$timestamp, type=$type, index=$findex"); $itext = empty($findex) ? '' : $findex; $known_size = isset($backup_history[$timestamp][$type.$itext.'-size']) ? $backup_history[$timestamp][$type.$itext.'-size'] : 0; $services = isset($backup_history[$timestamp]['service']) ? $backup_history[$timestamp]['service'] : false; if (is_string($services)) $services = array($services); $updraftplus->jobdata_set('service', $services); // Fetch it from the cloud, if we have not already got it $needs_downloading = false; if (!file_exists($fullpath)) { // If the file doesn't exist and they're using one of the cloud options, fetch it down from the cloud. $needs_downloading = true; $updraftplus->log('File does not yet exist locally - needs downloading'); } elseif ($known_size > 0 && filesize($fullpath) < $known_size) { $updraftplus->log("The file was found locally (".filesize($fullpath).") but did not match the size in the backup history ($known_size) - will resume downloading"); $needs_downloading = true; } elseif ($known_size > 0 && filesize($fullpath) > $known_size) { $updraftplus->log("The file was found locally (".filesize($fullpath).") but the size is larger than what is recorded in the backup history ($known_size) - will try to continue but if errors are encountered then check that the backup is correct"); } elseif ($known_size > 0) { $updraftplus->log('The file was found locally and matched the recorded size from the backup history ('.round($known_size/1024, 1).' KB)'); } else { $updraftplus->log('No file size was found recorded in the backup history. We will assume the local one is complete.'); $known_size = filesize($fullpath); } // The AJAX responder that updates on progress wants to see this $updraftplus->jobdata_set('dlfile_'.$timestamp.'_'.$type.'_'.$findex, "downloading:$known_size:$fullpath"); if ($needs_downloading) { // Update the "last modified" time to dissuade any other instances from thinking that no downloaders are active @touch($fullpath); $msg = array( 'result' => 'needs_download', 'request' => array( 'type' => $type, 'timestamp' => $timestamp, 'findex' => $findex ) ); if ($close_connection_callable && is_callable($close_connection_callable)) { call_user_func($close_connection_callable, $msg); } else { $updraftplus->close_browser_connection(json_encode($msg)); } $this->get_remote_file($services, $file, $timestamp); } // Now, be ready to spool the thing to the browser if (is_file($fullpath) && is_readable($fullpath)) { // That message is then picked up by the AJAX listener $updraftplus->jobdata_set('dlfile_'.$timestamp.'_'.$type.'_'.$findex, 'downloaded:'.filesize($fullpath).":$fullpath"); $result = 'downloaded'; } else { $updraftplus->jobdata_set('dlfile_'.$timestamp.'_'.$type.'_'.$findex, 'failed'); $updraftplus->jobdata_set('dlerrors_'.$timestamp.'_'.$type.'_'.$findex, $updraftplus->errors); $updraftplus->log('Remote fetch failed. File '.$fullpath.' did not exist or was unreadable. If you delete local backups then remote retrieval may have failed.'); $result = 'download_failed'; } restore_error_handler(); @fclose($updraftplus->logfile_handle); if (!$debug_mode) @unlink($updraftplus->logfile_name); // The browser connection was possibly already closed, but not necessarily return array('result' => $result, 'already_closed' => $needs_downloading); } /** * This method gets the remote storage information and objects and loops over each of them until we get a successful download of the passed in file. * * @param Array $services - a list of connected service identifiers (e.g. 'dropbox', 's3', etc.) * @param String $file - the name of the file * @param Integer $timestamp - the backup timestamp * @param Boolean $restore - a boolean to indicate if the caller of this method is a restore or not; if so, different messages are logged */ private function get_remote_file($services, $file, $timestamp, $restore = false) { global $updraftplus; $fullpath = $updraftplus->backups_dir_location().'/'.$file; $storage_objects_and_ids = $updraftplus->get_storage_objects_and_ids($services); $is_downloaded = false; $updraftplus->register_wp_http_option_hooks(); foreach ($services as $service) { if (empty($service) || 'none' == $service) continue; if ($is_downloaded) continue; if ($restore) { $service_description = empty($updraftplus->backup_methods[$service]) ? $service : $updraftplus->backup_methods[$service]; $updraftplus->log(__("File is not locally present - needs retrieving from remote storage", 'updraftplus')." ($service_description)", 'notice-restore'); } $object = $storage_objects_and_ids[$service]['object']; if (!$object->supports_feature('multi_options')) { error_log("UpdraftPlus_Admin::get_remote_file(): Multi-options not supported by: ".$service); continue; } $instance_ids = $storage_objects_and_ids[$service]['instance_settings']; $backups_instance_ids = isset($backup_history[$timestamp]['service_instance_ids'][$service]) ? $backup_history[$timestamp]['service_instance_ids'][$service] : array(false); foreach ($backups_instance_ids as $instance_id) { if (isset($instance_ids[$instance_id])) { $options = $instance_ids[$instance_id]; } else { // If we didn't find a instance id match, it could be a new UpdraftPlus upgrade or a wipe settings with the same details entered so try the default options saved. $options = $object->get_options(); } $object->set_options($options, false, $instance_id); $download = $this->download_file($file, $object); if (is_readable($fullpath) && false !== $download) { if ($restore) { $updraftplus->log(__("OK", 'updraftplus'), 'notice-restore'); } else { clearstatcache(); $updraftplus->log('Remote fetch was successful (file size: '.round(filesize($fullpath)/1024, 1).' KB)'); $is_downloaded = true; } break 2; } else { if ($restore) { $updraftplus->log(__("Error", 'updraftplus'), 'notice-restore'); } else { clearstatcache(); if (0 === @filesize($fullpath)) @unlink($fullpath); $updraftplus->log('Remote fetch failed'); } } } } $updraftplus->register_wp_http_option_hooks(false); } /** * Downloads a specified file into UD's directory * * @param String $file The name of the file * @param array $object The object of the service to use to download with. UpdraftPlus_BackupModule. * @return Boolean - Whether the operation succeeded. Inherited from the storage module's download() method. N.B. At the time of writing it looks like not all modules necessarily return true upon success; but false can be relied upon for detecting failure. */ private function download_file($file, $object) { global $updraftplus; @set_time_limit(UPDRAFTPLUS_SET_TIME_LIMIT); $service = $object->get_id(); $updraftplus->log("Requested file from remote service: $service: $file"); if (method_exists($object, 'download')) { try { return $object->download($file); } catch (Exception $e) { $log_message = 'Exception ('.get_class($e).') occurred during download: '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')'; error_log($log_message); // @codingStandardsIgnoreLine if (function_exists('wp_debug_backtrace_summary')) $log_message .= ' Backtrace: '.wp_debug_backtrace_summary(); $updraftplus->log($log_message); $updraftplus->log(sprintf(__('A PHP exception (%s) has occurred: %s', 'updraftplus'), get_class($e), $e->getMessage()), 'error'); return false; // @codingStandardsIgnoreLine } catch (Error $e) { $log_message = 'PHP Fatal error ('.get_class($e).') has occurred during download. Error Message: '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')'; error_log($log_message); // @codingStandardsIgnoreLine if (function_exists('wp_debug_backtrace_summary')) $log_message .= ' Backtrace: '.wp_debug_backtrace_summary(); $updraftplus->log($log_message); $updraftplus->log(sprintf(__('A PHP fatal error (%s) has occurred: %s', 'updraftplus'), get_class($e), $e->getMessage()), 'error'); return false; } } else { $updraftplus->log("Automatic backup restoration is not available with the method: $service."); $updraftplus->log("$file: ".sprintf(__("The backup archive for this file could not be found. The remote storage method in use (%s) does not allow us to retrieve files. To perform any restoration using UpdraftPlus, you will need to obtain a copy of this file and place it inside UpdraftPlus's working folder", 'updraftplus'), $service)." (".$this->prune_updraft_dir_prefix($updraftplus->backups_dir_location()).")", 'error'); return false; } } /** * This is used as a callback * * @param Mixed $msg The data to be JSON encoded and sent back */ public function _updraftplus_background_operation_started($msg) { global $updraftplus; // The extra spaces are because of a bug seen on one server in handling of non-ASCII characters; see HS#11739 $updraftplus->close_browser_connection(json_encode($msg).' '); } public function updraft_ajax_handler() { global $updraftplus; $nonce = empty($_REQUEST['nonce']) ? '' : $_REQUEST['nonce']; if (!wp_verify_nonce($nonce, 'updraftplus-credentialtest-nonce') || empty($_REQUEST['subaction'])) die('Security check'); $subaction = $_REQUEST['subaction']; // Mitigation in case the nonce leaked to an unauthorised user if ('dismissautobackup' == $subaction) { if (!current_user_can('update_plugins') && !current_user_can('update_themes')) return; } elseif ('dismissexpiry' == $subaction || 'dismissdashnotice' == $subaction) { if (!current_user_can('update_plugins')) return; } else { if (!UpdraftPlus_Options::user_can_manage()) return; } // All others use _POST $data_in_get = array('get_log', 'get_fragment'); // UpdraftPlus_WPAdmin_Commands extends UpdraftPlus_Commands - i.e. all commands are in there if (!class_exists('UpdraftPlus_WPAdmin_Commands')) include_once(UPDRAFTPLUS_DIR.'/includes/class-wpadmin-commands.php'); $commands = new UpdraftPlus_WPAdmin_Commands($this); if (method_exists($commands, $subaction)) { $data = in_array($subaction, $data_in_get) ? $_GET : $_POST; // Undo WP's slashing of GET/POST data $data = $updraftplus->wp_unslash($data); // TODO: Once all commands come through here and through updraft_send_command(), the data should always come from this attribute (once updraft_send_command() is modified appropriately). if (isset($data['action_data'])) $data = $data['action_data']; $results = call_user_func(array($commands, $subaction), $data); if (is_wp_error($results)) { $results = array( 'result' => false, 'error_code' => $results->get_error_code(), 'error_message' => $results->get_error_message(), 'error_data' => $results->get_error_data(), ); } if (is_string($results)) { // A handful of legacy methods, and some which are directly the source for iframes, for which JSON is not appropriate. echo $results; } else { echo json_encode($results); } die; } // Below are all the commands not ported over into class-commands.php or class-wpadmin-commands.php if ('activejobs_list' == $subaction) { // N.B. Also called from autobackup.php // TODO: This should go into UpdraftPlus_Commands, once the add-ons have been ported to use updraft_send_command() echo json_encode($this->get_activejobs_list($updraftplus->wp_unslash($_GET))); } elseif ('httpget' == $subaction) { // httpget $curl = empty($_REQUEST['curl']) ? false : true; echo $this->http_get($updraftplus->wp_unslash($_REQUEST['uri']), $curl); } elseif ('doaction' == $subaction && !empty($_REQUEST['subsubaction']) && 'updraft_' == substr($_REQUEST['subsubaction'], 0, 8)) { // These generally echo and die - they will need further work to port to one of the command classes. Some may already have equivalents in UpdraftPlus_Commands, if they are used from UpdraftCentral. do_action($updraftplus->wp_unslash($_REQUEST['subsubaction'])); } else { // These can be removed after a few releases include(UPDRAFTPLUS_DIR.'/includes/deprecated-actions.php'); } die; } /** * Run a credentials test for the indicated remote storage module * * @param Array $test_settings The test parameters, including the method itself indicated in the key 'method' * @param Boolean $return_instead_of_echo Whether to return or echo the results. N.B. More than just the results to echo will be returned * @return Array|Void - the results, if they are being returned (rather than echoed). Keys: 'output' (the output), 'data' (other data) */ public function do_credentials_test($test_settings, $return_instead_of_echo = false) { $method = (!empty($test_settings['method']) && preg_match("/^[a-z0-9]+$/", $test_settings['method'])) ? $test_settings['method'] : ""; $objname = "UpdraftPlus_BackupModule_$method"; $this->logged = array(); // TODO: Add action for WP HTTP SSL stuff set_error_handler(array($this, 'get_php_errors'), E_ALL & ~E_STRICT); if (!class_exists($objname)) include_once(UPDRAFTPLUS_DIR."/methods/$method.php"); $ret = ''; $data = null; // TODO: Add action for WP HTTP SSL stuff if (method_exists($objname, "credentials_test")) { $obj = new $objname; if ($return_instead_of_echo) ob_start(); $data = $obj->credentials_test($test_settings); if ($return_instead_of_echo) $ret .= ob_get_clean(); } if (count($this->logged) >0) { $ret .= "\n\n".__('Messages:', 'updraftplus')."\n"; foreach ($this->logged as $err) { $ret .= "* $err\n"; } if (!$return_instead_of_echo) echo $ret; } restore_error_handler(); if ($return_instead_of_echo) return array('output' => $ret, 'data' => $data); } /** * Delete a backup set, whilst respecting limits on how much to delete in one go * * @uses remove_backup_set_cleanup() * @param Array $opts - deletion options; with keys backup_timestamp, delete_remote, [remote_delete_limit] * @return Array - as from remove_backup_set_cleanup() */ public function delete_set($opts) { global $updraftplus; $backups = UpdraftPlus_Backup_History::get_history(); $timestamps = (string) $opts['backup_timestamp']; $remote_delete_limit = (isset($opts['remote_delete_limit']) && $opts['remote_delete_limit'] > 0) ? (int) $opts['remote_delete_limit'] : PHP_INT_MAX; $timestamps = explode(',', $timestamps); $delete_remote = empty($opts['delete_remote']) ? false : true; // You need a nonce before you can set job data. And we certainly don't yet have one. $updraftplus->backup_time_nonce(); // Set the job type before logging, as there can be different logging destinations $updraftplus->jobdata_set('job_type', 'delete'); $updraftplus->jobdata_set('job_time_ms', $updraftplus->job_time_ms); if (UpdraftPlus_Options::get_updraft_option('updraft_debug_mode')) { $updraftplus->logfile_open($updraftplus->nonce); set_error_handler(array($updraftplus, 'php_error'), E_ALL & ~E_STRICT); } $updraft_dir = $updraftplus->backups_dir_location(); $backupable_entities = $updraftplus->get_backupable_file_entities(true, true); $local_deleted = 0; $remote_deleted = 0; $sets_removed = 0; foreach ($timestamps as $i => $timestamp) { if (!isset($backups[$timestamp])) { return array('result' => 'error', 'message' => __('Backup set not found', 'updraftplus')); } $nonce = isset($backups[$timestamp]['nonce']) ? $backups[$timestamp]['nonce'] : ''; $delete_from_service = array(); if ($delete_remote) { // Locate backup set if (isset($backups[$timestamp]['service'])) { // Convert to an array so that there is no uncertainty about how to process it $services = is_string($backups[$timestamp]['service']) ? array($backups[$timestamp]['service']) : $backups[$timestamp]['service']; if (is_array($services)) { foreach ($services as $service) { if ($service && 'none' != $service && 'email' != $service) $delete_from_service[] = $service; } } } } $files_to_delete = array(); foreach ($backupable_entities as $key => $ent) { if (isset($backups[$timestamp][$key])) { $files_to_delete[$key] = $backups[$timestamp][$key]; } } // Delete DB foreach ($backups[$timestamp] as $key => $value) { if ('db' == strtolower(substr($key, 0, 2)) && '-size' != substr($key, -5, 5)) { $files_to_delete[$key] = $backups[$timestamp][$key]; } } // Also delete the log if ($nonce && !UpdraftPlus_Options::get_updraft_option('updraft_debug_mode')) { $files_to_delete['log'] = "log.$nonce.txt"; } $updraftplus->register_wp_http_option_hooks(); foreach ($files_to_delete as $key => $files) { if (is_string($files)) { $was_string = true; $files = array($files); } else { $was_string = false; } foreach ($files as $file) { if (is_file($updraft_dir.'/'.$file) && @unlink($updraft_dir.'/'.$file)) $local_deleted++; } if ('log' != $key && count($delete_from_service) > 0) { $storage_objects_and_ids = $updraftplus->get_storage_objects_and_ids($delete_from_service); foreach ($delete_from_service as $service) { if ('email' == $service || 'none' == $service || !$service) continue; $deleted = -1; $remote_obj = $storage_objects_and_ids[$service]['object']; $instance_settings = $storage_objects_and_ids[$service]['instance_settings']; $this->backups_instance_ids = empty($backups[$timestamp]['service_instance_ids'][$service]) ? array() : $backups[$timestamp]['service_instance_ids'][$service]; uksort($instance_settings, array($this, 'instance_ids_sort')); foreach ($instance_settings as $instance_id => $options) { $remote_obj->set_options($options, false, $instance_id); foreach ($files as $index => $file) { if ($remote_deleted == $remote_delete_limit) { return $this->remove_backup_set_cleanup(false, $backups, $local_deleted, $remote_deleted, $sets_removed); } $deleted = $remote_obj->delete($file); if (-1 === $deleted) { // echo __('Did not know how to delete from this cloud service.', 'updraftplus'); } elseif (false !== $deleted) { $remote_deleted++; } $itext = $index ? (string) $index : ''; if ($was_string) { unset($backups[$timestamp][$key]); if ('db' == strtolower(substr($key, 0, 2))) unset($backups[$timestamp][$key][$index.'-size']); } else { unset($backups[$timestamp][$key][$index]); unset($backups[$timestamp][$key.$itext.'-size']); if (empty($backups[$timestamp][$key])) unset($backups[$timestamp][$key]); } if (isset($backups[$timestamp]['checksums']) && is_array($backups[$timestamp]['checksums'])) { foreach (array_keys($backups[$timestamp]['checksums']) as $algo) { unset($backups[$timestamp]['checksums'][$algo][$key.$index]); } } // If we don't save the array back, then the above section will fire again for the same files - and the remote storage will be requested to delete already-deleted files, which then means no time is actually saved by the browser-backend loop method. UpdraftPlus_Backup_History::save_history($backups); } } } } } unset($backups[$timestamp]); UpdraftPlus_Backup_History::save_history($backups); $sets_removed++; } return $this->remove_backup_set_cleanup(true, $backups, $local_deleted, $remote_deleted, $sets_removed); } /** * This function sorts the array of instance ids currently saved so that any instance id that is in both the saved settings and the backup history move to the top of the array, as these are likely to work. Then values that don't appear in the backup history move to the bottom. * * @param String $a - the first instance id * @param String $b - the second instance id * @return Integer - returns an integer to indicate what position the $b value should be moved in */ public function instance_ids_sort($a, $b) { if (in_array($a, $this->backups_instance_ids)) { if (in_array($b, $this->backups_instance_ids)) return 0; return -1; } return in_array($b, $this->backups_instance_ids) ? 1 : 0; } /** * Called by self::delete_set() to finish up before returning (whether the complete deletion is finished or not) * * @param Boolean $delete_complete - whether the whole set is now gone (i.e. last round) * @param Array $backups - the backup history * @param Integer $local_deleted - how many backup archives were deleted from local storage * @param Integer $remote_deleted - how many backup archives were deleted from remote storage * @param Integer $sets_removed - how many complete sets were removed * * @return Array - information on the status, suitable for returning to the UI */ public function remove_backup_set_cleanup($delete_complete, $backups, $local_deleted, $remote_deleted, $sets_removed) { global $updraftplus; $updraftplus->register_wp_http_option_hooks(false); UpdraftPlus_Backup_History::save_history($backups); $updraftplus->log("Local files deleted: $local_deleted. Remote files deleted: $remote_deleted"); if ($delete_complete) { $set_message = __('Backup sets removed:', 'updraftplus'); $local_message = __('Local files deleted:', 'updraftplus'); $remote_message = __('Remote files deleted:', 'updraftplus'); if (UpdraftPlus_Options::get_updraft_option('updraft_debug_mode')) { restore_error_handler(); } return array('result' => 'success', 'set_message' => $set_message, 'local_message' => $local_message, 'remote_message' => $remote_message, 'backup_sets' => $sets_removed, 'backup_local' => $local_deleted, 'backup_remote' => $remote_deleted); } else { return array('result' => 'continue', 'backup_local' => $local_deleted, 'backup_remote' => $remote_deleted, 'backup_sets' => $sets_removed); } } public function get_history_status($rescan, $remotescan) { global $updraftplus; if ($rescan) $messages = UpdraftPlus_Backup_History::rebuild($remotescan); $backup_history = UpdraftPlus_Backup_History::get_history(); $output = $this->existing_backup_table($backup_history); $data = array(); if (!empty($messages) && is_array($messages)) { $noutput = ''; $updraftplus->log_e('Restore successful!'); echo '
'; $updraftplus->log("Restore successful"); $s_val = 1; if (!empty($this->entities_to_restore) && is_array($this->entities_to_restore)) { foreach ($this->entities_to_restore as $k => $v) { if ('db' != $v) $s_val = 2; } } $pval = ($updraftplus->have_addons) ? 1 : 0; echo ''.__('Actions', 'updraftplus').': '.__('Return to UpdraftPlus Configuration', 'updraftplus').''; return; } elseif (is_wp_error($backup_success)) { echo ''; $updraftplus->log_e('Restore failed...'); echo '
'; $updraftplus->log_wp_error($backup_success); $updraftplus->log("Restore failed"); $updraftplus->list_errors(); echo ''.__('Actions', 'updraftplus').': '.__('Return to UpdraftPlus Configuration', 'updraftplus').''; return; } elseif (false === $backup_success) { // This means, "not yet - but stay on the page because we may be able to do it later, e.g. if the user types in the requested information" echo ''; $updraftplus->log_e('Restore failed...'); echo '
'; $updraftplus->log("Restore failed"); $updraftplus->list_errors(); echo ''.__('Actions', 'updraftplus').': '.__('Return to UpdraftPlus Configuration', 'updraftplus').''; return; } } if (isset($_REQUEST['action']) && 'updraft_delete_old_dirs' == $_REQUEST['action']) { $nonce = (empty($_REQUEST['_wpnonce'])) ? "" : $_REQUEST['_wpnonce']; if (!wp_verify_nonce($nonce, 'updraftplus-credentialtest-nonce')) die('Security check'); $this->delete_old_dirs_go(); return; } if (!empty($_REQUEST['action']) && 'updraftplus_broadcastaction' == $_REQUEST['action'] && !empty($_REQUEST['subaction'])) { $nonce = (empty($_REQUEST['nonce'])) ? "" : $_REQUEST['nonce']; if (!wp_verify_nonce($nonce, 'updraftplus-credentialtest-nonce')) die('Security check'); do_action($_REQUEST['subaction']); return; } if (isset($_GET['error'])) { // This is used by Microsoft OneDrive authorisation failures (May 15). I am not sure what may have been using the 'error' GET parameter otherwise - but it is harmless. if (!empty($_GET['error_description'])) { $this->show_admin_warning(htmlspecialchars($_GET['error_description']).' ('.htmlspecialchars($_GET['error']).')', 'error'); } else { $this->show_admin_warning(htmlspecialchars($_GET['error']), 'error'); } } if (isset($_GET['message'])) $this->show_admin_warning(htmlspecialchars($_GET['message'])); if (isset($_GET['action']) && 'updraft_create_backup_dir' == $_GET['action'] && isset($_GET['nonce']) && wp_verify_nonce($_GET['nonce'], 'create_backup_dir')) { $created = $this->create_backup_dir(); if (is_wp_error($created)) { echo ''.__('Backup directory could not be created', 'updraftplus').'...
';
echo '
'.__('Backup directory successfully created.', 'updraftplus').'
'.__('For even more features and personal support, check out ', 'updraftplus').'UpdraftPlus Premium.
' : ""; echo " ';
$ret .= '(...)
';
$ret .= '
(...)
';
$ret .= '
: |
most_recently_modified_log_link(); ?> |
||
---|---|---|---|
'.__('Latest UpdraftPlus.com news:', 'updraftplus').' | ';
echo '
|
'.__('Your WordPress install has old directories from its state before you restored/migrated (technical information: these are suffixed with -old). You should press this button to delete them as soon as you have verified that the restoration worked.', 'updraftplus').'
'; } ?> '; } /** * Return cron status information about a specified in-progress job * * @param Boolean|String $job_id - the job to get information about; or, if not specified, all jobs * * @return Array|Boolean - the requested information, or false if it was not found. Format differs depending on whether info on all jobs, or a single job, was requested. */ public function get_cron($job_id = false) { $cron = get_option('cron'); if (!is_array($cron)) $cron = array(); if (false === $job_id) return $cron; foreach ($cron as $time => $job) { if (!isset($job['updraft_backup_resume'])) continue; foreach ($job['updraft_backup_resume'] as $hook => $info) { if (isset($info['args'][1]) && $job_id == $info['args'][1]) { global $updraftplus; $jobdata = $updraftplus->jobdata_getarray($job_id); return is_array($jobdata) ? array($time, $jobdata) : false; } } } } /** * Print active Jobs * * @param boolean $this_job_only A value for $this_job_only also causes something to always be returned (to allow detection of the job having started on the front-end) * @return [type] [description] */ private function print_active_jobs($this_job_only = false) { $cron = $this->get_cron(); $ret = ''; foreach ($cron as $time => $job) { if (isset($job['updraft_backup_resume'])) { foreach ($job['updraft_backup_resume'] as $hook => $info) { if (isset($info['args'][1])) { $job_id = $info['args'][1]; if (false === $this_job_only || $job_id == $this_job_only) { $ret .= $this->print_active_job($job_id, false, $time, $info['args'][0]); } } } } } // A value for $this_job_only implies that output is required if (false !== $this_job_only && !$ret) { $ret = $this->print_active_job($this_job_only); if ('' == $ret) { // The presence of the exact ID matters to the front-end - indicates that the backup job has at least begun $ret = ''.__('Old directories successfully removed.', 'updraftplus').'
',__('Old directory removal failed for some reason. You may want to do this manually.', 'updraftplus').'
'.__('The folder was created, but we had to change its file permissions to 777 (world-writable) to be able to write to it. You should check with your hosting provider that this will not cause any problems', 'updraftplus').'
'; return true; } else { @$wp_filesystem->chmod($default_backup_dir, 0775); $show_dir = (0 === strpos($default_backup_dir, ABSPATH)) ? substr($default_backup_dir, strlen(ABSPATH)) : $default_backup_dir; return new WP_Error('writable_error', __('The folder exists, but your webserver does not have permission to write to it.', 'updraftplus').' '.__('You will need to consult with your web hosting provider to find out how to set permissions for a WordPress plugin to write to the directory.', 'updraftplus').' ('.$show_dir.')'); } } return true; } /** * scans the content dir to see if any -old dirs are present * * @param Boolean $print_as_comment Echo information in an HTML comment * @return Boolean */ private function scan_old_dirs($print_as_comment = false) { global $updraftplus; $dirs = scandir(untrailingslashit(WP_CONTENT_DIR)); if (!is_array($dirs)) $dirs = array(); $dirs_u = @scandir($updraftplus->backups_dir_location()); if (!is_array($dirs_u)) $dirs_u = array(); foreach (array_merge($dirs, $dirs_u) as $dir) { if (preg_match('/-old$/', $dir)) { if ($print_as_comment) echo ''; return true; } } // No need to scan ABSPATH - we don't backup there if (is_dir(untrailingslashit(WP_PLUGIN_DIR).'-old')) { if ($print_as_comment) echo ''; return true; } return false; } /** * Outputs html for a storage method using the parameters passed in, this version should be removed when all remote storages use the multi version * * @param String $method a list of methods to be used when * @param String $header the table header content * @param String $contents the table contents */ public function storagemethod_row($method, $header, $contents) { ?>$text
$text
"; if ($echo) echo $ret; return $ret; } public function optionfilter_split_every($value) { return max(absint($value), UPDRAFTPLUS_SPLIT_MIN); } /** * Check if curl exists; if not, print or return appropriate error messages * * @param String $service the service description (used only for user-visible messages - so, use the description) * @param Boolean $has_fallback set as true if the lack of Curl only affects the ability to connect over SSL * @param String $extraclass an extra CSS class for any resulting message, passed on to show_double_warning() * @param Boolean $echo_instead_of_return whether the result should be echoed or returned * @return String any resulting message, if $echo_instead_of_return was set */ public function curl_check($service, $has_fallback = false, $extraclass = '', $echo_instead_of_return = true) { $ret = ''; // Check requirements if (!function_exists("curl_init") || !function_exists('curl_exec')) { $ret .= $this->show_double_warning(''.__('Warning', 'updraftplus').': '.sprintf(__("Your web server's PHP installation does not included a required (for %s) module (%s). Please contact your web hosting provider's support and ask for them to enable it.", 'updraftplus'), $service, 'Curl').' ', $extraclass, false); } else { $curl_version = curl_version(); $curl_ssl_supported= ($curl_version['features'] & CURL_VERSION_SSL); if (!$curl_ssl_supported) { if ($has_fallback) { $ret .= ''.__('Warning', 'updraftplus').': '.sprintf(__("Your web server's PHP/Curl installation does not support https access. Communications with %s will be unencrypted. Ask your web host to install Curl/SSL in order to gain the ability for encryption (via an add-on).", 'updraftplus'), $service).'
'; } else { $ret .= $this->show_double_warning(''.__('Warning', 'updraftplus').': '.sprintf(__("Your web server's PHP/Curl installation does not support https access. We cannot access %s without this support. Please contact your web hosting provider's support. %s requires Curl+https. Please do not file any support requests; there is no alternative.", 'updraftplus'), $service, $service).'
', $extraclass, false); } } else { $ret .= ''.sprintf(__("Good news: Your site's communications with %s can be encrypted. If you see any errors to do with encryption, then look in the 'Expert Settings' for more help.", 'updraftplus'), $service).'
'; } } if ($echo_instead_of_return) { echo $ret; } else { return $ret; } } /** * If $basedirs is passed as an array, then $directorieses must be too * Note: Reason $directorieses is being used because $directories is used within the foreach-within-a-foreach further down * * @param Array|String $directorieses List of of directories, or a single one * @param Array $exclude An exclusion array of directories * @param Array|String $basedirs A list of base directories, or a single one * @param String $format Return format - 'text' or 'numeric' * @return String|Integer */ private function recursive_directory_size($directorieses, $exclude = array(), $basedirs = '', $format = 'text') { $size = 0; if (is_string($directorieses)) { $basedirs = $directorieses; $directorieses = array($directorieses); } if (is_string($basedirs)) $basedirs = array($basedirs); foreach ($directorieses as $ind => $directories) { if (!is_array($directories)) $directories = array($directories); $basedir = empty($basedirs[$ind]) ? $basedirs[0] : $basedirs[$ind]; foreach ($directories as $dir) { if (is_file($dir)) { $size += @filesize($dir); } else { $suffix = ('' != $basedir) ? ((0 === strpos($dir, $basedir.'/')) ? substr($dir, 1+strlen($basedir)) : '') : ''; $size += $this->recursive_directory_size_raw($basedir, $exclude, $suffix); } } } if ('numeric' == $format) return $size; global $updraftplus; return $updraftplus->convert_numeric_size_to_text($size); } private function recursive_directory_size_raw($prefix_directory, &$exclude = array(), $suffix_directory = '') { $directory = $prefix_directory.('' == $suffix_directory ? '' : '/'.$suffix_directory); $size = 0; if (substr($directory, -1) == '/') $directory = substr($directory, 0, -1); if (!file_exists($directory) || !is_dir($directory) || !is_readable($directory)) return -1; if (file_exists($directory.'/.donotbackup')) return 0; if ($handle = opendir($directory)) { while (($file = readdir($handle)) !== false) { if ('.' != $file && '..' != $file) { $spath = ('' == $suffix_directory) ? $file : $suffix_directory.'/'.$file; if (false !== ($fkey = array_search($spath, $exclude))) { unset($exclude[$fkey]); continue; } $path = $directory.'/'.$file; if (is_file($path)) { $size += filesize($path); } elseif (is_dir($path)) { $handlesize = $this->recursive_directory_size_raw($prefix_directory, $exclude, $suffix_directory.('' == $suffix_directory ? '' : '/').$file); if ($handlesize >= 0) { $size += $handlesize; } } } } closedir($handle); } return $size; } private function raw_backup_info($backup_history, $key, $nonce) { global $updraftplus; $backup = $backup_history[$key]; $pretty_date = get_date_from_gmt(gmdate('Y-m-d H:i:s', (int) $key), 'M d, Y G:i'); $rawbackup = "'; $backupable_entities = $updraftplus->get_backupable_file_entities(true, true); if (!empty($nonce)) { $jd = $updraftplus->jobdata_getarray($nonce); } else { $jd = array(); } $checksums = $updraftplus->which_checksums(); foreach ($backupable_entities as $type => $info) { if (!isset($backup[$type])) continue; $rawbackup .= $updraftplus->printfile($info['description'], $backup, $type, $checksums, $jd, true); } $total_size = 0; foreach ($backup as $ekey => $files) { if ('db' == strtolower(substr($ekey, 0, 2)) && '-size' != substr($ekey, -5, 5)) { $rawbackup .= $updraftplus->printfile(__('Database', 'updraftplus'), $backup, $ekey, $checksums, $jd, true); } if (!isset($backupable_entities[$ekey]) && ('db' != substr($ekey, 0, 2) || '-size' == substr($ekey, -5, 5))) continue; if (is_string($files)) $files = array($files); foreach ($files as $findex => $file) { $size_key = (0 == $findex) ? $ekey.'-size' : $ekey.$findex.'-size'; $total_size = (false === $total_size || !isset($backup[$size_key]) || !is_numeric($backup[$size_key])) ? false : $total_size + $backup[$size_key]; } } $services = empty($backup['service']) ? array('none') : $backup['service']; if (!is_array($services)) $services = array('none'); $rawbackup .= ''.__('Uploaded to:', 'updraftplus').' '; $show_services = ''; foreach ($services as $serv) { if ('none' == $serv || '' == $serv) { $add_none = true; } elseif (isset($updraftplus->backup_methods[$serv])) { $show_services .= ($show_services) ? ', '.$updraftplus->backup_methods[$serv] : $updraftplus->backup_methods[$serv]; } else { $show_services .= ($show_services) ? ', '.$serv : $serv; } } if ('' == $show_services && $add_none) $show_services .= __('None', 'updraftplus'); $rawbackup .= $show_services; if (false !== $total_size) { $rawbackup .= '
'.__('Total backup size:', 'updraftplus').' '.$updraftplus->convert_numeric_size_to_text($total_size).''; } $rawbackup .= '
'.print_r($backup, true).''; if (!empty($jd) && is_array($jd)) { $rawbackup .= '
'.print_r($jd, true).''; } return esc_attr($rawbackup); } /** * Get the HTML for the table of existing backups * * @param Array|Boolean $backup_history - a list of backups to use, or false to get the current list from the database * * @return String - HTML for the table */ public function existing_backup_table($backup_history = false) { global $updraftplus; if (false === $backup_history) $backup_history = UpdraftPlus_Backup_History::get_history(); if (!is_array($backup_history) || empty($backup_history)) return "
".__('You have not yet made any backups.', 'updraftplus')."
"; $pass_values = array( 'backup_history' => $backup_history, 'updraft_dir' => $updraftplus->backups_dir_location(), 'backupable_entities' => $updraftplus->get_backupable_file_entities(true, true) ); return $this->include_template('wp-admin/settings/existing-backups-table.php', true, $pass_values); } private function download_db_button($bkey, $key, $esc_pretty_date, $backup, $accept = array()) { if (!empty($backup['meta_foreign']) && isset($accept[$backup['meta_foreign']])) { $desc_source = $accept[$backup['meta_foreign']]['desc']; } else { $desc_source = __('unknown source', 'updraftplus'); } $ret = ''; if ('db' == $bkey) { $dbt = empty($backup['meta_foreign']) ? esc_attr(__('Database', 'updraftplus')) : esc_attr(sprintf(__('Database (created by %s)', 'updraftplus'), $desc_source)); } else { $dbt = __('External database', 'updraftplus').' ('.substr($bkey, 2).')'; } $ret .= $this->download_button($bkey, $key, 0, null, '', $dbt, $esc_pretty_date, '0'); return $ret; } /** * Go through each of the file entities * * @param Array $backup An array of meta information * @param Integer $key Backup timestamp (epoch time) * @param Array $accept An array of values to be accepted from vaules within $backup * @param String $entities Entities to be added * @param String $esc_pretty_date Whether the button needs to escape the pretty date format * @return String - the resulting HTML */ public function download_buttons($backup, $key, $accept, &$entities, $esc_pretty_date) { global $updraftplus; $ret = ''; $backupable_entities = $updraftplus->get_backupable_file_entities(true, true); $first_entity = true; foreach ($backupable_entities as $type => $info) { if (!empty($backup['meta_foreign']) && 'wpcore' != $type) continue; $ide = ''; if ('wpcore' == $type) $wpcore_restore_descrip = $info['description']; if (empty($backup['meta_foreign'])) { $sdescrip = preg_replace('/ \(.*\)$/', '', $info['description']); if (strlen($sdescrip) > 20 && isset($info['shortdescription'])) $sdescrip = $info['shortdescription']; } else { $info['description'] = 'WordPress'; if (isset($accept[$backup['meta_foreign']])) { $desc_source = $accept[$backup['meta_foreign']]['desc']; $ide .= sprintf(__('Backup created by: %s.', 'updraftplus'), $accept[$backup['meta_foreign']]['desc']).' '; } else { $desc_source = __('unknown source', 'updraftplus'); $ide .= __('Backup created by unknown source (%s) - cannot be restored.', 'updraftplus').' '; } $sdescrip = (empty($accept[$backup['meta_foreign']]['separatedb'])) ? sprintf(__('Files and database WordPress backup (created by %s)', 'updraftplus'), $desc_source) : sprintf(__('Files backup (created by %s)', 'updraftplus'), $desc_source); if ('wpcore' == $type) $wpcore_restore_descrip = $sdescrip; } if (isset($backup[$type])) { if (!is_array($backup[$type])) $backup[$type] = array($backup[$type]); $howmanyinset = count($backup[$type]); $expected_index = 0; $index_missing = false; $set_contents = ''; $entities .= "/$type="; $whatfiles = $backup[$type]; ksort($whatfiles); foreach ($whatfiles as $findex => $bfile) { $set_contents .= ('' == $set_contents) ? $findex : ",$findex"; if ($findex != $expected_index) $index_missing = true; $expected_index++; } $entities .= $set_contents.'/'; if (!empty($backup['meta_foreign'])) { $entities .= '/plugins=0//themes=0//uploads=0//others=0/'; } $printing_first = true; foreach ($whatfiles as $findex => $bfile) { $pdescrip = ($findex > 0) ? $sdescrip.' ('.($findex+1).')' : $sdescrip; if ($printing_first) { $ide .= __('Press here to download or browse', 'updraftplus').' '.strtolower($info['description']); } else { $ret .= ' '; } else { $printing_first = false; } } } } return $ret; } public function date_label($pretty_date, $key, $backup, $jobdata, $nonce, $simple_format = false) { $pretty_date = $simple_format ? $pretty_date : ''.__('This backup does not exist in the backup history - restoration aborted. Timestamp:', 'updraftplus')." $timestamp
'.__('Why am I seeing this?', 'updraftplus').'
'; foreach ($wp_filesystem->errors->get_error_messages() as $message) show_message($message); exit; } // If we make it this far then WP_Filesystem has been instantiated and is functional // Set up logging $updraftplus->backup_time_nonce(); $updraftplus->jobdata_set('job_type', 'restore'); $updraftplus->jobdata_set('job_time_ms', $updraftplus->job_time_ms); $updraftplus->logfile_open($updraftplus->nonce); // Provide download link for the log file // TODO: Automatic purging of old log files // TODO: Provide option to auto-email the log file echo ''.__('ABORT: Could not find the information on which entities to restore.', 'updraftplus').'
'; echo ''.__('If making a request for support, please include this information:', 'updraftplus').' '.count($_POST).' : '.htmlspecialchars(serialize($_POST)).'
'; return new WP_Error('missing_info', 'Backup information not found'); } $this->entities_to_restore = $entities_to_restore; set_error_handler(array($updraftplus, 'php_error'), E_ALL & ~E_STRICT); /* $_POST['updraft_restore'] is typically something like: array(0=>'db', 1=>'plugins', 2=>'themes'), etc. i.e. array ('db', 'plugins', themes') */ if (empty($restore_options)) { // Gather the restore optons into one place - code after here should read the options, and not the HTTP layer $restore_options = array(); if (!empty($_POST['updraft_restorer_restore_options'])) { parse_str(stripslashes($_POST['updraft_restorer_restore_options']), $restore_options); } $restore_options['updraft_encryptionphrase'] = empty($_POST['updraft_encryptionphrase']) ? '' : (string) stripslashes($_POST['updraft_encryptionphrase']); $restore_options['updraft_restorer_wpcore_includewpconfig'] = empty($_POST['updraft_restorer_wpcore_includewpconfig']) ? false : true; $restore_options['updraft_incremental_restore_point'] = empty($_POST['updraft_incremental_restore_point']) ? -1 : (int) $_POST['updraft_incremental_restore_point']; $updraftplus->jobdata_set('restore_options', $restore_options); } $backupable_entities = $updraftplus->get_backupable_file_entities(true, true); if (defined('UPDRAFTPLUS_INCREMENTAL_RESTORE_POINT') && is_int(UPDRAFTPLUS_INCREMENTAL_RESTORE_POINT)) $restore_options['updraft_incremental_restore_point'] = UPDRAFTPLUS_INCREMENTAL_RESTORE_POINT; // If updraft_incremental_restore_point is equal to -1 then this is either not a incremental restore or we are going to restore up to the latest increment, so there is no need to prune the backup set of any unwanted backup archives. if (isset($restore_options['updraft_incremental_restore_point']) && $restore_options['updraft_incremental_restore_point'] > 0) { $restore_point = $restore_options['updraft_incremental_restore_point']; foreach ($backup_set['incremental_sets'] as $timestamp => $entities) { if ($timestamp > $restore_point) { foreach ($entities as $entity => $backups) { foreach ($backups as $key => $value) { unset($backup_set[$entity][$key]); } } } } } // Restore in the most helpful order uksort($backup_set, array($this, 'sort_restoration_entities')); // Now log $copy_restore_options = $restore_options; if (!empty($copy_restore_options['updraft_encryptionphrase'])) $copy_restore_options['updraft_encryptionphrase'] = '***'; $updraftplus->log("Restore job started. Entities to restore: ".implode(', ', array_flip($entities_to_restore)).'. Restore options: '.json_encode($copy_restore_options)); $backup_set['timestamp'] = $timestamp; // Allow add-ons to adjust the restore directory (but only in the case of restore - otherwise, they could just use the filter built into UpdraftPlus::get_backupable_file_entities) $backupable_entities = apply_filters('updraft_backupable_file_entities_on_restore', $backupable_entities, $restore_options, $backup_set); // We use a single object for each entity, because we want to store information about the backup set include_once(UPDRAFTPLUS_DIR.'/restorer.php'); global $updraftplus_restorer; $updraftplus_restorer = new Updraft_Restorer(new Updraft_Restorer_Skin, $backup_set, false, $restore_options); $second_loop = array(); echo "$type: "; $updraftplus->log(__('Skipping restoration of WordPress core when importing a single site into a multisite installation. If you had anything necessary in your WordPress directory then you will need to re-add it manually from the zip file.', 'updraftplus'), 'notice-restore'); // TODO // $updraftplus->log_e('Skipping restoration of WordPress core when importing a single site into a multisite installation. If you had anything necessary in your WordPress directory then you will need to re-add it manually from the zip file.'); echo "
"; continue; } if (is_string($files)) $files = array($files); foreach ($files as $ind => $file) { $fullpath = $updraft_dir.$file; $updraftplus->log(sprintf(__("Looking for %s archive: file name: %s", 'updraftplus'), $type, $file), 'notice-restore'); if (is_array($continuation_data) && isset($continuation_data['second_loop_entities'][$type]) && !in_array($file, $continuation_data['second_loop_entities'][$type])) { echo __('Skipping: this archive was already restored.', 'updraftplus')."'; ob_start(); $history = UpdraftPlus_Backup_History::get_history(); var_dump($history); $response["html"] .= ob_get_clean(); $response['html'] .= ''; $response['html'] .= '
'; $updraft_dir = $updraftplus->backups_dir_location(); $raw_output = array(); $d = dir($updraft_dir); while (false !== ($entry = $d->read())) { $fp = $updraft_dir.'/'.$entry; $mtime = filemtime($fp); if (is_dir($fp)) { $size = ' d'; } elseif (is_link($fp)) { $size = ' l'; } elseif (is_file($fp)) { $size = sprintf("%8.1f", round(filesize($fp)/1024, 1)).' '.gmdate('r', $mtime); } else { $size = ' ?'; } if (preg_match('/^log\.(.*)\.txt$/', $entry, $lmatch)) $entry = ''.$entry.''; $raw_output[$mtime] = empty($raw_output[$mtime]) ? sprintf("%s %s\n", $size, $entry) : $raw_output[$mtime].sprintf("%s %s\n", $size, $entry); } @$d->close(); krsort($raw_output, SORT_NUMERIC); foreach ($raw_output as $line) { $response['html'] .= $line; } $response['html'] .= ''; $response['html'] .= '
'.htmlspecialchars($opt).' | '.htmlspecialchars(print_r(UpdraftPlus_Options::get_updraft_option($opt), true)).' | '; } $response['html'] .= '
', '', $response['html']); $response['html'] = str_replace('', '', $response['html']); } return $response; } /** * This will call any wp_action * * @param Array $data The array of data with the vaules for wpaction * @param Callable|Boolean $close_connection_callable A callable to call to close the browser connection, or true for a default suitable for internal use, or false for none * @return Array - results */ public function call_wp_action($data = null, $close_connection_callable = false) { global $updraftplus; ob_start(); $res = 'Request received: '; if (preg_match('/^([^:]+)+:(.*)$/', $data['wpaction'], $matches)) { $action = $matches[1]; if (null === ($args = json_decode($matches[2], true))) { $res .= "The parameters (should be JSON) could not be decoded"; $action = false; } else { if (is_string($args)) $args = array($args); $res .= "Will despatch action: ".htmlspecialchars($action).", parameters: ".htmlspecialchars(implode(',', $args)); } } else { $action = $data['wpaction']; $res .= "Will despatch action: ".htmlspecialchars($action).", no parameters"; } $ret = ob_get_clean(); // Need to add this as the close browser should only work for UDP if ($close_connection_callable) { if (is_callable($close_connection_callable)) { call_user_func($close_connection_callable, array('r' => $res)); } else { $updraftplus->close_browser_connection(json_encode(array('r' => $res))); } } if (!empty($action)) { if (!empty($args)) { ob_start(); $returned = do_action_ref_array($action, $args); $output = ob_get_clean(); $res .= " - do_action_ref_array Trigger "; } else { ob_start(); do_action($action); $output = ob_get_contents(); ob_end_clean(); $res .= " - do_action Trigger "; } } $response['response'] = $res; $response['log'] = $output; // Check if response is empty if (!empty($returned)) $response['status'] = $returned; return $response; } /** * Enqueue JSTree JavaScript and CSS, taking into account whether it is already enqueued, and current debug settings */ public function enqueue_jstree() { static $already_enqueued = false; if ($already_enqueued) return; $already_enqueued = true; $jstree_enqueue_version = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '3.3'.'.'.time() : '3.3'; $min_or_not = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; wp_enqueue_script('jstree', UPDRAFTPLUS_URL.'/includes/jstree/jstree'.$min_or_not.'.js', array('jquery'), $jstree_enqueue_version); wp_enqueue_style('jstree', UPDRAFTPLUS_URL.'/includes/jstree/themes/default/style'.$min_or_not.'.css', array(), $jstree_enqueue_version); } }