diff --git a/.idea/bindAPI.iml b/.idea/bindAPI.iml index 880bd2f..905d1d5 100644 --- a/.idea/bindAPI.iml +++ b/.idea/bindAPI.iml @@ -2,7 +2,6 @@ - diff --git a/.idea/php.xml b/.idea/php.xml index ae6c920..8954636 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -1,5 +1,19 @@ + + + + + + @@ -72,9 +86,15 @@ + + + + \ No newline at end of file diff --git a/bin/console b/bin/console index 75e248c..610f564 100755 --- a/bin/console +++ b/bin/console @@ -11,13 +11,11 @@ use Exception; error_reporting(error_level: E_ALL & ~E_DEPRECATED); if (php_sapi_name() !== 'cli') { + echo 'This application must be run on the command line.' . PHP_EOL; exit; } -// version, store that somewhere else -$version = '0.0.1'; - if (!is_file(filename: dirname(path: __DIR__).'/vendor/autoload.php')) { die('Required runtime components are missing. Try running "composer install".' . PHP_EOL); } @@ -26,7 +24,7 @@ require dirname(path: __DIR__) . '/vendor/autoload.php'; $shortOpts = 'v::'; // version -$shortOpts = 'q::'; // version +$shortOpts .= 'q::'; // quiet $shortOpts .= "V::"; // verbose $shortOpts .= "h::"; // help @@ -39,28 +37,29 @@ $longOpts = [ $options = getopt(short_options: $shortOpts, long_options: $longOpts, rest_index: $restIndex); +$arguments = array_slice(array: $argv, offset: $restIndex); + if (array_key_exists(key: 'v', array: $options) || array_key_exists(key: 'version', array: $options)) { + $arguments = 'showVersion'; + $composerJson = json_decode(json: file_get_contents(filename: dirname(path: __DIR__) . '/composer.json'), associative: true); $name = $composerJson['name']; - $decription = $composerJson['decription']; + $description = $composerJson['description']; $version = $composerJson['version']; - $build_number = $composerJson['build_number']; + $buildNumber = $composerJson['build_number']; $authorName = $composerJson['authors'][0]['name']; $authorEmail = $composerJson['authors'][0]['email']; echo "Name: $name\n"; - echo "Description: $decription\n"; + echo "Description: $description\n"; echo "Version: $version\n"; - echo "Build Number: $build_number\n"; + echo "Build Number: $buildNumber\n"; echo "Author: $authorName ($authorEmail)\n"; - - print("bindAPI version: $version" . PHP_EOL); exit(0); } if (array_key_exists(key: 'h', array: $options) || array_key_exists(key: 'help', array: $options)) { - print("Help …" . PHP_EOL); - exit(0); + $arguments = "showUsage"; } if (array_key_exists(key: 'q', array: $options) || array_key_exists(key: 'quiet', array: $options)) { @@ -76,7 +75,6 @@ if (array_key_exists(key: 'V', array: $options) || array_key_exists(key: 'verbos $verbose = false; } -$arguments = array_slice(array: $argv, offset: $restIndex); try { $app = new BindAPI(verbose: $verbose, quiet: $quiet); @@ -88,13 +86,6 @@ try { } -/** - * @param String $message - * @param array $options - * @param string $default - * - * @return bool - */ function confirm(string $message = 'Are you sure? ', array $options = ['y', 'n'], string $default = 'n'): bool { // first $options means true, any other false @@ -102,7 +93,7 @@ function confirm(string $message = 'Are you sure? ', array $options = ['y', 'n'] $first = true; foreach ($options as $option) { // mark default - if ($option == $default) { + if ($option === $default) { $option = strtoupper(string: $option); } if ($first) { diff --git a/composer.json b/composer.json index 61d68bd..089b0b6 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { "name": "24unix/bindapi", - "decription": "fo", + "description": "manage Bind9 DNS server via REST API", "version": "2023.0.1", - "build_number": "1", + "build_number": "322", "authors": [ { "name": "Micha Espey", diff --git a/src/Controller/CLIController.php b/src/Controller/CLIController.php index 8c2a6ce..2c368cf 100644 --- a/src/Controller/CLIController.php +++ b/src/Controller/CLIController.php @@ -37,9 +37,6 @@ if (php_sapi_name() !== 'cli') { } -/** - * - */ class CLIController { private array $arguments; @@ -261,12 +258,12 @@ class CLIController $this->webmailDelete(); }, mandatoryParameters: ['ID']))); - } + function runCheckSetup(): void { - if (!$this->domainController->checkPermissions(disableVerbose: false)) { + if (!$this->domainController->checkPermissions(verbose: false)) { echo COLOR_RED . 'You need to setup the bindAPI first.' . COLOR_DEFAULT .PHP_EOL; } @@ -317,11 +314,6 @@ class CLIController $debug = $this->configController->getConfig(configKey: 'debug'); echo 'bindAPI version: todo (env: todo) '; - if ($debug) { - echo 'true'; - } else { - echo 'false'; - } echo COLOR_DEFAULT . ')' . PHP_EOL; echo COLOR_YELLOW . 'Usage:' . PHP_EOL; diff --git a/src/Controller/DomainController.php b/src/Controller/DomainController.php index 95ee4fc..6d923cd 100644 --- a/src/Controller/DomainController.php +++ b/src/Controller/DomainController.php @@ -141,18 +141,18 @@ class DomainController /** * @return bool */ - function checkPermissions(bool $disableVerbose = false): bool + function checkPermissions(bool $verbose = false, bool $quiet = false): bool { + $this->logger->debug(message: "checkPermissions()"); $setupIsValid = true; - - if (!$disableVerbose) { + if (!$verbose) { $verbose = $this->configController->getConfig(configKey: 'verbose'); - } else { - $verbose = false; } - $this->logger->debug(message: "checkPermissions()"); + if (!$quiet) { + $quiet = $this->configController->getConfig(configKey: 'quiet'); + } if ($verbose) { echo 'Checking permissions...' . PHP_EOL; @@ -227,7 +227,6 @@ class DomainController echo COLOR_RED . "\t❌Group needs write permission!" . PHP_EOL; } } - echo 'setup is valid:' . $setupIsValid ? 'true' : 'false'; return $setupIsValid; }