dns/dyndns: Implementend a basic PoC for Gandi LiveDNS (#1916)

This commit is contained in:
Adriano
2020-08-24 14:15:16 +02:00
committed by GitHub
parent 8daf9a122c
commit 5b91487ec2
3 changed files with 48 additions and 1 deletions
@@ -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',
@@ -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.";
+4 -1
View File
@@ -317,7 +317,8 @@ include("head.inc");
<input name="host" type="text" id="host" value="<?= $pconfig['host'] ?>" />
<div class="hidden" data-for="help_for_host">
<?= gettext("Enter the complete host/domain name. example: myhost.dyndns.org") ?><br />
<?= gettext("For he.net tunnelbroker, enter your tunnel ID") ?>
<?= gettext("For he.net tunnelbroker, enter your tunnel ID") ?><br />
<?= gettext('Gandi LiveDNS: Enter the 2nd-level domain ("example.org").') ?>
</div>
</td>
</tr>
@@ -366,6 +367,7 @@ include("head.inc");
<br /><?= gettext('dynv6: Enter your Token.') ?>
<br /><?= gettext('Azure: Enter your Azure AD application ID.') ?>
<br /><?= gettext('For Custom Entries, Username and Password represent HTTP Authentication username and passwords.') ?>
<br /><?= gettext('Gandi LiveDNS: The subdomain / record to update.') ?>
<br /><?= gettext('GoDaddy: Enter your API Key Token.') ?>
</div>
</td>
@@ -382,6 +384,7 @@ include("head.inc");
<br /><?= gettext('Azure: client secret of the AD application') ?>
<br /><?= gettext('Linode: Enter your Personal Access Token.') ?>
<br /><?= gettext('Cloudflare: Enter your API token or Global API key.') ?>
<br /><?= gettext('Gandi LiveDNS: Enter your API token.') ?>
<br /><?= gettext('GoDaddy: Enter your API Secret Token.') ?>
</div>
</td>