Skip to content

Commit

Permalink
Added add DNS zone & record functions using own params
Browse files Browse the repository at this point in the history
Added addDNSZoneFull() & addDNSRecord() functions where you create using chosen parameters
  • Loading branch information
cp6 committed Aug 18, 2022
1 parent 5a47b40 commit 5232171
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions dns_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
//Create a DNS zone with logging enable
$bunny->addDNSZone('zonedomain.com', true);

//Create a DNS zone with parameters from https://docs.bunny.net/reference/dnszonepublic_add
$parameters = array(
'Domain' => 'zonedomain.com', 'NameserversDetected' => true, 'CustomNameserversEnabled' => true,
'Nameserver1' => 'customns1.com', 'Nameserver2' => 'customns2.com', 'SoaEmail' => '[email protected]',
'DateModified' => '2022-08-18 23:59:59', 'DateCreated' => '2022-08-18 23:59:59', 'NameserversNextCheck' => '2022-08-28 23:59:59',
'LoggingEnabled' => true, 'LoggingIPAnonymizationEnabled' => true
);
$bunny->addDNSZoneFull($parameters);

//Delete DNS zone (1234 is the DNS zone id)
$bunny->deleteDNSZone(1234);

Expand All @@ -26,6 +35,10 @@
//Update DNS SOA email
$bunny->updateDNSZoneSoaEmail(12345, '[email protected]');

//Add a DNS record by using parameters of choice https://docs.bunny.net/reference/dnszonepublic_addrecord
$parameters = array('Type' => 0, 'Ttl' => 120, 'Accelerated' => true, 'Weight' => 200);
$bunny->addDNSRecord(12345, 'thehost.com', '114.12.219.52', $parameters);

//Add DNS A record
$bunny->addDNSRecordA(12345, 'thehost.com', '199.99.99.99');

Expand Down
17 changes: 17 additions & 0 deletions src/BunnyAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,11 @@ public function getDNSZoneStatistics(int $zone_id, $date_from = null, $date_to =
return $this->APIcall('GET', $url);
}

public function addDNSZoneFull(array $parameters): array
{//Add DNS zone by building up parameters from https://docs.bunny.net/reference/dnszonepublic_add
return $this->APIcall('POST', "dnszone", $parameters);
}

public function addDNSZone(string $domain, bool $logging = false, bool $log_ip_anon = true): array
{
$parameters = array(
Expand Down Expand Up @@ -1001,6 +1006,18 @@ public function deleteDNSZone(int $zone_id): array
return $this->APIcall('DELETE', "dnszone/$zone_id");
}

public function addDNSRecord(int $zone_id, string $name, string $value, array $parameters = array()): array
{//Add DNS record by building up parameters from https://docs.bunny.net/reference/dnszonepublic_addrecord
$parameters = array_merge(
array(
'Name' => $name,
'Value' => $value,
),
$parameters
);
return $this->APIcall('PUT', "dnszone/$zone_id/records", $parameters);
}

public function addDNSRecordA(int $zone_id, string $hostname, string $ipv4, int $ttl = 300, int $weight = 100): array
{
return $this->APIcall('PUT', "dnszone/$zone_id/records", array("Type" => 0, "Value" => $ipv4, "Name" => $hostname, "Ttl" => $ttl, "Weight" => $weight));
Expand Down

0 comments on commit 5232171

Please sign in to comment.