Skip to content
Snippets Groups Projects
Commit 97a62d3c authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Added client-side NS management & code cleanup

* Added ability to use the client-side ns/host management
* Code cleanup & comment fixes

Change-Id: I04bd90499c39a58d85b2d7550184f5b23dd4352c
parent df61c153
No related branches found
No related tags found
No related merge requests found
<?php
# Copyright (c) 2012, AllWorldIT
# Copyright (c) 2012-2013, AllWorldIT
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -55,19 +55,20 @@ function cozaepp_getConfigArray() {
# Function to return current nameservers
function cozaepp_GetNameservers($params) {
# Grab variables
$tld = $params["tld"];
$sld = $params["sld"];
$domain = "{$sld}.{$tld}";
$tld = $params["tld"];
$domain = "$sld.$tld";
# Create new EPP client
# Get client instance
$client = _cozaepp_Client();
if (PEAR::isError($client)) {
$values["error"] = 'GetNameservers/EPP: '.$client->toString();
return $values;
}
$result = $client->request($xml = '
# Get list of nameservers for domain
$result = $client->request('
<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>
......@@ -110,8 +111,8 @@ function cozaepp_GetNameservers($params) {
# Function to save set of nameservers
function cozaepp_SaveNameservers($params) {
# Grab variables
$tld = $params["tld"];
$sld = $params["sld"];
$tld = $params["tld"];
# Generate XML for nameservers
......@@ -149,14 +150,15 @@ function cozaepp_SaveNameservers($params) {
</domain:hostAttr>';
}
# Grab list of current nameservers
# Get client instance
$client = _cozaepp_Client();
if (PEAR::isError($client)) {
$values["error"] = 'SaveNameservers/EPP: '.$client->toString();
return $values;
}
$registrarinfo = $client->request('
# Grab list of current nameservers
$request = $client->request('
<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>
......@@ -170,7 +172,7 @@ function cozaepp_SaveNameservers($params) {
');
# Parse XML result
$doc= new DOMDocument();
$doc->loadXML($registrarinfo);
$doc->loadXML($request);
# Pull off status
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
......@@ -193,7 +195,7 @@ function cozaepp_SaveNameservers($params) {
}
# Build request
$domainrenew = $client->request('
$request = $client->request('
<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" xmlns:cozadomain="http://co.za/epp/extensions/cozadomain-1-0"
xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
......@@ -219,7 +221,7 @@ function cozaepp_SaveNameservers($params) {
# Parse XML result
$doc= new DOMDocument();
$doc->loadXML($domainrenew);
$doc->loadXML($request);
# Pull off status
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
......@@ -239,8 +241,8 @@ function cozaepp_SaveNameservers($params) {
# NOT IMPLEMENTED
function cozaepp_GetRegistrarLock($params) {
# Grab variables
$tld = $params["tld"];
$sld = $params["sld"];
$tld = $params["tld"];
# Get lock status
......@@ -266,8 +268,8 @@ function cozaepp_SaveRegistrarLock($params) {
# Function to register domain
function cozaepp_RegisterDomain($params) {
# Grab varaibles
$tld = $params["tld"];
$sld = $params["sld"];
$tld = $params["tld"];
$regperiod = $params["regperiod"];
# Get registrant details
......@@ -331,14 +333,15 @@ function cozaepp_RegisterDomain($params) {
</domain:hostAttr>';
}
# Send registration
# Get client instance
$client = _cozaepp_Client();
if (PEAR::isError($client)) {
$values["error"] = 'RegisterDomain/EPP: '.$client->toString();
return $values;
}
$contact = $client->request('
# Send registration
$request = $client->request('
<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>
......@@ -370,7 +373,7 @@ function cozaepp_RegisterDomain($params) {
# Parse XML result
$doc= new DOMDocument();
$doc->loadXML($contact);
$doc->loadXML($request);
# Pull off status
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
......@@ -385,7 +388,7 @@ function cozaepp_RegisterDomain($params) {
$values["status"] = $msg;
$domaincreate = $client->request('
$request = $client->request('
<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" xmlns:cozadomain="http://co.za/epp/extensions/cozadomain-1-0"
xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
......@@ -409,7 +412,7 @@ function cozaepp_RegisterDomain($params) {
</epp:epp>
');
$doc= new DOMDocument();
$doc->loadXML($domaincreate);
$doc->loadXML($request);
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
if($coderes != '1000') {
......@@ -428,8 +431,8 @@ function cozaepp_RegisterDomain($params) {
function cozaepp_TransferDomain($params) {
# Grab variables
$testmode = $params["TestMode"];
$tld = $params["tld"];
$sld = $params["sld"];
$tld = $params["tld"];
# Domain info
$regperiod = $params["regperiod"];
......@@ -462,14 +465,15 @@ function cozaepp_TransferDomain($params) {
$contactid = $RegistrantFirstName.$params['userid'];
# Grab registrar info
# Get client instance
$client = _cozaepp_Client();
if (PEAR::isError($client)) {
$values["error"] = 'TransferDomain/EPP: '.$client->toString();
return $values;
}
$registrarinfo = $client->request('
# Initiate transfer
$request = $client->request('
<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="request">
......@@ -482,7 +486,7 @@ function cozaepp_TransferDomain($params) {
# Parse XML result
$doc= new DOMDocument();
$doc->loadXML($registrarinfo);
$doc->loadXML($request);
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
# We should get a 1001 back
......@@ -494,7 +498,7 @@ function cozaepp_TransferDomain($params) {
$values["status"] = $msg;
# Create contact details
$contact = $client->request('
$request = $client->request('
<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>
......@@ -525,7 +529,7 @@ function cozaepp_TransferDomain($params) {
');
# Parse XML result
$doc= new DOMDocument();
$doc->loadXML($contact);
$doc->loadXML($request);
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
if($coderes == '1000') {
......@@ -549,19 +553,20 @@ function cozaepp_TransferDomain($params) {
# Function to renew domain
function cozaepp_RenewDomain($params) {
# Grab variables
$tld = $params["tld"];
$sld = $params["sld"];
$tld = $params["tld"];
$regperiod = $params["regperiod"];
# Put your code to renew domain here
# Get client instance
$client = _cozaepp_Client();
if (PEAR::isError($client)) {
$values["error"] = 'RenewDomain/EPP: '.$client->toString();
return $values;
}
$registrarinfo = $client->request('
# Send renewal request
$request = $client->request('
<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>
......@@ -576,7 +581,7 @@ function cozaepp_RenewDomain($params) {
# Parse XML result
$doc= new DOMDocument();
$doc->loadXML($registrarinfo);
$doc->loadXML($request);
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
if($coderes != '1000') {
......@@ -594,7 +599,7 @@ function cozaepp_RenewDomain($params) {
}
# Send request to renew
$domainrenew = $client->request('
$request = $client->request('
<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:renew>
......@@ -609,7 +614,7 @@ function cozaepp_RenewDomain($params) {
# Parse XML result
$doc= new DOMDocument();
$doc->loadXML($domainrenew);
$doc->loadXML($request);
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
if($coderes != '1000') {
......@@ -628,17 +633,19 @@ function cozaepp_RenewDomain($params) {
# Function to grab contact details
function cozaepp_GetContactDetails($params) {
# Grab variables
$tld = $params["tld"];
$sld = $params["sld"];
$tld = $params["tld"];
# Grab contact details
# Get client instance
$client = _cozaepp_Client();
if (PEAR::isError($client)) {
$values["error"] = 'GetContactDetails/EPP: '.$client->toString();
return $values;
}
$registrarinfo = $client->request('
# Grab domain info
$request = $client->request('
<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>
......@@ -653,7 +660,7 @@ function cozaepp_GetContactDetails($params) {
# Parse XML result
$doc= new DOMDocument();
$doc->loadXML($registrarinfo);
$doc->loadXML($request);
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
# Check result
......@@ -669,7 +676,8 @@ function cozaepp_GetContactDetails($params) {
return $values;
}
$domaininfo = $client->request('
# Grab contact info
$request = $client->request('
<epp:epp xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
<epp:command>
<epp:info>
......@@ -682,7 +690,7 @@ function cozaepp_GetContactDetails($params) {
');
# Parse XML result
$doc= new DOMDocument();
$doc->loadXML($domaininfo);
$doc->loadXML($request);
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
# Check result
......@@ -726,14 +734,16 @@ function cozaepp_SaveContactDetails($params) {
#$registrant_fax = '',
$registrant_email = $params["contactdetails"]["Registrant"]["Email"];
# Grab domain info
# Get client instance
$client = _cozaepp_Client();
if (PEAR::isError($client)) {
$values["error"] = 'SaveContactDetails/EPP: '.$client->toString();
return $values;
}
$registrarinfo = $client->request('
# Grab domain info
$request = $client->request('
<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>
......@@ -747,7 +757,7 @@ function cozaepp_SaveContactDetails($params) {
');
# Parse XML result
$doc= new DOMDocument();
$doc->loadXML($registrarinfo);
$doc->loadXML($request);
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
if($coderes != '1000') {
......@@ -759,7 +769,9 @@ function cozaepp_SaveContactDetails($params) {
# Time to do the update
$registrant = $doc->getElementsByTagName('registrant')->item(0)->nodeValue;
$contact = $client->request('
# Save contact details
$request = $client->request('
<epp:epp xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
<epp:command>
<epp:update>
......@@ -790,7 +802,7 @@ function cozaepp_SaveContactDetails($params) {
# Parse XML result
$doc= new DOMDocument();
$doc->loadXML($contact);
$doc->loadXML($request);
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
if($coderes != '1001') {
......@@ -811,8 +823,8 @@ function cozaepp_GetEPPCode($params) {
$username = $params["Username"];
$password = $params["Password"];
$testmode = $params["TestMode"];
$tld = $params["tld"];
$sld = $params["sld"];
$tld = $params["tld"];
$values["eppcode"] = '';
......@@ -823,26 +835,65 @@ function cozaepp_GetEPPCode($params) {
# NOT IMPLEMENTED
# Function to register nameserver
function cozaepp_RegisterNameserver($params) {
# Grab varaibles
$username = $params["Username"];
$password = $params["Password"];
$testmode = $params["TestMode"];
$tld = $params["tld"];
$sld = $params["sld"];
$tld = $params["tld"];
$nameserver = $params["nameserver"];
$ipaddress = $params["ipaddress"];
# If error, return the error message in the value below
$values["error"] = $error;
# Grab client instance
$client = _cozaepp_Client();
if (PEAR::isError($client)) {
$values["error"] = 'SaveNameservers/EPP: '.$client->toString();
return $values;
}
# Register nameserver
$request = $client->request('
<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:add>
<domain:ns>
<domain:hostAttr>
<domain:hostName>'.$nameserver.'</domain:hostName>
<domain:hostAddr ip="v4">'.$ipaddress.'</domain:hostAddr>
</domain:hostAttr>
</domain:ns>
</domain:add>
</domain:update>
</epp:update>
</epp:command>
</epp:epp>
');
# Parse XML result
$doc= new DOMDocument();
$doc->loadXML($request);
# Pull off status
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
# Check if result is ok
if($coderes != '1001') {
$values["error"] = "RegisterNameserver/domain-update($sld.$tld): Code ($coderes) $msg";
return $values;
}
$values['status'] = $msg;
return $values;
}
# NOT IMPLEMENTED
# Modify nameserver
function cozaepp_ModifyNameserver($params) {
# Grab variables
$username = $params["Username"];
......@@ -854,15 +905,53 @@ function cozaepp_ModifyNameserver($params) {
$currentipaddress = $params["currentipaddress"];
$newipaddress = $params["newipaddress"];
# If error, return the error message in the value below
$values["error"] = $error;
# Grab client instance
$client = _cozaepp_Client();
if (PEAR::isError($client)) {
$values["error"] = 'SaveNameservers/EPP: '.$client->toString();
return $values;
}
# Modify nameserver
$request = $client->request('
<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:add>
<domain:ns>
<domain:hostAttr>
<domain:hostName>'.$nameserver.'</domain:hostName>
<domain:hostAddr ip="v4">'.$newipaddress.'</domain:hostAddr>
</domain:hostAttr>
</domain:ns>
</domain:add>
</domain:update>
</epp:update>
</epp:command>
</epp:epp>
');
# Parse XML result
$doc= new DOMDocument();
$doc->loadXML($request);
# Pull off status
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
# Check if result is ok
if($coderes != '1001') {
$values["error"] = "ModifyNameserver/domain-update($sld.$tld): Code ($coderes) $msg";
return $values;
}
$values['status'] = $msg;
return $values;
}
# NOT IMPLEMENTED
# Delete nameserver
function cozaepp_DeleteNameserver($params) {
# Grab variables
$username = $params["Username"];
......@@ -872,8 +961,49 @@ function cozaepp_DeleteNameserver($params) {
$sld = $params["sld"];
$nameserver = $params["nameserver"];
# If error, return the error message in the value below
$values["error"] = $error;
# Grab client instance
$client = _cozaepp_Client();
if (PEAR::isError($client)) {
$values["error"] = 'SaveNameservers/EPP: '.$client->toString();
return $values;
}
# If we were given hostname. blow away all of the stuff behind it and allow us to remove hostname
$nameserver = preg_replace('/\.\.\S+/','',$nameserver);
# Delete nameserver
$request = $client->request('
<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:rem>
<domain:ns>
<domain:hostAttr>
<domain:hostName>'.$nameserver.'</domain:hostName>
</domain:hostAttr>
</domain:ns>
</domain:rem>
</domain:update>
</epp:update>
</epp:command>
</epp:epp>
');
# Parse XML result
$doc= new DOMDocument();
$doc->loadXML($request);
# Pull off status
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
# Check if result is ok
if($coderes != '1001') {
$values["error"] = "DeleteNameserver/domain-update($sld.$tld): Code ($coderes) $msg";
return $values;
}
$values['status'] = $msg;
return $values;
}
......@@ -890,7 +1020,7 @@ function _cozaepp_message($code) {
# Ack a POLL message
function _cozaepp_ackpoll($client,$msgid) {
# Ack poll message
$output = $client->request('
$request = $client->request('
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<poll op="ack" msgID="'.$msgid.'"/>
......@@ -904,12 +1034,12 @@ function _cozaepp_ackpoll($client,$msgid) {
# Decipher XML
$doc = new DOMDocument();
$doc->loadXML($output);
$doc->loadXML($request);
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
# Check result
if($coderes != '1301') {
if($coderes != '1301' && $coderes != '1300') {
return new PEAR_Error("ackpoll/poll-ack($id): Code ($coderes) $msg");
}
}
......@@ -954,7 +1084,7 @@ function _cozaepp_Client() {
}
# Perform login
$result = $client->request('
$request = $client->request('
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<login>
......@@ -997,7 +1127,8 @@ function cozaepp_Sync($params) {
return $values;
}
$registrarinfo = $client->request('
# Grab domain info
$request = $client->request('
<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>
......@@ -1011,7 +1142,7 @@ function cozaepp_Sync($params) {
');
$doc= new DOMDocument();
$doc->loadXML($registrarinfo);
$doc->loadXML($request);
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
# Check result
......
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