Muuta omat tunnukset ja domain nimet (ddnsupdate.php).
echo $wanIP=file_get_contents("http://ipn.tsekkaus_osoite");
echo updateDADNS("palvelimen_IP","kayttajanimi","salasana","domainini.com","subdoimain_tai_domain",$wanIP); //YOUR_DOMAIN.COM_SETUP_IN_DIRECT_ADMIN
echo "\n RUNNING DNS UPDATER";
function updateDADNS($ip,$username,$password,$domain,$recName,$wanIP)
{
$url = 'http://' . $ip . ':2222';
// set temp cookie
$ckfile = tempnam("/tmp", "CURLCOOKIE");
// make list of POST fields
$fields = array(
'referer' => urlencode('/'),
'username' => urlencode($username),
'password' => urlencode($password)
);
$fields_string = '';
foreach ($fields as $key => $value) {
$fields_string .= $key . '=' . $value . '&';
}
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url . '/CMD_LOGIN');
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
echo $result;
if ($result === false) {
die('CURL ERROR: ' . curl_error($ch));
echo 'die';
} else {
curl_setopt($ch, CURLOPT_URL, $url . '/CMD_API_DNS_CONTROL?domain=' . $domain);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
echo 'LIST' . $result;
curl_setopt($ch, CURLOPT_URL, $url . '/CMD_API_DNS_CONTROL?domain=' . $domain . '&action=select&arecs0=name=' . $recName . '&value=' . $wanIP);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
echo "\nDELETE" . $result . "\n";
curl_setopt($ch, CURLOPT_URL, $url . '/CMD_API_DNS_CONTROL?domain=' . $domain . '&action=add&type=A&name=' . $recName . '&value=' . $wanIP);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
echo "\nADD" . $result . "\n";
curl_close($ch);
}
}
?>
Voit ajastaa scriptin crontabilla.
Ajoita esim seuraavasti crontab -e
Lisää seuraava rivi:
*/15 * * * * php /home/user/ddnsupdate.php
Tämä ajaa scriptin joka 15 min.
IP:n tsekkaus scripti voi olla seuraavanlainen joka laitetaan palvelimelle (index.php).
<?php
echo $_SERVER["REMOTE_ADDR"];
?>