diff options
-rw-r--r-- | dns.php | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -6,6 +6,36 @@ error_reporting(E_ALL); define("ZONEROOT", "/var/bind/pri/"); define("ZONESUFFIX", ".zone"); +function incrementserial($zonetext) { + $serial = array(""); + $newserial = ""; + + // See if we can detect a serial number + if (preg_match("/\(($|^|[[:space:]])*[0-9]{10}([[:space:]]|;|$|^)+/", $zonetext, $matches)) {; + // Only bother with the first match + preg_match("/[0-9]{10}/", $matches[0], $serial); + + $today = date("Ymd00"); + + if ($serial[0] < $today) { + $newserial = $today; + } else { + $newserial = $serial[0] + 1; + } + + // The effort below is gone to to avoid replacing more than one match with our *one* new serial number + + // Prepare a string to replace the string we found the serial in + $rebuiltstring = str_replace($serial[0], $newserial, $matches[0]); + // Escape special regex characters since we need to use preg_replace below to limit to one replacement + $escapedmatch = preg_quote($matches[0]); + + $zonetext = preg_replace("/" . $escapedmatch . "/", $rebuiltstring, $zonetext, 1); + } + + return array($zonetext, $serial[0], $newserial); +} + function sshrun($command) { $host = "misc.tghost.co.uk"; $user = "bladns.net"; @@ -48,6 +78,10 @@ function writezone($domain, $password, $zonetext) { die("somehow the password went bad"); } + if (isset($_POST['increment'])) { + $zonetext = incrementserial($zonetext)[0]; + } + $zonetext = str_replace('$', '\$', $zonetext); sshrun("echo -e \"$zonetext\" > " . ZONEROOT . "$domain" . ZONESUFFIX); @@ -67,6 +101,14 @@ if (isset($_POST['domain']) && isset($_POST['password']) && !isset($_POST['zonet ?> <form action="dns.php" method="post"> <textarea rows="24" cols="80" name="zonetext" autofocus><?php echo $zonefile; ?></textarea><br> +<?php + $arrincrement = incrementserial($zonefile); + if ($arrincrement[0] != $zonefile) { +?> + <input type="checkbox" name="increment" checked>Automatically increment <?php echo $arrincrement[1] . " to " . $arrincrement[2]; ?>?</input><br> +<?php + } +?> <input type="hidden" name="domain" value="<?php echo $_POST['domain']; ?>"> <input type="hidden" name="password" value="<?php echo $password; ?>"> <input type="submit" value="Update zonefile"><br> |