Added two additional zone serial algorithms

This commit is contained in:
Pinga 2024-11-21 12:42:11 +02:00
parent c4ea5b7993
commit 12ece7d8ae
3 changed files with 26 additions and 2 deletions

View file

@ -45,6 +45,7 @@ return [
// ... more name servers as needed ... // ... more name servers as needed ...
], ],
'dns_soa' => 'hostmaster.example.com', 'dns_soa' => 'hostmaster.example.com',
'dns_serial' => 1, // change to 2 for YYYYMMDDXX format, and 3 for Cloudflare-like serial
'zone_mode' => 'default', // nice is also available 'zone_mode' => 'default', // nice is also available
// URS Configuration // URS Configuration

View file

@ -284,3 +284,26 @@ function processUrlAbuseData($fileContent) {
function checkUrlAbuse($domain, Map $urlAbuseData) { function checkUrlAbuse($domain, Map $urlAbuseData) {
return $urlAbuseData->get($domain, false); return $urlAbuseData->get($domain, false);
} }
function generateSerial($soa_type = null) {
// Default to Type 1 if $soa_type is not set, null, or invalid
$soa_type = $soa_type ?? 1;
switch ($soa_type) {
case 2: // Date-based, updates every 15 minutes
$hour = (int) date('H');
$segment = (int)(date('i') / 15); // 0 through 3
$offset = $hour * 4 + $segment; // Converts hour + quarter into a unique number
return date('Ymd') . str_pad($offset, 2, '0', STR_PAD_LEFT);
case 3: // Cloudflare-like serial
$referenceTimestamp = strtotime("2020-11-01 00:00:00"); // Reference point
$timeDifference = time() - $referenceTimestamp; // Difference in seconds
$serial = $timeDifference + 2350000000; // Offset to ensure longer serials
return $serial;
case 1: // Fixed-length, second-based serial (default)
default:
return time();
}
}

View file

@ -38,7 +38,7 @@ Coroutine::create(function () use ($pool, $log, $c) {
$pdo = $pool->get(); $pdo = $pool->get();
$sth = $pdo->prepare('SELECT id, tld FROM domain_tld'); $sth = $pdo->prepare('SELECT id, tld FROM domain_tld');
$sth->execute(); $sth->execute();
$timestamp = time(); $serial = generateSerial($c['dns_serial'] ?? 1);
$tlds = []; $tlds = [];
@ -54,7 +54,7 @@ Coroutine::create(function () use ($pool, $log, $c) {
$soa->setRdata(Factory::Soa( $soa->setRdata(Factory::Soa(
$c['ns']['ns1'] . '.', $c['ns']['ns1'] . '.',
$c['dns_soa'] . '.', $c['dns_soa'] . '.',
$timestamp, $serial,
900, 900,
1800, 1800,
3600000, 3600000,