Skip to content

Commit

Permalink
DigitalOcean dynamic DNS (#1342)
Browse files Browse the repository at this point in the history
  • Loading branch information
dheishman authored and fichtner committed Jun 25, 2019
1 parent 7e494c0 commit a93a949
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions dns/dyndns/src/etc/inc/plugins.inc.d/dyndns.inc
Expand Up @@ -103,6 +103,7 @@ function dyndns_list()
'custom' => 'Custom',
'custom-v6' => 'Custom (v6)',
'dhs' => 'DHS',
'digitalocean' => 'DigitalOcean',
'dnsexit' => 'DNSexit',
'dnsomatic' => 'DNS-O-Matic',
'duckdns' => 'Duck DNS',
Expand Down
32 changes: 32 additions & 0 deletions dns/dyndns/src/etc/inc/plugins.inc.d/dyndns/phpDynDNS.inc
Expand Up @@ -39,6 +39,7 @@
* - Oray (oray.com)
* - regfish (regfish.de)
* - regfish IPv6 (regfish.de)
* - DigitalOcean (digitalocean.com)
* +----------------------------------------------------+
* Requirements:
* - PHP version 4.0.2 or higher with the CURL Library and the PCRE Library
Expand Down Expand Up @@ -90,6 +91,7 @@
* regfish - Last Tested: 15 August 2017
* regfish v6 - Last Tested: 15 August 2017
* Amazon Route53 v6 - Last Tested: 19 November 2017
* DigitalOcean - Last Tested: 25 June 2019
* +====================================================+
*
* @author E.Kristensen
Expand Down Expand Up @@ -293,6 +295,7 @@ class updatedns
case 'custom-v6':
case 'dhs':
case 'dnsexit':
case 'digitalocean':
case 'dnsomatic':
case 'duckdns':
case 'dyndns':
Expand Down Expand Up @@ -606,6 +609,25 @@ class updatedns
curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser . ':' . $this->_dnsPass);
curl_setopt($ch, CURLOPT_URL, $server . 'hostname=' . $this->_dnsHost);
break;
case 'digitalocean':
/*
* dnsHost should be the root domain
* dnsUser should be the record ID
* dnsPass should be the API key
*/
$server = "https://api.digitalocean.com/v2/domains/" . $this->_dnsHost . "/records/" . $this->_dnsUser;
$hostData = array("data" => "{$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(
"Authorization: Bearer {$this->_dnsPass}",
'Content-Type: application/json'
));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($hostData));
curl_setopt($ch, CURLOPT_URL, $server);
break;
case 'selfhost':
if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") {
$this->_dnsWildcard = "ON";
Expand Down Expand Up @@ -1130,6 +1152,16 @@ class updatedns
log_error("Dynamic DNS ({$this->_dnsHost}): PAYLOAD: {$data}");
}
break;
case 'digitalocean':
$output = json_decode($data);
if ($output->domain_record->data === $this->_dnsIP) {
$status = "Dynamic DNS: (Success) Record ID {$this->_dnsUser} updated to {$this->_dnsIP}";
$successful_update = true;
} else {
$status = "Dynamic DNS Record ID ({$this->_dnsUser}): UNKNOWN ERROR";
log_error("Dynamic DNS Record ID ({$this->_dnsUser}): PAYLOAD: {$data}");
}
break;
case 'gratisdns':
if (preg_match('/Forkerte værdier/i', $data)) {
$status = "Dynamic DNS: (Error) Wrong values - Update could not be completed.";
Expand Down

0 comments on commit a93a949

Please sign in to comment.