Skip to content

Commit 5232171

Browse files
committed
Added add DNS zone & record functions using own params
Added addDNSZoneFull() & addDNSRecord() functions where you create using chosen parameters
1 parent 5a47b40 commit 5232171

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

dns_example.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
//Create a DNS zone with logging enable
1515
$bunny->addDNSZone('zonedomain.com', true);
1616

17+
//Create a DNS zone with parameters from https://docs.bunny.net/reference/dnszonepublic_add
18+
$parameters = array(
19+
'Domain' => 'zonedomain.com', 'NameserversDetected' => true, 'CustomNameserversEnabled' => true,
20+
'Nameserver1' => 'customns1.com', 'Nameserver2' => 'customns2.com', 'SoaEmail' => '[email protected]',
21+
'DateModified' => '2022-08-18 23:59:59', 'DateCreated' => '2022-08-18 23:59:59', 'NameserversNextCheck' => '2022-08-28 23:59:59',
22+
'LoggingEnabled' => true, 'LoggingIPAnonymizationEnabled' => true
23+
);
24+
$bunny->addDNSZoneFull($parameters);
25+
1726
//Delete DNS zone (1234 is the DNS zone id)
1827
$bunny->deleteDNSZone(1234);
1928

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

38+
//Add a DNS record by using parameters of choice https://docs.bunny.net/reference/dnszonepublic_addrecord
39+
$parameters = array('Type' => 0, 'Ttl' => 120, 'Accelerated' => true, 'Weight' => 200);
40+
$bunny->addDNSRecord(12345, 'thehost.com', '114.12.219.52', $parameters);
41+
2942
//Add DNS A record
3043
$bunny->addDNSRecordA(12345, 'thehost.com', '199.99.99.99');
3144

src/BunnyAPI.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,11 @@ public function getDNSZoneStatistics(int $zone_id, $date_from = null, $date_to =
967967
return $this->APIcall('GET', $url);
968968
}
969969

970+
public function addDNSZoneFull(array $parameters): array
971+
{//Add DNS zone by building up parameters from https://docs.bunny.net/reference/dnszonepublic_add
972+
return $this->APIcall('POST', "dnszone", $parameters);
973+
}
974+
970975
public function addDNSZone(string $domain, bool $logging = false, bool $log_ip_anon = true): array
971976
{
972977
$parameters = array(
@@ -1001,6 +1006,18 @@ public function deleteDNSZone(int $zone_id): array
10011006
return $this->APIcall('DELETE', "dnszone/$zone_id");
10021007
}
10031008

1009+
public function addDNSRecord(int $zone_id, string $name, string $value, array $parameters = array()): array
1010+
{//Add DNS record by building up parameters from https://docs.bunny.net/reference/dnszonepublic_addrecord
1011+
$parameters = array_merge(
1012+
array(
1013+
'Name' => $name,
1014+
'Value' => $value,
1015+
),
1016+
$parameters
1017+
);
1018+
return $this->APIcall('PUT', "dnszone/$zone_id/records", $parameters);
1019+
}
1020+
10041021
public function addDNSRecordA(int $zone_id, string $hostname, string $ipv4, int $ttl = 300, int $weight = 100): array
10051022
{
10061023
return $this->APIcall('PUT', "dnszone/$zone_id/records", array("Type" => 0, "Value" => $ipv4, "Name" => $hostname, "Ttl" => $ttl, "Weight" => $weight));

0 commit comments

Comments
 (0)