| @@ -50,38 +50,25 @@ | ||
| 50 | 50 | public function isAPICall() { |
| 51 | 51 | return array_key_exists('apicall', $this->params); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - public function curlRequest($url, $body) { | |
| 55 | - $ch = curl_init($url); | |
| 56 | - curl_setopt($ch, CURLOPT_POST, 1); | |
| 57 | - curl_setopt($ch, CURLOPT_TIMEOUT, 15); | |
| 58 | - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($body)); | |
| 59 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| 60 | - return curl_exec($ch); | |
| 61 | - } | |
| 54 | + public function http_request($url, $body) { | |
| 55 | + $body = http_build_query($body); | |
| 56 | + $response = wp_remote_post($url, array( | |
| 57 | + 'body' => $body, | |
| 58 | + 'timeout' => 15, | |
| 59 | + 'headers' => array( | |
| 60 | + 'Content-Type' => 'application/x-www-form-urlencoded', | |
| 61 | + ), | |
| 62 | + )); | |
| 62 | 63 | |
| 63 | - public function fileGetContentRequest($url, $body) { | |
| 64 | - $options = array( | |
| 65 | - 'http' => array( | |
| 66 | - 'header' => "Content-type: application/x-www-form-urlencoded\r\n", | |
| 67 | - 'method' => 'POST', | |
| 68 | - 'content' => http_build_query($body) | |
| 69 | - ) | |
| 70 | - ); | |
| 64 | + if (is_wp_error($response)) { | |
| 65 | + return false; | |
| 66 | + } | |
| 71 | 67 | |
| 72 | - $context = stream_context_create($options); | |
| 73 | - return file_get_contents($url, false, $context); | |
| 68 | + return wp_remote_retrieve_body($response); | |
| 74 | 69 | } |
| 75 | 70 | |
| 76 | - public function http_request($url, $body) { | |
| 77 | - if (in_array('curl', get_loaded_extensions())) { | |
| 78 | - return $this->curlRequest($url, $body); | |
| 79 | - } else { | |
| 80 | - return $this->fileGetContentRequest($url, $body); | |
| 81 | - } | |
| 82 | - } | |
| 83 | - | |
| 84 | 71 | public function get_params_via_api($params_key, $apiurl) { |
| 85 | 72 | $res = $this->http_request($apiurl, array('bvkey' => $params_key)); |
| 86 | 73 | |
| 87 | 74 | if ($res === FALSE) { |
| @@ -246,14 +233,17 @@ | ||
| 246 | 233 | $this->error["message"] = "OPENSSL_FUNCS_NOT_FOUND"; |
| 247 | 234 | return false; |
| 248 | 235 | } |
| 249 | 236 | |
| 250 | - $key_file = dirname( __FILE__ ) . '/../public_keys/' . $this->pubkey_name . '.pub'; | |
| 237 | + $key_file = dirname( __DIR__ ) . '/public_keys/' . $this->pubkey_name . '.pub'; | |
| 251 | 238 | if (!file_exists($key_file)) { |
| 252 | 239 | $this->error["message"] = "PUBLIC_KEY_NOT_FOUND"; |
| 253 | 240 | return false; |
| 254 | 241 | } |
| 255 | - $public_key_str = file_get_contents($key_file); | |
| 242 | + | |
| 243 | + $filesystem = WPRHelper::get_direct_filesystem(); | |
| 244 | + $public_key_str = $filesystem->get_contents($key_file); | |
| 245 | + | |
| 256 | 246 | $public_key = openssl_pkey_get_public($public_key_str); |
| 257 | 247 | if (!$public_key) { |
| 258 | 248 | $this->error["message"] = "UNABLE_TO_LOAD_PUBLIC_KEY"; |
| 259 | 249 | return false; |
| @@ -288,8 +278,9 @@ | ||
| 288 | 278 | |
| 289 | 279 | public function authFailedResp() { |
| 290 | 280 | $api_public_key = WPRAccount::getApiPublicKey($this->settings); |
| 291 | 281 | $default_secret = WPRRecover::getDefaultSecret($this->settings); |
| 282 | + $default_account_pubkey = WPRAccount::getDefaultPublicKey(); | |
| 292 | 283 | $bvinfo = new WPRInfo($this->settings); |
| 293 | 284 | $resp = array( |
| 294 | 285 | "request_info" => $this->info(), |
| 295 | 286 | "bvinfo" => $bvinfo->info(), |
| @@ -294,10 +285,15 @@ | ||
| 294 | 285 | "request_info" => $this->info(), |
| 295 | 286 | "bvinfo" => $bvinfo->info(), |
| 296 | 287 | "statusmsg" => "FAILED_AUTH", |
| 297 | 288 | "api_pubkey" => substr($api_public_key, 0, 8), |
| 289 | + "def_key_status" => WPRRecover::getSecretStatus($this->settings), | |
| 298 | 290 | "def_sigmatch" => substr(hash('sha1', $this->method.$default_secret.$this->time.$this->version), 0, 8) |
| 299 | 291 | ); |
| 292 | + | |
| 293 | + if (is_string($default_account_pubkey) && strlen($default_account_pubkey) >= 32) { | |
| 294 | + $resp["default_account_pubkey"] = substr($default_account_pubkey, 0, 8); | |
| 295 | + } | |
| 300 | 296 | |
| 301 | 297 | if ($this->account) { |
| 302 | 298 | $resp["account_info"] = $this->account->info(); |
| 303 | 299 | $resp["sigmatch"] = substr(hash('sha1', $this->method.$this->account->secret.$this->time.$this->version), 0, 6); |