-
-
Save it-can/05eba840b700f2019b18 to your computer and use it in GitHub Desktop.
TransIP API 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 | |
// SETTINGS | |
// The domain to edit | |
define('DOMAIN', 'example.com'); | |
// The authentication key | |
define('KEY', '69l67Le20e819360d3YHO1175'); | |
// The DNS entries to update (name => content) | |
// This script will NOT add new entries | |
$newValues = [ | |
'www' => $_SERVER['REMOTE_ADDR'], | |
]; | |
// SCRIPT | |
// Exit if the key does not match | |
if($_GET['key'] != KEY) exit(); | |
// Include the required files from the API | |
require_once('Transip/DomainService.php'); | |
// Get the current DNS entries from TransIP | |
$dnsEntries = Transip_DomainService::getInfo(DOMAIN)->dnsEntries; | |
// Check every DNS entry | |
foreach($dnsEntries as $dnsEntry) | |
{ | |
// Check if the entry has to be updated and update it | |
if(array_key_exists($dnsEntry->name, $newValues)) $dnsEntry->content = $newValues[$dnsEntry->name]; | |
} | |
try | |
{ | |
// Commit the changes to the TransIP DNS servers | |
Transip_DomainService::setDnsEntries(DOMAIN, $dnsEntries); | |
// Done | |
echo 'DNS updated.'; | |
} | |
catch(SoapFault $f) | |
{ | |
// An error occured | |
echo 'DNS not updated. ' . $f->getMessage(); | |
} |
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 | |
// --- Settings | |
$login = ''; | |
$domainName = ''; | |
$subDomain = '@'; | |
$keyFile = 'transip.key'; | |
$publicIpApi = 'https://api.ipify.org'; | |
// --- Script | |
require_once('Transip/DomainService.php'); | |
Transip_ApiSettings::$login = $login; | |
Transip_ApiSettings::$privateKey = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . $keyFile); | |
$currentPublicIp = file_get_contents($publicIpApi); | |
$domain = Transip_DomainService::getInfo($domainName); | |
$updatedDnsEntries = array(); | |
foreach($domain->dnsEntries as $dnsEntry) | |
{ | |
if($dnsEntry->name == $subDomain && $dnsEntry->type == 'A') { | |
$dnsEntry->content = $currentPublicIp; | |
} | |
$updatedDnsEntries[] = $dnsEntry; | |
} | |
Transip_DomainService::setDnsEntries($domainName, $updatedDnsEntries); | |
echo 'Succesfully set home.' . $domainName . ' to ip: '. $currentPublicIp . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment