From d62586feb0ade99fdb834513662088aeaf71dbd2 Mon Sep 17 00:00:00 2001 From: tracer Date: Tue, 9 Apr 2024 18:45:28 +0200 Subject: [PATCH] before test on ns3 --- composer.json | 2 +- src/Controller/CLIController.php | 16 ++++++++++++---- .../Commands/CommandGroupContainer.php | 6 +++++- src/Controller/DomainController.php | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 5c92f29..054cf88 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": "327", + "build_number": "328", "authors": [ { "name": "Micha Espey", diff --git a/src/Controller/CLIController.php b/src/Controller/CLIController.php index 74147b1..cafccc9 100644 --- a/src/Controller/CLIController.php +++ b/src/Controller/CLIController.php @@ -184,8 +184,9 @@ class CLIController callback: function () { $this->domainsRefresh(); }, - mandatoryParameters: ['name'], - optionalParameters: ['A=', 'AAAA=', 'apikey=']))) +// mandatoryParameters: ['name'], +// optionalParameters: ['A=', 'AAAA=', 'apikey=']))) + description: 'Refresh domains'))) ->addCommandGroup(commandGroup: (new CommandGroup(name: 'dyndns', description: 'handle DynDNS entries')) ->addCommand(command: new Command( name: 'list', @@ -1717,10 +1718,17 @@ class CLIController foreach ($domains as $domain) { $domainCount++; echo COLOR_YELLOW . ' ' . $domain->domain; - if ($this->domainRepository->findByName(name: $domain->domain)) { + if ($domain = $this->domainRepository->findByName(name: $domain->domain)) { + $currentPanel = $domain->getPanel(); + $panelName = $panel->getName(); + if ($currentPanel !== $panelName) { + $domain->setPanel(panel: $panelName); + } + $this->domainRepository->update(domain: $domain); + echo COLOR_DEFAULT . ' updated to: ' . COLOR_YELLOW .$panelName; echo COLOR_GREEN . ' OK' . COLOR_DEFAULT . PHP_EOL; } else { - $newDomain = new Domain(name: $domain->domain, panel: $panel->getName()); + $newDomain = new Domain(name: $domain->getName(), panel: $panel->getName()); $result = $this->domainRepository->insert(domain: $newDomain); echo COLOR_DEFAULT . ' has been created with id ' . COLOR_YELLOW . $result . COLOR_DEFAULT . '.' . PHP_EOL; } diff --git a/src/Controller/Commands/CommandGroupContainer.php b/src/Controller/Commands/CommandGroupContainer.php index edbc45c..39e9ad7 100644 --- a/src/Controller/Commands/CommandGroupContainer.php +++ b/src/Controller/Commands/CommandGroupContainer.php @@ -63,9 +63,13 @@ class CommandGroupContainer if ($group = $this->findGroupByName(command: $command)) { if ($group->exec(subcommand: $subcommand)) { exit(0); + } else { + echo COLOR_DEFAULT . 'Unknown subcommand ' . COLOR_YELLOW . $subcommand . COLOR_DEFAULT .' for ' . COLOR_YELLOW . $command . COLOR_DEFAULT . '.' . PHP_EOL; + exit(1); } } else { - echo COLOR_DEFAULT . 'Unknown subcommand ' . COLOR_YELLOW . $command . ' for ' . $command . COLOR_DEFAULT . '.' . PHP_EOL; + echo COLOR_DEFAULT . 'Unknown subcommand ' . COLOR_YELLOW . $subcommand . COLOR_DEFAULT .' for ' . COLOR_YELLOW . $command . COLOR_DEFAULT . '.' . PHP_EOL; + exit(1); } } else { // check for command group and print available commands diff --git a/src/Controller/DomainController.php b/src/Controller/DomainController.php index bfa26db..69db289 100644 --- a/src/Controller/DomainController.php +++ b/src/Controller/DomainController.php @@ -52,7 +52,7 @@ class DomainController } fclose(stream: $oFile); - exec(command: '/usr/sbin/named-checkconf', output: $output, result_code: $resultCode); + exec(command: '/usr/bin/named-checkconf', output: $output, result_code: $resultCode); if ($resultCode != 0) { echo 'There was an error:' . PHP_EOL; foreach ($output as $line) {