diff options
author | Erich Eckner <git@eckner.net> | 2020-02-21 23:42:48 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2020-02-21 23:42:48 +0100 |
commit | 1279067ba0777771a5ae28aa5ea6f7c44b4c451e (patch) | |
tree | d795af4f1f49a1b980db178c96af2134e392eb1d | |
parent | 9ac0cdfc639288dcb35b1b0e1b93ee2a84b7d4dd (diff) | |
download | ddns-1279067ba0777771a5ae28aa5ea6f7c44b4c451e.tar.xz |
ddns.php: set reverse records, too
-rw-r--r-- | ddns.php | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -13,6 +13,16 @@ return '120'; }; + function reverse_entry($addr) { + $addrTeile = explode('.', $addr); + return $addrTeile[3].'.'.$addrTeile[2].'.'.$addrTeile[1].'.'.$addrTeile[0].'.in-addr.arpa.'; + }; + + function reverse_zone($addr) { + $addrTeile = explode('.', $addr); + return $addrTeile[2].'.'.$addrTeile[1].'.'.$addrTeile[0].'.in-addr.arpa.'; + }; + // invalid syntax? if ((!array_key_exists('i', $_GET)) || (strlen($_GET['i']) != 64) || @@ -110,6 +120,22 @@ } $updateCommand .= "send\n"; + foreach ($ips as $i => $ip) { + if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { + $reverse_entry = reverse_entry($ip); + $updateCommand .= + "zone ".reverse_zone($ip)."\n"; + // delete old record if existing + $updateCommand .= + "prereq yxrrset " . $reverse_entry . " IN PTR\n" . + "update delete " . $reverse_entry . " IN PTR\n" . + "send\n"; + // set new records no matter what + $updateCommand .= + "update add " . $reverse_entry . " " . lifetime($ip) . " IN PTR " . $domain . ".ddns.eckner.net.\n" . + "send\n"; + } + } // actually do something $pin = popen('nsupdate -l', 'w'); |