summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2023-05-05 21:45:50 +0200
committerErich Eckner <git@eckner.net>2023-05-05 21:45:50 +0200
commit7cc605964b02ba21e08ca4096bb47538192b198f (patch)
tree2e05e2b19a088f2f7fd72b219bacc786c2edd236
parent1d224431db8f22452f2fa80ccaf92f2d9d4ad014 (diff)
downloadddns-7cc605964b02ba21e08ca4096bb47538192b198f.tar.xz
tor-ddns.php new for handling CNAMEs to *.onion addressesHEADmaster
-rw-r--r--tor-ddns.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/tor-ddns.php b/tor-ddns.php
new file mode 100644
index 0000000..33a1dd2
--- /dev/null
+++ b/tor-ddns.php
@@ -0,0 +1,50 @@
+<?php
+
+ // invalid syntax?
+ if ((!array_key_exists('i', $_GET)) ||
+ (strlen($_GET['i']) != 64) ||
+ (preg_match('@^[0-9A-Za-z]{64}$@', $_GET['i']) != 1))
+ die();
+
+ $line = preg_grep('@^' . $_GET['i'] . ' @', file('/srv/http/vhosts/eckner.net/ddns/tokens'));
+
+ // unknown token?
+ if (count($line) != 1)
+ die();
+
+ $domain = substr(explode(' ', implode('', $line))[1], 0, -1);
+ if (array_key_exists('address', $_GET))
+ $ip = $_GET['address'];
+ else
+ die();
+
+ if (preg_match('@^[0-9a-z]{56}\.onion@', $ip) != 1)
+ die();
+
+ $updateCommand = "zone ddns.eckner.net.\n";
+ $logContent = '';
+
+ // delete old record if existing
+ $updateCommand .=
+ "prereq yxrrset " . $domain . ".tor.ddns.eckner.net IN CNAME\n" .
+ "update delete " . $domain . ".tor.ddns.eckner.net IN CNAME\n" .
+ "send\n";
+
+ $updateCommand .=
+ "update add " . $domain . ".tor.ddns.eckner.net. 7200 IN CNAME " . $ip . "\n";
+ $logContent .=
+ date('Y-m-d H:i:s') . ' ' . $domain . ' ' . $ip . "\n";
+ $updateCommand .=
+ "send\n";
+
+ // actually do something
+ $pin = popen('nsupdate -l', 'w');
+ if ($pin === FALSE)
+ die_http(500, 'Internal Server Error', 'Failed to update Zone.');
+
+ fwrite($pin, $updateCommand);
+ pclose($pin);
+
+ file_put_contents('/srv/http/vhosts/eckner.net/ddns/log', $logContent, FILE_APPEND | LOCK_EX);
+
+ print "updated ips for domain \"" . $domain . ".ddns.eckner.net\": " . implode(", ", $ips) . "\n";