Refactored, removed $config, added $verbose & $debug
Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
parent
5444035a09
commit
ac4cb3473e
|
@ -23,10 +23,17 @@ class DomainController
|
|||
private string $zoneCachePath;
|
||||
|
||||
|
||||
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 readonly NameserverRepository $nameserverRepository,
|
||||
private readonly ApiController $checkController,
|
||||
private readonly DomainRepository $domainRepository,
|
||||
private readonly PanelRepository $panelRepository,
|
||||
private readonly bool $verbose,
|
||||
private readonly bool $debug,
|
||||
private readonly Logger $log)
|
||||
{
|
||||
|
||||
if ($this->config['debug']) {
|
||||
if ($this->$debug) {
|
||||
$this->log->debug(message: "__construct()");
|
||||
}
|
||||
|
||||
|
@ -37,9 +44,9 @@ class DomainController
|
|||
}
|
||||
|
||||
|
||||
function createIncludeFile()
|
||||
function createIncludeFile(): void
|
||||
{
|
||||
if ($this->config['debug']) {
|
||||
if ($this->debug) {
|
||||
$this->log->debug(message: "createIncludeFile()");
|
||||
}
|
||||
|
||||
|
@ -67,9 +74,9 @@ class DomainController
|
|||
}
|
||||
|
||||
|
||||
function updateSlaveZones()
|
||||
function updateSlaveZones(): void
|
||||
{
|
||||
if ($this->config['verbose']) {
|
||||
if ($this->verbose) {
|
||||
echo 'Delete all slave zones';
|
||||
}
|
||||
|
||||
|
@ -81,7 +88,7 @@ class DomainController
|
|||
$domains = $this->domainRepository->findAll();
|
||||
|
||||
foreach ($domains as $domain) {
|
||||
if ($this->config['verbose']) {
|
||||
if ($this->verbose) {
|
||||
echo 'Create zone: ' . $domain->getName() . PHP_EOL;
|
||||
}
|
||||
$this->createSlaveZoneFile(domain: $domain);
|
||||
|
@ -91,9 +98,9 @@ class DomainController
|
|||
}
|
||||
|
||||
|
||||
function deleteOnNameservers(Domain $domain)
|
||||
function deleteOnNameservers(Domain $domain): void
|
||||
{
|
||||
if ($this->config['debug']) {
|
||||
if ($this->debug) {
|
||||
$this->log->debug(message: "deleteOnNameserver()");
|
||||
}
|
||||
|
||||
|
@ -116,9 +123,9 @@ class DomainController
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function deleteZone(Domain $domain)
|
||||
function deleteZone(Domain $domain): void
|
||||
{
|
||||
if ($this->config['debug']) {
|
||||
if ($this->debug) {
|
||||
$this->log->debug(message: "deleteZone()");
|
||||
}
|
||||
|
||||
|
@ -138,79 +145,79 @@ class DomainController
|
|||
{
|
||||
$setupIsValid = true;
|
||||
|
||||
if ($this->config['debug']) {
|
||||
if ($this->debug) {
|
||||
$this->log->debug(message: "checkPermissions()");
|
||||
}
|
||||
|
||||
if ($this->config['verbose']) {
|
||||
if ($this->verbose) {
|
||||
echo 'Checking permissions...' . PHP_EOL;
|
||||
}
|
||||
$uid = posix_geteuid();
|
||||
if ($this->config['verbose']) {
|
||||
if ($this->verbose) {
|
||||
echo "UID:\t" . COLOR_YELLOW . $uid . PHP_EOL;
|
||||
}
|
||||
$pwuid = posix_getpwuid(user_id: $uid);
|
||||
$name = $pwuid['name'];
|
||||
if ($this->config['verbose']) {
|
||||
if ($this->verbose) {
|
||||
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)) {
|
||||
if ($this->config['verbose']) {
|
||||
if ($this->verbose) {
|
||||
echo "\t✅ $name" . COLOR_DEFAULT . ' is in group ' . COLOR_YELLOW . 'bind' . PHP_EOL;
|
||||
}
|
||||
} else {
|
||||
$setupIsValid = false;
|
||||
if ($this->config['verbose']) {
|
||||
if ($this->verbose) {
|
||||
echo COLOR_RED . "\t❌$name needs to be in group " . COLOR_YELLOW . 'bind' . COLOR_DEFAULT . '!' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
if ($this->config['verbose']) {
|
||||
if ($this->verbose) {
|
||||
echo COLOR_DEFAULT . 'Checking ' . COLOR_YELLOW . $this->localZoneFile . PHP_EOL;
|
||||
}
|
||||
$localZoneFilePermissions = @fileperms(filename: $this->localZoneFile);
|
||||
if ($localZoneFilePermissions & 0x0010) {
|
||||
if ($this->config['verbose']) {
|
||||
if ($this->verbose) {
|
||||
echo COLOR_DEFAULT . "\t✅ Group has write access." . PHP_EOL;
|
||||
}
|
||||
} else {
|
||||
$setupIsValid = false;
|
||||
if ($this->config['verbose']) {
|
||||
if ($this->verbose) {
|
||||
echo COLOR_RED . "\t❌Group needs write permission!" . COLOR_DEFAULT . PHP_EOL;
|
||||
}
|
||||
}
|
||||
if ($this->config['verbose']) {
|
||||
if ($this->verbose) {
|
||||
echo 'Checking ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL;
|
||||
}
|
||||
if ($namedConfLocal = file_get_contents(filename: $this->namedConfLocalFile)) {
|
||||
if (!str_contains(haystack: $namedConfLocal, needle: $this->localZoneFile)) {
|
||||
$setupIsValid = false;
|
||||
if ($this->config['verbose']) {
|
||||
if ($this->verbose) {
|
||||
echo "\t❌ $this->localZoneFile" . COLOR_RED . ' needs to be included in ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL;
|
||||
}
|
||||
} else {
|
||||
if ($this->config['verbose']) {
|
||||
if ($this->verbose) {
|
||||
echo "\t✅ $this->localZoneFile" . COLOR_DEFAULT . ' is included in ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$setupIsValid = false;
|
||||
if ($this->config['verbose']) {
|
||||
if ($this->verbose) {
|
||||
echo "\t❌ No access to '$this->namedConfLocalFile' . Please check permissions" . PHP_EOL;
|
||||
}
|
||||
}
|
||||
if ($this->config['verbose']) {
|
||||
if ($this->verbose) {
|
||||
echo COLOR_DEFAULT . 'Checking directory: ' . COLOR_YELLOW . $this->localZonesDir . PHP_EOL;
|
||||
}
|
||||
$localZoneDirPermissions = @fileperms(filename: $this->localZonesDir);
|
||||
if ($localZoneDirPermissions & 0x0010) {
|
||||
if ($this->config['verbose']) {
|
||||
if ($this->verbose) {
|
||||
echo "\t✅ Group has write access." . PHP_EOL;
|
||||
}
|
||||
} else {
|
||||
$setupIsValid = false;
|
||||
if ($this->config['verbose']) {
|
||||
if ($this->verbose) {
|
||||
echo COLOR_RED . "\t❌Group needs write permission!" . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
@ -224,7 +231,7 @@ class DomainController
|
|||
*/
|
||||
function checkDomains(): void
|
||||
{
|
||||
if (!file_exists($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;
|
||||
exit(1);
|
||||
}
|
||||
|
@ -266,7 +273,7 @@ class DomainController
|
|||
public function createSlaveZoneFile(Domain $domain): void
|
||||
{
|
||||
$domainName = $domain->getName();
|
||||
if ($this->config['debug']) {
|
||||
if ($this->debug) {
|
||||
$this->log->debug(message: "createZoneFile($domainName)");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue