From b877c78716d7da8bdfd37879344a9f60526d2eba Mon Sep 17 00:00:00 2001 From: tracer Date: Tue, 19 Sep 2023 18:32:03 +0200 Subject: [PATCH] made the default checkPermission always quet --- composer.json | 2 +- src/Controller/CLIController.php | 2 +- src/Controller/DomainController.php | 33 ++++++++++++++++------------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index 089b0b6..690149a 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "24unix/bindapi", "description": "manage Bind9 DNS server via REST API", "version": "2023.0.1", - "build_number": "322", + "build_number": "323", "authors": [ { "name": "Micha Espey", diff --git a/src/Controller/CLIController.php b/src/Controller/CLIController.php index 2c368cf..1e87514 100644 --- a/src/Controller/CLIController.php +++ b/src/Controller/CLIController.php @@ -263,7 +263,7 @@ class CLIController function runCheckSetup(): void { - if (!$this->domainController->checkPermissions(verbose: false)) { + if (!$this->domainController->checkPermissions(quiet: true)) { echo COLOR_RED . 'You need to setup the bindAPI first.' . COLOR_DEFAULT .PHP_EOL; } diff --git a/src/Controller/DomainController.php b/src/Controller/DomainController.php index 6d923cd..3d60cec 100644 --- a/src/Controller/DomainController.php +++ b/src/Controller/DomainController.php @@ -154,76 +154,79 @@ class DomainController $quiet = $this->configController->getConfig(configKey: 'quiet'); } - if ($verbose) { +// echo 'verbose: ' . ($verbose ? 'true' : 'false') . PHP_EOL; +// echo 'quiet: ' . ($quiet ? 'true' : 'false') . PHP_EOL; + + if ($verbose && !$quiet) { echo 'Checking permissions...' . PHP_EOL; } $uid = posix_geteuid(); - if ($verbose) { + if ($verbose && !$quiet) { echo "UID:\t" . COLOR_YELLOW . $uid . PHP_EOL; } $pwuid = posix_getpwuid(user_id: $uid); $name = $pwuid['name']; - if ($verbose) { + if ($verbose && !$quiet) { 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 ($verbose) { + if ($verbose && !$quiet) { echo "\t✅ $name" . COLOR_DEFAULT . ' is in group ' . COLOR_YELLOW . 'bind' . PHP_EOL; } } else { $setupIsValid = false; - if ($verbose) { + if ($verbose && !$quiet) { echo COLOR_RED . "\t❌$name needs to be in group " . COLOR_YELLOW . 'bind' . COLOR_DEFAULT . '!' . PHP_EOL; } } - if ($verbose) { + if ($verbose && !$quiet) { echo COLOR_DEFAULT . 'Checking ' . COLOR_YELLOW . $this->localZoneFile . PHP_EOL; } $localZoneFilePermissions = @fileperms(filename: $this->localZoneFile); if ($localZoneFilePermissions & 0x0010) { - if ($verbose) { + if ($verbose && !$quiet) { echo COLOR_DEFAULT . "\t✅ Group has write access." . PHP_EOL; } } else { $setupIsValid = false; - if ($verbose) { + if ($verbose && !$quiet) { echo COLOR_RED . "\t❌Group needs write permission!" . COLOR_DEFAULT . PHP_EOL; } } - if ($verbose) { + if ($verbose && !$quiet) { 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 ($verbose) { + if ($verbose && !$quiet) { echo "\t❌ $this->localZoneFile" . COLOR_RED . ' needs to be included in ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL; } } else { - if ($verbose) { + if ($verbose && !$quiet) { echo "\t✅ $this->localZoneFile" . COLOR_DEFAULT . ' is included in ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL; } } } else { $setupIsValid = false; - if ($verbose) { + if ($verbose && !$quiet) { echo "\t❌ No access to '$this->namedConfLocalFile' . Please check permissions" . PHP_EOL; } } - if ($verbose) { + if ($verbose && !$quiet) { echo COLOR_DEFAULT . 'Checking directory: ' . COLOR_YELLOW . $this->localZonesDir . PHP_EOL; } $localZoneDirPermissions = @fileperms(filename: $this->localZonesDir); if ($localZoneDirPermissions & 0x0010) { - if ($verbose) { + if ($verbose && !$quiet) { echo "\t✅ Group has write access." . PHP_EOL; } } else { $setupIsValid = false; - if ($verbose) { + if ($verbose && !$quiet) { echo COLOR_RED . "\t❌Group needs write permission!" . PHP_EOL; } }