Compare commits

..

No commits in common. "c9b1d097c1c505e5444d3c1887cdeb2bb68f0ac4" and "5a71d5efded73daed78439542a19a9844d16b3b7" have entirely different histories.

1 changed files with 10 additions and 18 deletions

View File

@ -21,6 +21,7 @@ class DomainController
private string $localZonesDir; private string $localZonesDir;
private string $namedConfLocalFile; private string $namedConfLocalFile;
private string $zoneCachePath; private string $zoneCachePath;
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)
@ -34,6 +35,7 @@ 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';
} }
@ -47,22 +49,10 @@ class DomainController
$oFile = fopen(filename: $this->localZoneFile, mode: 'w'); $oFile = fopen(filename: $this->localZoneFile, mode: 'w');
foreach ($domains as $domain) { foreach ($domains as $domain) {
if (!$this->isMasterZone(domain: $domain)) { fputs(stream: $oFile, data: 'include "' . $this->localZonesDir . $domain->getName() . '";' . PHP_EOL);
fputs(stream: $oFile, data: 'include "' . $this->localZonesDir . $domain->getName() . '";' . PHP_EOL);
}
} }
fclose(stream: $oFile); fclose(stream: $oFile);
exec(command: '/usr/sbin/named-checkconf', output: $output, result_code: $resultCode);
if ($resultCode != 0) {
echo 'There was an error:' . PHP_EOL;
foreach ($output as $line) {
echo $line . PHP_EOL;
}
echo 'You need to fix the error before the configuration can be activated.' . PHP_EOL;
exit(1);
}
exec(command: '/usr/sbin/rndc reload'); exec(command: '/usr/sbin/rndc reload');
} }
@ -128,11 +118,12 @@ class DomainController
if (in_array(needle: $name, haystack: $members)) { if (in_array(needle: $name, haystack: $members)) {
echo "\t$name" . COLOR_DEFAULT . ' is in group ' . COLOR_YELLOW . '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 " . COLOR_YELLOW . 'bind' . COLOR_DEFAULT . '!' . PHP_EOL; echo "\t$name needs to be in group $bindGroup!" . PHP_EOL;
} }
echo COLOR_DEFAULT . 'Checking ' . COLOR_YELLOW . $this->localZoneFile . PHP_EOL; echo COLOR_DEFAULT . 'Checking ' . COLOR_YELLOW . $this->localZoneFile . PHP_EOL;
$localZoneFilePermissions = @fileperms(filename: $this->localZoneFile); $localZoneFilePermissions = fileperms(filename: $this->localZoneFile);
if ($localZoneFilePermissions & 0x0010) { if ($localZoneFilePermissions & 0x0010) {
echo COLOR_DEFAULT . "\t✅ Group has write access." . PHP_EOL; echo COLOR_DEFAULT . "\t✅ Group has write access." . PHP_EOL;
} else { } else {
@ -151,7 +142,7 @@ class DomainController
} }
echo COLOR_DEFAULT . 'Checking directory: ' . COLOR_YELLOW . $this->localZonesDir . PHP_EOL; echo COLOR_DEFAULT . 'Checking directory: ' . COLOR_YELLOW . $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 {
@ -208,8 +199,9 @@ class DomainController
} }
// check if we're a master zone // check if we're a master zone
if ($this->isMasterZone(domain: $domain)) { $keyhelpConf = file_get_contents(filename: $this->keyhelpNamedCond);
echo 'We are zone master for ' . $domain->getName() . PHP_EOL; if (str_contains(haystack: $keyhelpConf, needle: $domain->getName())) {
echo 'We a zone master for ' . $domain->getName() . PHP_EOL;
exit(1); exit(1);
} }