Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added in verify action for TLD domains (i.e., .com.au domains) #49

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ tags
/vendor/
composer.lock
.vagrant
.DS_Store
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,3 @@ var_dump($osrsHandler);
[OpenSRS API Documentation Page](http://www.opensrs.com/site/resources/documentation/api)

[OpenSRS/osrs-toolkit-php Wiki](https://github.com/OpenSRS/osrs-toolkit-php/wiki)

78 changes: 45 additions & 33 deletions opensrs/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Base
* openSRS_base object constructor.
*
* Closes an existing socket connection, if we have one
*
*
* @since 3.1
*/
public function __construct()
Expand Down Expand Up @@ -66,7 +66,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 @@ -79,15 +79,15 @@ private function _verifySystemProperties()
*
* @param string $request Raw XML request
*
* @return string $data Raw XML response
*
* @return string $data Raw XML response
*
* @since 3.1
*/
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 @@ -106,15 +106,15 @@ public function send_cmd($request)
* Method to initialize a socket connection to the OpenSRS server.
*
* @return bool True if connected
*
*
* @since 3.1
*/
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 All @@ -126,7 +126,7 @@ private function init_socket()
* Method to check if a socket connection exists.
*
* @return bool True if connected
*
*
* @since 3.4
*/
public function is_connected()
Expand All @@ -136,7 +136,7 @@ public function is_connected()

/**
* Method to close the socket connection.
*
*
* @since 3.4
*/
private function close_socket()
Expand All @@ -148,7 +148,7 @@ private function close_socket()

/**
* Method to read data from the buffer stream.
*
*
* @return string XML response
*
* @since 3.1
Expand All @@ -163,25 +163,25 @@ private function read_data()
$data = $buf;
}
if (!empty($this->osrs_debug)) {
print_r('<pre>'.htmlentities($data).'</pre>');
print_r('<pre>' . htmlentities($data) . '</pre>');
}

return $data;
}

/**
* Method to send data.
*
*
* @param string $message XML request
*
* @return string $message XML response
* @return string $message XML response
*
* @since 3.1
*/
private function send_data($message)
{
if (!empty($this->osrs_debug)) {
print_r('<pre>'.htmlentities($message).'</pre>');
print_r('<pre>' . htmlentities($message) . '</pre>');
}

return $this->writeData($this->_socket, $message);
Expand All @@ -198,12 +198,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 All @@ -212,8 +212,8 @@ private function writeData(&$fh, $msg)
/**
* Reads header data.
*
* @param int socket handle
* @param int timeout for read
* @param int socket handle
* @param int timeout for read
*
* @return hash hash containing header key/value pairs
*/
Expand Down Expand Up @@ -253,8 +253,8 @@ private function readHeader($fh, $timeout = 5)
/**
* Reads data from a socket.
*
* @param int socket handle
* @param int timeout for read
* @param int socket handle
* @param int timeout for read
*
* @return mixed buffer with data, or an error for a short read
*/
Expand All @@ -264,11 +264,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 Down Expand Up @@ -302,13 +302,13 @@ public function convertArray2Formatted($type = '', $data = '')
}

/**
* Get configured tlds for domain call
* Will use (in order of preference)...
* 1. selected tlds
* 2. supplied default tlds
* Get configured tlds for domain call
* Will use (in order of preference)...
* 1. selected tlds
* 2. supplied default tlds
* 3. included default tlds.
*
* @return array tlds
*
* @return array tlds
*/
public function getConfiguredTlds()
{
Expand Down Expand Up @@ -345,7 +345,7 @@ public function setDataObject($format, $dataObject)

/**
* Does the dataObject have a domain set?
*
*
* @return bool
*/
public function hasDomain()
Expand Down Expand Up @@ -390,6 +390,8 @@ public function send($dataObject, $returnFullResponse = true)
// Flip Array to XML
$xmlCMD = $this->_opsHandler->encode(json_decode(json_encode($dataObject), true));

$xmlCMD = $this->modifyXml($xmlCMD);

// Send XML
$XMLresult = $this->send_cmd($xmlCMD);

Expand Down Expand Up @@ -496,4 +498,14 @@ public function isValidField($value)

return $isValid;
}

/**
* Use this to customise the XML sent to the API
*
* @param string $xml
* @return string
*/
protected function modifyXml($xml) {
return $xml;
}
}
8 changes: 5 additions & 3 deletions opensrs/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class RequestFactory
'persquery' => 'domains\personalnames\PersonalNamesQuery',
'perssuregister' => 'domains\personalnames\PersonalNamesSURegister',
'persupdate' => 'domains\personalnames\PersonalNamesUpdate',
'verifytlddata' => 'domains\verify\VerifyTldData',
'dnssecset' => 'domains\dnssec\DnsSecSet',
'pubcreate' => 'publishing\Create',
'pubdelete' => 'publishing\Delete',
'pubdisable' => 'publishing\Disable',
Expand Down Expand Up @@ -132,7 +134,7 @@ class RequestFactory
'mailsetdomaindisabledstatus' => 'mail\SetDomainDisabledStatus',
'mailsetdomainmailboxlimits' => 'mail\SetDomainMailboxLimits',
'accountgetbalance' => 'account\GetBalance'
);
);

