summaryrefslogtreecommitdiff
path: root/ddns.php
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2020-03-11 14:00:12 +0100
committerErich Eckner <git@eckner.net>2020-03-11 14:00:12 +0100
commitf4e56aea7df740b05f3ca09b5c5679f0a4f6e2f4 (patch)
treed859c20d303aced4ffe7051d972a64d97683a421 /ddns.php
parent0903bc7397d4ebe33580d0895ca535988938e35a (diff)
downloadddns-f4e56aea7df740b05f3ca09b5c5679f0a4f6e2f4.tar.xz
ddns.php: update aliases, too
Diffstat (limited to 'ddns.php')
-rw-r--r--ddns.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/ddns.php b/ddns.php
index 977e47c..afa1bfc 100644
--- a/ddns.php
+++ b/ddns.php
@@ -191,6 +191,39 @@
"send\n";
}
+ $aliasess = preg_grep('@ ' . $domain . '\b@', file('/srv/http/vhosts/eckner.net/ddns/aliases'));
+ if (count($aliasess)) {
+ $pin = popen(
+ 'dig @127.0.0.1 ddns.eckner.net AXFR' .
+ ' | sed "s/^\([^;.[:space:]]\+\)\.ddns\.eckner\.net\.\s\+\([0-9]\+\)\s\+IN\s\+\(AAAA\|A\)\s\+\(\S\+\)$/\1 \2 \3 \4/;t;d"',
+ 'r');
+ if ($pin === FALSE)
+ die_http(500, 'Internal Server Error', 'Failed to get Zone.');
+ while (!feof($pin))
+ $zone_file .= fread($pin, 1024);
+ $zone_file = explode("\n", trim($zone_file));
+ pclose($pin);
+ foreach($aliasess as $aliases) {
+ $aliases = explode(' ', trim($aliases));
+ $alias = array_shift($aliases);
+ $updateCommand .=
+ "zone ddns.eckner.net.\n" .
+ "prereq yxrrset " . $alias . ".ddns.eckner.net.\n" .
+ "update delete " . $alias . ".ddns.eckner.net.\n" .
+ "send\n";
+ foreach($aliases as $representative) {
+ foreach($zone_file as $zone_file_entry) {
+ if (preg_match('/^'.$representative.' ([0-9]+) (AAAA|A) (\S+)$/', $zone_file_entry, $match)) {
+ $updateCommand .=
+ "update add " . $alias . ".ddns.eckner.net. " . $match[1] . " IN " . $match[2] . " " . $match[3] . "\n";
+ }
+ }
+ }
+ $updateCommand .=
+ "send\n";
+ }
+ }
+
// actually do something
$pin = popen('nsupdate -l', 'w');
if ($pin === FALSE)