Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 41 additions & 20 deletions opensrs/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace opensrs;

use stdClass;

defined('OPENSRSURI') or die;

/**
Expand All @@ -19,6 +21,21 @@ class Base
private $_socketTimeout = 120; // seconds
private $_socketReadTimeout = 120; // seconds

private $osrs_debug = false;

private stdClass $dataObject;

public $action;
public $object;

public $_formatHolder;
public $resultFullRaw;
public $resultRaw;
public $resultFullFormatted;
public $resultFormatted;

protected $dataFormat;

protected $_opsHandler;

public $defaultTlds = array('.com', '.net', '.org');
Expand Down Expand Up @@ -66,7 +83,7 @@ public function __destruct()
private function _verifySystemProperties()
{
if (!function_exists('version_compare') || version_compare('4.3', phpversion(), '>=')) {
$error_message = 'PHP version must be v4.3+ (current version is '.phpversion().') to use "SSL" encryption';
$error_message = 'PHP version must be v4.3+ (current version is ' . phpversion() . ') to use "SSL" encryption';
throw new Exception($error_message);
} elseif (!function_exists('openssl_open')) {
$error_message = 'PHP must be compiled using --with-openssl to use "SSL" encryption';
Expand All @@ -87,7 +104,7 @@ public function send_cmd($request)
{
// make or get the socket filehandle
if (!$this->init_socket()) {
throw new Exception('oSRS Error - Unable to establish socket: ('.$this->_socketErrorNum.') '.$this->_socketErrorMsg);
throw new Exception('oSRS Error - Unable to establish socket: (' . $this->_socketErrorNum . ') ' . $this->_socketErrorMsg);
}

$this->send_data($request);
Expand All @@ -114,7 +131,7 @@ private function init_socket()
if ($this->is_connected()) {
return true;
}
$this->_socket = fsockopen(CRYPT_TYPE.'://'.OSRS_HOST, OSRS_SSL_PORT, $this->_socketErrorNum, $this->_socketErrorMsg, $this->_socketTimeout);
$this->_socket = fsockopen(CRYPT_TYPE . '://' . OSRS_HOST, OSRS_SSL_PORT, $this->_socketErrorNum, $this->_socketErrorMsg, $this->_socketTimeout);
if (!$this->_socket) {
return false;
} else {
Expand Down Expand Up @@ -162,8 +179,8 @@ private function read_data()
} else {
$data = $buf;
}
if (!empty($this->osrs_debug)) {
print_r('<pre>'.htmlentities($data).'</pre>');
if ($this->osrs_debug) {
print_r('<pre>' . htmlentities($data) . '</pre>');
}

return $data;
Expand All @@ -180,8 +197,8 @@ private function read_data()
*/
private function send_data($message)
{
if (!empty($this->osrs_debug)) {
print_r('<pre>'.htmlentities($message).'</pre>');
if ($this->osrs_debug) {
print_r('<pre>' . htmlentities($message) . '</pre>');
}

return $this->writeData($this->_socket, $message);
Expand All @@ -198,12 +215,12 @@ private function writeData(&$fh, $msg)
$header = '';
$len = strlen($msg);

$signature = md5(md5($msg.OSRS_KEY).OSRS_KEY);
$header .= 'POST / HTTP/1.0'.CRLF;
$header .= 'Content-Type: text/xml'.CRLF;
$header .= 'X-Username: '.OSRS_USERNAME.CRLF;
$header .= 'X-Signature: '.$signature.CRLF;
$header .= 'Content-Length: '.$len.CRLF.CRLF;
$signature = md5(md5($msg . OSRS_KEY) . OSRS_KEY);
$header .= 'POST / HTTP/1.0' . CRLF;
$header .= 'Content-Type: text/xml' . CRLF;
$header .= 'X-Username: ' . OSRS_USERNAME . CRLF;
$header .= 'X-Signature: ' . $signature . CRLF;
$header .= 'Content-Length: ' . $len . CRLF . CRLF;

fputs($fh, $header);
fputs($fh, $msg, $len);
Expand Down Expand Up @@ -264,11 +281,11 @@ private function readData(&$fh, $timeout = 5)
/* PHP doesn't have timeout for fread ... we just set the timeout for the socket */
socket_set_timeout($fh, $timeout);
$header = $this->readHeader($fh, $timeout);
if (!$header || !isset($header{'content-length'}) || (empty($header{'content-length'}))) {
if (!$header || !isset($header['content-length']) || (empty($header['content-length']))) {
throw new Exception('oSRS Error - UNEXPECTED ERROR: No Content-Length header provided! Please make sure IP is whitelisted in RWI.');
}

$len = (int) $header{'content-length'};
$len = (int) $header['content-length'];
$line = '';
while (strlen($line) < $len) {
$line .= fread($fh, $len);
Expand All @@ -295,7 +312,7 @@ public function convertArray2Formatted($type = '', $data = '')
$resultString = json_encode($data);
}
if ($type == 'yaml') {
$resultString = Spyc::YAMLDump($data);
$resultString = \Spyc::YAMLDump($data);
}

return $resultString;
Expand Down Expand Up @@ -337,7 +354,7 @@ public function getConfiguredTlds()
return $this->defaultTlds;
}

public function setDataObject($format, $dataObject)
public function setDataObject($format, stdClass $dataObject)
{
$this->dataObject = $dataObject;
$this->dataFormat = $format;
Expand Down Expand Up @@ -417,9 +434,7 @@ public function send($dataObject, $returnFullResponse = true)
);
}

if (method_exists($this, 'customResponseHandling')) {
$arrayResult = $this->customResponseHandling($arrayResult, $returnFullResponse);
}
$arrayResult = $this->customResponseHandling($arrayResult, $returnFullResponse);

// Results
$this->resultFullRaw = $arrayResult;
Expand All @@ -440,6 +455,12 @@ public function send($dataObject, $returnFullResponse = true)
$this->resultFormatted = $this->convertArray2Formatted($this->_formatHolder, $this->resultRaw);
}

