fixed a display bug listing avalable subcommands

This commit is contained in:
tracer 2024-04-08 19:01:13 +02:00
parent 4189d35c09
commit 6f16cfd76c
8 changed files with 161 additions and 126 deletions

View File

@ -2,7 +2,7 @@
"name": "24unix/bindapi", "name": "24unix/bindapi",
"description": "manage Bind9 DNS server via REST API", "description": "manage Bind9 DNS server via REST API",
"version": "2023.0.1", "version": "2023.0.1",
"build_number": "326", "build_number": "327",
"authors": [ "authors": [
{ {
"name": "Micha Espey", "name": "Micha Espey",

View File

@ -28,7 +28,7 @@ class BindAPI
/** /**
* @throws Exception * @throws Exception
*/ */
public function __construct($verbose = false, $quiet = false) public function __construct($quiet = false)
{ {
// init the logger // init the logger
$dateFormat = "Y:m:d H:i:s"; $dateFormat = "Y:m:d H:i:s";
@ -51,8 +51,7 @@ class BindAPI
$containerBuilder = new ContainerBuilder(); $containerBuilder = new ContainerBuilder();
$containerBuilder->addDefinitions([ $containerBuilder->addDefinitions([
ConfigController::class => autowire() ConfigController::class => autowire()
->constructorParameter(parameter: 'quiet', value: $quiet) ->constructorParameter(parameter: 'quiet', value: $quiet),
->constructorParameter(parameter: 'verbose', value: $verbose),
CLIController::class => autowire() CLIController::class => autowire()
->constructorParameter(parameter: 'logger', value: $this->logger), ->constructorParameter(parameter: 'logger', value: $this->logger),
DomainController::class => autowire() DomainController::class => autowire()

View File

@ -66,7 +66,7 @@ class CLIController
callback: function () { callback: function () {
$this->checkPermissions(); $this->checkPermissions();
}, },
description: 'health checks the system can perform')) description: 'check file permissions'))
->addCommand(command: new Command( ->addCommand(command: new Command(
name: 'panels', name: 'panels',
callback: function () { callback: function () {
@ -128,7 +128,7 @@ class CLIController
$this->panelsUpdate(); $this->panelsUpdate();
}, },
mandatoryParameters: ['ID'], mandatoryParameters: ['ID'],
optionalParameters: ['name=<name>', 'A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>'])) optionalParameters: ['name=<name>', 'A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>', 'self=<0|1>']))
->addCommand(command: new Command( ->addCommand(command: new Command(
name: 'delete', name: 'delete',
callback: function () { callback: function () {
@ -237,27 +237,27 @@ class CLIController
callback: function () { callback: function () {
$this->apikeysDelete(); $this->apikeysDelete();
}, },
mandatoryParameters: ['ID'])))
->addCommandGroup(commandGroup: (new CommandGroup(name: 'webmail', description: 'manage webmail setup'))
->addCommand(command: new Command(
name: 'check',
callback: function () {
$this->webmailCheck();
},
mandatoryParameters: ['example.com']
))
->addCommand(command: new Command(
name: 'create',
callback: function () {
$this->webmailCreate();
},
mandatoryParameters: ['example.com']))
->addCommand(command: new Command(
name: 'delete',
callback: function () {
$this->webmailDelete();
},
mandatoryParameters: ['ID']))); mandatoryParameters: ['ID'])));
// ->addCommandGroup(commandGroup: (new CommandGroup(name: 'webmail', description: 'manage webmail setup'))
// ->addCommand(command: new Command(
// name: 'check',
// callback: function () {
// $this->webmailCheck();
// },
// mandatoryParameters: ['example.com']
// ))
// ->addCommand(command: new Command(
// name: 'create',
// callback: function () {
// $this->webmailCreate();
// },
// mandatoryParameters: ['example.com']))
// ->addCommand(command: new Command(
// name: 'delete',
// callback: function () {
// $this->webmailDelete();
// },
// mandatoryParameters: ['ID'])));
} }
@ -314,7 +314,6 @@ class CLIController
$this->logger->debug(message: "showUsage()"); $this->logger->debug(message: "showUsage()");
$debug = $this->configController->getConfig(configKey: 'debug'); $debug = $this->configController->getConfig(configKey: 'debug');
echo 'bindAPI version: todo (env: todo) ';
echo COLOR_DEFAULT . ')' . PHP_EOL; echo COLOR_DEFAULT . ')' . PHP_EOL;
echo COLOR_YELLOW . 'Usage:' . PHP_EOL; echo COLOR_YELLOW . 'Usage:' . PHP_EOL;
@ -322,7 +321,7 @@ class CLIController
echo COLOR_YELLOW . 'Options:' . PHP_EOL; echo COLOR_YELLOW . 'Options:' . PHP_EOL;
echo COLOR_GREEN . "\t-v, --version\t\t" . COLOR_DEFAULT . "Display the version of the API" . PHP_EOL; echo COLOR_GREEN . "\t-v, --version\t\t" . COLOR_DEFAULT . "Display the version of the API" . PHP_EOL;
echo COLOR_GREEN . "\t-V, --verbose\t\t" . COLOR_DEFAULT . "All :lists command are auto-verbose" . PHP_EOL . PHP_EOL; echo COLOR_GREEN . "\t-q, --quiet\t\t" . COLOR_DEFAULT . "No output to stdout, for cronjobs" . PHP_EOL . PHP_EOL;
echo COLOR_YELLOW . 'Arguments: ' . COLOR_WHITE . '<mandatory> {optional}' . PHP_EOL; echo COLOR_YELLOW . 'Arguments: ' . COLOR_WHITE . '<mandatory> {optional}' . PHP_EOL;
@ -339,7 +338,7 @@ class CLIController
$this->logger->debug(message: "checkPermissions()"); $this->logger->debug(message: "checkPermissions()");
if (!$this->domainController->checkPermissions()) { if (!$this->domainController->checkPermissions()) {
if ($this->configController->getConfig(configKey: 'verbose')) { if (!$this->configController->getConfig(configKey: 'quiet')) {
echo PHP_EOL . COLOR_DEFAULT; echo PHP_EOL . COLOR_DEFAULT;
echo 'Missing permissions, please run ' . COLOR_YELLOW . './bin/console check:setup' . COLOR_DEFAULT . ' as root or with sudo.' . PHP_EOL; echo 'Missing permissions, please run ' . COLOR_YELLOW . './bin/console check:setup' . COLOR_DEFAULT . ' as root or with sudo.' . PHP_EOL;
} }
@ -482,7 +481,6 @@ class CLIController
$encryptionKey = $this->configController->getConfig(configKey: 'encryptionKey'); $encryptionKey = $this->configController->getConfig(configKey: 'encryptionKey');
$decryptedKey = $this->encryptionController->safeDecrypt(encrypted: $panel->getApikey(), key: $encryptionKey); $decryptedKey = $this->encryptionController->safeDecrypt(encrypted: $panel->getApikey(), key: $encryptionKey);
if ($this->configController->getConfig(configKey: 'verbose')) {
if (empty($panel->getA())) { if (empty($panel->getA())) {
$panelRequest = $this->apiController->sendCommand( $panelRequest = $this->apiController->sendCommand(
requestType: 'GET', requestType: 'GET',
@ -509,9 +507,6 @@ class CLIController
$responseTime = 'n/a'; $responseTime = 'n/a';
} }
echo COLOR_DEFAULT . ' KeyHelp version: ' . $panelVersion . " ($responseTime seconds)" . PHP_EOL; echo COLOR_DEFAULT . ' KeyHelp version: ' . $panelVersion . " ($responseTime seconds)" . PHP_EOL;
} else {
echo PHP_EOL;
}
if (empty($panel->getA())) { if (empty($panel->getA())) {
$result = $this->apiController->sendCommand( $result = $this->apiController->sendCommand(
@ -567,6 +562,7 @@ class CLIController
$domainCount = 0; $domainCount = 0;
foreach ($tmpDomainList as $domain) { foreach ($tmpDomainList as $domain) {
echo COLOR_DEFAULT . " Domain: " . COLOR_YELLOW . str_pad(string: $domain->getDomain(), length: $maxDomainNameLength); echo COLOR_DEFAULT . " Domain: " . COLOR_YELLOW . str_pad(string: $domain->getDomain(), length: $maxDomainNameLength);
if (!$domain->isSubdomain()) { if (!$domain->isSubdomain()) {
$this->checkNS(domainName: $domain->getDomain(), panel: $panel); $this->checkNS(domainName: $domain->getDomain(), panel: $panel);
$domainCount++; $domainCount++;
@ -610,7 +606,7 @@ class CLIController
} }
} }
echo "fould domain ***" . $foundDomain . PHP_EOL; echo "found domain ***" . $foundDomain . PHP_EOL;
/* /*
// system domain // system domain
@ -937,13 +933,7 @@ class CLIController
} }
} }
} }
if (!$this->configController->getConfig(configKey: 'quiet')) {
echo PHP_EOL;
}
if ($error) { if ($error) {
if (!$this->configController->getConfig(configKey: 'verbose')) {
echo 'There were errors, run command with -V (or -verbose) to see the errors.' . PHP_EOL;
}
exit(1); exit(1);
} else { } else {
exit(0); exit(0);
@ -1002,7 +992,7 @@ class CLIController
$a = $server->getA() ?? ''; $a = $server->getA() ?? '';
if (!empty($a)) { if (!empty($a)) {
$this->logger->debug("check a"); $this->logger->debug("check a");
if ($this->configController->getConfig(configKey: 'verbose')) { if (!$this->configController->getConfig(configKey: 'quiet')) {
echo COLOR_DEFAULT . ' ' . str_pad(string: $a, length: $maxA, pad_type: STR_PAD_LEFT) . ' '; echo COLOR_DEFAULT . ' ' . str_pad(string: $a, length: $maxA, pad_type: STR_PAD_LEFT) . ' ';
} }
if ($result = $this->apiController->sendCommand( if ($result = $this->apiController->sendCommand(
@ -1017,7 +1007,7 @@ class CLIController
echo ' ' . COLOR_GREEN . $result['data']; echo ' ' . COLOR_GREEN . $result['data'];
} else { } else {
echo COLOR_BLUE . ' skip' . COLOR_DEFAULT; echo COLOR_BLUE . ' skip' . COLOR_DEFAULT;
if ($this->configController->getConfig(configKey: 'verbose')) { if (!$this->configController->getConfig(configKey: 'quiet')) {
echo ' ' . $result['data']; echo ' ' . $result['data'];
} }
} }
@ -1029,7 +1019,7 @@ class CLIController
$aaaa = $server->getAaaa() ?? ''; $aaaa = $server->getAaaa() ?? '';
if (!empty($aaaa)) { if (!empty($aaaa)) {
$this->logger->debug("check aaaa"); $this->logger->debug("check aaaa");
if ($this->configController->getConfig(configKey: 'verbose')) { if (!$this->configController->getConfig(configKey: 'quiet')) {
echo COLOR_DEFAULT . ' ' . str_pad(string: $aaaa, length: $maxAAAA, pad_type: STR_PAD_LEFT) . ' '; echo COLOR_DEFAULT . ' ' . str_pad(string: $aaaa, length: $maxAAAA, pad_type: STR_PAD_LEFT) . ' ';
} }
if ($result = $this->apiController->sendCommand( if ($result = $this->apiController->sendCommand(
@ -1044,7 +1034,7 @@ class CLIController
echo ' ' . COLOR_GREEN . $result['data']; echo ' ' . COLOR_GREEN . $result['data'];
} else { } else {
echo COLOR_BLUE . ' skip' . COLOR_DEFAULT; echo COLOR_BLUE . ' skip' . COLOR_DEFAULT;
if ($this->configController->getConfig(configKey: 'verbose')) { if (!$this->configController->getConfig(configKey: 'quiet')) {
echo ' ' . $result['data']; echo ' ' . $result['data'];
} }
} }
@ -1270,23 +1260,24 @@ class CLIController
} }
if ($this->configController->getConfig(configKey: 'verbose')) { if (!$this->configController->getConfig(configKey: 'quiet')) {
echo "Found domain: " . COLOR_YELLOW . $foundDomain . COLOR_DEFAULT . PHP_EOL; echo "Found domain: " . COLOR_YELLOW . $foundDomain . COLOR_DEFAULT . PHP_EOL;
} }
// get host // get host
if ($this->dynDNSRepository->findByName(name: $name)) { if ($this->dynDNSRepository->findByName(name: $name)) {
if ($this->configController->getConfig(configKey: 'verbose')) { if (!$this->configController->getConfig(configKey: 'quiet')) {
echo "DynDNS host " . COLOR_YELLOW . $name . COLOR_DEFAULT . "already exists." . PHP_EOL; echo "DynDNS host " . COLOR_YELLOW . $name . COLOR_DEFAULT . "already exists." . PHP_EOL;
exit(0); exit(0);
} }
} else { } else {
if ($this->configController->getConfig(configKey: 'verbose')) { if (!$this->configController->getConfig(configKey: 'quiet')) {
echo "DynDNS host " . COLOR_YELLOW . $name . COLOR_DEFAULT . "will be created." . PHP_EOL; echo "DynDNS host " . COLOR_YELLOW . $name . COLOR_DEFAULT . "will be created." . PHP_EOL;
// insert in db // insert in db
$dyndnsHost = new DynDNS(name: $name); $dyndnsHost = new DynDNS(name: $name);
$dyndnsHost->setName($name); // why is the property set in the cunstructor and afterwards again? FIXME
$dyndnsHost->setName(name: $name);
} }
} }
@ -1610,7 +1601,7 @@ class CLIController
exit(1); exit(1);
} }
if ($this->configController->getConfig(configKey: 'verbose')) { if (!$this->configController->getConfig(configKey: 'quiet')) {
echo "Updating DynDNS host: $hostName" . PHP_EOL; echo "Updating DynDNS host: $hostName" . PHP_EOL;
} }
@ -1645,7 +1636,7 @@ class CLIController
} }
if ($result['header'] == 200) { if ($result['header'] == 200) {
if ($this->configController->getConfig(configKey: 'verbose')) { if (!$this->configController->getConfig(configKey: 'quiet')) {
$data = $result['data']; $data = $result['data'];
$decodedData = json_decode(json: $data, associative: true); $decodedData = json_decode(json: $data, associative: true);
echo $decodedData['message'] . PHP_EOL; echo $decodedData['message'] . PHP_EOL;
@ -1746,7 +1737,6 @@ class CLIController
public function webmailCheck(): void public function webmailCheck(): void
{ {
$quiet = $this->configController->getConfig(configKey: 'quiet'); $quiet = $this->configController->getConfig(configKey: 'quiet');
$verbose = $this->configController->getConfig(configKey: 'verbose');
if (empty($this->arguments[1])) { if (empty($this->arguments[1])) {
if (!$quiet) { if (!$quiet) {
@ -1783,7 +1773,7 @@ class CLIController
$webmailDomain = 'webmail.' . $domainName; $webmailDomain = 'webmail.' . $domainName;
if (!empty($panel->getAAAA())) { if (!empty($panel->getAAAA())) {
if (!$quiet && $verbose) { if (!$quiet) {
echo 'Check using IPv6: ' . COLOR_YELLOW . $panel->getAaaa() . '.' . COLOR_DEFAULT . PHP_EOL; echo 'Check using IPv6: ' . COLOR_YELLOW . $panel->getAaaa() . '.' . COLOR_DEFAULT . PHP_EOL;
} }
$result = $this->apiController->sendCommand( $result = $this->apiController->sendCommand(
@ -1794,7 +1784,7 @@ class CLIController
command: 'domains/name/' . $webmailDomain, command: 'domains/name/' . $webmailDomain,
serverType: 'panel'); serverType: 'panel');
} else { } else {
if (!$quiet && $verbose) { if (!$quiet) {
echo 'Check using IPv4: ' . COLOR_YELLOW . $panel->getA() . COLOR_DEFAULT . PHP_EOL; echo 'Check using IPv4: ' . COLOR_YELLOW . $panel->getA() . COLOR_DEFAULT . PHP_EOL;
} }
$result = $this->apiController->sendCommand( $result = $this->apiController->sendCommand(

View File

@ -46,10 +46,6 @@ class CommandGroupContainer
} }
/**
* @param string $command
* @return ?CommandGroup
*/
private function findGroupByName(string $command): ?CommandGroup private function findGroupByName(string $command): ?CommandGroup
{ {
foreach ($this->commandGroups as $group) { foreach ($this->commandGroups as $group) {
@ -70,13 +66,12 @@ class CommandGroupContainer
} }
} else { } else {
echo COLOR_DEFAULT . 'Unknown subcommand ' . COLOR_YELLOW . $command . ' for ' . $command . COLOR_DEFAULT . '.' . PHP_EOL; echo COLOR_DEFAULT . 'Unknown subcommand ' . COLOR_YELLOW . $command . ' for ' . $command . COLOR_DEFAULT . '.' . PHP_EOL;
} }
} else { } else {
// check for command group and print available commands // check for command group and print available commands
foreach ($this->commandGroups as $group) { foreach ($this->commandGroups as $group) {
echo 'Available subcommands for : ' . COLOR_YELLOW . $group->getName() . COLOR_DEFAULT . ':' . PHP_EOL;
if ($group->getName() === $command) { if ($group->getName() === $command) {
echo 'Available subcommands for : ' . COLOR_YELLOW . $group->getName() . COLOR_DEFAULT . ':' . PHP_EOL;
$group->printCommands(strlen(string: $group->getName())); $group->printCommands(strlen(string: $group->getName()));
exit(0); exit(0);
} }

View File

@ -10,11 +10,10 @@ class ConfigController
private array $config; private array $config;
/** /**
* @param bool $verbose
* @param bool $quiet * @param bool $quiet
* @param bool $test * @param bool $test
*/ */
public function __construct(bool $verbose = false, bool $quiet = false, bool $test = false) public function __construct(private readonly bool $quiet = false, bool $test = false)
{ {
if ($test) { if ($test) {
@ -51,7 +50,6 @@ class ConfigController
$this->config = json_decode(json: $configJSON, associative: true); $this->config = json_decode(json: $configJSON, associative: true);
$this->config['verbose'] = (bool)$verbose;
$this->config['quiet'] = (bool)$quiet; $this->config['quiet'] = (bool)$quiet;
$this->config['test'] = (bool)$test; $this->config['test'] = (bool)$test;
} }

View File

@ -78,9 +78,8 @@ class DomainController
$domains = $this->domainRepository->findAll(); $domains = $this->domainRepository->findAll();
foreach ($domains as $domain) { foreach ($domains as $domain) {
if ($this->configController->getConfig(configKey: 'verbose')) { // FIXME check for quiet
echo 'Create zone: ' . $domain->getName() . PHP_EOL; echo 'Create zone: ' . $domain->getName() . PHP_EOL;
}
$this->createSlaveZoneFile(domain: $domain); $this->createSlaveZoneFile(domain: $domain);
} }
@ -138,23 +137,18 @@ class DomainController
} }
function checkPermissions(bool $verbose = false, bool $quiet = false, $impersonatedUserId = null): bool function checkPermissions(bool $quiet = false, $impersonatedUserId = null): bool
{ {
$this->logger->debug(message: "checkPermissions()"); $this->logger->debug(message: "checkPermissions()");
$setupIsValid = true; $setupIsValid = true;
if (!$verbose) {
$verbose = $this->configController->getConfig(configKey: 'verbose');
}
if (!$quiet) { if (!$quiet) {
$quiet = $this->configController->getConfig(configKey: 'quiet'); $quiet = $this->configController->getConfig(configKey: 'quiet');
} }
// echo 'verbose: ' . ($verbose ? 'true' : 'false') . PHP_EOL;
// echo 'quiet: ' . ($quiet ? 'true' : 'false') . PHP_EOL; // echo 'quiet: ' . ($quiet ? 'true' : 'false') . PHP_EOL;
if ($verbose && !$quiet) { if (!$quiet) {
echo 'Checking permissions...' . PHP_EOL; echo 'Checking permissions...' . PHP_EOL;
} }
if ($impersonatedUserId) { if ($impersonatedUserId) {
@ -162,12 +156,12 @@ class DomainController
} else { } else {
$uid = posix_geteuid(); $uid = posix_geteuid();
} }
if ($verbose && !$quiet) { if (!$quiet) {
echo "UID:\t" . COLOR_YELLOW . $uid . PHP_EOL; echo "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'];
if ($verbose && !$quiet) { if (!$quiet) {
echo COLOR_DEFAULT . "Name:\t" . COLOR_YELLOW . $name . PHP_EOL; echo COLOR_DEFAULT . "Name:\t" . COLOR_YELLOW . $name . PHP_EOL;
} }
@ -176,60 +170,60 @@ class DomainController
} }
$members = $bindGroup['members'] ?? []; $members = $bindGroup['members'] ?? [];
if (in_array(needle: $name, haystack: $members)) { if (in_array(needle: $name, haystack: $members)) {
if ($verbose && !$quiet) { if (!$quiet) {
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 {
$setupIsValid = false; $setupIsValid = false;
if ($verbose && !$quiet) { if (!$quiet) {
echo COLOR_RED . "\t$name needs to be in group " . COLOR_YELLOW . 'bind' . COLOR_DEFAULT . '!' . PHP_EOL; echo COLOR_RED . "\t$name needs to be in group " . COLOR_YELLOW . 'bind' . COLOR_DEFAULT . '!' . PHP_EOL;
} }
} }
if ($verbose && !$quiet) { if (!$quiet) {
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) {
if ($verbose && !$quiet) { if (!$quiet) {
echo COLOR_DEFAULT . "\t✅ Group has write access." . PHP_EOL; echo COLOR_DEFAULT . "\t✅ Group has write access." . PHP_EOL;
} }
} else { } else {
$setupIsValid = false; $setupIsValid = false;
if ($verbose && !$quiet) { if (!$quiet) {
echo COLOR_RED . "\t❌Group needs write permission!" . COLOR_DEFAULT . PHP_EOL; echo COLOR_RED . "\t❌Group needs write permission!" . COLOR_DEFAULT . PHP_EOL;
} }
} }
if ($verbose && !$quiet) { if (!$quiet) {
echo 'Checking ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL; echo 'Checking ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL;
} }
if (file_exists(filename: $this->namedConfLocalFile) && $namedConfLocal = file_get_contents(filename: $this->namedConfLocalFile)) { if (file_exists(filename: $this->namedConfLocalFile) && $namedConfLocal = file_get_contents(filename: $this->namedConfLocalFile)) {
if (!str_contains(haystack: $namedConfLocal, needle: $this->localZoneFile)) { if (!str_contains(haystack: $namedConfLocal, needle: $this->localZoneFile)) {
$setupIsValid = false; $setupIsValid = false;
if ($verbose && !$quiet) { if (!$quiet) {
echo "\t$this->localZoneFile" . COLOR_RED . ' needs to be included in ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL; echo "\t$this->localZoneFile" . COLOR_RED . ' needs to be included in ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL;
} }
} else { } else {
if ($verbose && !$quiet) { if (!$quiet) {
echo "\t$this->localZoneFile" . COLOR_DEFAULT . ' is included in ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL; echo "\t$this->localZoneFile" . COLOR_DEFAULT . ' is included in ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL;
} }
} }
} else { } else {
$setupIsValid = false; $setupIsValid = false;
if ($verbose && !$quiet) { if (!$quiet) {
echo "\t❌ No access to '$this->namedConfLocalFile' . Please check permissions" . PHP_EOL; echo "\t❌ No access to '$this->namedConfLocalFile' . Please check permissions" . PHP_EOL;
} }
} }
if ($verbose && !$quiet) { if (!$quiet) {
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) {
if ($verbose && !$quiet) { if (!$quiet) {
echo "\t✅ Group has write access." . PHP_EOL; echo "\t✅ Group has write access." . PHP_EOL;
} }
} else { } else {
$setupIsValid = false; $setupIsValid = false;
if ($verbose && !$quiet) { if (!$quiet) {
echo COLOR_RED . "\t❌Group needs write permission!" . PHP_EOL; echo COLOR_RED . "\t❌Group needs write permission!" . PHP_EOL;
} }
} }

View File

@ -28,6 +28,70 @@ class KeyHelpDomain
private Target $target; private Target $target;
private Security $security; private Security $security;
private Apache $apache; private Apache $apache;
private string $dkimSelector;
private string $dkimRecord;
private ?string $dkimTextRecord;
public function __construct()
{
$this->dkimTextRecord = null;
}
private int $traffic;
private bool $isEmailSendingOnly;
public function isEmailSendingOnly(): bool
{
return $this->isEmailSendingOnly;
}
public function setIsEmailSendingOnly(bool $isEmailSendingOnly): void
{
$this->isEmailSendingOnly = $isEmailSendingOnly;
}
public function getTraffic(): int
{
return $this->traffic;
}
public function setTraffic(int $traffic): void
{
$this->traffic = $traffic;
}
public function getDkimTextRecord(): string
{
return $this->dkimTextRecord;
}
public function setDkimTextRecord(string $dkimTextRecord): void
{
$this->dkimTextRecord = $dkimTextRecord;
}
public function getDkimRecord(): string
{
return $this->dkimRecord;
}
public function setDkimRecord(string $dkimRecord): void
{
$this->dkimRecord = $dkimRecord;
}
public function getDkimSelector(): string
{
return $this->dkimSelector;
}
public function setDkimSelector(string $dkimSelector): void
{
$this->dkimSelector = $dkimSelector;
}
/** /**
* @return Apache * @return Apache

View File

@ -28,13 +28,15 @@ $arguments = array_slice(array: $argv, offset: $restIndex);
if (array_key_exists(key: 'v', array: $options) || array_key_exists(key: 'version', array: $options)) { if (array_key_exists(key: 'v', array: $options) || array_key_exists(key: 'version', array: $options)) {
$arguments = 'showVersion'; $arguments = 'showVersion';
$composerJson = json_decode(json: file_get_contents(filename: dirname(path: __DIR__, levels: 2) . '/composer.json'), associative: true); $composerJson = json_decode(json: file_get_contents(filename: dirname(path: __DIR__, levels: 2) . '/composer.json'));
$name = $composerJson['name']; $name = $composerJson->name;
$description = $composerJson['description']; $description = $composerJson->description;
$version = $composerJson['version']; $version = $composerJson->version;
$buildNumber = $composerJson['build_number']; $buildNumber = $composerJson->build_number;
$authorName = $composerJson['authors'][0]['name']; $authors = $composerJson->authors;
$authorEmail = $composerJson['authors'][0]['email']; // currently only one author, so just handle only first entry
$authorName = $authors[0]->name;
$authorEmail = $authors[0]->email;
echo "Name: $name\n"; echo "Name: $name\n";
echo "Description: $description\n"; echo "Description: $description\n";
@ -55,15 +57,8 @@ if (array_key_exists(key: 'q', array: $options) || array_key_exists(key: 'quiet'
} }
if (array_key_exists(key: 'V', array: $options) || array_key_exists(key: 'verbose', array: $options)) {
$verbose = true;
} else {
$verbose = false;
}
try { try {
$app = new BindAPI(verbose: $verbose, quiet: $quiet); $app = new BindAPI(quiet: $quiet);
} catch (Exception $e) { } catch (Exception $e) {
echo 'Could not initialize the application: ' . $e->getMessage() . PHP_EOL; echo 'Could not initialize the application: ' . $e->getMessage() . PHP_EOL;
exit(1); exit(1);
@ -74,7 +69,7 @@ try {
$app->runCommand(arguments: $arguments); $app->runCommand(arguments: $arguments);
} catch (Exception $e) { } catch (Exception $e) {
$exceptionMessage = $e->getMessage(); $exceptionMessage = $e->getMessage();
preg_match(pattern: '/\[1045\]/', subject: $exceptionMessage, matches: $matches); preg_match(pattern: '/\[1045]/', subject: $exceptionMessage, matches: $matches);
if (!empty($matches)) { if (!empty($matches)) {
echo 'Access was denied for a user when trying to access the database.' . PHP_EOL; echo 'Access was denied for a user when trying to access the database.' . PHP_EOL;
} else { } else {