Skip to content
Snippets Groups Projects
cozaepp.php 35.2 KiB
Newer Older
	if($coderes != '1001') {
		$values["error"] = "DeleteNameserver/domain-update($sld.$tld): Code ($coderes) $msg";
		return $values;
	}

	$values['status'] = $msg;
	return $values;
# Function to return meaningful message from response code
function _cozaepp_message($code) {

	return "Code $code";

}


# Ack a POLL message
function _cozaepp_ackpoll($client,$msgid) {
	# Ack poll message
	$request = $client->request('
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
		<poll op="ack" msgID="'.$msgid.'"/>
	</command>
</epp>
');
	# Check for error
	if (PEAR::isError($output)) {
		return $output;
	}

	# Decipher XML
	$doc = new DOMDocument();
	$doc->loadXML($request);
	$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
	$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
	if($coderes != '1301' && $coderes != '1300') {
		return new PEAR_Error("ackpoll/poll-ack($id): Code ($coderes) $msg");
# Function to create internal COZA EPP request
function _cozaepp_Client() {
	# Setup include dir
	$include_path = ROOTDIR . '/modules/registrars/cozaepp';
	set_include_path($include_path . PATH_SEPARATOR . get_include_path());
Nigel Kukard's avatar
Nigel Kukard committed
	# Include EPP stuff we need
	require_once 'Net/EPP/Client.php';
	require_once 'Net/EPP/Protocol.php';


	# Grab module parameters
	$params = getregistrarconfigoptions('cozaepp');

	# Are we using ssl?
	$use_ssl = false;
	if (isset($params['SSL']) && $params['SSL'] == 'on') {
		$use_ssl = true;
	}
	# Set certificate if we have one
 	if ($use_ssl && !empty($params['Certificate'])) {
		if (!file_exists($params['Certificate'])) {
			return PEAR_Error("Certificate file does not exist");
		}

		# Create SSL context
		$context = stream_context_create();
		stream_context_set_option($context, 'ssl', 'local_cert', $params['Certificate']);
	}

	# Create EPP client
	$client = new Net_EPP_Client();
	# Connect
	$res = $client->connect($params['Server'], $params['Port'], 30, $use_ssl, $context);
	# Check for error
	if (PEAR::isError($res)) {
		return $res;
	}

	# Perform login
	$request = $client->request('
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
	<command>
		<login>
			<clID>'.$params['Username'].'</clID>
			<pw>'.$params['Password'].'</pw>
			<options>
			<version>1.0</version>
			<lang>en</lang>
			</options>
			<svcs>
				<objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>
				<objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
			</svcs>
		</login>
	</command>
</epp>
');

	return $client;
}

function cozaepp_Sync($params) {
	$domainid = $params['domainid'];
	$domain = $params['domain'];
	$sld = $params['sld'];
	$tld = $params['tld'];
	$registrar = $params['registrar'];
	$regperiod = $params['regperiod'];
	$status = $params['status'];
	$dnsmanagement = $params['dnsmanagement'];
	$emailforwarding = $params['emailforwarding'];
	$idprotection = $params['idprotection'];

	# Other parameters used in your _getConfigArray() function would also be available for use in this function

	# Grab domain info
	$client = _cozaepp_Client();
	if (PEAR::isError($client)) {
		$values["error"] = 'Sync/EPP: '.$client->toString();
		return $values;
	}

	# 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>
		<epp:info>
			<domain:info xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd">
				<domain:name hosts="all">'.$domain.'</domain:name>
			</domain:info>
		</epp:info>
	</epp:command>
</epp:epp>
');
	$doc= new DOMDocument();
	$doc->loadXML($request);
	$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
	$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
	# Check result
	if($coderes != '1000') {
		$values['error'] = "Sync/domain-info($domain): Code("._cozaepp_message($coderes).") $msg";
		return $values;
	}

	# Check if we can get a status back
	if($doc->getElementsByTagName('status')->item(0)) {
		$statusres = $doc->getElementsByTagName('status')->item(0)->getAttribute('s');
		$createdate = substr($doc->getElementsByTagName('crDate')->item(0)->nodeValue,0,10);
		$nextduedate = substr($doc->getElementsByTagName('exDate')->item(0)->nodeValue,0,10);
	} else {
		$values['error'] = "Sync/domain-info($domain): Domain not found";
		return $values;
	}

	$values['status'] = $msg;

	# Check status and update
	if ($statusres == "ok") {
		$values['active'] = true;

	} elseif ($statusres == "serverHold") {

	} elseif ($statusres == "expired") {
		$values['expired'] = true;

	} else {
		$values['error'] = "Sync/domain-info($domain): Unknown status code '$statusres' (File a bug report here: http://devlabs.linuxassist.net/projects/whmcs-coza-epp/issues/new)";
	}

	$values['expirydate'] = $nextduedate;

	return $values;
}