From 7d761215639910e269e151886ca8e93df5269c8a Mon Sep 17 00:00:00 2001 From: hackersrage Date: Mon, 23 Mar 2015 23:25:56 -0400 Subject: [PATCH] Corrected communication with DotTK registrar * Changed file_get_contents to use cURL instead * Stripped any html received from registrar before attempting to process JSON response. * Added urlencoding to email and password. * Added trap for communication errors. --- bb-library/Registrar/Adapter/Dottk.php | 55 ++++++++++++++++++-------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/bb-library/Registrar/Adapter/Dottk.php b/bb-library/Registrar/Adapter/Dottk.php index 6aa535a..d9a51d9 100644 --- a/bb-library/Registrar/Adapter/Dottk.php +++ b/bb-library/Registrar/Adapter/Dottk.php @@ -217,8 +217,8 @@ private function _rest_call($call, $args = array()) $nameservers = null; $keywords = null; - $args['email'] = $this->config['email']; - $args['password'] = $this->config['password']; + $args['email'] = urlencode($this->config['email']); + $args['password'] = urlencode($this->config['password']); if (array_key_exists("nameservers", $args)) { if($args["nameservers"] != null) { @@ -248,21 +248,42 @@ private function _rest_call($call, $args = array()) if ($keywords) $postdata = $postdata."&keyword=".join("&keyword=", $keywords); - $opts=array("http" => array("method" => "POST", - "header" => "Content-type: application/x-www-form-urlencoded", - "content" => $postdata)); - - $res = stream_context_create($opts); - $output = file_get_contents($base_url . $call . ".json", false, $res); - $response = json_decode($output,true); - - if($this->_testMode){ - error_log("DotTk Response: " . print_r($response, 1)); - } - - if($response['status'] == 'NOT OK') { - throw new Registrar_Exception($response['reason']); - } + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $base_url . $call . ".json"); + curl_setopt($ch, CURLOPT_POST, true); + //curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + // curl_setopt($ch, CURL_IPRESOLVE_V4, true); + curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); + + // Disabling SSL Certificate support temporarly + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); + + $output = curl_exec($ch); + if($output) { + $pos = strrpos($output, "_testMode){ + error_log("DotTk Response: " . print_r($response, 1)); + } + + if($response['status'] == 'NOT OK') { + throw new Registrar_Exception($response['reason']); + } + } else { + $error = curl_error($ch); + if($error) { + throw new Registrar_Exception("CURL ERROR: " . $error); + } else { + throw new Registrar_Exception("Unable to reach server."); + } + } return $response; }