====== Custom DynDNS mit der Fritzbox ====== ===== Originalscript ===== von https://dersobi.de/fritzbox-cloudflare-dynamic-dns-update/ "https://api.cloudflare.com/client/v4/zones", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "cache-control: no-cache", "X-Auth-Email: ".$email, "X-Auth-Key: ".$apiKey ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { exit ("cURL Error #:" . $err); } else { $obj = json_decode($response,true); if( $obj["success"]!=1) { exit ("GetZoneId Failed"); } $zones =($obj['result']); foreach($zones as $zoneResult) { if($zoneResult['name']==$zone) $zoneId = $zoneResult['id']; } if ($zoneId =="") { exit ("Zone not found!"); } } } // end get Zone ID { // get Record ID $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.cloudflare.com/client/v4/zones/".$zoneId."/dns_records", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "Cache-Control: no-cache", "X-Auth-Email: ".$email, "X-Auth-Key: ".$apiKey ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { exit ("cURL Error #:" . $err); } else { $obj = json_decode($response,true); if( $obj["success"]!=1) { exit ("GetRecordID Failed"); } $zones =($obj['result']); foreach($zones as $zoneResult) { if($zoneResult['name'] == $dnsRecord) $recordId[$zoneResult['type']] = $zoneResult['id']; } } } // end get Record ID { // Update records function updateCloudflare($zid, $rid, $eml, $aky, $d, $opr) { if ($rid!="") { $rid = "/".$rid; if ($opr!="DELETE") { $opr = "PUT"; } } $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.cloudflare.com/client/v4/zones/".$zid."/dns_records".$rid, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => $opr, CURLOPT_HTTPHEADER => array( "Cache-Control: no-cache", "Content-Type: application/json", "X-Auth-Email:".$eml, "X-Auth-Key: ".$aky ) )); if ($opr!="DELETE") { curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($d)); } $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { exit ("cURL Error #:" . $err); } else { return json_decode($response); } } // end function // Update/Create ipv4 record $data = array ( 'type' => 'A', 'name' => $dnsRecord, 'content' => $ip4, 'proxiable' => true, 'proxied' => $enableProxy, 'ttl' => $ttl, 'locked' => false, 'zone_id' => $zoneId, 'zone_name' => $zone ); updateCloudflare($zoneId, $recordId['A'], $email, $apiKey, $data, "POST"); if ($ip6) { $data['type'] = 'AAAA'; $data['content'] = $ip6; updateCloudflare($zoneId, $recordId['AAAA'], $email, $apiKey, $data, "POST"); } elseif ($recordId['AAAA']) { // we've received no ipv6 address but there is one on Cloudflare updateCloudflare($zoneId, $recordId['AAAA'], $email, $apiKey, $data, "DELETE"); } } // end update records ?> You need to open your router DynDNS configuration page, for FRITZ!Box under: Internet >> Permit Access >> DynDNS {{:computer:network:pasted:20220321-215217.png}} Complete the fields as follows: "DynDNS Provider": User-defined "Update URL": https://yourserver.tld/ddns.php?domain=&ipv4=&ipv6=&user=&pass= "Domain name": subdomain.yourdomain.tld "User name": wie6Zoh2 (username of your choosing) "Password": ohgh9Atu (choose a password) In the update URL the ““, “” and “” will pass along to the server the corresponding values of the fields below, and ““, “” will pass the ipv4 and ipv6 addresses from the FRITZ!Box router. ===== Nutzung ===== Installiert als ''/var/www/html/dyn/dns.php'' auf Pihole mit dem korrekten API-Key von cloudflare. Aufgerufen von der Fritzbox