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

@ -24,7 +24,7 @@ class DomainController
private string $keyhelpNamedCond; private string $keyhelpNamedCond;
public function __construct(private NameserverRepository $nameserverRepository, private ApiController $checkController, private DomainRepository $domainRepository, private PanelRepository $panelRepository, private array $config, private Logger $log) public function __construct(private NameserverRepository $nameserverRepository, private ApiController $checkController, private DomainRepository $domainRepository, private PanelRepository $panelRepository, private array $config, private Logger $log)
{ {
if ($this->config['debug']) { if ($this->config['debug']) {
@ -35,11 +35,10 @@ class DomainController
$this->localZonesDir = '/etc/bind/zones/'; $this->localZonesDir = '/etc/bind/zones/';
$this->namedConfLocalFile = '/etc/bind/named.conf.local'; $this->namedConfLocalFile = '/etc/bind/named.conf.local';
$this->zoneCachePath = '/var/cache/bind/'; $this->zoneCachePath = '/var/cache/bind/';
$this-> keyhelpNamedCond = '/etc/bind/named.conf.keyhelp'; $this->keyhelpNamedCond = '/etc/bind/named.conf.keyhelp';
} }
function createIncludeFile() function createIncludeFile()
{ {
if ($this->config['debug']) { if ($this->config['debug']) {
@ -109,15 +108,15 @@ class DomainController
echo 'Checking permission:' . PHP_EOL . PHP_EOL; echo 'Checking permission:' . PHP_EOL . PHP_EOL;
$uid = posix_geteuid(); $uid = posix_geteuid();
print("UID:\t$uid" . PHP_EOL); print("UID:\t" . COLOR_YELLOW . $uid . PHP_EOL);
$pwuid = posix_getpwuid(user_id: $uid); $pwuid = posix_getpwuid(user_id: $uid);
$name = $pwuid['name']; $name = $pwuid['name'];
print("Name:\t$name" . PHP_EOL); echo COLOR_DEFAULT . "Name:\t" . COLOR_YELLOW . $name . PHP_EOL;
$bindGroup = posix_getgrnam(name: 'bind'); $bindGroup = posix_getgrnam(name: 'bind');
$members = $bindGroup['members']; $members = $bindGroup['members'];
if (in_array(needle: $name, haystack: $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 { } else {
echo "\t$name needs to be in group $bindGroup!" . PHP_EOL; echo "\t$name needs to be in group $bindGroup!" . PHP_EOL;
@ -126,7 +125,7 @@ class DomainController
echo 'Checking file: ' . $this->localZoneFile . PHP_EOL; echo 'Checking file: ' . $this->localZoneFile . PHP_EOL;
$localZoneFilePermissions = fileperms(filename: $this->localZoneFile); $localZoneFilePermissions = fileperms(filename: $this->localZoneFile);
if ($localZoneFilePermissions & 0x0010) { if ($localZoneFilePermissions & 0x0010) {
echo "\t✅ Group has write access . " . PHP_EOL; echo "\t✅ Group has write access." . PHP_EOL;
} else { } else {
echo "\t❌Group needs write permission!" . PHP_EOL; echo "\t❌Group needs write permission!" . PHP_EOL;
} }
@ -145,7 +144,7 @@ class DomainController
echo 'Checking directory: ' . $this->localZonesDir . PHP_EOL; echo 'Checking directory: ' . $this->localZonesDir . PHP_EOL;
$localZoneDirPermissions = fileperms(filename: $this->localZonesDir); $localZoneDirPermissions = fileperms(filename: $this->localZonesDir);
if ($localZoneDirPermissions & 0x0010) { if ($localZoneDirPermissions & 0x0010) {
echo "\t✅ Group has write access . " . PHP_EOL; echo "\t✅ Group has write access." . PHP_EOL;
} else { } else {
echo "\t❌Group needs write permission!" . PHP_EOL; echo "\t❌Group needs write permission!" . PHP_EOL;
} }
@ -153,47 +152,37 @@ class DomainController
/** /**
* @return array|bool * @return void
*/ */
function checkDomains(): array|bool function checkDomains(): void
{ {
$localZones = file_get_contents(filename: $this->localZoneFile);
$maxNameLength = $this->domainRepository->getLongestEntry(field: 'name');
$domains = $this->domainRepository->findAll();
return true; foreach ($domains as $domain) {
/* echo COLOR_YELLOW . str_pad(string: $domain->getName(), length: $maxNameLength + 1) . COLOR_DEFAULT;
$domains = $this->findAll();
if ($namedConfLocal = file_get_contents(filename: $this->namedConfLocalFile)) { if ($this->isMasterZone(domain: $domain)) {
if (!str_contains(haystack: $namedConfLocal, needle: $this->localZoneFile)) { echo 'Master Zone lies on this panel.';
return "$this->localZoneFile needs to be included in $this->namedConfLocalFile . "; } else {
} if (!str_contains(haystack: $localZones, needle: $domain->getName())) {
} else { echo COLOR_RED . ' is missing in ' . COLOR_YELLOW . $this->localZoneFile . COLOR_DEFAULT;
return "No access to '$this->namedConfLocalFile' . Please check permissions"; } else {
} echo $domain->getName() . ' exists in ' . COLOR_YELLOW . $this->localZoneFile;
}
if (!fileperms($this->localZoneFile)) { $zoneFile = $this->localZonesDir . $domain->getName();
return "No access to $this->localZoneFile . Please check permissions . ";
}
$localZones = file_get_contents($this->localZoneFile); if (!file_exists(filename: $zoneFile)) {
echo "Missing zone file for $zoneFile . Update zone to create it";
foreach($domains as $domain) { }
if(!str_contains($localZones, $domain['name'])) {
$errors[] = $domain['name'] . " is missing in '$this->localZoneFile'";
} }
$zoneFile = $this->localZonesDir . $domain['name'];
if (!file_exists($zoneFile)) { echo COLOR_DEFAULT . PHP_EOL;
$errors[] = "Missing zone file for $zoneFile . Update zone to create it";
}
} }
if (empty($errors)) {
return true;
} else {
return $errors;
}
*/
} }
@ -237,5 +226,12 @@ class DomainController
$this->createIncludeFile(); $this->createIncludeFile();
} }
private function isMasterZone(Domain $domain): bool
{
if (file_exists(filename: '/etc/bind/keyhelp_domains/' . $domain->getName())) {
return true;
} else {
return false;
}
}
} }