diff --git a/modules/registrars/cozaepp/cozaepp.php b/modules/registrars/cozaepp/cozaepp.php index 408e30a49a6fdb3a4949dd15e8f998728a01e4f6..56cdbf2c14aa7eee5a5e4d8df3a6b3a77fad4311 100644 --- a/modules/registrars/cozaepp/cozaepp.php +++ b/modules/registrars/cozaepp/cozaepp.php @@ -55,6 +55,7 @@ function cozaepp_AdminCustomButtonArray() { "Approve Transfer" => "ApproveTransfer", "Cancel Transfer Request" => "CancelTransferRequest", "Reject Transfer" => "RejectTransfer", + "Recreate Contact" => "RecreateContact", ); return $buttonarray; } @@ -73,7 +74,8 @@ function cozaepp_GetNameservers($params) { # Get list of nameservers for domain $result = $client->request($xml = ' -<epp:epp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"> +<epp:epp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" + xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"> <epp:command> <epp:info> <domain:info xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd"> @@ -279,6 +281,76 @@ function cozaepp_SaveRegistrarLock($params) { 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 if($coderes == '2201') { + $values['contact'] = 'Contact Already exists and is not owned by you'; + } 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 cozaepp_RegisterDomain($params) { # Grab varaibles @@ -658,18 +730,12 @@ function cozaepp_RenewDomain($params) { return $values; } - - -# Function to grab contact details -function cozaepp_GetContactDetails($params) { - # Grab variables - $sld = $params["sld"]; - $tld = $params["tld"]; - - +function _getContactDetails($domain, $client = null) { # Get client instance try { - $client = _cozaepp_Client(); + if (!isset($client)) { + $client = _cozaepp_Client(); + } # Grab domain info $request = $client->request($xml = ' @@ -678,7 +744,7 @@ function cozaepp_GetContactDetails($params) { <epp:command> <epp:info> <domain:info xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd"> - <domain:name hosts="all">'.$sld.'.'.$tld.'</domain:name> + <domain:name hosts="all">'.$domain.'</domain:name> </domain:info> </epp:info> </epp:command> @@ -688,20 +754,21 @@ function cozaepp_GetContactDetails($params) { # Parse XML result $doc= new DOMDocument(); $doc->loadXML($request); - logModuleCall('Cozaepp', 'GetContactDetails', $xml, $request); + logModuleCall('Cozaepp', '_GetContactDetails', $xml, $request); $coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code'); $msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue; + # Check result if($coderes != '1000') { - $values["error"] = "GetContactDetails/domain-info($sld.$tld): Code (".$coderes.") ".$msg; + $values["error"] = "_GetContactDetails/domain-info($domain): Code (".$coderes.") ".$msg; return $values; } # Grab contact info $registrant = $doc->getElementsByTagName('registrant')->item(0)->nodeValue; if (empty($registrant)) { - $values["error"] = "GetContactDetails/domain-info($sld.$tld): Registrant info not available"; + $values["error"] = "_GetContactDetails/domain-info($domain): Registrant info not available"; return $values; } @@ -720,13 +787,13 @@ function cozaepp_GetContactDetails($params) { # Parse XML result $doc= new DOMDocument(); $doc->loadXML($request); - logModuleCall('Cozaepp', 'GetContactDetails', $xml, $request); + logModuleCall('Cozaepp', '_GetContactDetails', $xml, $request); $coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code'); $msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue; # Check result if($coderes != '1000') { - $values["error"] = "GetContactDetails/contact-info($registrant): Code (".$coderes.") ".$msg; + $values["error"] = "_GetContactDetails/contact-info($registrant): Code (".$coderes.") ".$msg; return $values; } @@ -748,11 +815,26 @@ function cozaepp_GetContactDetails($params) { $results["Registrant"]["Phone"] = $doc->getElementsByTagName('voice')->item(0)->nodeValue; $results["Registrant"]["Email"] = $doc->getElementsByTagName('email')->item(0)->nodeValue; + return $results; } catch (Exception $e) { $values["error"] = 'GetContactDetails/EPP: '.$e->getMessage(); return $values; } +} + +# Function to grab contact details +function cozaepp_GetContactDetails($params) { + # Grab variables + $sld = $params["sld"]; + $tld = $params["tld"]; + # Fetching contact details + $results = _getContactDetails($sld . '.' . $tld); + + # If there was an error return it + if (isset($results["error"])) { + return $results; + } # What we going to do here is make sure all the attirbutes we return back are set # If we don't do this WHMCS won't display the options for editing @@ -811,7 +893,7 @@ function cozaepp_SaveContactDetails($params) { </epp:command> </epp:epp> '); - # Parse XML result + # Parse XML result $doc= new DOMDocument(); $doc->loadXML($request); logModuleCall('Cozaepp', 'SaveContactDetails', $xml, $request); @@ -1229,7 +1311,7 @@ function cozaepp_TransferSync($params) { } else if ($coderes != '1000') { $values['error'] = "TransferSync/domain-info($domain): Code("._cozaepp_message($coderes).") $msg"; return $values; - } + } # Check if we can get a status back if ($doc->getElementsByTagName('status')->item(0)) { @@ -1261,7 +1343,107 @@ function cozaepp_TransferSync($params) { return $values; } +function cozaepp_RecreateContact($params) { + # Grab variables + $tld = $params["tld"]; + $sld = $params["sld"]; + # Get client instance + try { + $client = _cozaepp_Client(); + + # Fetching contact details + $contact = _getContactDetails($sld . '.' . $tld, $client); + + # If there was an error return it + if (isset($contact["error"])) { + return $contact; + } + + # Check for available contact id + $registrant = _cozaepp_CheckContact($sld . '.' . $tld); + + # Recreate contact + $request = $client->request($xml = ' +<epp:epp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" + xmlns:contact="urn:ietf:params:xml:ns:contact-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"> + <epp:command> + <epp:create> + <contact:create xsi:schemaLocation="urn:ietf:params:xml:ns:contact-1.0 contact-1.0.xsd"> + <contact:id>'.$registrant.'</contact:id> + <contact:postalInfo type="loc"> + <contact:name>'.$contact["Registrant"]["Contact Name"].'</contact:name> + <contact:org>'.$contact["Registrant"]["Organisation"].'</contact:org> + <contact:addr> + <contact:street>'.$contact["Registrant"]["Address line 1"].'</contact:street> + <contact:street>'.$contact["Registrant"]["Address line 2"].'</contact:street> + <contact:city>'.$contact["Registrant"]["TownCity"].'</contact:city> + <contact:sp>'.$contact["Registrant"]["State"].'</contact:sp> + <contact:pc>'.$contact["Registrant"]["Zip code"].'</contact:pc> + <contact:cc>'.$contact["Registrant"]["Country Code"].'</contact:cc> + </contact:addr> + </contact:postalInfo> + <contact:voice>'.$contact["Registrant"]["Phone"].'</contact:voice> + <contact:fax></contact:fax> + <contact:email>'.$contact["Registrant"]["Email"].'</contact:email> + <contact:authInfo> + <contact:pw>AxA8AjXbAH'.rand().rand().'</contact:pw> + </contact:authInfo> + </contact:create> + </epp:create> + </epp:command> +</epp:epp> +'); + + # Parse XML result + $doc= new DOMDocument(); + $doc->loadXML($request); + logModuleCall('Cozaepp', 'RecreateContact', $xml, $request); + $coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code'); + $msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue; + if($coderes != '1000') { + $values["error"] = "RecreateContact/contact-create($registrant): Code ($coderes) $msg"; + return $values; + } + + $values["status"] = $msg; + + # Update domain registrant + $request = $client->request($xml = ' +<epp:epp xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"> + <epp:command> + <epp:update> + <domain:update> + <domain:name>'.$sld.'.'.$tld.'</domain:name> + <domain:chg> + <domain:registrant>'.$registrant.'</domain:registrant> + </domain:chg> + </domain:update> + </epp:update> + </epp:command> +</epp:epp> +'); + # Parse XML result + $doc= new DOMDocument(); + $doc->loadXML($request); + logModuleCall('Cozaepp', 'RecreateContact', $xml, $request); + + $coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code'); + $msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue; + if($coderes != '1001') { + $values["error"] = "RecreateContact/domain-info($sld.$tld): Code (".$coderes.") ".$msg; + return $values; + } + + $values["status"] = $msg; + + } catch (Exception $e) { + $values["error"] = 'RecreateContact/EPP: '.$e->getMessage(); + return $values; + } + + return $values; +} function cozaepp_Sync($params) { $domainid = $params['domainid']; @@ -1306,11 +1488,11 @@ function cozaepp_Sync($params) { $msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue; # Check result if ($coderes == '2303') { - # code 2303, domain not found + # Code 2303, domain not found $values['error'] = "TransferSync/domain-info($domain): Domain not found"; return $values; } else if ($coderes == '1000') { - # code 1000, success + # Code 1000, success if ( $doc->getElementsByTagName('infData') && $doc->getElementsByTagName('infData')->item(0)->getElementsByTagName('ns')->item(0) && @@ -1373,10 +1555,8 @@ function cozaepp_RequestDelete($params) { # Grab domain info $request = $client->request($xml = ' -<epp:epp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" -xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" -xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" -xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"> +<epp:epp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" + xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"> <epp:command> <epp:delete> <domain:delete xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd"> @@ -1513,8 +1693,7 @@ function cozaepp_RejectTransfer($params) { # Grab domain info $request = $client->request($xml = ' -<epp:epp xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" -xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"> +<epp:epp xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"> <epp:command> <epp:transfer op="reject"> <domain:transfer>