mirror of
https://github.com/netbirdio/plugins.git
synced 2026-05-22 18:44:07 -07:00
Updated Cloudflare to use token auth and update ttl (#1726)
This commit is contained in:
@@ -100,8 +100,10 @@ function dyndns_list()
|
||||
'azure' => 'Azure DNS',
|
||||
'azurev6' => 'Azure DNS (v6)',
|
||||
'citynetwork' => 'City Network',
|
||||
'cloudflare' => 'CloudFlare',
|
||||
'cloudflare-v6' => 'CloudFlare (v6)',
|
||||
'cloudflare' => 'Cloudflare',
|
||||
'cloudflare-v6' => 'Cloudflare (v6)',
|
||||
'cloudflare-token' => 'Cloudflare w/API token',
|
||||
'cloudflare-token-v6' => 'Cloudflare w/API token (v6)',
|
||||
'custom' => 'Custom',
|
||||
'custom-v6' => 'Custom (v6)',
|
||||
'dhs' => 'DHS',
|
||||
|
||||
@@ -26,8 +26,10 @@
|
||||
* - DNS-O-Matic (dnsomatic.com)
|
||||
* - Custom dynamic DNS (any URL)
|
||||
* - Custom dynamic DNS IPv6 (any URL)
|
||||
* - CloudFlare (www.cloudflare.com)
|
||||
* - CloudFlare IPv6 (www.cloudflare.com)
|
||||
* - Cloudflare (www.cloudflare.com)
|
||||
* - Cloudflare IPv6 (www.cloudflare.com)
|
||||
* - Cloudflare API token (www.cloudflare.com)
|
||||
* - Cloudflare API token IPv6 (www.cloudflare.com)
|
||||
* - Eurodns (eurodns.com)
|
||||
* - GratisDNS (gratisdns.dk)
|
||||
* - City Network (citynetwork.se)
|
||||
@@ -58,47 +60,49 @@
|
||||
* - _debug()
|
||||
* - _checkIP()
|
||||
* +----------------------------------------------------+
|
||||
* DynDNS Dynamic - Last Tested: 12 July 2005
|
||||
* DynDNS Static - Last Tested: NEVER
|
||||
* DynDNS Custom - Last Tested: NEVER
|
||||
* No-IP - Last Tested: 20 July 2008
|
||||
* HN.org - Last Tested: 12 July 2005
|
||||
* EasyDNS - Last Tested: 20 July 2008
|
||||
* DHS - Last Tested: 12 July 2005
|
||||
* ZoneEdit - Last Tested: NEVER
|
||||
* Dyns - Last Tested: NEVER
|
||||
* ODS - Last Tested: 02 August 2005
|
||||
* FreeDNS - Last Tested: 23 Feb 2011
|
||||
* Loopia - Last Tested: NEVER
|
||||
* StaticCling - Last Tested: 27 April 2006
|
||||
* DNSexit - Last Tested: 20 July 2008
|
||||
* Namecheap - Last Tested: 31 August 2010
|
||||
* HE.net - Last Tested: 7 July 2013
|
||||
* HE.net IPv6 - Last Tested: 7 July 2013
|
||||
* HE.net Tunnel - Last Tested: 28 June 2011
|
||||
* SelfHost - Last Tested: 26 December 2011
|
||||
* Amazon Route53 - Last Tested: 01 April 2012
|
||||
* DNS-O-Matic - Last Tested: 9 September 2010
|
||||
* CloudFlare - Last Tested: 16 April 2019
|
||||
* CloudFlare IPv6 - Last Tested: 16 April 2019
|
||||
* Eurodns - Last Tested: 25 July 2018
|
||||
* GratisDNS - Last Tested: 26 January 2020
|
||||
* OVH DynHOST - Last Tested: NEVER
|
||||
* City Network - Last Tested: 13 November 2013
|
||||
* Duck DNS - Last Tested: 04 March 2015
|
||||
* Google Domains - Last Tested: 20 February 2017
|
||||
* STRATO - Last Tested: 09 May 2017
|
||||
* 3322 - Last Tested: 26 May 2017
|
||||
* Oray - Last Tested: 26 May 2017
|
||||
* regfish - Last Tested: 15 August 2017
|
||||
* regfish v6 - Last Tested: 15 August 2017
|
||||
* Amazon Route53 v6 - Last Tested: 19 November 2017
|
||||
* dynv6 - Last Tested: 25 June 2019
|
||||
* dynv6 v6 - Last Tested: 25 June 2019
|
||||
* DigitalOcean - Last Tested: 25 June 2019
|
||||
* Azure DNS - Last Tested: 16 October 2019
|
||||
* Linode - Last Tested: 25 February 2020
|
||||
* Linode v6 - Last Tested: 25 February 2020
|
||||
* DynDNS Dynamic - Last Tested: 12 July 2005
|
||||
* DynDNS Static - Last Tested: NEVER
|
||||
* DynDNS Custom - Last Tested: NEVER
|
||||
* No-IP - Last Tested: 20 July 2008
|
||||
* HN.org - Last Tested: 12 July 2005
|
||||
* EasyDNS - Last Tested: 20 July 2008
|
||||
* DHS - Last Tested: 12 July 2005
|
||||
* ZoneEdit - Last Tested: NEVER
|
||||
* Dyns - Last Tested: NEVER
|
||||
* ODS - Last Tested: 02 August 2005
|
||||
* FreeDNS - Last Tested: 23 Feb 2011
|
||||
* Loopia - Last Tested: NEVER
|
||||
* StaticCling - Last Tested: 27 April 2006
|
||||
* DNSexit - Last Tested: 20 July 2008
|
||||
* Namecheap - Last Tested: 31 August 2010
|
||||
* HE.net - Last Tested: 7 July 2013
|
||||
* HE.net IPv6 - Last Tested: 7 July 2013
|
||||
* HE.net Tunnel - Last Tested: 28 June 2011
|
||||
* SelfHost - Last Tested: 26 December 2011
|
||||
* Amazon Route53 - Last Tested: 01 April 2012
|
||||
* DNS-O-Matic - Last Tested: 9 September 2010
|
||||
* Cloudflare - Last Tested: 16 April 2019
|
||||
* Cloudflare IPv6 - Last Tested: 16 April 2019
|
||||
* Cloudflare w/API token - Last Tested: 13 June 2020
|
||||
* Cloudflare w/API token v6 - Last Tested: NEVER
|
||||
* Eurodns - Last Tested: 25 July 2018
|
||||
* GratisDNS - Last Tested: 26 January 2020
|
||||
* OVH DynHOST - Last Tested: NEVER
|
||||
* City Network - Last Tested: 13 November 2013
|
||||
* Duck DNS - Last Tested: 04 March 2015
|
||||
* Google Domains - Last Tested: 20 February 2017
|
||||
* STRATO - Last Tested: 09 May 2017
|
||||
* 3322 - Last Tested: 26 May 2017
|
||||
* Oray - Last Tested: 26 May 2017
|
||||
* regfish - Last Tested: 15 August 2017
|
||||
* regfish v6 - Last Tested: 15 August 2017
|
||||
* Amazon Route53 v6 - Last Tested: 19 November 2017
|
||||
* dynv6 - Last Tested: 25 June 2019
|
||||
* dynv6 v6 - Last Tested: 25 June 2019
|
||||
* DigitalOcean - Last Tested: 25 June 2019
|
||||
* Azure DNS - Last Tested: 16 October 2019
|
||||
* Linode - Last Tested: 25 February 2020
|
||||
* Linode v6 - Last Tested: 25 February 2020
|
||||
* +====================================================+
|
||||
*
|
||||
* @author E.Kristensen
|
||||
@@ -251,6 +255,16 @@ class updatedns
|
||||
$this->_error(9);
|
||||
}
|
||||
break;
|
||||
case 'cloudflare-token':
|
||||
case 'cloudflare-token-v6':
|
||||
if (!$dnsPass) {
|
||||
$this->_error(4);
|
||||
} elseif (!$dnsHost) {
|
||||
$this->_error(5);
|
||||
} elseif (!$dnsTTL) {
|
||||
$this->_error(9);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (!$dnsUser) {
|
||||
$this->_error(3);
|
||||
@@ -271,6 +285,7 @@ class updatedns
|
||||
case 'linode-v6':
|
||||
case 'regfish-v6':
|
||||
case 'route53-v6':
|
||||
case 'cloudflare-token-v6':
|
||||
$this->_useIPv6 = true;
|
||||
break;
|
||||
default:
|
||||
@@ -319,6 +334,8 @@ class updatedns
|
||||
case 'citynetwork':
|
||||
case 'cloudflare':
|
||||
case 'cloudflare-v6':
|
||||
case 'cloudflare-token':
|
||||
case 'cloudflare-token-v6':
|
||||
case 'custom':
|
||||
case 'custom-v6':
|
||||
case 'dhs':
|
||||
@@ -749,21 +766,35 @@ class updatedns
|
||||
break;
|
||||
case 'cloudflare':
|
||||
case 'cloudflare-v6':
|
||||
case 'cloudflare-token':
|
||||
case 'cloudflare-token-v6':
|
||||
$baseUrl = 'https://api.cloudflare.com/client/v4';
|
||||
$fqdn = str_replace(' ', '', $this->_dnsHost);
|
||||
$recordType = ($this->_useIPv6) ? 'AAAA' : 'A';
|
||||
$ttlData = intval($this->_dnsTTL) < 1 ? 1 : intval($this->_dnsTTL);
|
||||
$hostData = array(
|
||||
"content" => "{$this->_dnsIP}",
|
||||
"type" => $recordType,
|
||||
"name" => $fqdn
|
||||
"name" => $fqdn,
|
||||
"ttl" => $ttlData
|
||||
);
|
||||
|
||||
// Determine if service is token based or user/password based and define appropriate header
|
||||
if (strpos($this->_dnsService, 'token') !== false) {
|
||||
$headerAuth = array(
|
||||
"Authorization: Bearer {$this->_dnsPass}",
|
||||
'Content-Type: application/json'
|
||||
);
|
||||
} else {
|
||||
$headerAuth = array(
|
||||
"X-Auth-Email: {$this->_dnsUser}",
|
||||
"X-Auth-Key: {$this->_dnsPass}",
|
||||
'Content-Type: application/json'
|
||||
);
|
||||
}
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
"X-Auth-Email: {$this->_dnsUser}",
|
||||
"X-Auth-Key: {$this->_dnsPass}",
|
||||
'Content-Type: application/json'
|
||||
));
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerAuth);
|
||||
|
||||
// Get all zone info
|
||||
$zonesUrl = "$baseUrl/zones";
|
||||
@@ -1322,12 +1353,14 @@ class updatedns
|
||||
break;
|
||||
case 'cloudflare':
|
||||
case 'cloudflare-v6':
|
||||
case 'cloudflare-token':
|
||||
case 'cloudflare-token-v6':
|
||||
$output = json_decode($data);
|
||||
if ($output->result->content === $this->_dnsIP) {
|
||||
$status = "Dynamic DNS: (Success) {$this->_dnsHost} updated to {$this->_dnsIP}";
|
||||
$successful_update = true;
|
||||
} elseif ($output->errors[0]->code === 9103) {
|
||||
$status = "Dynamic DNS ({$this->_dnsHost}): ERROR - Invalid Credentials! Don't forget to use API Key for password field with CloudFlare.";
|
||||
$status = "Dynamic DNS ({$this->_dnsHost}): ERROR - Invalid Credentials! Don't forget to use API Key for password field with Cloudflare.";
|
||||
} elseif (($output->success) && (!$output->result[0]->id)) {
|
||||
$status = "Dynamic DNS ({$this->_dnsHost}): ERROR - Zone ID was not found.";
|
||||
} else {
|
||||
|
||||
@@ -75,7 +75,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
}
|
||||
$input_errors = array();
|
||||
$pconfig = $_POST;
|
||||
if(($pconfig['type'] == "freedns" || $pconfig['type'] == "linode" || $pconfig['type'] == "linode-v6" || $pconfig['type'] == "namecheap") && $pconfig['username'] == "") {
|
||||
if(($pconfig['type'] == "freedns" || $pconfig['type'] == "linode" || $pconfig['type'] == "linode-v6" || $pconfig['type'] == "namecheap" || $pconfig['type'] == "cloudflare-token" || $pconfig['type'] == "cloudflare-token-v6") && $pconfig['username'] == "") {
|
||||
$pconfig['username'] = "none";
|
||||
}
|
||||
|
||||
@@ -114,6 +114,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
switch ($pconfig['type']) {
|
||||
case 'cloudflare':
|
||||
case 'cloudflare-v6':
|
||||
case 'cloudflare-token':
|
||||
case 'cloudflare-token-v6':
|
||||
case 'eurodns':
|
||||
case 'googledomains':
|
||||
case 'linode':
|
||||
@@ -137,6 +139,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
$input_errors[] = gettext("The username contains invalid characters.");
|
||||
}
|
||||
|
||||
if ((string)((int)$pconfig['ttl']) != $pconfig['ttl']) {
|
||||
$input_errors[] = gettext("The TTL value needs to be a valid integer number.");
|
||||
}
|
||||
|
||||
if (count($input_errors) == 0) {
|
||||
$dyndns = array();
|
||||
@@ -212,6 +217,15 @@ include("head.inc");
|
||||
case "azurev6":
|
||||
$(".type_azure").show();
|
||||
break;
|
||||
case 'cloudflare':
|
||||
case 'cloudflare-v6':
|
||||
$(".type_default").show();
|
||||
$(".type_cloudflare").show();
|
||||
break;
|
||||
case 'cloudflare-token':
|
||||
case 'cloudflare-token-v6':
|
||||
$(".type_cloudflare").show();
|
||||
break;
|
||||
default:
|
||||
$(".type_default").show();
|
||||
break;
|
||||
@@ -339,7 +353,7 @@ include("head.inc");
|
||||
<?= gettext("Verify SSL peer") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr class ="opt_field type_custom type_route53 type_azure type_default">
|
||||
<td><a id="help_for_username" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?= gettext("Username") ?></td>
|
||||
<td>
|
||||
<input name="username" type="text" id="username" value="<?= $pconfig['username'] ?>" />
|
||||
@@ -364,7 +378,7 @@ include("head.inc");
|
||||
<br /><?= gettext('dynv6: Leave blank.') ?>
|
||||
<br /><?= gettext('Azure: client secret of the AD application') ?>
|
||||
<br /><?= gettext('Linode: Enter your Personal Access Token.') ?>
|
||||
<br /><?= gettext('Cloudflare: Enter Global API Key.') ?>
|
||||
<br /><?= gettext('Cloudflare: Enter your API token or Global API key.') ?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -414,12 +428,13 @@ include("head.inc");
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="opt_field type_route53 type_azure">
|
||||
<tr class="opt_field type_route53 type_azure type_cloudflare">
|
||||
<td><a id="help_for_ttl" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("TTL");?></td>
|
||||
<td>
|
||||
<input name="ttl" type="text" id="ttl" value="<?= $pconfig['ttl'] ?>" />
|
||||
<div class="hidden" data-for="help_for_ttl">
|
||||
<?= gettext("Choose TTL for your dns record.") ?>
|
||||
<br /><?= gettext('Cloudflare: value "1" means "Auto". Anything below 1 will be updated with value 1/Auto.') ?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user