refactored zone deletion

This commit is contained in:
tracer 2022-09-21 16:01:14 +02:00
parent f81b0451b4
commit cd5361c65b
1 changed files with 46 additions and 23 deletions

View File

@ -83,7 +83,7 @@ class DomainController
} }
$this->createSlaveZoneFile(domain: $domain); $this->createSlaveZoneFile(domain: $domain);
} }
$this->createIncludeFile(); $this->createIncludeFile();
} }
@ -98,16 +98,30 @@ class DomainController
'name' => $domain->getName() 'name' => $domain->getName()
]; ];
if (!empty($nameserver->getAaaa())) { if (!empty($nameserver->getAaaa())) {
$this->checkController->sendCommand(requestType: 'DELETE', serverName: $nameserver->getName(), versionIP: 6, apiKey: $nameserver->getApikey(), command: 'delete', serverType: 'nameserver', body: $body); $this->checkController->sendCommand(
requestType: 'DELETE',
serverName: $nameserver->getName(),
versionIP: 6,
apiKey: $nameserver->getApikey(),
command: 'delete',
serverType: 'nameserver',
body: $body);
} else { } else {
$this->checkController->sendCommand(requestType: 'DELETE', serverName: $nameserver->getName(), versionIP: 4, apiKey: $nameserver->getApikey(), command: 'delete', serverType: 'nameserver', body: $body); $this->checkController->sendCommand(
requestType: 'DELETE',
serverName: $nameserver->getName(),
versionIP: 4,
apiKey: $nameserver->getApikey(),
command: 'delete',
serverType: 'nameserver',
body: $body);
} }
} }
} }
/** /**
* @param \App\Entity\Domain $domain * @param Domain $domain
* *
* @return void * @return void
*/ */
@ -230,25 +244,34 @@ class DomainController
$domains = $this->domainRepository->findAll(); $domains = $this->domainRepository->findAll();
foreach ($domains as $domain) { foreach ($domains as $domain) {
echo COLOR_YELLOW . str_pad(string: $domain->getName(), length: $maxNameLength + 1) . COLOR_DEFAULT; $idString = '(' . strval(value: $domain->getId()) . ') ';
echo COLOR_YELLOW .
str_pad(string: $domain->getName(), length: $maxNameLength + 1)
. COLOR_DEFAULT
. str_pad(string: $idString, length: 7, pad_type: STR_PAD_LEFT);
$hasError = false;
if ($this->isMasterZone(domain: $domain)) { if ($this->isMasterZone(domain: $domain)) {
echo 'Master Zone lies on this panel.'; echo 'Master Zone lies on this panel.';
} 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; echo COLOR_RED . 'is missing in ' . COLOR_YELLOW . $this->localZoneFile . COLOR_DEFAULT;
$hasError = true;
} else { } else {
echo $domain->getName() . ' exists in ' . COLOR_YELLOW . $this->localZoneFile; echo COLOR_GREEN . 'OK';
} }
$zoneFile = $this->localZonesDir . $domain->getName(); $zoneFile = $this->localZonesDir . $domain->getName();
if (!file_exists(filename: $zoneFile)) { if (!file_exists(filename: $zoneFile)) {
echo "Missing zone file for $zoneFile . Update zone to create it"; echo ' Missing zone file for ' . COLOR_YELLOW . $zoneFile . COLOR_DEFAULT;
$hasError = true;
} }
if ($hasError) {
echo " Update zone (Domain) to create it.";
}
} }
echo COLOR_DEFAULT . PHP_EOL; echo COLOR_DEFAULT . PHP_EOL;
} }
@ -256,7 +279,7 @@ class DomainController
/** /**
* @param \App\Entity\Domain $domain * @param Domain $domain
* *
* @return void * @return void
*/ */
@ -267,11 +290,11 @@ 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;
exit(1); return;
} }
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; echo "Error: Panel $panelName doesn't exist." . PHP_EOL;
@ -279,18 +302,18 @@ class DomainController
} }
$a = $panel->getA(); $a = $panel->getA();
$aaaa = $panel->getAaaa(); $aaaa = $panel->getAaaa();
fputs(stream: $zonefile, data: 'zone "' . $domainName . '"' . ' IN {' . PHP_EOL); fputs(stream: $zoneFile, data: 'zone "' . $domainName . '"' . ' IN {' . PHP_EOL);
fputs(stream: $zonefile, data: "\ttype slave;" . PHP_EOL); fputs(stream: $zoneFile, data: "\ttype slave;" . PHP_EOL);
fputs(stream: $zonefile, data: "\tfile \"" . $this->zoneCachePath . $domainName . '.db";' . PHP_EOL); fputs(stream: $zoneFile, data: "\tfile \"" . $this->zoneCachePath . $domainName . '.db";' . PHP_EOL);
fputs(stream: $zonefile, data: "\tmasters {" . PHP_EOL); fputs(stream: $zoneFile, data: "\tmasters {" . PHP_EOL);
if (!empty($a)) { if (!empty($a)) {
fputs(stream: $zonefile, data: "\t\t" . $a . ';' . PHP_EOL); fputs(stream: $zoneFile, data: "\t\t" . $a . ';' . PHP_EOL);
} }
if (!empty($aaaa)) { if (!empty($aaaa)) {
fputs(stream: $zonefile, data: "\t\t" . $aaaa . ';' . PHP_EOL); fputs(stream: $zoneFile, data: "\t\t" . $aaaa . ';' . PHP_EOL);
} }
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);
} }
} }