// method which may be implemented by child classes
protected function customResponseHandling(array $arrayResult, bool $returnFullResponse = true): array
{
return $arrayResult;
}

/**
* Method for any shared validation that is applicable to all
* API calls. Checks API call class for requiredFields array
Expand Down
2 changes: 1 addition & 1 deletion opensrs/domains/lookup/AllInOneDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __destruct()
parent::__destruct();
}

public function customResponseHandling($arrayResult, $returnFullResponse = true)
public function customResponseHandling( array $arrayResult, bool $returnFullResponse = true): array
{
if ($returnFullResponse) {
if (isset($arrayResult['attributes']['premium']['items'])) {
Expand Down
2 changes: 1 addition & 1 deletion opensrs/domains/lookup/GetOrdersByDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __destruct()
parent::__destruct();
}

public function customResponseHandling($arrayResult, $returnFullResponse = true)
public function customResponseHandling( array $arrayResult, bool $returnFullResponse = true): array
{
if (!$returnFullResponse) {
if (isset($arrayResult['attributes']['lookup']['items'])) {
Expand Down
2 changes: 1 addition & 1 deletion opensrs/domains/lookup/NameSuggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __destruct()
parent::__destruct();
}

public function customResponseHandling($arrayResult, $returnFullResponse = true)
public function customResponseHandling( array $arrayResult, bool $returnFullResponse = true): array
{
if (!$returnFullResponse) {
if (isset($arrayResult['attributes'])) {
Expand Down
2 changes: 1 addition & 1 deletion opensrs/domains/lookup/PremiumDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __destruct()
parent::__destruct();
}

public function customResponseHandling($arrayResult, $returnFullResponse = true)
public function customResponseHandling( array $arrayResult, bool $returnFullResponse = true): array
{
if (!$returnFullResponse) {
if (isset($arrayResult['attributes'])) {
Expand Down
2 changes: 1 addition & 1 deletion opensrs/domains/provisioning/SWRegister.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __destruct()
parent::__destruct();
}

public function customResponseHandling($arrayResult, $returnFullResponse = true)
public function customResponseHandling( array $arrayResult, bool $returnFullResponse = true): array
{
/* Added by BC : NG : 16-7-2014 : To set error message for Insufficient Funds */
if (isset($arrayResult['attributes']['forced_pending']) and $arrayResult['attributes']['forced_pending'] != '' and $arrayResult['is_success'] == 1) {
Expand Down