Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp.../includes
File: updraftplus-login.php
<?php
[0] Fix | Delete
[1] Fix | Delete
if (!defined('UPDRAFTPLUS_DIR')) die('No direct access allowed.');
[2] Fix | Delete
[3] Fix | Delete
abstract class UpdraftPlus_Login {
[4] Fix | Delete
[5] Fix | Delete
/**
[6] Fix | Delete
* Pulls the appropriate message for the given code and translate it before
[7] Fix | Delete
* returning it to the caller
[8] Fix | Delete
*
[9] Fix | Delete
* @internal
[10] Fix | Delete
* @param string $code The code of the message to pull
[11] Fix | Delete
* @return string - The translated message
[12] Fix | Delete
*/
[13] Fix | Delete
abstract protected function translate_message($code);
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* Executes login or registration process. Connects and sends request to the UpdraftCentral Cloud
[17] Fix | Delete
* and returns the response coming from the server
[18] Fix | Delete
*
[19] Fix | Delete
* @internal
[20] Fix | Delete
* @param array $data The submitted form data
[21] Fix | Delete
* @param boolean $register Indicates whether the current call is for a registration process or not. Defaults to false.
[22] Fix | Delete
* @return array - The response from the request
[23] Fix | Delete
*/
[24] Fix | Delete
abstract protected function login_or_register($data, $register = false);
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* Handles the actual sending of the request to the remote server (UpdraftCentral Cloud) and pre-checks the response
[28] Fix | Delete
* and wraps it up for the caller before sending it back
[29] Fix | Delete
*
[30] Fix | Delete
* @internal
[31] Fix | Delete
* @param array $data The submitted form data
[32] Fix | Delete
* @param string $action The name of the action or service that will be triggered in UpdraftCentral Cloud
[33] Fix | Delete
* @return array - The response from the server
[34] Fix | Delete
*/
[35] Fix | Delete
protected function send_remote_request($data, $action) {
[36] Fix | Delete
global $updraftplus;
[37] Fix | Delete
$result = wp_remote_post($updraftplus->get_url('mothership').'/?udm_action='.$action,
[38] Fix | Delete
array(
[39] Fix | Delete
'timeout' => 20,
[40] Fix | Delete
'headers' => apply_filters('updraftplus_auth_headers', ''),
[41] Fix | Delete
'body' => $data
[42] Fix | Delete
)
[43] Fix | Delete
);
[44] Fix | Delete
[45] Fix | Delete
// If we got an error then we return the WP_Error object itself
[46] Fix | Delete
// and let the caller handle it.
[47] Fix | Delete
if (is_wp_error($result)) return $result;
[48] Fix | Delete
[49] Fix | Delete
$response = json_decode(wp_remote_retrieve_body($result), true);
[50] Fix | Delete
if (!is_array($response) || !isset($response['mothership']) || !isset($response['status'])) {
[51] Fix | Delete
[52] Fix | Delete
if (preg_match('/has banned your IP address \(([\.:0-9a-f]+)\)/', $result['body'], $matches)) {
[53] Fix | Delete
return new WP_Error('banned_ip', sprintf(__("UpdraftPlus.com has responded with 'Access Denied'.", 'updraftplus').'<br>'.__("It appears that your web server's IP Address (%s) is blocked.", 'updraftplus').' '.__('This most likely means that you share a webserver with a hacked website that has been used in previous attacks.', 'updraftplus').'<br> <a href="'.apply_filters("updraftplus_com_link", "https://updraftplus.com/unblock-ip-address/").'" target="_blank">'.__('To remove the block, please go here.', 'updraftplus').'</a> ', $matches[1]));
[54] Fix | Delete
} else {
[55] Fix | Delete
return new WP_Error('unknown_response', sprintf(__('UpdraftPlus.Com returned a response which we could not understand (data: %s)', 'updraftplus'), wp_remote_retrieve_body($result)));
[56] Fix | Delete
}
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
return $response;
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* The ajax based request point of entry for the login process
[64] Fix | Delete
*
[65] Fix | Delete
* @param array $data - The submitted form data
[66] Fix | Delete
* @param boolean $echo_results - Whether to echo/display the results directly to the user or assign it to a variable
[67] Fix | Delete
* @return array - Response of the process
[68] Fix | Delete
*/
[69] Fix | Delete
public function ajax_process_login($data = array(), $echo_results = true) {
[70] Fix | Delete
try {
[71] Fix | Delete
if (isset($data['form_data'])) {
[72] Fix | Delete
if (is_string($data['form_data'])) {
[73] Fix | Delete
parse_str($data['form_data'], $form_data);
[74] Fix | Delete
} elseif (is_array($data['form_data'])) {
[75] Fix | Delete
$form_data = $data['form_data'];
[76] Fix | Delete
}
[77] Fix | Delete
}
[78] Fix | Delete
$response = $this->login_or_register($form_data);
[79] Fix | Delete
} catch (Exception $e) {
[80] Fix | Delete
$response = array('error' => true, 'message' => $e->getMessage());
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
if ($echo_results) {
[84] Fix | Delete
echo json_encode($response);
[85] Fix | Delete
} else {
[86] Fix | Delete
return $response;
[87] Fix | Delete
}
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
/**
[91] Fix | Delete
* The ajax based request point of entry for the registration process
[92] Fix | Delete
*
[93] Fix | Delete
* @param array $data - The submitted form data
[94] Fix | Delete
* @param boolean $echo_results - Whether to echo/display the results directly to the user or assign it to a variable
[95] Fix | Delete
* @return array - Response of the process
[96] Fix | Delete
*/
[97] Fix | Delete
public function ajax_process_registration($data = array(), $echo_results = true) {
[98] Fix | Delete
try {
[99] Fix | Delete
if (isset($data['form_data'])) parse_str($data['form_data'], $form_data);
[100] Fix | Delete
[101] Fix | Delete
$response = $this->login_or_register($form_data, true);
[102] Fix | Delete
} catch (Exception $e) {
[103] Fix | Delete
$response = array('error' => true, 'message' => $e->getMessage());
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
if ($echo_results) {
[107] Fix | Delete
echo json_encode($response);
[108] Fix | Delete
} else {
[109] Fix | Delete
return $response;
[110] Fix | Delete
}
[111] Fix | Delete
}
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function