Last active
December 14, 2015 16:29
-
-
Save ryanrhanson/5115490 to your computer and use it in GitHub Desktop.
Loop through dns records on account, storing them in 'zones/$domain.tld.db'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
This script will take all dns records on a SoftLayer account and create a dns zone file for them in the 'zones' subdirectory. If this subdirectory does not exist, it will be created. | |
If single_use is set to true, you can supply your API Username and Key as arguments to the script. single_use also assumes that it is in the same directory as the SoftLayer folder from the PHP API Client. If single_use is false, it will draw from a file in the 'configuration' subdirectory named apiconfig.php, which should define apiUsername, apiKey, and the path to the SoapClient.class.php file. | |
*/ | |
$single_use = true; | |
if ($single_use) { | |
require_once('SoftLayer/SoapClient.class.php'); | |
$apiUsername = readline("API User: "); | |
$apiKey = readline("API Key: "); | |
} | |
else { | |
require_once('configuration/apiconfig.php'); | |
} | |
//Create connection to the SoftLayer_Account API Service. | |
$client = SoftLayer_SoapClient::getClient('SoftLayer_Account', null, $apiUsername, $apiKey); | |
//Set an Object Mask to return domain information. | |
$dnsMask = new SoftLayer_ObjectMask(); | |
$dnsMask = 'mask[domains[id,name]]'; | |
$client->setObjectMask($dnsMask); | |
$dnslist = $client->getObject(); | |
/* | |
Loop through the array we got back from SoftLayer_Account, and for each domain, create a zonefile in the 'zones' sudir with the following format: | |
'zones/<domain name>.db' - This should be easy enough to drop into a cpanel server, as it contains zone information formatted as a standard zone file. | |
*/ | |
if (!is_dir('zones')){ | |
mkdir('zones'); | |
} | |
foreach ($dnslist->domains as $domainlist) { | |
$zones = SoftLayer_SoapClient::getClient('SoftLayer_Dns_Domain', $domainlist->id, $apiUsername, $apiKey); | |
$zonefile = $zones->getZoneFileContents(); | |
echo "Creating zone file for " . $domainlist->name . " in 'zones/" . $domainlist->name . ".db'\n\r"; | |
$f = fopen("zones/" . $domainlist->name . ".db", "w"); | |
fwrite ($f, $zonefile); | |
fclose($f); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment