From 65ea85da39420115b8dbebad720cee2686f7d308 Mon Sep 17 00:00:00 2001 From: tracer Date: Thu, 18 Apr 2024 17:33:07 +0200 Subject: [PATCH] updated domain refresh --- composer.json | 2 +- src/Controller/CLIController.php | 17 +++++++++----- src/Controller/DomainController.php | 35 ++++++++++++++++------------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/composer.json b/composer.json index e73e17f..95e7514 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "24unix/bindapi", "description": "manage Bind9 DNS server via REST API", "version": "2023.0.1", - "build_number": "342", + "build_number": "343", "authors": [ { "name": "Micha Espey", diff --git a/src/Controller/CLIController.php b/src/Controller/CLIController.php index ff4c00b..d0434ce 100644 --- a/src/Controller/CLIController.php +++ b/src/Controller/CLIController.php @@ -911,11 +911,15 @@ class CLIController $self = $this->arguments['self'] ?? ''; if ($id == 0) { - echo 'An ID is required' . PHP_EOL; + if (!$this->quiet) { + echo 'An ID is required' . PHP_EOL; + } exit(1); } if (!$this->panelRepository->findByID(id: $id)) { - echo "Panel with ID : $id doesn't exist." . PHP_EOL; + if (!$this->quiet) { + echo "Panel with ID : $id doesn't exist." . PHP_EOL; + } exit(1); } if ($apikey) { @@ -923,11 +927,14 @@ class CLIController } else { $panel = new Panel(name: $name, id: $id, a: $a, aaaa: $aaaa, self: $self); } - var_dump($panel); if ($this->panelRepository->update(panel: $panel) !== false) { - echo 'Panel ' . COLOR_YELLOW . $id . COLOR_DEFAULT . ' has been updated' . PHP_EOL; + if (!$this->quiet) { + echo 'Panel ' . COLOR_YELLOW . $id . COLOR_DEFAULT . ' has been updated' . PHP_EOL; + } } else { - echo 'Error while updating domain server.' . PHP_EOL; + if (!$this->quiet) { + echo 'Error while updating domain server.' . PHP_EOL; + } } } diff --git a/src/Controller/DomainController.php b/src/Controller/DomainController.php index 0d37fba..20e94e9 100644 --- a/src/Controller/DomainController.php +++ b/src/Controller/DomainController.php @@ -70,35 +70,40 @@ class DomainController function updateSlaveZones(): void { - $this->logger->debug(message: 'Delete all slave zones'); + $this->logger->debug(message: 'update slave zones'); $existingZones = glob(pattern: $this->localZonesDir . '*'); $domains = $this->domainRepository->findAll(); $longestEntry = $this->domainRepository->getLongestEntry(field: 'name'); - + $self = $this->panelRepository->getSelf(); + foreach ($domains as $domain) { $zoneFile = $this->localZonesDir . $domain->getName(); if (!$this->quiet) { echo ' ' . COLOR_YELLOW . str_pad(string: $domain->getName(), length: $longestEntry + 1, pad_string: " ", pad_type: STR_PAD_RIGHT) ; } - if (!file_exists(filename: $zoneFile)) { - if (!$this->quiet) { - echo COLOR_GREEN . ' OK' . COLOR_DEFAULT . PHP_EOL; - } - $this->createSlaveZoneFile(domain: $domain); - } else { - if (($key = array_search(needle: $zoneFile, haystack: $existingZones)) !== false) { - if (isset($existingZones[$key])) { - unset($existingZones[$key]); + if (strcmp(string1: $self->getName(), string2: $domain->getPanel()) !== 0) { + if (!file_exists(filename: $zoneFile)) { + if (!$this->quiet) { + echo COLOR_GREEN . ' OK' . COLOR_DEFAULT . PHP_EOL; } + $this->createSlaveZoneFile(domain: $domain); } else { - echo 'missing value: ' . $zoneFile; - } - if (!$this->quiet) { - echo COLOR_DEFAULT . 'Zone already exists.' . PHP_EOL; + if (($key = array_search(needle: $zoneFile, haystack: $existingZones)) !== false) { + if (isset($existingZones[$key])) { + unset($existingZones[$key]); + } + } else { + echo 'missing value: ' . $zoneFile; + } + if (!$this->quiet) { + echo COLOR_DEFAULT . 'Zone already exists.' . PHP_EOL; + } } + } else { + echo COLOR_DEFAULT . 'We are master for ' . COLOR_YELLOW . $domain->getName() . PHP_EOL; } } // remove stale zones