updated domain refresh

This commit is contained in:
tracer 2024-04-18 17:33:07 +02:00
parent 2c65f743e7
commit 65ea85da39
3 changed files with 33 additions and 21 deletions

View File

@ -2,7 +2,7 @@
"name": "24unix/bindapi", "name": "24unix/bindapi",
"description": "manage Bind9 DNS server via REST API", "description": "manage Bind9 DNS server via REST API",
"version": "2023.0.1", "version": "2023.0.1",
"build_number": "342", "build_number": "343",
"authors": [ "authors": [
{ {
"name": "Micha Espey", "name": "Micha Espey",

View File

@ -911,11 +911,15 @@ class CLIController
$self = $this->arguments['self'] ?? ''; $self = $this->arguments['self'] ?? '';
if ($id == 0) { if ($id == 0) {
if (!$this->quiet) {
echo 'An ID is required' . PHP_EOL; echo 'An ID is required' . PHP_EOL;
}
exit(1); exit(1);
} }
if (!$this->panelRepository->findByID(id: $id)) { if (!$this->panelRepository->findByID(id: $id)) {
if (!$this->quiet) {
echo "Panel with ID : $id doesn't exist." . PHP_EOL; echo "Panel with ID : $id doesn't exist." . PHP_EOL;
}
exit(1); exit(1);
} }
if ($apikey) { if ($apikey) {
@ -923,13 +927,16 @@ class CLIController
} else { } else {
$panel = new Panel(name: $name, id: $id, a: $a, aaaa: $aaaa, self: $self); $panel = new Panel(name: $name, id: $id, a: $a, aaaa: $aaaa, self: $self);
} }
var_dump($panel);
if ($this->panelRepository->update(panel: $panel) !== false) { if ($this->panelRepository->update(panel: $panel) !== false) {
if (!$this->quiet) {
echo 'Panel ' . COLOR_YELLOW . $id . COLOR_DEFAULT . ' has been updated' . PHP_EOL; echo 'Panel ' . COLOR_YELLOW . $id . COLOR_DEFAULT . ' has been updated' . PHP_EOL;
}
} else { } else {
if (!$this->quiet) {
echo 'Error while updating domain server.' . PHP_EOL; echo 'Error while updating domain server.' . PHP_EOL;
} }
} }
}
/** /**
*/ */

View File

@ -70,12 +70,13 @@ class DomainController
function updateSlaveZones(): void function updateSlaveZones(): void
{ {
$this->logger->debug(message: 'Delete all slave zones'); $this->logger->debug(message: 'update slave zones');
$existingZones = glob(pattern: $this->localZonesDir . '*'); $existingZones = glob(pattern: $this->localZonesDir . '*');
$domains = $this->domainRepository->findAll(); $domains = $this->domainRepository->findAll();
$longestEntry = $this->domainRepository->getLongestEntry(field: 'name'); $longestEntry = $this->domainRepository->getLongestEntry(field: 'name');
$self = $this->panelRepository->getSelf();
foreach ($domains as $domain) { foreach ($domains as $domain) {
$zoneFile = $this->localZonesDir . $domain->getName(); $zoneFile = $this->localZonesDir . $domain->getName();
@ -83,6 +84,7 @@ class DomainController
echo ' ' . COLOR_YELLOW . str_pad(string: $domain->getName(), length: $longestEntry + 1, pad_string: " ", pad_type: STR_PAD_RIGHT) ; echo ' ' . COLOR_YELLOW . str_pad(string: $domain->getName(), length: $longestEntry + 1, pad_string: " ", pad_type: STR_PAD_RIGHT) ;
} }
if (strcmp(string1: $self->getName(), string2: $domain->getPanel()) !== 0) {
if (!file_exists(filename: $zoneFile)) { if (!file_exists(filename: $zoneFile)) {
if (!$this->quiet) { if (!$this->quiet) {
echo COLOR_GREEN . ' OK' . COLOR_DEFAULT . PHP_EOL; echo COLOR_GREEN . ' OK' . COLOR_DEFAULT . PHP_EOL;
@ -100,6 +102,9 @@ class DomainController
echo COLOR_DEFAULT . 'Zone already exists.' . PHP_EOL; 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 // remove stale zones
foreach ($existingZones as $zone) { foreach ($existingZones as $zone) {