Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand

1) Start with providing instance information, API key, Secret Key, and DNS Server IP

Code Block
languagephp
<?php
//
//
// supply the URL of your ProVision instance, your API key and your Secret key.
$proVisionURL = "https://ops.6connect.com/qa-4.2.2";
$apiKey = "Nnvz8xKZDQUWke6gDxb";
$apiSecretKey = "2YojRbrHnToPZ7cDeFBzcTAvcfMbPVmX";
// this example uses 6connect's PHP APIClient
require_once("APIClient.php");
// set up the connection
$apiClient = new APIClient($proVisionURL, $apiKey, $apiSecretKey);

// save this.  IP of the DNS Server we're creating.
$serverIp = "208.39.106.184";

2) Add a DNS server

Code Block
languagephp
// begin making api calls.  We begin by adding a simple DNS server.
$params = array();
$params['displayName'] = "Example Server";							// the pretty name of the DNS server
$params['server'] = "208.39.106.184";								// the IP of the DNS Server
$params['active'] = 1;												// whether or not this server is currently enabled
$params['transferType'] = "SCP";                                    // we are using an ISC Bind server which we will communicate with via SCP
$params['username'] = "6connect";									// the username used to SCP zones to this server
$params['password'] = "password";									// the password used to SCP zones to this server
$params['port'] = 22;                                               // the port used to SCP zones to this server
$params['serverType'] = "master";									// whether this server is a master or a slave
$params['SOA'] = "ns1.dns.6connect.net. hostmaster.6connect.net."; 	// the default SOA
$params['remoteDirectory'] = "/tmp/";								// where to place the zone files on the server
$params['namedConfPath'] = "/tmp/";									// the path to the zones within the configuration file.  Usually the same as 'remoteDirectory'
$params['postCommand'] = "touch /tmp/allFinished";					// the command to execute on the server after the transfer is complete.  
// add the server
$apiResponse = $apiClient->sendRequest('dnsServer', 'add', $params);
if ($apiResponse->status == 1) {
	echo "Successfully added DNS Server '" . $params['displayName'] . "'\n";
} else {
	echo "Could not add DNS Server '" . $params['displayName'] . "' !\n";
	die();
}

// now we fetch the id of our newly created server
$params = array();
$apiResponse = $apiClient->sendRequest('dnsServer', 'get', $params);
$data = $apiResponse->data;
for ($i = 0; $i < count($data); $i++) {
	if ($data[$i]['server'] == $serverIp) {
			// we save the id for later.
			$serverId = $data[$i]['id'];
			break;
	}
}
echo "Server Id is: $serverId \n";

3) Create a zone

Code Block
languagephp
// okay, DNS server is set up -- time to create a zone.
$params = array();
$params['zoneName'] = "atestzone.com";				// zone name
$params['zoneResourceId'] = 1;						// the owner of the zone; 1 is default
$apiResponse = $apiClient->sendRequest('zone', 'add', $params);
if ($apiResponse->status == 1) {
    echo "Successfully added DNS Zone '" . $params['zoneName'] . "'\n";
} else {
    echo "Could not add DNS Zone '" . $params['zoneName'] . "' !\n";
    die();
}
// snag the zoneId for later.
$zoneId = $apiResponse->data;
4) Add Zone records
Code Block
languagephp
// Lets add some records to our new zone!
$params = array();
$params['newRecordZoneId'] = $zoneId;		           // parent zone id
$params['newRecordType'] = 'A';			               // record type
$params['newRecordHost'] = "www";                      // the host field of the record
$params['newRecordValue'] = "1.2.3.4";                 // the value field of the record
$params['newRecordTTL'] = "3600";                      // the value of the TTL field
$apiResponse = $apiClient->sendRequest('record', 'add', $params);
if ($apiResponse->status == 1) {
    echo "Successfully added Record to zone #$zoneId\n";
} else {
    echo "Could not add Record to zone #$zoneId!\n";
    die();
}

$params = array();
$params['newRecordZoneId'] = $zoneId;                   // parent zone id
$params['newRecordType'] = 'A';                         // record type
$params['newRecordHost'] = "dev";                       // the host field of the record
$params['newRecordValue'] = "2.3.4.5";  	            // the value field of the record
$params['newRecordTTL'] = "3600";     	     	      	// the value of the TTL field
$apiResponse = $apiClient->sendRequest('record', 'add', $params);
if ($apiResponse->status == 1) {
    echo "Successfully added Record to zone #$zoneId\n";
} else {
    echo "Could not add Record to zone #$zoneId!\n";
    die();
}

$params = array();
$params['newRecordZoneId'] = $zoneId;                  // parent zone id
$params['newRecordType'] = 'A';                        // record type
$params['newRecordHost'] = "cloud";                    // the host field of the record
$params['newRecordValue'] = "3.4.5.6";                 // the value field of the record
$params['newRecordTTL'] = "3600";                      // the value of the TTL field
$apiResponse = $apiClient->sendRequest('record', 'add', $params);
if ($apiResponse->status == 1) {
    echo "Successfully added Record to zone #$zoneId\n";
} else {
    echo "Could not add Record to zone #$zoneId!\n";
    die();
}

4) Link the Zone to the new DNS server and push

Code Block
languagephp
 
// Okay, we have some zones with records.  Time to link this zone to the new DNS Server
$params = array();
$params['serverId'] = $serverId;						// the server id
$params['zoneId'] = $zoneId;							// the zone id  
$params['serverSlave'] = 0;								// not a slave zone
$apiResponse = $apiClient->sendRequest('zoneLinkage', 'add', $params);
if ($apiResponse->status == 1) {
    echo "Successfully linked Zone #$zoneId to server #serverId\n";
} else {
    echo "Could not link Zone #$zoneId to server #serverId!\n";
    die();
}
// now we can push the zone to the server
$params = array();
$params['zoneId'] = $zoneId;                            // the zone id to push
$apiResponse = $apiClient->sendRequest('dnsServer', 'transferSingle', $params);
if ($apiResponse->status == 1) {
    echo "Zone pushed!\n";
} else {
    echo "Could not push zone!\n";
    die();
}
?>

Context: How do I update the notes field of an IP block using the API in PHP?