From ba20ea509ad827c71973807a20ecebe99378f05e Mon Sep 17 00:00:00 2001 From: Wildan M Date: Fri, 23 Jul 2021 00:09:21 +0700 Subject: [PATCH] Also increment SOA serial number --- src/dns/main.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/dns/main.php b/src/dns/main.php index 86f1894..7c5b75f 100644 --- a/src/dns/main.php +++ b/src/dns/main.php @@ -31,11 +31,13 @@ if ($dns_file === $replaced_file) { die("Updated, nothing changed\n"); } - if (file_put_contents($_SERVER['DNS_PATH'], $replaced_file, LOCK_EX) === false) { + preg_match('/(IN\tSOA.+?)(\d+)/s', $replaced_file, $matches); + $replaced_file = preg_replace('/(IN\tSOA.+?)(\d+)/s', '$1'.(intval($matches[2]) + 1), $replaced_file, 1); + if (!$replaced_file || file_put_contents($_SERVER['DNS_PATH'], $replaced_file, LOCK_EX) === false) { die("ERROR: unable to write config\n"); } exec($_SERVER['DNS_RELOAD']); - echo "Updated for A Record\n"; + echo "Updated for $record Record\n"; } else if ($_GET['action'] === 'del') { $dns_file = file_get_contents($_SERVER['DNS_PATH']); if (!$dns_file) { @@ -50,9 +52,11 @@ if ($dns_file === $replaced_file) { die("Updated, Nothing changed\n"); } - if (file_put_contents($_SERVER['DNS_PATH'], $replaced_file, LOCK_EX) === false) { + preg_match('/(IN\tSOA.+?)(\d+)/s', $replaced_file, $matches); + $replaced_file = preg_replace('/(IN\tSOA.+?)(\d+)/s', '$1'.(intval($matches[2]) + 1), $replaced_file, 1); + if (!$replaced_file || file_put_contents($_SERVER['DNS_PATH'], $replaced_file, LOCK_EX) === false) { die("ERROR: unable to write config\n"); } exec($_SERVER['DNS_RELOAD']); - echo "Updated for A Record\n"; + echo "Updated for $record Record\n"; }