Created
April 5, 2017 17:38
-
-
Save Doxylamin/ca908d8cc574a1fdbeee80c32a286d55 to your computer and use it in GitHub Desktop.
Cloudflare + FritzBox -> DynDNS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
FRITZ!Box DynDNS Howto: | |
Update-URL: http://your-domain.tld/filename.php?user=<username>&pass=<pass>&hostname=<domain>&myip=<ipaddr> | |
Domainname: dyndns.your-domain.tld | |
Username: your-cloudflare-email-address | |
Password: your-cloudflare-api-token | |
*/ | |
// static config: | |
$cfZoneId = ""; //put your CloudFlare Zone ID here | |
$cfDnsId = ""; // put your CloudFlare DNS Identifier here | |
// dynamic config | |
$cfEmail = $_GET['user']; | |
$cfApikey = $_GET['pass']; | |
$updateDomain = $_GET['hostname']; | |
$ipAddr = $_GET['myip']; | |
$cfUrl = "https://api.cloudflare.com/client/v4/zones/".$cfZoneId."/dns_records/".$cfDnsId; | |
$data = array( | |
"type" => "A", | |
"name" => "{$updateDomain}", | |
"content" => "{$ipAddr}", | |
"ttl" => 120, | |
"proxied" => false, | |
); | |
$curl = curl_init($cfUrl); | |
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); | |
curl_setopt($curl, CURLOPT_HEADER, false); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json',"X-Auth-Email: $cfEmail","X-Auth-Key: $cfApikey")); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); | |
$response = curl_exec($curl); | |
if (!$response) { | |
die("Connection failure."); | |
}else{ | |
var_dump($response); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Although this script isn't really maintained and in use anymore, vou can actually run in wherever you want, as long as there's PHP and curl available. The FRITZ!Box itself has to be configured to a custom DynDNS Provider, pointing to the url where this script is located. That can be on a RPI or a shared webhosting, as long as it's reachable for your FRITZ!Box. There's no cron needed, as the FRITZ!Box automatically fires a request as soon as a new IP is assigned or the box is rebooted.
Additionally, see the forks of this script which seemingly have been updated to an easier-to-understand version. I actually uploaded this gist almost 4 years ago just to have it saved somewhere, not knewing that this might be used somewhere else :P
Example FRITZ!Box Configuration: https://img.doxylamin.pro/2020-06-07/gdu5yOZpNb.png
I've initially made the username and password to cloudflare email & api token just to have some kind of "security" so not everyone who knows the path of the script can override the DNS entry.