finished check domains

Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
tracer 2022-03-01 16:43:48 +01:00
parent 7cc0f5d9f0
commit 77808f84cf
1 changed files with 38 additions and 42 deletions

View File

@ -39,7 +39,6 @@ class DomainController
}
function createIncludeFile()
{
if ($this->config['debug']) {
@ -109,15 +108,15 @@ class DomainController
echo 'Checking permission:' . PHP_EOL . PHP_EOL;
$uid = posix_geteuid();
print("UID:\t$uid" . PHP_EOL);
print("UID:\t" . COLOR_YELLOW . $uid . PHP_EOL);
$pwuid = posix_getpwuid(user_id: $uid);
$name = $pwuid['name'];
print("Name:\t$name" . PHP_EOL);
echo COLOR_DEFAULT . "Name:\t" . COLOR_YELLOW . $name . PHP_EOL;
$bindGroup = posix_getgrnam(name: 'bind');
$members = $bindGroup['members'];
if (in_array(needle: $name, haystack: $members)) {
echo "\t$name is in group 'bind" . PHP_EOL;
echo "\t$name" . COLOR_DEFAULT . ' is in group ' . COLOR_YELLOW . 'bind' . PHP_EOL;
} else {
echo "\t$name needs to be in group $bindGroup!" . PHP_EOL;
@ -153,47 +152,37 @@ class DomainController
/**
* @return array|bool
* @return void
*/
function checkDomains(): array|bool
function checkDomains(): void
{
return true;
/*
$domains = $this->findAll();
if ($namedConfLocal = file_get_contents(filename: $this->namedConfLocalFile)) {
if (!str_contains(haystack: $namedConfLocal, needle: $this->localZoneFile)) {
return "$this->localZoneFile needs to be included in $this->namedConfLocalFile . ";
}
} else {
return "No access to '$this->namedConfLocalFile' . Please check permissions";
}
if (!fileperms($this->localZoneFile)) {
return "No access to $this->localZoneFile . Please check permissions . ";
}
$localZones = file_get_contents($this->localZoneFile);
$localZones = file_get_contents(filename: $this->localZoneFile);
$maxNameLength = $this->domainRepository->getLongestEntry(field: 'name');
$domains = $this->domainRepository->findAll();
foreach ($domains as $domain) {
if(!str_contains($localZones, $domain['name'])) {
$errors[] = $domain['name'] . " is missing in '$this->localZoneFile'";
}
echo COLOR_YELLOW . str_pad(string: $domain->getName(), length: $maxNameLength + 1) . COLOR_DEFAULT;
$zoneFile = $this->localZonesDir . $domain['name'];
if (!file_exists($zoneFile)) {
$errors[] = "Missing zone file for $zoneFile . Update zone to create it";
}
}
if (empty($errors)) {
return true;
if ($this->isMasterZone(domain: $domain)) {
echo 'Master Zone lies on this panel.';
} else {
return $errors;
if (!str_contains(haystack: $localZones, needle: $domain->getName())) {
echo COLOR_RED . ' is missing in ' . COLOR_YELLOW . $this->localZoneFile . COLOR_DEFAULT;
} else {
echo $domain->getName() . ' exists in ' . COLOR_YELLOW . $this->localZoneFile;
}
*/
$zoneFile = $this->localZonesDir . $domain->getName();
if (!file_exists(filename: $zoneFile)) {
echo "Missing zone file for $zoneFile . Update zone to create it";
}
}
echo COLOR_DEFAULT . PHP_EOL;
}
}
@ -237,5 +226,12 @@ class DomainController
$this->createIncludeFile();
}
private function isMasterZone(Domain $domain): bool
{
if (file_exists(filename: '/etc/bind/keyhelp_domains/' . $domain->getName())) {
return true;
} else {
return false;
}
}
}