mirror of
https://github.com/getnamingo/registry.git
synced 2025-08-12 20:39:20 +02:00
Fixed incorrect zone reload and sign #176
This commit is contained in:
parent
f62b19ef03
commit
ff871dd4ae
1 changed files with 62 additions and 59 deletions
|
@ -40,12 +40,14 @@ Coroutine::create(function () use ($pool, $log, $c) {
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
$timestamp = time();
|
$timestamp = time();
|
||||||
|
|
||||||
|
$tlds = [];
|
||||||
|
|
||||||
while (list($id, $tld) = $sth->fetch(PDO::FETCH_NUM)) {
|
while (list($id, $tld) = $sth->fetch(PDO::FETCH_NUM)) {
|
||||||
$tldRE = preg_quote($tld, '/');
|
$tldRE = preg_quote($tld, '/');
|
||||||
$cleanedTld = ltrim(strtolower($tld), '.');
|
$cleanedTld = ltrim(strtolower($tld), '.');
|
||||||
$zone = new Zone($cleanedTld.'.');
|
$zone = new Zone($cleanedTld.'.');
|
||||||
$zone->setDefaultTtl(3600);
|
$zone->setDefaultTtl(3600);
|
||||||
|
|
||||||
$soa = new ResourceRecord;
|
$soa = new ResourceRecord;
|
||||||
$soa->setName('@');
|
$soa->setName('@');
|
||||||
$soa->setClass(Classes::INTERNET);
|
$soa->setClass(Classes::INTERNET);
|
||||||
|
@ -67,10 +69,10 @@ Coroutine::create(function () use ($pool, $log, $c) {
|
||||||
$nsRecord->setRdata(Factory::Ns($ns . '.'));
|
$nsRecord->setRdata(Factory::Ns($ns . '.'));
|
||||||
$zone->addResourceRecord($nsRecord);
|
$zone->addResourceRecord($nsRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch domains for this TLD
|
// Fetch domains for this TLD
|
||||||
$sthDomains = $pdo->prepare('SELECT DISTINCT domain.id, domain.name FROM domain WHERE tldid = :id AND (exdate > CURRENT_TIMESTAMP OR rgpstatus = \'pendingRestore\') ORDER BY domain.name');
|
$sthDomains = $pdo->prepare('SELECT DISTINCT domain.id, domain.name FROM domain WHERE tldid = :id AND (exdate > CURRENT_TIMESTAMP OR rgpstatus = \'pendingRestore\') ORDER BY domain.name');
|
||||||
|
|
||||||
$domainIds = [];
|
$domainIds = [];
|
||||||
$sthDomains->execute([':id' => $id]);
|
$sthDomains->execute([':id' => $id]);
|
||||||
while ($row = $sthDomains->fetch(PDO::FETCH_ASSOC)) {
|
while ($row = $sthDomains->fetch(PDO::FETCH_ASSOC)) {
|
||||||
|
@ -86,7 +88,7 @@ Coroutine::create(function () use ($pool, $log, $c) {
|
||||||
$statuses[$row['domain_id']] = $row['id'];
|
$statuses[$row['domain_id']] = $row['id'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sthDomains->execute([':id' => $id]);
|
$sthDomains->execute([':id' => $id]);
|
||||||
|
|
||||||
while (list($did, $dname) = $sthDomains->fetch(PDO::FETCH_NUM)) {
|
while (list($did, $dname) = $sthDomains->fetch(PDO::FETCH_NUM)) {
|
||||||
|
@ -157,65 +159,66 @@ Coroutine::create(function () use ($pool, $log, $c) {
|
||||||
|
|
||||||
file_put_contents("{$basePath}/{$cleanedTld}.zone", $completed_zone);
|
file_put_contents("{$basePath}/{$cleanedTld}.zone", $completed_zone);
|
||||||
|
|
||||||
if ($c['dns_server'] == 'opendnssec') {
|
$tlds[] = $cleanedTld;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($tlds as $cleanedTld) {
|
||||||
|
if ($c['dns_server'] == 'bind') {
|
||||||
|
exec("rndc reload {$cleanedTld}.", $output, $return_var);
|
||||||
|
if ($return_var != 0) {
|
||||||
|
$log->error('Failed to reload BIND. ' . $return_var);
|
||||||
|
}
|
||||||
|
|
||||||
|
exec("rndc notify {$cleanedTld}.", $output, $return_var);
|
||||||
|
if ($return_var != 0) {
|
||||||
|
$log->error('Failed to notify secondary servers. ' . $return_var);
|
||||||
|
}
|
||||||
|
} elseif ($c['dns_server'] == 'nsd') {
|
||||||
|
exec("nsd-control reload", $output, $return_var);
|
||||||
|
if ($return_var != 0) {
|
||||||
|
$log->error('Failed to reload NSD. ' . $return_var);
|
||||||
|
}
|
||||||
|
} elseif ($c['dns_server'] == 'knot') {
|
||||||
|
exec("knotc reload", $output, $return_var);
|
||||||
|
if ($return_var != 0) {
|
||||||
|
$log->error('Failed to reload Knot DNS. ' . $return_var);
|
||||||
|
}
|
||||||
|
|
||||||
|
exec("knotc zone-notify {$cleanedTld}.", $output, $return_var);
|
||||||
|
if ($return_var != 0) {
|
||||||
|
$log->error('Failed to notify secondary servers. ' . $return_var);
|
||||||
|
}
|
||||||
|
} elseif ($c['dns_server'] == 'opendnssec') {
|
||||||
chown("{$basePath}/{$cleanedTld}.zone", 'opendnssec');
|
chown("{$basePath}/{$cleanedTld}.zone", 'opendnssec');
|
||||||
chgrp("{$basePath}/{$cleanedTld}.zone", 'opendnssec');
|
chgrp("{$basePath}/{$cleanedTld}.zone", 'opendnssec');
|
||||||
}
|
|
||||||
|
|
||||||
|
exec("ods-signer sign {$cleanedTld}");
|
||||||
|
sleep(1);
|
||||||
|
copy("/var/lib/opendnssec/signed/{$cleanedTld}", "/var/lib/bind/{$cleanedTld}.zone.signed");
|
||||||
|
|
||||||
|
exec("rndc reload {$cleanedTld}.", $output, $return_var);
|
||||||
|
if ($return_var != 0) {
|
||||||
|
$log->error('Failed to reload BIND. ' . $return_var);
|
||||||
|
}
|
||||||
|
|
||||||
|
exec("rndc notify {$cleanedTld}.", $output, $return_var);
|
||||||
|
if ($return_var != 0) {
|
||||||
|
$log->error('Failed to notify secondary servers. ' . $return_var);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Default
|
||||||
|
exec("rndc reload {$cleanedTld}.", $output, $return_var);
|
||||||
|
if ($return_var != 0) {
|
||||||
|
$log->error('Failed to reload BIND. ' . $return_var);
|
||||||
|
}
|
||||||
|
|
||||||
|
exec("rndc notify {$cleanedTld}.", $output, $return_var);
|
||||||
|
if ($return_var != 0) {
|
||||||
|
$log->error('Failed to notify secondary servers. ' . $return_var);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($c['dns_server'] == 'bind') {
|
|
||||||
exec("rndc reload {$cleanedTld}.", $output, $return_var);
|
|
||||||
if ($return_var != 0) {
|
|
||||||
$log->error('Failed to reload BIND. ' . $return_var);
|
|
||||||
}
|
|
||||||
|
|
||||||
exec("rndc notify {$cleanedTld}.", $output, $return_var);
|
|
||||||
if ($return_var != 0) {
|
|
||||||
$log->error('Failed to notify secondary servers. ' . $return_var);
|
|
||||||
}
|
|
||||||
} elseif ($c['dns_server'] == 'nsd') {
|
|
||||||
exec("nsd-control reload", $output, $return_var);
|
|
||||||
if ($return_var != 0) {
|
|
||||||
$log->error('Failed to reload NSD. ' . $return_var);
|
|
||||||
}
|
|
||||||
} elseif ($c['dns_server'] == 'knot') {
|
|
||||||
exec("knotc reload", $output, $return_var);
|
|
||||||
if ($return_var != 0) {
|
|
||||||
$log->error('Failed to reload Knot DNS. ' . $return_var);
|
|
||||||
}
|
|
||||||
|
|
||||||
exec("knotc zone-notify {$cleanedTld}.", $output, $return_var);
|
|
||||||
if ($return_var != 0) {
|
|
||||||
$log->error('Failed to notify secondary servers. ' . $return_var);
|
|
||||||
}
|
|
||||||
} elseif ($c['dns_server'] == 'opendnssec') {
|
|
||||||
exec("ods-signer sign {$cleanedTld}");
|
|
||||||
sleep(1);
|
|
||||||
copy("/var/lib/opendnssec/signed/{$cleanedTld}", "/var/lib/bind/{$cleanedTld}.zone.signed");
|
|
||||||
|
|
||||||
exec("rndc reload {$cleanedTld}.", $output, $return_var);
|
|
||||||
if ($return_var != 0) {
|
|
||||||
$log->error('Failed to reload BIND. ' . $return_var);
|
|
||||||
}
|
|
||||||
|
|
||||||
exec("rndc notify {$cleanedTld}.", $output, $return_var);
|
|
||||||
if ($return_var != 0) {
|
|
||||||
$log->error('Failed to notify secondary servers. ' . $return_var);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Default
|
|
||||||
exec("rndc reload {$cleanedTld}.", $output, $return_var);
|
|
||||||
if ($return_var != 0) {
|
|
||||||
$log->error('Failed to reload BIND. ' . $return_var);
|
|
||||||
}
|
|
||||||
|
|
||||||
exec("rndc notify {$cleanedTld}.", $output, $return_var);
|
|
||||||
if ($return_var != 0) {
|
|
||||||
$log->error('Failed to notify secondary servers. ' . $return_var);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$log->info('job finished successfully.');
|
$log->info('job finished successfully.');
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
$log->error('Database error: ' . $e->getMessage());
|
$log->error('Database error: ' . $e->getMessage());
|
||||||
|
@ -225,4 +228,4 @@ Coroutine::create(function () use ($pool, $log, $c) {
|
||||||
// Return the connection to the pool
|
// Return the connection to the pool
|
||||||
$pool->put($pdo);
|
$pool->put($pdo);
|
||||||
}
|
}
|
||||||
});
|
});
|
Loading…
Add table
Add a link
Reference in a new issue