public static function build($func, $type, $dataObject)
{
Expand All @@ -144,11 +146,11 @@ public static function build($func, $type, $dataObject)
$route = self::$RequestRoutes[$routeKey];
}

$class = '\opensrs\\'.$route;
$class = '\opensrs\\' . $route;

if (class_exists($class)) {
if (!isset($dataObject->attributes)) {
$dataconversionRoute = '\opensrs\backwardcompatibility\dataconversion\\'.$route;
$dataconversionRoute = '\opensrs\backwardcompatibility\dataconversion\\' . $route;

if (class_exists($dataconversionRoute)) {
$dc = new $dataconversionRoute();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace opensrs\backwardcompatibility\dataconversion\domains\bulkchange;

use opensrs\backwardcompatibility\dataconversion\DataConversion;

class SimpleTransfer extends DataConversion
{
// New structure for API calls handled by
// the toolkit.
//
// index: field name
// value: location of data to map to this
// field from the original structure
//
// example 1:
// "cookie" => 'data->cookie'
// this will map ->data->cookie in the
// original object to ->cookie in the
// new format
//
// example 2:
// ['attributes']['domain'] = 'data->domain'
// this will map ->data->domain in the original
// to ->attributes->domain in the new format
protected $newStructure = array(
'attributes' => array(
'domain_list' => 'data->domain_list',
'domain_name' => 'data->domain_name',
'auth_info' => 'data->auth_info',

'reg_domain' => 'data->reg_domain',
'reg_username' => 'data->reg_username',
'reg_password' => 'data->reg_password',

'nameserver_list' => 'data->nameserver_list',
'dns_template' => 'data->dns_template'
)
);

public function convertDataObject($dataObject, $newStructure = null)
{
$p = new parent();

if (is_null($newStructure)) {
$newStructure = $this->newStructure;
}

$newDataObject = $p->convertDataObject($dataObject, $newStructure);

if(isset($newDataObject->attributes->domain_name)){
if (!is_array($newDataObject->attributes->domain_list)) {
$newDataObject->attributes->domain_list = array(//domain list can't be empty, so fill it with the single domain we have.
array(
'domain_name' => $newDataObject->attributes->domain_name,
'auth_info' => $newDataObject->attributes->auth_info
)
);
}
}

return $newDataObject;
}
}
50 changes: 50 additions & 0 deletions opensrs/domains/bulkchange/SimpleTransfer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace opensrs\domains\bulkchange;

use opensrs\Base;

class SimpleTransfer extends Base
{
public $action = 'simple_transfer';
public $object = 'domain';

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

public $requiredFields = array(
'attributes' => array(
'domain_list',
'domain_name',
'auth_info',
),
);

public function __construct($formatString, $dataObject, $returnFullResponse = true)
{
parent::__construct();

$this->_formatHolder = $formatString;

if(empty($dataObject->attributes->domain_list)){//if it's empty, lets try populate with the individual domain so it works.
$dataObject->attributes->domain_list = array(
array(
'domain_name' => $dataObject->attributes->domain_name,
'auth_info' => $dataObject->attributes->auth_info
)
);
}

$this->_validateObject($dataObject);

$this->send($dataObject, $returnFullResponse);
}

public function __destruct()
{
parent::__destruct();
}
}
Loading