diff --git a/src/Controller/DomainController.php b/src/Controller/DomainController.php index 77d283c..7945aae 100644 --- a/src/Controller/DomainController.php +++ b/src/Controller/DomainController.php @@ -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) { if ($this->config['debug']) { @@ -202,25 +226,28 @@ class DomainController */ public function createSlaveZoneFile(Domain $domain): void { + $domainName = $domain->getName(); if ($this->config['debug']) { - $domainName = $domain->getName(); $this->log->debug(message: "createZoneFile($domainName)"); } // check if we're a master zone 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); } - if ($zonefile = fopen(filename: $this->localZonesDir . $domain->getName(), mode: 'w')) { + if ($zonefile = fopen(filename: $this->localZonesDir . $domainName, mode: 'w')) { $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(); $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: "\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); if (!empty($a)) { 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: "};" . 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())) { return true;