Skip to content
Snippets Groups Projects
Commit be7bd273 authored by Charl Mert's avatar Charl Mert
Browse files

added contact availability check

parent a68fe778
No related branches found
No related tags found
No related merge requests found
...@@ -279,6 +279,75 @@ function cozaepp_SaveRegistrarLock($params) { ...@@ -279,6 +279,75 @@ function cozaepp_SaveRegistrarLock($params) {
return $values; return $values;
} }
# Function to retrieve an available contact id
function _cozaepp_CheckContact($prehash) {
$prehash = $prehash . time() . rand(0, 1000000);
$contactid = substr(md5($prehash), 0,15);
# Get client instance and check for available contact id
try {
$client = _cozaepp_Client();
$contactAvailable = 0;
$count = 0;
while ($contactAvailable == 0) {
# Check if contact exists
$request = $client->request($xml = '
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<check>
<contact:check
xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
<contact:id>'.$contactid.'</contact:id>
</contact:check>
</check>
</command>
</epp>
');
# Parse XML result
$doc= new DOMDocument();
$doc->loadXML($request);
logModuleCall('Cozaepp', 'RegisterDomain:CheckContact', $xml, $request);
# Pull off status
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
$contactAvailable = $doc->getElementsByTagName('id')->item(0)->getAttribute('avail');
$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
if($coderes == '1000') {
$values['contact'] = 'Contact Created';
} else if($coderes == '2302') {
$values['contact'] = 'Contact Already exists';
} else {
$values["error"] = "RegisterDomain/contact-check($contactid): Code ($coderes) $msg";
return $values;
}
$values["status"] = $msg;
# if contact still isn't available attempt to add a random time again rehash and return
if ($contactAvailable == 0) {
$contactAvailable = substr(md5($prehash . time() . rand(0, 1000000) . $count), 0,15);
}
if ($count >= 10) {
break;
}
$count++;
}
return $contactid;
} catch (Exception $e) {
$values["error"] = 'RegisterDomain/EPP: '.$e->getMessage();
return $values;
}
}
# Function to register domain # Function to register domain
function cozaepp_RegisterDomain($params) { function cozaepp_RegisterDomain($params) {
# Grab varaibles # Grab varaibles
...@@ -309,7 +378,8 @@ function cozaepp_RegisterDomain($params) { ...@@ -309,7 +378,8 @@ function cozaepp_RegisterDomain($params) {
$AdminEmailAddress = $params["adminemail"]; $AdminEmailAddress = $params["adminemail"];
$AdminPhone = $params["adminphonenumber"]; $AdminPhone = $params["adminphonenumber"];
# Our details # Our details
$contactid = substr(md5($sld . '.' . $tld), 0,15); $contactid = _cozaepp_CheckContact($sld . '.' . $tld);
# Generate XML for namseverss # Generate XML for namseverss
if ($nameserver1 = $params["ns1"]) { if ($nameserver1 = $params["ns1"]) {
...@@ -482,7 +552,7 @@ function cozaepp_TransferDomain($params) { ...@@ -482,7 +552,7 @@ function cozaepp_TransferDomain($params) {
$AdminEmailAddress = $params["adminemail"]; $AdminEmailAddress = $params["adminemail"];
$AdminPhone = $params["adminphonenumber"]; $AdminPhone = $params["adminphonenumber"];
# Our details # Our details
$contactid = substr(md5($sld . '.' . $tld), 0,15); $contactid = _cozaepp_CheckContact($sld . '.' . $tld);
# Get client instance # Get client instance
try { try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment