From 610c259272cadd57a19905853d75a68eb04d28c1 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Thu, 13 Apr 2017 00:31:15 +0100 Subject: Offer to automatically increment the zone serial number --- dns.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'dns.php') diff --git a/dns.php b/dns.php index ddae571..b184a95 100644 --- a/dns.php +++ b/dns.php @@ -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 ?>

+ + Automatically increment ?
+
-- cgit v1.2.3