Dropbox2
6 years ago
Google
6 years ago
checkout-embed
6 years ago
cloudfiles
12 years ago
handlebars
6 years ago
images
9 years ago
jquery.serializeJSON
7 years ago
jstree
6 years ago
labelauty
6 years ago
tether
6 years ago
tether-shepherd
7 years ago
updraftclone
6 years ago
S3.php
6 years ago
S3compat.php
6 years ago
cacert.pem
6 years ago
class-backup-history.php
6 years ago
class-commands.php
6 years ago
class-database-utility.php
6 years ago
class-filesystem-functions.php
6 years ago
class-job-scheduler.php
6 years ago
class-manipulation-functions.php
7 years ago
class-partialfileservlet.php
9 years ago
class-remote-send.php
6 years ago
class-semaphore.php
6 years ago
class-storage-methods-interface.php
6 years ago
class-udrpc.php
6 years ago
class-updraft-dashboard-news.php
6 years ago
class-updraftcentral-updraftplus-commands.php
8 years ago
class-updraftplus-encryption.php
6 years ago
class-wpadmin-commands.php
6 years ago
class-zip.php
6 years ago
ftp.class.php
7 years ago
get-cpanel-quota-usage.pl
12 years ago
google-extensions.php
9 years ago
jquery-ui.custom.css
7 years ago
jquery-ui.custom.min.css
7 years ago
jquery-ui.custom.min.css.map
7 years ago
jquery.blockUI.js
8 years ago
jquery.blockUI.min.js
8 years ago
updraft-admin-common.js
6 years ago
updraft-admin-common.min.js
6 years ago
updraft-notices.php
6 years ago
updraft-restorer-skin-compatibility.php
6 years ago
updraft-restorer-skin.php
6 years ago
updraftcentral.php
7 years ago
updraftplus-clone.php
6 years ago
updraftplus-login.php
7 years ago
updraftplus-notices.php
6 years ago
updraftplus-tour.php
7 years ago
updraftvault.php
6 years ago
updraftplus-login.php
115 lines
| 1 | <?php |
| 2 | |
| 3 | if (!defined('UPDRAFTPLUS_DIR')) die('No direct access allowed.'); |
| 4 | |
| 5 | abstract class UpdraftPlus_Login { |
| 6 | |
| 7 | /** |
| 8 | * Pulls the appropriate message for the given code and translate it before |
| 9 | * returning it to the caller |
| 10 | * |
| 11 | * @internal |
| 12 | * @param string $code The code of the message to pull |
| 13 | * @return string - The translated message |
| 14 | */ |
| 15 | abstract protected function translate_message($code); |
| 16 | |
| 17 | /** |
| 18 | * Executes login or registration process. Connects and sends request to the UpdraftCentral Cloud |
| 19 | * and returns the response coming from the server |
| 20 | * |
| 21 | * @internal |
| 22 | * @param array $data The submitted form data |
| 23 | * @param boolean $register Indicates whether the current call is for a registration process or not. Defaults to false. |
| 24 | * @return array - The response from the request |
| 25 | */ |
| 26 | abstract protected function login_or_register($data, $register = false); |
| 27 | |
| 28 | /** |
| 29 | * Handles the actual sending of the request to the remote server (UpdraftCentral Cloud) and pre-checks the response |
| 30 | * and wraps it up for the caller before sending it back |
| 31 | * |
| 32 | * @internal |
| 33 | * @param array $data The submitted form data |
| 34 | * @param string $action The name of the action or service that will be triggered in UpdraftCentral Cloud |
| 35 | * @return array - The response from the server |
| 36 | */ |
| 37 | protected function send_remote_request($data, $action) { |
| 38 | global $updraftplus; |
| 39 | $result = wp_remote_post($updraftplus->get_url('mothership').'/?udm_action='.$action, |
| 40 | array( |
| 41 | 'timeout' => 20, |
| 42 | 'headers' => apply_filters('updraftplus_auth_headers', ''), |
| 43 | 'body' => $data |
| 44 | ) |
| 45 | ); |
| 46 | |
| 47 | // If we got an error then we return the WP_Error object itself |
| 48 | // and let the caller handle it. |
| 49 | if (is_wp_error($result)) return $result; |
| 50 | |
| 51 | $response = json_decode(wp_remote_retrieve_body($result), true); |
| 52 | if (!is_array($response) || !isset($response['mothership']) || !isset($response['status'])) { |
| 53 | |
| 54 | if (preg_match('/has banned your IP address \(([\.:0-9a-f]+)\)/', $result['body'], $matches)) { |
| 55 | 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])); |
| 56 | } else { |
| 57 | 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))); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | return $response; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * The ajax based request point of entry for the login process |
| 66 | * |
| 67 | * @param array $data - The submitted form data |
| 68 | * @param boolean $echo_results - Whether to echo/display the results directly to the user or assign it to a variable |
| 69 | * @return array - Response of the process |
| 70 | */ |
| 71 | public function ajax_process_login($data = array(), $echo_results = true) { |
| 72 | try { |
| 73 | if (isset($data['form_data'])) { |
| 74 | if (is_string($data['form_data'])) { |
| 75 | parse_str($data['form_data'], $form_data); |
| 76 | } elseif (is_array($data['form_data'])) { |
| 77 | $form_data = $data['form_data']; |
| 78 | } |
| 79 | } |
| 80 | $response = $this->login_or_register($form_data); |
| 81 | } catch (Exception $e) { |
| 82 | $response = array('error' => true, 'message' => $e->getMessage()); |
| 83 | } |
| 84 | |
| 85 | if ($echo_results) { |
| 86 | echo json_encode($response); |
| 87 | } else { |
| 88 | return $response; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * The ajax based request point of entry for the registration process |
| 94 | * |
| 95 | * @param array $data - The submitted form data |
| 96 | * @param boolean $echo_results - Whether to echo/display the results directly to the user or assign it to a variable |
| 97 | * @return array - Response of the process |
| 98 | */ |
| 99 | public function ajax_process_registration($data = array(), $echo_results = true) { |
| 100 | try { |
| 101 | if (isset($data['form_data'])) parse_str($data['form_data'], $form_data); |
| 102 | |
| 103 | $response = $this->login_or_register($form_data, true); |
| 104 | } catch (Exception $e) { |
| 105 | $response = array('error' => true, 'message' => $e->getMessage()); |
| 106 | } |
| 107 | |
| 108 | if ($echo_results) { |
| 109 | echo json_encode($response); |
| 110 | } else { |
| 111 | return $response; |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 |