reworked most of the check commands
This commit is contained in:
parent
d115a5d775
commit
43698c0fae
|
@ -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": "332",
|
"build_number": "333",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Micha Espey",
|
"name": "Micha Espey",
|
||||||
|
|
|
@ -53,8 +53,9 @@ class BindAPI
|
||||||
ConfigController::class => autowire()
|
ConfigController::class => autowire()
|
||||||
->constructorParameter(parameter: 'quiet', value: $quiet),
|
->constructorParameter(parameter: 'quiet', value: $quiet),
|
||||||
CLIController::class => autowire()
|
CLIController::class => autowire()
|
||||||
->constructorParameter(parameter: 'logger', value: $this->logger),
|
->constructorParameter(parameter: 'logger', value: $this->logger)
|
||||||
DomainController::class => autowire()
|
->constructorParameter(parameter: 'quiet', value: $quiet),
|
||||||
|
DomainController::class => autowire()
|
||||||
->constructorParameter(parameter: 'logger', value: $this->logger)
|
->constructorParameter(parameter: 'logger', value: $this->logger)
|
||||||
->constructorParameter(parameter: 'quiet', value: $quiet),
|
->constructorParameter(parameter: 'quiet', value: $quiet),
|
||||||
DomainRepository::class => autowire()
|
DomainRepository::class => autowire()
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -78,12 +78,17 @@ class DomainController
|
||||||
}
|
}
|
||||||
|
|
||||||
$domains = $this->domainRepository->findAll();
|
$domains = $this->domainRepository->findAll();
|
||||||
|
$longestEntry = $this->domainRepository->getLongestEntry('name');
|
||||||
|
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
if (!$this->quiet) {
|
if (!$this->quiet) {
|
||||||
echo 'Create zone: ' . $domain->getName() . PHP_EOL;
|
echo ' ' . COLOR_YELLOW . str_pad($domain->getName(), $longestEntry + 1, " ", STR_PAD_RIGHT) ;
|
||||||
|
}
|
||||||
|
if ($this->createSlaveZoneFile(domain: $domain)) {
|
||||||
|
if (!$this->quiet) {
|
||||||
|
echo COLOR_GREEN . ' OK' . COLOR_DEFAULT . PHP_EOL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->createSlaveZoneFile(domain: $domain);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->createIncludeFile();
|
$this->createIncludeFile();
|
||||||
|
@ -234,7 +239,9 @@ class DomainController
|
||||||
function checkDomains(): void
|
function checkDomains(): void
|
||||||
{
|
{
|
||||||
if (!file_exists(filename: $this->localZoneFile)) {
|
if (!file_exists(filename: $this->localZoneFile)) {
|
||||||
echo COLOR_DEFAULT . 'Local Zone file ' . COLOR_YELLOW . $this->localZoneFile . COLOR_DEFAULT . ' does not exist.' . PHP_EOL;
|
if (!$this->quiet) {
|
||||||
|
echo COLOR_DEFAULT . 'Local Zone file ' . COLOR_YELLOW . $this->localZoneFile . COLOR_DEFAULT . ' does not exist.' . PHP_EOL;
|
||||||
|
}
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
$localZones = file_get_contents(filename: $this->localZoneFile);
|
$localZones = file_get_contents(filename: $this->localZoneFile);
|
||||||
|
@ -243,20 +250,28 @@ class DomainController
|
||||||
|
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
$idString = '(' . $domain->getId() . ') ';
|
$idString = '(' . $domain->getId() . ') ';
|
||||||
echo COLOR_YELLOW .
|
if (!$this->quiet) {
|
||||||
str_pad(string: $domain->getName(), length: $maxNameLength + 1)
|
echo COLOR_YELLOW .
|
||||||
. COLOR_DEFAULT
|
str_pad(string: $domain->getName(), length: $maxNameLength + 1)
|
||||||
. str_pad(string: $idString, length: 7, pad_type: STR_PAD_LEFT);
|
. COLOR_DEFAULT
|
||||||
|
. str_pad(string: $idString, length: 7, pad_type: STR_PAD_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
$hasError = false;
|
$hasError = false;
|
||||||
if ($this->isMasterZone(domain: $domain)) {
|
if ($this->isMasterZone(domain: $domain)) {
|
||||||
echo 'Master Zone lies on this panel.';
|
if (!$this->quiet) {
|
||||||
|
echo COLOR_GREEN . 'Master Zone';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!str_contains(haystack: $localZones, needle: $domain->getName())) {
|
if (!str_contains(haystack: $localZones, needle: $domain->getName())) {
|
||||||
echo COLOR_RED . 'is missing in ' . COLOR_YELLOW . $this->localZoneFile . COLOR_DEFAULT;
|
if (!$this->quiet) {
|
||||||
|
echo COLOR_RED . 'is missing in ' . COLOR_YELLOW . $this->localZoneFile . COLOR_DEFAULT;
|
||||||
|
}
|
||||||
$hasError = true;
|
$hasError = true;
|
||||||
} else {
|
} else {
|
||||||
echo COLOR_GREEN . 'OK';
|
if (!$this->quiet) {
|
||||||
|
echo COLOR_GREEN . 'OK';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$zoneFile = $this->localZonesDir . $domain->getName();
|
$zoneFile = $this->localZonesDir . $domain->getName();
|
||||||
|
@ -270,7 +285,9 @@ class DomainController
|
||||||
echo " Update zone (Domain) to create it.";
|
echo " Update zone (Domain) to create it.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo COLOR_DEFAULT . PHP_EOL;
|
if (!$this->quiet) {
|
||||||
|
echo COLOR_DEFAULT . PHP_EOL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -281,7 +298,7 @@ class DomainController
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function createSlaveZoneFile(Domain $domain): void
|
public function createSlaveZoneFile(Domain $domain): bool
|
||||||
{
|
{
|
||||||
$domainName = $domain->getName();
|
$domainName = $domain->getName();
|
||||||
$this->logger->info(message: "createZoneFile($domainName)");
|
$this->logger->info(message: "createZoneFile($domainName)");
|
||||||
|
@ -289,14 +306,16 @@ class DomainController
|
||||||
// check if we're a master zone
|
// check if we're a master zone
|
||||||
if ($this->isMasterZone(domain: $domain)) {
|
if ($this->isMasterZone(domain: $domain)) {
|
||||||
//echo 'We are zone master for ' . $domainName . PHP_EOL;
|
//echo 'We are zone master for ' . $domainName . PHP_EOL;
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($zoneFile = fopen(filename: $this->localZonesDir . $domainName, mode: 'w')) {
|
if ($zoneFile = fopen(filename: $this->localZonesDir . $domainName, mode: 'w')) {
|
||||||
$panelName = $domain->getPanel();
|
$panelName = $domain->getPanel();
|
||||||
if (!$panel = $this->panelRepository->findByName(name: $panelName)) {
|
if (!$panel = $this->panelRepository->findByName(name: $panelName)) {
|
||||||
echo "Error: Panel $panelName doesn't exist." . PHP_EOL;
|
if (!$this->quiet) {
|
||||||
exit(1);
|
echo "Error: Panel $panelName doesn't exist." . PHP_EOL;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
$a = $panel->getA();
|
$a = $panel->getA();
|
||||||
$aaaa = $panel->getAaaa();
|
$aaaa = $panel->getAaaa();
|
||||||
|
@ -312,7 +331,13 @@ class DomainController
|
||||||
}
|
}
|
||||||
fputs(stream: $zoneFile, data: "\t};" . PHP_EOL);
|
fputs(stream: $zoneFile, data: "\t};" . PHP_EOL);
|
||||||
fputs(stream: $zoneFile, data: "};" . PHP_EOL);
|
fputs(stream: $zoneFile, data: "};" . PHP_EOL);
|
||||||
}
|
return true;
|
||||||
|
} else {
|
||||||
|
if (!$this->quiet) {
|
||||||
|
echo COLOR_RED . ' Error: ' . COLOR_DEFAULT . 'unable to create ' . COLOR_YELLOW . $this->localZonesDir . $domainName . COLOR_DEFAULT . PHP_EOL;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -218,7 +218,8 @@ readonly class DomainRepository
|
||||||
{
|
{
|
||||||
$domainName = $domain->getName();
|
$domainName = $domain->getName();
|
||||||
$this->logger->debug(message: "delete($domainName)");
|
$this->logger->debug(message: "delete($domainName)");
|
||||||
|
|
||||||
|
// FIXME, add force parameter, reject deletion if domains left on panel
|
||||||
$sql = "
|
$sql = "
|
||||||
DELETE FROM " . DatabaseConnection::TABLE_DOMAINS . "
|
DELETE FROM " . DatabaseConnection::TABLE_DOMAINS . "
|
||||||
WHERE id = :id";
|
WHERE id = :id";
|
||||||
|
|
Loading…
Reference in New Issue