From 5232171c6c6e866a902f9c32484e3b3e7accf515 Mon Sep 17 00:00:00 2001 From: cp6 Date: Thu, 18 Aug 2022 23:57:05 +1000 Subject: [PATCH] Added add DNS zone & record functions using own params Added addDNSZoneFull() & addDNSRecord() functions where you create using chosen parameters --- dns_example.php | 13 +++++++++++++ src/BunnyAPI.php | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/dns_example.php b/dns_example.php index ea05afa..040b262 100644 --- a/dns_example.php +++ b/dns_example.php @@ -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' => 'contact@zonedomain.com', + '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); @@ -26,6 +35,10 @@ //Update DNS SOA email $bunny->updateDNSZoneSoaEmail(12345, 'mass_contact@mymail.com'); +//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'); diff --git a/src/BunnyAPI.php b/src/BunnyAPI.php index c2238b6..16c0d18 100644 --- a/src/BunnyAPI.php +++ b/src/BunnyAPI.php @@ -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( @@ -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));