added semaphore fo zone creation

This commit is contained in:
tracer 2024-04-21 13:04:38 +02:00
parent 8784acbed9
commit 6fc85b8692
3 changed files with 52 additions and 6 deletions

View File

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

View File

@ -919,13 +919,34 @@ class CLIController
}
exit(1);
}
if (!$this->panelRepository->findByID(id: $id)) {
if (!$this->quiet) {
echo "Panel with ID : $id doesn't exist." . PHP_EOL;
}
exit(1);
}
if ($apikey) {
// sanity check for panel apikey
if (!str_contains(haystack: $apikey, needle: '.')) {
$this->exitInvalidPanelApiKey();
} else {
[$prefix, $key] = explode(separator: '.', string: $apikey);
$prefixLen = strlen(string: $prefix);
if ($prefixLen != 8) {
$errorMessage = 'The prefix must be 8 characters long';
$this->exitInvalidPanelApiKey(details: $errorMessage);
}
var_dump($prefix, $key);
echo 'Length of prefix: ' . strlen($prefix) . PHP_EOL;
echo 'Length of key: ' . strlen($key) . PHP_EOL;
die();
}
$panel = new Panel(name: $name, id: $id, a: $a, aaaa: $aaaa, passphrase: $apikey, self: $self);
} else {
$panel = new Panel(name: $name, id: $id, a: $a, aaaa: $aaaa, self: $self);
@ -1100,7 +1121,9 @@ class CLIController
if ($result['data'] == 'pong') {
echo ' ' . COLOR_GREEN . $result['data'];
} else {
echo COLOR_BLUE . ' skip' . COLOR_DEFAULT;
var_dump($result);
die;
echo COLOR_BLUE . ' xxskip' . COLOR_DEFAULT;
if (!$this->configController->getConfig(configKey: 'quiet')) {
echo ' ' . $result['data'];
}
@ -1657,8 +1680,24 @@ class CLIController
$this->domainController->checkDomains();
}
public function exitInvalidPanelApiKey(string $details = null): void
{
if (!$this->quiet) {
if ($details) {
echo COLOR_YELLOW . $details . COLOR_DEFAULT . PHP_EOL;
}
echo 'This is no valid panel apikey. A valid key looks like this one:' . PHP_EOL;
echo COLOR_YELLOW . 'A7hjZx52.u8Rzj2S5KUvqozPlQwh4k3eDCrLikL8ZYlcdPr488QkbOW2JaS6Hg5syNllgnNOpQv6TntNMzt62LiH5CTlrMovRQhMcwZzM5dOfLKzqEePFRv1y6qZ7CT9' . PHP_EOL;
}
exit(1);
}
/**
public function exitInvalidNameserverApiKey(string $details = null): void
{
echo 'fixme';
}
/**
*/
private function dynDnsPush(): void
{
@ -1775,7 +1814,7 @@ class CLIController
}
if (!empty($result['error'])) {
echo $result['data'] . PHP_EOL;
echo 'Error: ' . $result['data'] . PHP_EOL;
exit(1);
}
if (!empty($result['data'])) {

View File

@ -111,10 +111,15 @@ class DomainController
if (!$this->quiet) {
echo 'Removing stale zone: ' . COLOR_YELLOW . $zone . COLOR_DEFAULT . PHP_EOL;
}
echo $zone . PHP_EOL;
unlink(filename: $zone);
}
$this->createIncludeFile();
$semaphore = $this->localZonesDir . 'zones.flag';
if (file_exists(filename: $semaphore)) {
unlink(filename: $semaphore);
$this->createIncludeFile();
}
}
@ -323,7 +328,9 @@ class DomainController
*/
public function createSlaveZoneFile(Domain $domain): bool
{
$domainName = $domain->getName();
touch(filename: $this->localZonesDir . 'zones.flag');
$domainName = $domain->getName();
$this->logger->info(message: "createZoneFile($domainName)");
// check if we're a master zone