<?php
/* Disable cache */
ini_set('soap.wsdl_cache_enabled', 0);
/* Connection data */
$ip = 'CHANGEME'; // ip or hostname of the server, without port
$auth->username = 'CHANGEME'; //username and password
$auth->password = 'CHANGEME';
/*the id of the client who will own the zone */
$client_id = 'CHANGEME';
/* set SSL context options */
$streamContext = stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
));
/* Create SOAP client based on WSDL, with trace for debugging */
$client = new SoapClient("https://".$ip."/soap/schema/1.5/dnsmanagerservice.wsdl", array('trace' => 1, 'exceptions' => 1, 'stream_context' => $streamContext));
$authvalues = new SoapVar($auth, SOAP_ENC_OBJECT, "http://4psa.com/HeaderData.xsd/1.0");
$header = new SoapHeader('http://4psa.com/HeaderData.xsd/1.0', 'userCredentials', $authvalues, false);
$client->__setSoapHeaders(array($header));
/* Add dns zone*/
$zone = new stdClass();
$zone->name = 'myzone.test';
$zone->clientId = $client_id;
$zone->type = 'master';
$result = $client ->AddDNSZone($zone);
echo "\n\n======AddDNSZone=======\n";
echo "\n<pre> REQUEST AddDNSZone :\n</pre>";
echo preg_replace(array("/></i", "/</i", "/>/i", "/\n/i"), array(">\n<", "<", ">", "<br />"), $client->__getLastRequest() );
echo "\n<pre> RESPONSE AddDNSZone :\n</pre>";
echo preg_replace(array("/></i", "/</i", "/>/i", "/\n/i"), array(">\n<", "<", ">", "<br />"), $client->__getLastResponse() );
/*Add dns record - NS*/
$add_dns_record->DNSZoneName ='myzone.test.';
$add_dns_record->status = 'enabled';
$add_dns_record->type = 'NS';
$add_dns_record->value = 'ns1.mynszone.test.';
$result = $client->AddDNSRecord($add_dns_record);
/*Add dns record - A*/
$add_dns_record->DNSZoneName ='myzone.test.';
$add_dns_record->status = 'enabled';
$add_dns_record->type = 'A';
$add_dns_record->host = 'www'; //or FQDN: 'www.myzone.test.'
$add_dns_record->value = '1.1.1.1';
$result = $client->AddDNSRecord($add_dns_record);
/*display SOAP request and response for add "A" dns record */
echo "\n\n======AddDNSRecord=======\n";
echo "\n<pre> REQUEST AddDNSRecord :\n</pre>";
echo preg_replace(array("/></i", "/</i", "/>/i", "/\n/i"), array(">\n<", "<", ">", "<br />"), $client->__getLastRequest() );
echo "\n<pre> RESPONSE AddDNSRecord :\n</pre>";
echo preg_replace(array("/></i", "/</i", "/>/i", "/\n/i"), array(">\n<", "<", ">", "<br />"), $client->__getLastResponse() );
/* Parse SOAP response and get DNSRecordId of the record previously added*/
$res = $client->__getLastResponse();
$xml = new SimpleXMLElement($res);
$dns_record_container = $xml->children('SOAP-ENV',true)->Body->children("ns3", true)->AddDNSRecordResponse->children("ns2", true)->DNSRecord->children("ns2", true) ;
$dns_record = $dns_record_container->DNSRecordId;
$dns_record_id = $dns_record[0];
/* Edit dns record */
$edit_dns_record = new stdClass();
$edit_dns_record->host = 'ftp.myzone.test.';
$edit_dns_record->value = '2.2.2.2';
$edit_dns_record->DNSRecordId = $dns_record_id;
$edit_dns_record->status = 'disabled';
$result = $client->EditDNSRecord($edit_dns_record);
/*display SOAP request and response for edit the "A" record */
echo "\n\n======EditDNSRecord=======\n";
echo "\n<pre> REQUEST EditDNSRecord :\n</pre>";
echo preg_replace(array("/></i", "/</i", "/>/i", "/\n/i"), array(">\n<", "<", ">", "<br />"), $client->__getLastRequest() );
echo "\n<pre> RESPONSE EditDNSRecord :\n</pre>";
echo preg_replace(array("/></i", "/</i", "/>/i", "/\n/i"), array(">\n<", "<", ">", "<br />"), $client->__getLastResponse() );
?>