From 16c2130e0b562f2452e5f2aa4e48e9e7345c22e8 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Sun, 28 Dec 2025 01:46:05 +0000 Subject: Add support for updating TXT records. --- dns.php | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 3 deletions(-) diff --git a/dns.php b/dns.php index 95ace68..7ca8174 100644 --- a/dns.php +++ b/dns.php @@ -212,6 +212,63 @@ if (isset($_GET['mode']) && isset($_GET['zone']) && isset($_GET['hash'])) { writezone($_GET['zone'], $newzonetext); echo "

record(s) updated :)

"; } + + } else if ($_GET['mode'] == "txt" && isset($_POST['record'])) { + $zonetext = getzone($_GET['zone']); + // Only use \n for newlines + $zonetext = str_replace("\r", "", $zonetext); + // Split into individual lines + $zonelines = explode("\n", $zonetext); + $matches = array(); + // Find lines that ended with the hash provided (if any) + $i = 0; + foreach ($zonelines as $line) { + if (preg_match("/^[^;].*;.*" . $_GET['hash'] . "$/", $line)) { + array_push($matches, array($i, $line)); + } + $i++; + } + + // Go through the lines that matched the hash and see if we can find an update to do + foreach ($matches as $arrline) { + $line = $arrline[1]; + // Get rid of the comment + $exploded = explode(";", $line); + $record = $exploded[0]; + // Split into individual components + $parts = preg_split("/\s+/", $record); + // Make sure the last element isn't blank (would happen if the comment had a space before it) + while ($parts[sizeof($parts) - 1] == "") { + array_pop($parts); + } + + $parts[sizeof($parts) - 1] = $_POST['record']; + + // Update original zone file array with the new line at the correct position + $zonelines[$arrline[0]] = preg_replace('/((TXT|txt)\s+)[^;]+(;.*)/', "$1" . $parts[sizeof($parts) - 1] . " $3", $line); + } + + // Next we need to turn the zone file array back into a string again + $newzonetext = ""; + // If the last element was blank, remove it since we'll add a new blank ourselves + if ($zonelines[sizeof($zonelines) - 1] == "") { + array_pop($zonelines); + } + // Do the actual converstion to string + foreach ($zonelines as $line) { + $newzonetext .= $line . "\n"; + } + // See if there was actually a change as a result of this request... + if ($zonetext == $newzonetext) { + // ...if not, abandon ship + echo "

no changes detected :)

"; + } else { + // ...if so, increment the serial number and... + $newzonetext = incrementserial($newzonetext)[0]; + // ...finally write the zone with the updated record(s) + writezone($_GET['zone'], $newzonetext); + echo "

record(s) updated :)

"; + } } } else if (isset($_POST['domain']) && isset($_POST['password']) && !isset($_POST['zonetext'])) { if (!preg_match('/^[0-9A-Za-z\.\-]*$/', $_POST['domain'])) { @@ -224,14 +281,19 @@ if (isset($_GET['mode']) && isset($_GET['zone']) && isset($_GET['hash'])) { ?>

1. Your zonefile is below.

2. Ensure the first line always ends with a SHA-256 hash of your chosen password.

-

3. To automatically update a particular record, give the line a comment ending with a secret ID (e.g. a SHA-256 hash), e.g.:

+

3. To automatically update a particular A or AAAA record with the source IP address of your request, give the line a comment ending with a secret ID (e.g. a SHA-256 hash), e.g.:

 test    300     IN      A       192.168.0.1 ; sha256 = 7f480e744a79953eb916b68f540e0eeec6f9cf23edf4aa08cc1cdf5f077c0f6f
 test    300     IN      AAAA    ::1 ; sha256 = b493d48364afe44d11c0165cf470a4164d1e2609911ef998be868d46ade3de4e
     
-

And then do an HTTP(S) request to:

+

Then do an HTTP(S) GET request to:

https://bladns.net/dns.php?mode=update&zone=yourdomain.tld&hash=yourid
-

Your record will be updated with the IP you did the request from.

+

Your record will be updated with the IP address you did the request from.

+

4. To update a TXT record, do an HTTP(S) POST request to:

+
https://bladns.net/dns.php?mode=txt&zone=yourdomain.tld&hash=yourid
+

Include a POST value named "record" containing the text you would like in the TXT record. Example cURL:

+
curl "https://bladns.net/dns.php?mode=txt&zone=yourdomain.tld&hash=yourid" --data-raw 'record="foo bar baz"'
+