I use a PHP-Script to submit my IPv4 Address to my own PowerDNS-Server using that link:
script.php?domain=test.dns.com&ipaddr=11.22.33.44&passwd=auth-phrase
Therefore I modified the link in a way that the IPv4 and IPv6 are being updated simultaneously. I modified the update script, but then only one version will be updated (IPv4):
script.php?domain=test.dns.com&ipaddr=11.22.33.44&passwd=auth-phrase&ip6addr=2001:0db8:1234:0000:0000:0000:0000:0000
Here is the script I'm using:
<?php
// DynDNS-Service für PowerDNS
// @date 06.09.2012
$dsn = 'mysql:dbname=pdns;host=127.0.0.1'; // Datenbank DSN
$user = 'pdns'; // Name der Datenbank
$pass = 'password'; // Datenbank Passwort
// Auth-String der als GET-Parameter übermittelt werden muss
$auth = 'auth-phrase';
// Für alle im Array enthaltenen Records dürfen Updates gefahren werden
$allowed = array('ip4.test.dns.tld');
$domain = (isset($_GET['domain'])) ? $_GET['domain'] : null;
$ip = (isset($_GET['ipaddr'])) ? $_GET['ipaddr'] : null;
$ip6 = (isset($_GET['ip6addr'])) ? $_GET['ip6addr'] : null;
$domain6 = 'ip6.test.dns.tld';
if ((empty($domain) || is_null($domain)) || (empty($ip6) || is_null($ip6))) {
die('missing parameter');
exit;
}
if (!in_array($domain, $allowed)) {
die('forbidden domain name');
exit;
}
if (!isset($_GET['passwd']) || $_GET['passwd'] != $auth) {
die('authentification failed');
exit;
}
try {
$dbh = new PDO($dsn, $user, $pass);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
// HERE THE PROBLEM STARTS
//IPv4 UPDATE
$check = $dbh->prepare('SELECT id FROM records WHERE name = :name AND type = :type');
$check->bindParam(':name', $domain);
$check->bindValue(':type', 'A');
$check->execute();
$result = $check->fetch(PDO::FETCH_ASSOC);
if (empty($result)) {
die('record not found');
exit;
} else {
$update = $dbh->prepare('UPDATE records SET content = :content WHERE id = :id LIMIT 1');
$update->bindParam(':content', $ip);
$update->bindParam(':id', $result['id']);
// if ($update->execute()) {
// die('update successful (' . htmlentities($ip, ENT_QUOTES) . ')');
// exit;
// }
// die('update returned false');
// exit;
}
//IPv6 UPDATE
$check2 = $dbh->prepare('SELECT id FROM records WHERE name = :name AND type = :type');
$check2->bindParam2(':name', $domain6);
$check2->bindValue2(':type', 'AAAA');
$check2->execute2();
$result2 = $check2->fetch(PDO::FETCH_ASSOC);
if (empty($result2)) {
die('record not found');
exit;
} else {
$update2 = $dbh->prepare('UPDATE records SET content = :content WHERE id = :id LIMIT 1');
$update2->bindParam2(':content', $ip6);
$update2->bindParam2(':id', $result2['id']);
if ($update2->execute2()) {
die('update successful (' . htmlentities($ip, ENT_QUOTES) . ')');
exit;
}
die('update returned false');
exit;
}
?>
I already removed the die();
part in the first part of the code. I also tried to rename the variable of the second part (check -> check2). But it's still not working. What did I do wrong? Why isn't it possible to write two times in the mysql-database?
I receive a blank site without any errors. But still: The update didn't work. There is no new updated IPv6 entry in my database.