From 5b91487ec2d8a51afbb17e66a704bc526b9dc1ef Mon Sep 17 00:00:00 2001 From: Adriano Date: Mon, 24 Aug 2020 14:15:16 +0200 Subject: [PATCH] dns/dyndns: Implementend a basic PoC for Gandi LiveDNS (#1916) --- .../src/etc/inc/plugins.inc.d/dyndns.inc | 1 + .../inc/plugins.inc.d/dyndns/phpDynDNS.inc | 43 +++++++++++++++++++ dns/dyndns/src/www/services_dyndns_edit.php | 5 ++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns.inc b/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns.inc index ac717b747..40744ebd5 100644 --- a/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns.inc +++ b/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns.inc @@ -120,6 +120,7 @@ function dyndns_list() 'easydns' => 'easyDNS', 'eurodns' => 'EuroDNS', 'freedns' => 'freeDNS', + 'gandi-livedns' => 'Gandi LiveDNS', 'godaddy' => 'GoDaddy', 'godaddy-v6' => 'GoDaddy (v6)', 'googledomains' => 'Google Domains', diff --git a/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns/phpDynDNS.inc b/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns/phpDynDNS.inc index a40a5bd41..7a423bd4e 100644 --- a/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns/phpDynDNS.inc +++ b/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns/phpDynDNS.inc @@ -42,6 +42,7 @@ * - regfish IPv6 (regfish.de) * - dynv6 IPv6 (dynv6.com) * - DigitalOcean (digitalocean.com) + * - Gandi LiveDNS (gandi.net) * - Azure DNS (azure.microsoft.com) * - Linode (linode.com) * - Linode IPv6 (linode.com) @@ -107,6 +108,7 @@ * Linode v6 - Last Tested: 25 February 2020 * GoDaddy - Last Tested: 10 July 2020 * GoDaddy v6 - Last Tested: 10 July 2020 + * Gandi LiveDNS - Last Tested: 24 August 2020 * +====================================================+ * * @author E.Kristensen @@ -345,6 +347,7 @@ class updatedns case 'custom-v6': case 'dhs': case 'digitalocean': + case 'gandi-livedns': case 'dnsexit': case 'dnsomatic': case 'duckdns': @@ -669,6 +672,28 @@ class updatedns curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($hostData)); curl_setopt($ch, CURLOPT_URL, $server); break; + case 'gandi-livedns': + /* + * https://github.com/vizion8-dan + * Tested on OPNsense 20.1.8_1-amd64 - IPv4 (A) + * dnsHost ("Hostname" field in OPNsense) should be the 2nd-level domain ("example.org") + * dnsUser ("Username" field in OPNsense) should be the subdomain / A-record ("myrecord" in 2nd-level domain) + * dnsPass should be the Gandi-API key + */ + $server = "https://dns.api.gandi.net/api/v5/domains/". $this->_dnsHost . "/records/" . $this->_dnsUser . "/A"; + + $body = '{"rrset_ttl":"' . "300" . '", "rrset_values":["'. $this->_dnsIP . '"]}'; + + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + "X-Api-Key: {$this->_dnsPass}", + 'Content-Type: application/json' + )); + curl_setopt($ch, CURLOPT_POSTFIELDS, $body); + curl_setopt($ch, CURLOPT_URL, $server); + break; case 'selfhost': if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") { $this->_dnsWildcard = "ON"; @@ -1425,6 +1450,24 @@ class updatedns log_error("Dynamic DNS Record ID ({$this->_dnsUser}): PAYLOAD: {$data}"); } break; + case 'gandi-livedns': + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + if ($http_code == 401) { + $status = 'Dynamic DNS: (Error) Bad authentication attempt because of a wrong API Key.'; + } elseif ($http_code == 403) { + $status = 'Dynamic DNS: (Error) Access to the resource is denied. Mainly due to a lack of permissions to access it!'; + } elseif ($http_code == 201) { + $status = 'Dynamic DNS: (Success) Record was created!'; + $successful_update = true; + } elseif ($http_code == 200) { + $status = 'Dynamic DNS: (Success) Same record already exists. Nothing was changed!'; + $successful_update = true; + } else { + $status = 'Dynamic DNS: (Error) "Unknown Response"'; + log_error("Dynamic DNS: HTTP Status: {$http_code} PAYLOAD: {$data}"); + $this->_debug($data); + } + break; case 'gratisdns': if (preg_match('/Forkerte værdier/i', $data)) { $status = "Dynamic DNS: (Error) Wrong values - Update could not be completed."; diff --git a/dns/dyndns/src/www/services_dyndns_edit.php b/dns/dyndns/src/www/services_dyndns_edit.php index 3db2e4e0f..b503bdbb1 100644 --- a/dns/dyndns/src/www/services_dyndns_edit.php +++ b/dns/dyndns/src/www/services_dyndns_edit.php @@ -317,7 +317,8 @@ include("head.inc"); @@ -366,6 +367,7 @@ include("head.inc");


+

@@ -382,6 +384,7 @@ include("head.inc");


+