modified handling of slave zones

Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
tracer 2022-04-06 16:27:58 +02:00
parent 22e2d57b61
commit ddae287748
1 changed files with 35 additions and 8 deletions

View File

@ -67,6 +67,30 @@ class DomainController
} }
function updateSlaveZones()
{
if ($this->config['verbose']) {
echo 'Delete all slave zones';
}
$zones = glob(pattern: $this->localZonesDir . '*');
foreach ($zones as $zone) {
unlink(filename: $zone);
}
$domains = $this->domainRepository->findAll();
foreach ($domains as $domain) {
if ($this->config['verbose']) {
echo 'Create zone: ' . $domain->getName() . PHP_EOL;
}
$this->createSlaveZoneFile(domain: $domain);
}
$this->createIncludeFile();
}
function deleteOnNameservers(Domain $domain) function deleteOnNameservers(Domain $domain)
{ {
if ($this->config['debug']) { if ($this->config['debug']) {
@ -202,25 +226,28 @@ class DomainController
*/ */
public function createSlaveZoneFile(Domain $domain): void public function createSlaveZoneFile(Domain $domain): void
{ {
$domainName = $domain->getName();
if ($this->config['debug']) { if ($this->config['debug']) {
$domainName = $domain->getName();
$this->log->debug(message: "createZoneFile($domainName)"); $this->log->debug(message: "createZoneFile($domainName)");
} }
// check if we're a master zone // check if we're a master zone
if ($this->isMasterZone(domain: $domain)) { if ($this->isMasterZone(domain: $domain)) {
echo 'We are zone master for ' . $domain->getName() . PHP_EOL; echo 'We are zone master for ' . $domainName . PHP_EOL;
exit(1); exit(1);
} }
if ($zonefile = fopen(filename: $this->localZonesDir . $domain->getName(), mode: 'w')) { if ($zonefile = fopen(filename: $this->localZonesDir . $domainName, mode: 'w')) {
$panelName = $domain->getPanel(); $panelName = $domain->getPanel();
$panel = $this->panelRepository->findByName(name: $panelName); if (!$panel = $this->panelRepository->findByName(name: $panelName)) {
echo "Error: Panel $panelName doesn't exist." . PHP_EOL;
die();
}
$a = $panel->getA(); $a = $panel->getA();
$aaaa = $panel->getAaaa(); $aaaa = $panel->getAaaa();
fputs(stream: $zonefile, data: 'zone "' . $domain->getName() . '"' . ' IN {' . PHP_EOL); fputs(stream: $zonefile, data: 'zone "' . $domainName . '"' . ' IN {' . PHP_EOL);
fputs(stream: $zonefile, data: "\ttype slave;" . PHP_EOL); fputs(stream: $zonefile, data: "\ttype slave;" . PHP_EOL);
fputs(stream: $zonefile, data: "\tfile \"" . $this->zoneCachePath . $domain->getName() . '.db";' . PHP_EOL); fputs(stream: $zonefile, data: "\tfile \"" . $this->zoneCachePath . $domainName . '.db";' . PHP_EOL);
fputs(stream: $zonefile, data: "\tmasters {" . PHP_EOL); fputs(stream: $zonefile, data: "\tmasters {" . PHP_EOL);
if (!empty($a)) { if (!empty($a)) {
fputs(stream: $zonefile, data: "\t\t" . $a . ';' . PHP_EOL); fputs(stream: $zonefile, data: "\t\t" . $a . ';' . PHP_EOL);
@ -231,10 +258,10 @@ class DomainController
fputs(stream: $zonefile, data: "\t};" . PHP_EOL); fputs(stream: $zonefile, data: "\t};" . PHP_EOL);
fputs(stream: $zonefile, data: "};" . PHP_EOL); fputs(stream: $zonefile, data: "};" . PHP_EOL);
} }
$this->createIncludeFile();
} }
private function isMasterZone(Domain $domain): bool
public function isMasterZone(Domain $domain): bool
{ {
if (file_exists(filename: '/etc/bind/keyhelp_domains/' . $domain->getName())) { if (file_exists(filename: '/etc/bind/keyhelp_domains/' . $domain->getName())) {
return true; return true;