is for a new box.
This cause issues specifically with fetch log events. Do this by passing true
to the method show_raw_backups
*/
$response = $updraftplus_admin->show_raw_backups(true);
return $response['html'];
}
public function reset_site_id() {
if (false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');
delete_site_option('updraftplus-addons_siteid');
return $updraftplus->siteid();
}
public function search_replace($query) {
if (!class_exists('UpdraftPlus_Addons_Migrator')) {
return new WP_Error('error', '', 'no_class_found');
}
global $updraftplus_addons_migrator;
if (!is_a($updraftplus_addons_migrator, 'UpdraftPlus_Addons_Migrator')) {
return new WP_Error('error', 'no_object_found');
}
$_POST = $query;
ob_start();
do_action('updraftplus_adminaction_searchreplace', $query);
$response = array('log' => ob_get_clean());
return $response;
}
public function change_lock_settings($data) {
global $updraftplus_addon_lockadmin;
if (!class_exists('UpdraftPlus_Addon_LockAdmin')) {
return new WP_Error('error', '', 'no_class_found');
}
if (!is_a($updraftplus_addon_lockadmin, "UpdraftPlus_Addon_LockAdmin")) {
return new WP_Error('error', '', 'no_object_found');
}
$session_length = empty($data["session_length"]) ? '' : $data["session_length"];
$password = empty($data["password"]) ? '' : $data["password"];
$old_password = empty($data["old_password"]) ? '' : $data["old_password"];
$support_url = $data["support_url"];
$user = wp_get_current_user();
if (0 == $user->ID) {
return new WP_Error('no_user_found');
}
$options = $updraftplus_addon_lockadmin->return_opts();
if ($old_password == $options['password']) {
$options['password'] = (string) $password;
$options['support_url'] = (string) $support_url;
$options['session_length'] = (int) $session_length;
UpdraftPlus_Options::update_updraft_option('updraft_adminlocking', $options);
return "lock_changed";
} else {
return new WP_Error('error', '', 'wrong_old_password');
}
}
public function delete_key($key_id) {
global $updraftcentral_main;
if (!is_a($updraftcentral_main, 'UpdraftCentral_Main')) {
return new WP_Error('error', '', 'UpdraftCentral_Main object not found');
}
$response = $updraftcentral_main->delete_key($key_id);
return $response;
}
public function create_key($data) {
global $updraftcentral_main;
if (!is_a($updraftcentral_main, 'UpdraftCentral_Main')) {
return new WP_Error('error', '', 'UpdraftCentral_Main object not found');
}
$response = call_user_func(array($updraftcentral_main, 'create_key'), $data);
return $response;
}
public function fetch_log($data) {
global $updraftcentral_main;
if (!is_a($updraftcentral_main, 'UpdraftCentral_Main')) {
return new WP_Error('error', '', 'UpdraftCentral_Main object not found');
}
$response = call_user_func(array($updraftcentral_main, 'get_log'), $data);
return $response;
}
/**
* A handler method to call the UpdraftPlus admin auth_remote_method
*
* @param Array - $data It consists of below key elements:
* $remote_method - Remote storage service
* $instance_id - Remote storage instance id
* @return Array An Array response to be sent back
*/
public function auth_remote_method($data) {
if (false === ($updraftplus_admin = $this->_load_ud_admin()) || false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Unused variable is for future use.
if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
$response = $updraftplus_admin->auth_remote_method($data);
return $response;
}
/**
* A handler method to call the UpdraftPlus admin deauth_remote_method
*
* @param Array - $data It consists of below key elements:
* $remote_method - Remote storage service
* $instance_id - Remote storage instance id
* @return Array An Array response to be sent back
*/
public function deauth_remote_method($data) {
if (false === ($updraftplus_admin = $this->_load_ud_admin()) || false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Unused variable is for future use.
if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
$response = $updraftplus_admin->deauth_remote_method($data);
return $response;
}
/**
* A handler method to call the relevant remote storage manual authentication methods and return the authentication result
*
* @param array $data - an array of authentication data, normally includes the state and auth code
*
* @return array - an array response to be sent back to the frontend
*/
public function manual_remote_storage_authentication($data) {
if (false === ($updraftplus_admin = $this->_load_ud_admin()) || false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Unused variable is for future use.
$response = array(
'result' => 'success'
);
$method = $data['method'];
$enabled_services = UpdraftPlus_Storage_Methods_Interface::get_enabled_storage_objects_and_ids(array($method));
if (empty($enabled_services[$method]['object']) || empty($enabled_services[$method]['instance_settings']) || !$enabled_services[$method]['object']->supports_feature('manual_authentication')) {
$response['result'] = 'error';
$response['data'] = __('Manual authentication is not available for this remote storage method', 'updraftplus') . '(' . $method . ')';
return $response;
}
$backup_obj = $enabled_services[$method]['object'];
$auth_data = json_decode(base64_decode($data['auth_data']), true);
$instance_id = '';
$state = isset($auth_data['state']) ? urldecode($auth_data['state']) : '';
$code = isset($auth_data['code']) ? urldecode($auth_data['code']) : '';
if (empty($code) && isset($auth_data['access_token']) && isset($auth_data['user_id'])) {
// If there is no code, but the access_token and user_id is set then this is for Google Drive so create a code array using these values
$access_token = urldecode($auth_data['access_token']);
$user_id = urldecode($auth_data['user_id']);
$code = array(
'access_token' => $access_token,
'user_id' => $user_id
);
} elseif (empty($code) && isset($auth_data['token'])) {
// If there is no code, but a token is set then this is for OneDrive so assign token to code
$encoded_token = stripslashes($auth_data['token']);
$token = json_decode($encoded_token);
$code = $token;
}
if (empty($state) || empty($code)) {
$response['result'] = 'error';
$response['data'] = __('Missing authentication data:', 'updraftplus') . " ({$state}) ({$code})";
return $response;
}
if (false !== strpos($state, ':')) {
$parts = explode(':', $state);
$instance_id = $parts[1];
}
if (empty($instance_id)) {
$response['result'] = 'error';
$response['data'] = __('Missing instance id:', 'updraftplus') . " ($state)";
return $response;
}
if (isset($enabled_services[$method]['instance_settings'][$instance_id])) {
$opts = $enabled_services[$method]['instance_settings'][$instance_id];
$backup_obj->set_options($opts, false, $instance_id);
}
$result = $backup_obj->complete_authentication($state, $code, true);
$response['data'] = $result;
return $response;
}
/**
* A handler method to call the UpdraftPlus admin wipe settings method
*
* @return Array An Array response to be sent back
*/
public function wipe_settings() {
if (false === ($updraftplus_admin = $this->_load_ud_admin())) return new WP_Error('no_updraftplus');
if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
// pass false to this method so that it does not remove the UpdraftCentral key
$response = $updraftplus_admin->wipe_settings(false);
return $response;
}
/**
* Retrieves backup information (next scheduled backups, last backup jobs and last log message)
* for UpdraftCentral consumption
*
* @return Array An array containing the results of the backup information retrieval
*/
public function get_backup_info() {
try {
// load global updraftplus admin
if (false === ($updraftplus_admin = $this->_load_ud_admin())) return new WP_Error('no_updraftplus');
ob_start();
$updraftplus_admin->next_scheduled_backups_output();
$next_scheduled_backups = ob_get_clean();
$response = array(
'next_scheduled_backups' => $next_scheduled_backups,
'last_backup_job' => $updraftplus_admin->last_backup_html(),
'last_log_message' => UpdraftPlus_Options::get_updraft_lastmessage()
);
$updraft_last_backup = UpdraftPlus_Options::get_updraft_option('updraft_last_backup', false);
$backup_history = UpdraftPlus_Backup_History::get_history();
if (false !== $updraft_last_backup && !empty($backup_history)) {
$backup_nonce = $updraft_last_backup['backup_nonce'];
$response['backup_nonce'] = $backup_nonce;
$response['log'] = $this->get_log($backup_nonce);
}
} catch (Exception $e) {
$response = array('error' => true, 'message' => $e->getMessage());
}
return $response;
}
/**
* This method will check the connection status to UpdraftPlus.com using the submitted credentials and return the result of that check.
*
* @param array $data - an array that contains the users UpdraftPlus.com credentials
*
* @return array - an array with the result of the connection status
*/
public function updraftplus_com_login_submit($data) {
if (false === ($updraftplus_admin = $this->_load_ud_admin()) || false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Unused variable is for future use.
global $updraftplus_addons2, $updraftplus;
$options = $updraftplus_addons2->get_option(UDADDONS2_SLUG.'_options');
$new_options = $data['data'];
// Check if we can make a connection if we can then we don't want to reset the options in the case where the user has removed their password from the form
$result = !empty($options['email']) ? $updraftplus_addons2->connection_status() : false;
if (true !== $result) {
// We failed to make a connection so try the new options
$updraftplus_addons2->update_option(UDADDONS2_SLUG.'_options', $new_options);
$result = $updraftplus_addons2->connection_status();
}
if (true !== $result) {
if (is_wp_error($result)) {
$connection_errors = array();
foreach ($result->get_error_messages() as $msg) {
$connection_errors[] = $msg;
}
} else {
if (!empty($options['email']) && !empty($options['password'])) $connection_errors = array(__('An unknown error occurred when trying to connect to UpdraftPlus.Com', 'updraftplus'));
}
$result = false;
}
if ($result && isset($new_options['auto_update'])) {
$updraftplus->set_automatic_updates($new_options['auto_update']);
}
if ($result) {
return array(
'success' => true
);
} else {
// There was an error reset the options so that we don't get unwanted notices on the dashboard.
$updraftplus_addons2->update_option(UDADDONS2_SLUG.'_options', array('email' => '', 'password' => ''));
return array(
'error' => true,
'message' => $connection_errors
);
}
}
/**
* This method will create UI for a list of local backups that can be remote sent and return it
*
* @return array - an array with the results from the backup search
*/
public function get_backup_list() {
if (false === ($updraftplus_admin = $this->_load_ud_admin()) || false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');
$response = array(
'result' => 'success'
);
$output = '';
$backup_history = UpdraftPlus_Backup_History::get_history();
foreach ($backup_history as $key => $backup) {
$backup_complete = $updraftplus_admin->check_backup_is_complete($backup, false, false, true);
$remote_sent = !empty($backup['service']) && ((is_array($backup['service']) && in_array('remotesend', $backup['service'])) || 'remotesend' === $backup['service']);
if (!$backup_complete || $remote_sent) unset($backup_history[$key]);
}
if (!empty($backup_history)) {
$output .= '';
$output .= ' '.__('Backup:', 'updraftplus').' ';
$output .= '';
$output .= ' ';
$output .= '
';
} else {
$output .= ''.__('You have no local backups to send.', 'updraftplus').'
';
}
$response['data'] = $output;
return $response;
}
/**
* This function will add some needed filters in order to be able to send a local backup to remote storage it will then boot the backup process.
*
* @param array $data - data sent from the front end, it includes the backup timestamp and nonce
*
* @return array - the response to be sent back to the front end
*/
public function upload_local_backup($data) {
if (false === ($updraftplus_admin = $this->_load_ud_admin()) || false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');
add_filter('updraftplus_initial_jobdata', array($updraftplus_admin, 'upload_local_backup_jobdata'), 10, 3);
add_filter('updraftplus_get_backup_file_basename_from_time', array($updraftplus_admin, 'upload_local_backup_name'), 10, 3);
$background_operation_started_method_name = empty($data['background_operation_started_method_name']) ? '_updraftplus_background_operation_started' : $data['background_operation_started_method_name'];
$msg = array(
'nonce' => $data['use_nonce'],
'm' => apply_filters('updraftplus_backupnow_start_message', ''.__('Start backup', 'updraftplus').': '.htmlspecialchars(__('OK.', 'updraftplus').' '.__('You should soon see activity in the "Last log message" field below.', 'updraftplus')), $data['use_nonce'])
);
$close_connection_callable = array($this->_uc_helper, $background_operation_started_method_name);
if (is_callable($close_connection_callable)) {
call_user_func($close_connection_callable, $msg);
} else {
$updraftplus->close_browser_connection(json_encode($msg));
}
do_action('updraft_backupnow_backup_all', apply_filters('updraft_backupnow_options', $data, array()));
// Control returns when the backup finished; but, the browser connection should have been closed before
die;
}
/**
* Pre-check before sending request and delegates login request to the appropriate service
*
* @param array $params - The submitted form data
* @return string - the result of the call
*/
public function process_updraftcentral_login($params) {
if (false === ($updraftplus_admin = $this->_load_ud_admin())) return new WP_Error('no_updraftplus');
if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
return $updraftplus_admin->get_updraftcentral_cloud()->ajax_process_login($params);
}
/**
* Pre-check before sending request and delegates registration request to the appropriate service
*
* @param array $params - The submitted form data
* @return string - the result of the call
*/
public function process_updraftcentral_registration($params) {
if (false === ($updraftplus_admin = $this->_load_ud_admin())) return new WP_Error('no_updraftplus');
if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
return $updraftplus_admin->get_updraftcentral_cloud()->ajax_process_registration($params);
}
/**
* Pre-check before sending request and delegates login request to the appropriate service
*
* @param array $params - The submitted form data
* @return string - the result of the call
*/
public function process_updraftplus_clone_login($params) {
if (false === ($updraftplus_admin = $this->_load_ud_admin()) || false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');
if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
if (!defined('UPDRAFTPLUS_DO_NOT_USE_IPINFO') || !UPDRAFTPLUS_DO_NOT_USE_IPINFO) {
// Try to get the users region code we can then use this to find their closest clone region
$response = wp_remote_get('https://ipinfo.io/json', array(
'timeout' => 3,
// The API always returns 429 rate limit unless this header is passed
'headers' => array(
'Referer' => network_site_url()
)
));
if (200 === wp_remote_retrieve_response_code($response)) {
$body = wp_remote_retrieve_body($response);
$response = json_decode($body, true);
if (isset($response['country'])) $params['form_data']['country_code'] = $response['country'];
}
}
$response = $updraftplus->get_updraftplus_clone()->ajax_process_login($params, false);
if (isset($response['status']) && 'authenticated' == $response['status']) {
UpdraftPlus::load_checkout_embed();
global $updraftplus_checkout_embed;
$checkout_url = $updraftplus->get_url('buy_clone_tokens');
if (is_a($updraftplus_checkout_embed, 'Updraft_Checkout_Embed')) {
$checkout_url = $updraftplus_checkout_embed->get_product('updraftplus-clone-tokens', UpdraftPlus_Options::admin_page_url().'?page=updraftplus&tab=migrate');
}
$tokens = isset($response['tokens']) ? $response['tokens'] : 0;
$content = '';
$content .= '';
$content .= '' . __("Available temporary clone tokens:", "updraftplus") . ' ' . esc_html($tokens) . '
';
$content .= ''.__('You can buy more temporary clone tokens here.', 'updraftplus').'
';
$content .= '';
if (0 != $response['tokens']) {
$is_vps_tester = !empty($response['is_vps_tester']);
$supported_wp_versions = isset($response['supported_wp_versions']) ? $response['supported_wp_versions'] : array();
$supported_packages = isset($response['supported_packages']) ? $response['supported_packages'] : array();
$supported_packages_label = isset($response['supported_packages_label']) ? $response['supported_packages_label'] : array();
$supported_regions = isset($response['supported_regions']) ? $response['supported_regions'] : array();
$nearest_region = isset($response['nearest_region']) ? $response['nearest_region'] : '';
$content .= '';
$content .= $updraftplus_admin->updraftplus_clone_ui_widget($is_vps_tester, $supported_wp_versions, $supported_packages, $supported_regions, $nearest_region, $supported_packages_label);
$content .= '';
$content .= '';
$content .= '' . __('Processing', 'updraftplus') . '...
';
$content .= '';
$content .= '';
}
$content .= ''; // end .updraftclone-main-row
$content .= isset($response['clone_list']) ? ''.__('Current clones', 'updraftplus').' - '.__('manage', 'updraftplus').'
'.$response['clone_list'].'' : '';
$response['html'] = $content;
}
return $response;
}
/**
* This function sends the request to create the clone
*
* @param array $params - The submitted data
* @return string - the result of the call
*/
public function process_updraftplus_clone_create($params) {
if (false === ($updraftplus_admin = $this->_load_ud_admin()) || false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');
if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
$response = $updraftplus->get_updraftplus_clone()->ajax_process_clone($params);
if (!isset($response['status']) && 'success' != $response['status']) return $response;
$content = '';
$url = '';
if (isset($response['data'])) {
$tokens = isset($response['data']['tokens']) ? $response['data']['tokens'] : 0;
$url = isset($response['data']['url']) ? $response['data']['url'] : '';
if (isset($response['data']['secret_token'])) {
$response['secret_token'] = $response['data']['secret_token'];
unset($response['data']['secret_token']);
}
$content .= '';
$content .= '';
$content .= '' . __("Available temporary clone tokens:", "updraftplus") . ' ' . esc_html($tokens) . '
';
$content .= '';
$content .= '';
$content .= $updraftplus_admin->updraftplus_clone_info($url);
$content .= '';
$content .= ''; // end .updraftclone-main-row
}
if (isset($params['form_data']['install_info']['wp_only'])) {
$content .= '' . __('No backup will be started.', 'updraftplus').' '.__('The creation of your clone should now begin, and your WordPress username and password will be displayed below when ready.', 'updraftplus') . ' ' . __('N.B. You will be charged one token once the clone is ready.', 'updraftplus').' '.__('If the clone fails to boot, then the token will be released within an hour.', 'updraftplus') . '' . __('Processing', 'updraftplus') . '...
';
} else {
$content .= '' . __('The creation of your data for creating the clone should now begin.', 'updraftplus') . ' ' . __('N.B. You will be charged one token once the clone is ready.', 'updraftplus').' '.__('If the clone fails to boot, then the token will be released within an hour.', 'updraftplus') . '' . __('Processing', 'updraftplus') . '...
';
$content .= '';
}
$response['html'] = $content;
$response['url'] = $url;
$response['key'] = '';
return $response;
}
/**
* This function will get the clone network and credential info
*
* @param array $params - the parameters for the call
*
* @return array|WP_Error - the response array that includes the credential info or a WP_Error
*/
public function process_updraftplus_clone_poll($params) {
if (false === ($updraftplus_admin = $this->_load_ud_admin()) || false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Unused variable is for future use.
if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
$response = $updraftplus->get_updraftplus_clone()->clone_info_poll($params);
return $response;
}
/**
* This function will get the clone network info HTML for the passed in clone URL
*
* @param array $params - the parameters for the call
*
* @return array - the response array that includes the network HTML
*/
public function get_clone_network_info($params) {
if (false === ($updraftplus_admin = $this->_load_ud_admin()) || false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Unused variable is for future use.
if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
$url = empty($params['clone_url']) ? '' : $params['clone_url'];
$response = array();
$response['html'] = $updraftplus_admin->updraftplus_clone_info($url);
return $response;
}
/**
* This function will get the restore resume notice
*
* @param array $params - the parameters for the call
*
* @return array|WP_Error - the response array that includes the restore resume notice
*/
public function get_restore_resume_notice($params) {
if (false === ($updraftplus_admin = $this->_load_ud_admin()) || false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Unused variable is for future use.
if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
$job_id = empty($params['job_id']) ? '' : $params['job_id'];
$response = array(
'status' => 'success',
);
if (empty($job_id)) return new WP_Error('missing_parameter', 'Missing parameters.');
$html = $updraftplus_admin->get_restore_resume_notice($job_id);
if (is_wp_error($html)) return $html;
$response['html'] = $html;
return $response;
}
/**
* This function will add updraft_dismiss_admin_warning_litespeed option to hide litespeed admin warning after dismissed
*
* @return array - an empty array
*/
public function dismiss_admin_warning_litespeed() {
UpdraftPlus_Options::update_updraft_option('updraft_dismiss_admin_warning_litespeed', true);
return array();
}
/**
* This function will add updraft_dismiss_admin_warning_pclzip option to hide pclzip admin warning after dismissed
*
* @return array - an empty array
*/
public function dismiss_admin_warning_pclzip() {
UpdraftPlus_Options::update_updraft_option('updraft_dismiss_admin_warning_pclzip', true);
return array();
}
}