moced color consts to a utility class
This commit is contained in:
parent
f04c306f91
commit
bb1a16988d
8
TODO
8
TODO
|
@ -1,6 +1,12 @@
|
|||
b4 cron job: check panel, check nameserver1
|
||||
check:cache
|
||||
check:bootstrap
|
||||
check:version remove option update, we have -v as option
|
||||
move stuff to dev:xxx which is not needed for endusers
|
||||
make use of environment, somehow, dev, prod, test
|
||||
check log file location
|
||||
API Endpoint cleanup
|
||||
check keytype of panel/bindApi
|
||||
check:configkey => update config.json
|
||||
more UNIT tests
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"name": "24unix/bindapi",
|
||||
"description": "manage Bind9 DNS server via REST API",
|
||||
"version": "1.0.9",
|
||||
"build_number": "374",
|
||||
"build_number": "375",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Micha Espey",
|
||||
|
@ -23,6 +23,7 @@
|
|||
"ext-posix": "*",
|
||||
"ext-sodium": "*",
|
||||
"arubacao/tld-checker": "^1.2",
|
||||
"bartlett/php-compatinfo": "^7.1",
|
||||
"monolog/monolog": "^3.1",
|
||||
"netresearch/jsonmapper": "^4.4",
|
||||
"php-di/php-di": "^6.3",
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,9 +1,10 @@
|
|||
{
|
||||
"env": "prod",
|
||||
"dbHost": "localhost",
|
||||
"dbPort": 3306,
|
||||
"dbDatabase": "sampledb",
|
||||
"dbUser": "sampleuser",
|
||||
"dbPassword": "secret",
|
||||
"encryptionKey": "changeme",
|
||||
"encryptionKey": "1bad::babe",
|
||||
"debug": false
|
||||
}
|
||||
|
|
|
@ -4,13 +4,6 @@ namespace App\Controller;
|
|||
|
||||
error_reporting(error_level: E_ALL);
|
||||
|
||||
define(constant_name: 'COLOR_RED', value: "\033[31m");
|
||||
define(constant_name: 'COLOR_GREEN', value: "\033[32m");
|
||||
define(constant_name: 'COLOR_YELLOW', value: "\033[33m");
|
||||
define(constant_name: 'COLOR_BLUE', value: "\033[34m");
|
||||
define(constant_name: 'COLOR_WHITE', value: "\033[37m");
|
||||
define(constant_name: 'COLOR_DEFAULT', value: "\033[39m");
|
||||
|
||||
use App\Controller\Commands\Command;
|
||||
use App\Controller\Commands\CommandGroup;
|
||||
use App\Controller\Commands\CommandGroupContainer;
|
||||
|
@ -27,6 +20,7 @@ use App\Repository\NameserverRepository;
|
|||
use App\Repository\PanelRepository;
|
||||
use App\Repository\SettingsRepository;
|
||||
use App\Service\ApiClient;
|
||||
use App\Utilities\Colors;
|
||||
use Arubacao\TldChecker\Validator;
|
||||
use Exception;
|
||||
use JsonMapper;
|
||||
|
@ -333,8 +327,8 @@ class CLIController
|
|||
function runCheckSetup(): void
|
||||
{
|
||||
if (!$this->domainController->checkPermissions()) {
|
||||
echo COLOR_RED . 'You need to setup the bindAPI permission first.' . COLOR_DEFAULT . PHP_EOL;
|
||||
echo 'Run ' . COLOR_YELLOW . './bin/console check:setup' . COLOR_DEFAULT . ' as root or with sudo.' . PHP_EOL;
|
||||
echo Colors::RED . 'You need to setup the bindAPI permission first.' . Colors::DEFAULT . PHP_EOL;
|
||||
echo 'Run ' . Colors::YELLOW . './bin/console check:setup' . Colors::DEFAULT . ' as root or with sudo.' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -370,14 +364,14 @@ class CLIController
|
|||
|
||||
$debug = $this->configController->getConfig(configKey: 'debug');
|
||||
|
||||
echo COLOR_YELLOW . 'Usage:' . PHP_EOL;
|
||||
echo COLOR_DEFAULT . "\t./bin/console {options} {arguments}" . PHP_EOL . PHP_EOL;
|
||||
echo Colors::YELLOW . 'Usage:' . PHP_EOL;
|
||||
echo Colors::DEFAULT . "\t./bin/console {options} {arguments}" . PHP_EOL . 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-q, --quiet\t\t" . COLOR_DEFAULT . "No output to stdout, for cronjobs" . PHP_EOL . PHP_EOL;
|
||||
echo Colors::YELLOW . 'Options:' . PHP_EOL;
|
||||
echo Colors::GREEN . "\t-v, --version\t\t" . Colors::DEFAULT . "Display the version of the API" . PHP_EOL;
|
||||
echo Colors::GREEN . "\t-q, --quiet\t\t" . Colors::DEFAULT . "No output to stdout, for cronjobs" . PHP_EOL . PHP_EOL;
|
||||
|
||||
echo COLOR_YELLOW . 'Arguments: ' . COLOR_WHITE . '<mandatory> {optional}' . PHP_EOL;
|
||||
echo Colors::YELLOW . 'Arguments: ' . Colors::WHITE . '<mandatory> {optional}' . PHP_EOL;
|
||||
|
||||
$this->commandGroupContainer->printCommands();
|
||||
|
||||
|
@ -392,9 +386,9 @@ class CLIController
|
|||
$this->logger->debug(message: "checkPermissions()");
|
||||
|
||||
if (!$this->domainController->checkPermissions()) {
|
||||
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||
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;
|
||||
if (!$this->quiet) {
|
||||
echo PHP_EOL . Colors::DEFAULT;
|
||||
echo 'Missing permissions, please run ' . Colors::YELLOW . './bin/console check:setup' . Colors::DEFAULT . ' as root or with sudo.' . PHP_EOL;
|
||||
}
|
||||
exit(1);
|
||||
} else {
|
||||
|
@ -430,7 +424,7 @@ class CLIController
|
|||
|
||||
// for /etc/bind/local.zones file
|
||||
if (!file_exists(filename: $this->domainController->localZoneFile)) {
|
||||
echo 'Could not find ' . COLOR_YELLOW . $this->domainController->localZoneFile . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
echo 'Could not find ' . Colors::YELLOW . $this->domainController->localZoneFile . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
echo 'Creating …';
|
||||
touch(filename: $this->domainController->localZoneFile);
|
||||
if (!file_exists(filename: $this->domainController->localZoneFile)) {
|
||||
|
@ -449,9 +443,9 @@ class CLIController
|
|||
}
|
||||
} else {
|
||||
// check /etc/bind/local.zones permissions
|
||||
echo 'Found ' . COLOR_YELLOW . $this->domainController->localZoneFile . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
echo 'Found ' . Colors::YELLOW . $this->domainController->localZoneFile . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
|
||||
echo 'Check permissions for ' . COLOR_YELLOW . $this->domainController->localZoneFile . COLOR_DEFAULT . ' …';
|
||||
echo 'Check permissions for ' . Colors::YELLOW . $this->domainController->localZoneFile . Colors::DEFAULT . ' …';
|
||||
|
||||
// dont repeat yourself, use check from DomainController FIXME
|
||||
$this->domainController->checkPermissions(impersonatedUserId: $impersonatedUserId);
|
||||
|
@ -460,26 +454,26 @@ class CLIController
|
|||
// /etc/bind/local.zones file must be included in /etc/bind/named.conf.local
|
||||
$namedConfLocal = file_get_contents(filename: $this->domainController->namedConfLocalFile);
|
||||
if (str_contains(haystack: $namedConfLocal, needle: $this->domainController->localZoneFile)) {
|
||||
echo 'Found ' . COLOR_YELLOW . $this->domainController->localZoneFile . COLOR_DEFAULT . ' included ' . COLOR_YELLOW . $this->domainController->namedConfLocalFile . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
echo 'Found ' . Colors::YELLOW . $this->domainController->localZoneFile . Colors::DEFAULT . ' included ' . Colors::YELLOW . $this->domainController->namedConfLocalFile . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
} else {
|
||||
echo 'Could not find ' . COLOR_YELLOW . $this->domainController->localZoneFile . COLOR_DEFAULT . ' in ' . COLOR_YELLOW . $this->domainController->namedConfLocalFile . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
echo 'Could not find ' . Colors::YELLOW . $this->domainController->localZoneFile . Colors::DEFAULT . ' in ' . Colors::YELLOW . $this->domainController->namedConfLocalFile . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
echo 'Adding …';
|
||||
$namedConfLocal .= PHP_EOL . 'include "' . $this->domainController->localZoneFile . '";' . PHP_EOL;
|
||||
file_put_contents(filename: $this->domainController->namedConfLocalFile, data: $namedConfLocal);
|
||||
if (str_contains(haystack: $namedConfLocal, needle: $this->domainController->localZoneFile)) {
|
||||
echo ' done.' . PHP_EOL;
|
||||
} else {
|
||||
echo 'Could not add ' . COLOR_YELLOW . $this->domainController->localZoneFile . COLOR_DEFAULT . ' to ' . COLOR_YELLOW . $this->domainController->namedConfLocalFile . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
echo 'Could not add ' . Colors::YELLOW . $this->domainController->localZoneFile . Colors::DEFAULT . ' to ' . Colors::YELLOW . $this->domainController->namedConfLocalFile . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// check /etc/bind/zones exists
|
||||
echo 'Check for ' . COLOR_YELLOW . $this->domainController->localZonesDir . COLOR_DEFAULT . ' …';
|
||||
echo 'Check for ' . Colors::YELLOW . $this->domainController->localZonesDir . Colors::DEFAULT . ' …';
|
||||
if (is_dir(filename: $this->domainController->localZonesDir)) {
|
||||
echo " exists." . PHP_EOL;
|
||||
} else {
|
||||
echo ' Could not find ' . COLOR_YELLOW . $this->domainController->localZonesDir . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
echo ' Could not find ' . Colors::YELLOW . $this->domainController->localZonesDir . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
echo 'Creating …';
|
||||
mkdir(directory: $this->domainController->localZonesDir, permissions: 0775, recursive: true);
|
||||
echo ' done.' . PHP_EOL;
|
||||
|
@ -533,7 +527,7 @@ class CLIController
|
|||
$this->logger->debug(message: "checkSinglePanel()");
|
||||
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_DEFAULT . 'KeyHelp-Panel: ' . COLOR_YELLOW . $panel->getName() . COLOR_DEFAULT;
|
||||
echo Colors::DEFAULT . 'KeyHelp-Panel: ' . Colors::YELLOW . $panel->getName() . Colors::DEFAULT;
|
||||
}
|
||||
|
||||
$encryptionKey = $this->configController->getConfig(configKey: 'encryptionKey');
|
||||
|
@ -541,7 +535,7 @@ class CLIController
|
|||
|
||||
$f = $panel->getA();
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_DEFAULT . ' IPv4: ' . COLOR_YELLOW . $f . COLOR_DEFAULT;
|
||||
echo Colors::DEFAULT . ' IPv4: ' . Colors::YELLOW . $f . Colors::DEFAULT;
|
||||
}
|
||||
|
||||
if (!empty($panel->getA())) {
|
||||
|
@ -570,7 +564,7 @@ class CLIController
|
|||
$responseTime = 'n/a';
|
||||
}
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_DEFAULT . ' KeyHelp version: ' . $panelVersion . " ($responseTime seconds)" . PHP_EOL;
|
||||
echo Colors::DEFAULT . ' KeyHelp version: ' . $panelVersion . " ($responseTime seconds)" . PHP_EOL;
|
||||
}
|
||||
|
||||
if (empty($panel->getA())) {
|
||||
|
@ -631,7 +625,7 @@ class CLIController
|
|||
$domainCount = 0;
|
||||
foreach ($tmpDomainList as $domain) {
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_DEFAULT . " Domain: " . COLOR_YELLOW . str_pad(string: $domain->getDomain(), length: $maxDomainNameLength);
|
||||
echo Colors::DEFAULT . " Domain: " . Colors::YELLOW . str_pad(string: $domain->getDomain(), length: $maxDomainNameLength);
|
||||
}
|
||||
|
||||
if (!$domain->isSubdomain()) {
|
||||
|
@ -642,7 +636,7 @@ class CLIController
|
|||
|
||||
if ($domainCount == 0) {
|
||||
if (!$this->quiet) {
|
||||
echo 'No second level domains found.' . COLOR_DEFAULT . PHP_EOL;
|
||||
echo 'No second level domains found.' . Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
}
|
||||
if (!$this->quiet) {
|
||||
|
@ -744,7 +738,7 @@ class CLIController
|
|||
$decryptedKey = $this->encryptionController->safeDecrypt(encrypted: $nameserver->getApikey(), key: $encryptionKey);
|
||||
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_YELLOW . ' ' . $nameserver->getName();
|
||||
echo Colors::YELLOW . ' ' . $nameserver->getName();
|
||||
}
|
||||
if (!empty($nameserver->getA())) {
|
||||
$result = $this->apiClient->sendCommand(
|
||||
|
@ -767,17 +761,17 @@ class CLIController
|
|||
switch ($result['header']) {
|
||||
case 200:
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_GREEN . ' OK';
|
||||
echo Colors::GREEN . ' OK';
|
||||
}
|
||||
break;
|
||||
case 401:
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_RED . ' Error: ' . COLOR_YELLOW . $result['data'] . COLOR_DEFAULT . PHP_EOL;
|
||||
echo Color::RED . ' Error: ' . Colors::YELLOW . $result['data'] . Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
exit(1);
|
||||
case 404:
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_RED . ' ' . $result['header'] . COLOR_DEFAULT;
|
||||
echo Color::RED . ' ' . $result['header'] . Colors::DEFAULT;
|
||||
}
|
||||
if (!empty($this->arguments['fix']) && $this->arguments['fix'] == 'yes') {
|
||||
if (!$this->quiet) {
|
||||
|
@ -814,7 +808,7 @@ class CLIController
|
|||
die("make error handling");
|
||||
} else {
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_GREEN . 'OK' . COLOR_DEFAULT;
|
||||
echo Colors::GREEN . 'OK' . Colors::DEFAULT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -985,7 +979,7 @@ class CLIController
|
|||
}
|
||||
if ($this->panelRepository->update(panel: $panel) !== false) {
|
||||
if (!$this->quiet) {
|
||||
echo 'Panel ' . COLOR_YELLOW . $id . COLOR_DEFAULT . ' has been updated' . PHP_EOL;
|
||||
echo 'Panel ' . Colors::YELLOW . $id . Colors::DEFAULT . ' has been updated' . PHP_EOL;
|
||||
}
|
||||
} else {
|
||||
if (!$this->quiet) {
|
||||
|
@ -1040,7 +1034,7 @@ class CLIController
|
|||
$error = true;
|
||||
}
|
||||
} else {
|
||||
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||
if (!$this->quiet) {
|
||||
echo "Unknown $type ID $id" . PHP_EOL;
|
||||
}
|
||||
$error = true;
|
||||
|
@ -1101,8 +1095,8 @@ class CLIController
|
|||
$maxAAAA = $this->panelRepository->getLongestEntry(field: 'aaaa');
|
||||
}
|
||||
|
||||
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||
echo COLOR_YELLOW . str_pad(string: $server->getName(), length: $maxName);
|
||||
if (!$this->quiet) {
|
||||
echo Colors::YELLOW . str_pad(string: $server->getName(), length: $maxName);
|
||||
}
|
||||
|
||||
$encryptionKey = $this->configController->getConfig(configKey: 'encryptionKey');
|
||||
|
@ -1112,8 +1106,8 @@ class CLIController
|
|||
$a = $server->getA() ?? '';
|
||||
if (!empty($a)) {
|
||||
$this->logger->debug("check a");
|
||||
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||
echo COLOR_DEFAULT . ' ' . str_pad(string: $a, length: $maxA, pad_type: STR_PAD_LEFT) . ' ';
|
||||
if (!$this->quiet) {
|
||||
echo Colors::DEFAULT . ' ' . str_pad(string: $a, length: $maxA, pad_type: STR_PAD_LEFT) . ' ';
|
||||
}
|
||||
if ($result = $this->apiClient->sendCommand(
|
||||
requestType: 'GET',
|
||||
|
@ -1122,12 +1116,12 @@ class CLIController
|
|||
apiKey: $decryptedKey,
|
||||
command: 'ping',
|
||||
serverType: $type)) {
|
||||
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||
if (!$this->quiet) {
|
||||
if ($result['data'] == 'pong') {
|
||||
echo ' ' . COLOR_GREEN . $result['data'];
|
||||
echo ' ' . Colors::GREEN . $result['data'];
|
||||
} else {
|
||||
echo COLOR_BLUE . ' skip' . COLOR_DEFAULT;
|
||||
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||
echo Colors::BLUE . ' skip' . Colors::DEFAULT;
|
||||
if (!$this->quiet) {
|
||||
echo ' ' . $result['data'];
|
||||
}
|
||||
}
|
||||
|
@ -1139,8 +1133,8 @@ class CLIController
|
|||
$aaaa = $server->getAaaa() ?? '';
|
||||
if (!empty($aaaa)) {
|
||||
$this->logger->debug("check aaaa");
|
||||
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||
echo COLOR_DEFAULT . ' ' . str_pad(string: $aaaa, length: $maxAAAA, pad_type: STR_PAD_LEFT) . ' ';
|
||||
if (!$this->quiet) {
|
||||
echo Colors::DEFAULT . ' ' . str_pad(string: $aaaa, length: $maxAAAA, pad_type: STR_PAD_LEFT) . ' ';
|
||||
}
|
||||
if ($result = $this->apiClient->sendCommand(
|
||||
requestType: 'GET',
|
||||
|
@ -1149,12 +1143,12 @@ class CLIController
|
|||
apiKey: $decryptedKey,
|
||||
command: 'ping',
|
||||
serverType: $type)) {
|
||||
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||
if (!$this->quiet) {
|
||||
if ($result['data'] == 'pong') {
|
||||
echo ' ' . COLOR_GREEN . $result['data'];
|
||||
echo ' ' . Colors::GREEN . $result['data'];
|
||||
} else {
|
||||
echo COLOR_BLUE . ' xxskip' . COLOR_DEFAULT;
|
||||
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||
echo Colors::BLUE . ' xxskip' . Colors::DEFAULT;
|
||||
if (!$this->quiet) {
|
||||
echo ' ' . $result['data'];
|
||||
}
|
||||
}
|
||||
|
@ -1169,8 +1163,8 @@ class CLIController
|
|||
exit($e->getMessage() . PHP_EOL);
|
||||
}
|
||||
|
||||
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||
echo COLOR_DEFAULT . PHP_EOL;
|
||||
if (!$this->quiet) {
|
||||
echo Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
return !$error;
|
||||
}
|
||||
|
@ -1199,17 +1193,17 @@ class CLIController
|
|||
if ($result['error'] === false) {
|
||||
$data = $result['data'];
|
||||
$decodedData = json_decode(json: $data);
|
||||
echo COLOR_DEFAULT . ' Version: ' . COLOR_YELLOW . $decodedData->version;
|
||||
echo COLOR_DEFAULT . ' (Build: ' . COLOR_YELLOW . $decodedData->buildnumber . COLOR_DEFAULT . ')' . PHP_EOL;
|
||||
echo Colors::DEFAULT . ' Version: ' . Colors::YELLOW . $decodedData->version;
|
||||
echo Colors::DEFAULT . ' (Build: ' . Colors::YELLOW . $decodedData->buildnumber . Colors::DEFAULT . ')' . PHP_EOL;
|
||||
} else {
|
||||
echo COLOR_RED . ' Error: ' . COLOR_YELLOW . $result['data'] . COLOR_DEFAULT . PHP_EOL;
|
||||
echo Color::RED . ' Error: ' . Colors::YELLOW . $result['data'] . Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
// var_dump($result);
|
||||
$skipAAAA = true;
|
||||
// if ($result['data'] == 'pong') {
|
||||
// echo ' ' . COLOR_GREEN . $result['data'];
|
||||
// echo ' ' . Colors::GREEN . $result['data'];
|
||||
// } else {
|
||||
// echo COLOR_BLUE . ' skip' . COLOR_DEFAULT;
|
||||
// echo Colors::BLUE . ' skip' . Colors::DEFAULT;
|
||||
// if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||
// echo ' ' . $result['data'];
|
||||
// }
|
||||
|
@ -1233,9 +1227,9 @@ class CLIController
|
|||
if (!$this->quiet) {
|
||||
echo $result;
|
||||
// if ($result['data'] == 'pong') {
|
||||
// echo ' ' . COLOR_GREEN . $result['data'];
|
||||
// echo ' ' . Colors::GREEN . $result['data'];
|
||||
// } else {
|
||||
// echo COLOR_BLUE . ' xxskip' . COLOR_DEFAULT;
|
||||
// echo Colors::BLUE . ' xxskip' . Colors::DEFAULT;
|
||||
// if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||
// echo ' ' . $result['data'];
|
||||
// }
|
||||
|
@ -1251,8 +1245,8 @@ class CLIController
|
|||
exit($e->getMessage() . PHP_EOL);
|
||||
}
|
||||
|
||||
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||
echo COLOR_DEFAULT . PHP_EOL;
|
||||
if (!$this->quiet) {
|
||||
echo Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
return !$error;
|
||||
}
|
||||
|
@ -1283,13 +1277,13 @@ class CLIController
|
|||
$result = $this->apikeyRepository->insert(apikey: $apikey);
|
||||
|
||||
if ($name) {
|
||||
echo 'API key ' . COLOR_YELLOW . $name . COLOR_DEFAULT;
|
||||
echo 'API key ' . Colors::YELLOW . $name . Colors::DEFAULT;
|
||||
} else {
|
||||
echo 'Unnamed API key ';
|
||||
}
|
||||
|
||||
echo ' with ID ' . COLOR_YELLOW . $result . COLOR_DEFAULT . ' has been generated. Store it in a safe place, it cannot be recovered.' . PHP_EOL;
|
||||
echo COLOR_YELLOW . $apiKeyPrefix . '.' . $apikeyRand . COLOR_DEFAULT . PHP_EOL;
|
||||
echo ' with ID ' . Colors::YELLOW . $result . Colors::DEFAULT . ' has been generated. Store it in a safe place, it cannot be recovered.' . PHP_EOL;
|
||||
echo Colors::YELLOW . $apiKeyPrefix . '.' . $apikeyRand . Colors::DEFAULT . PHP_EOL;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
@ -1357,10 +1351,10 @@ class CLIController
|
|||
}
|
||||
if ($this->apikeyRepository->findByID(id: $id)) {
|
||||
$this->apikeyRepository->delete(id: $id);
|
||||
echo 'API key ' . COLOR_YELLOW . $id . COLOR_DEFAULT . ' has been deleted.' . PHP_EOL;
|
||||
echo 'API key ' . Colors::YELLOW . $id . Colors::DEFAULT . ' has been deleted.' . PHP_EOL;
|
||||
exit(0);
|
||||
} else {
|
||||
echo 'Unknown ID ' . COLOR_YELLOW . $id . '.' . PHP_EOL;
|
||||
echo 'Unknown ID ' . Colors::YELLOW . $id . '.' . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -1463,20 +1457,20 @@ class CLIController
|
|||
|
||||
}
|
||||
|
||||
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||
echo "Found domain: " . COLOR_YELLOW . $foundDomain . COLOR_DEFAULT . PHP_EOL;
|
||||
if (!$this->quiet) {
|
||||
echo "Found domain: " . Colors::YELLOW . $foundDomain . Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
|
||||
// get host
|
||||
|
||||
if ($this->dynDNSRepository->findByName(name: $name)) {
|
||||
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||
echo "DynDNS host " . COLOR_YELLOW . $name . COLOR_DEFAULT . "already exists." . PHP_EOL;
|
||||
if (!$this->quiet) {
|
||||
echo "DynDNS host " . Colors::YELLOW . $name . Colors::DEFAULT . "already exists." . PHP_EOL;
|
||||
exit(0);
|
||||
}
|
||||
} else {
|
||||
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||
echo "DynDNS host " . COLOR_YELLOW . $name . COLOR_DEFAULT . "will be created." . PHP_EOL;
|
||||
if (!$this->quiet) {
|
||||
echo "DynDNS host " . Colors::YELLOW . $name . Colors::DEFAULT . "will be created." . PHP_EOL;
|
||||
// insert in db
|
||||
$dyndnsHost = new DynDNS(name: $name);
|
||||
// why is the property set in the cunstructor and afterwards again? FIXME
|
||||
|
@ -1494,12 +1488,12 @@ class CLIController
|
|||
exit(1);
|
||||
} else {
|
||||
if (!$this->panelRepository->findByName(name: $panel)) {
|
||||
echo 'Unknown panel: ' . COLOR_YELLOW . $panel . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
echo 'Unknown panel: ' . Colors::YELLOW . $panel . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
$domain = new Domain(name: $name, panel: $panel);
|
||||
$result = $this->domainRepository->insert(domain: $domain);
|
||||
echo 'Domain' . COLOR_YELLOW . $name . COLOR_DEFAULT . ' has been created with id ' . COLOR_YELLOW . $result . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
echo 'Domain' . Colors::YELLOW . $name . Colors::DEFAULT . ' has been created with id ' . Colors::YELLOW . $result . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
$this->domainController->createSlaveZoneFile(domain: $domain);
|
||||
exit(0);
|
||||
}
|
||||
|
@ -1539,12 +1533,12 @@ class CLIController
|
|||
exit(1);
|
||||
} else {
|
||||
if (!$this->panelRepository->findByName(name: $panel)) {
|
||||
echo 'Unknown panel: ' . COLOR_YELLOW . $panel . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
echo 'Unknown panel: ' . Colors::YELLOW . $panel . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
$domain = new Domain(name: $name, panel: $panel);
|
||||
$result = $this->domainRepository->insert(domain: $domain);
|
||||
echo 'Domain' . COLOR_YELLOW . $name . COLOR_DEFAULT . ' has been created with id ' . COLOR_YELLOW . $result . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
echo 'Domain' . Colors::YELLOW . $name . Colors::DEFAULT . ' has been created with id ' . Colors::YELLOW . $result . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
$this->domainController->createSlaveZoneFile(domain: $domain);
|
||||
exit(0);
|
||||
}
|
||||
|
@ -1578,7 +1572,7 @@ class CLIController
|
|||
// }
|
||||
//
|
||||
// if (empty($name) && empty($panel)) {
|
||||
// echo COLOR_DEFAULT . 'No name or panel given, just recreate the config file' . PHP_EOL;
|
||||
// echo Colors::DEFAULT . 'No name or panel given, just recreate the config file' . PHP_EOL;
|
||||
// $this->domainController->updateSlaveZones();
|
||||
// exit(1);
|
||||
// }
|
||||
|
@ -1658,7 +1652,7 @@ class CLIController
|
|||
} else {
|
||||
$nameserver = new Nameserver(name: $name, a: $a, aaaa: $aaaa, passphrase: $apikey, self: $self);
|
||||
$result = $this->nameserverRepository->insert(nameserver: $nameserver);
|
||||
echo 'Nameserver ' . COLOR_YELLOW . $name . COLOR_DEFAULT . ' has been created with id ' . COLOR_YELLOW . $result . COLOR_DEFAULT . PHP_EOL;
|
||||
echo 'Nameserver ' . Colors::YELLOW . $name . Colors::DEFAULT . ' has been created with id ' . Colors::YELLOW . $result . Colors::DEFAULT . PHP_EOL;
|
||||
$this->createOpenAPIBootstrap();
|
||||
exit(0);
|
||||
}
|
||||
|
@ -1691,7 +1685,7 @@ class CLIController
|
|||
$versionSting = $dbVersion->version->major . '.' . $dbVersion->version->minor . '.' . $dbVersion->version->patch;
|
||||
} else {
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_RED . 'Error: ' . COLOR_DEFAULT . 'Check version settings.' . PHP_EOL;
|
||||
echo Color::RED . 'Error: ' . Colors::DEFAULT . 'Check version settings.' . PHP_EOL;
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
@ -1759,7 +1753,7 @@ const VERSION = '{$versionSting}';
|
|||
exit(1);
|
||||
}
|
||||
if (!$this->nameserverRepository->findByID(id: intval(value: $id))) {
|
||||
echo 'Nameserver with ID ' . COLOR_YELLOW . $id . COLOR_DEFAULT . " doesn't exist." . PHP_EOL;
|
||||
echo 'Nameserver with ID ' . Colors::YELLOW . $id . Colors::DEFAULT . " doesn't exist." . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -1772,11 +1766,11 @@ const VERSION = '{$versionSting}';
|
|||
if ($this->nameserverRepository->update(nameserver: $nameserver) !== false) {
|
||||
$this->createOpenAPIBootstrap();
|
||||
if (!$this->quiet) {
|
||||
echo 'Nameserver ' . COLOR_YELLOW . $id . COLOR_DEFAULT . ' has been updated.' . PHP_EOL;
|
||||
echo 'Nameserver ' . Colors::YELLOW . $id . Colors::DEFAULT . ' has been updated.' . PHP_EOL;
|
||||
}
|
||||
} else {
|
||||
if (!$this->quiet) {
|
||||
echo 'Error while updating nameserver ' . COLOR_YELLOW . $id . '.' . PHP_EOL;
|
||||
echo 'Error while updating nameserver ' . Colors::YELLOW . $id . '.' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1796,13 +1790,13 @@ const VERSION = '{$versionSting}';
|
|||
$id = intval(value: $this->arguments[1] ?? 0);
|
||||
if ($id == 0) {
|
||||
if (!$this->quiet) {
|
||||
echo 'Nameserver with ID ' . COLOR_YELLOW . $id . COLOR_DEFAULT . ' not found.' . PHP_EOL;
|
||||
echo 'Nameserver with ID ' . Colors::YELLOW . $id . Colors::DEFAULT . ' not found.' . PHP_EOL;
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
if (!$this->nameserverRepository->findByID(id: $id)) {
|
||||
if (!$this->quiet) {
|
||||
echo 'There is no nameserver with ID ' . COLOR_YELLOW . $id . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
echo 'There is no nameserver with ID ' . Colors::YELLOW . $id . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
@ -1810,7 +1804,7 @@ const VERSION = '{$versionSting}';
|
|||
$this->createOpenAPIBootstrap();
|
||||
|
||||
if (!$this->quiet) {
|
||||
echo 'The nameserver with ID ' . COLOR_YELLOW . $id . COLOR_DEFAULT . ' has been deleted.' . PHP_EOL;
|
||||
echo 'The nameserver with ID ' . Colors::YELLOW . $id . Colors::DEFAULT . ' has been deleted.' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1828,8 +1822,8 @@ const VERSION = '{$versionSting}';
|
|||
}
|
||||
|
||||
|
||||
echo COLOR_DEFAULT . 'You need to add these lines to ' . COLOR_YELLOW . '/etc/bind/local.bindapi.options' . COLOR_DEFAULT . ' on every panel and make sure' . PHP_EOL;
|
||||
echo 'that ' . COLOR_YELLOW . 'include "/etc/bind/local.bindapi.options";' . COLOR_DEFAULT . ' exists in ' . COLOR_YELLOW . '/etc/bind/named.conf.options' . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
echo Colors::DEFAULT . 'You need to add these lines to ' . Colors::YELLOW . '/etc/bind/local.bindapi.options' . Colors::DEFAULT . ' on every panel and make sure' . PHP_EOL;
|
||||
echo 'that ' . Colors::YELLOW . 'include "/etc/bind/local.bindapi.options";' . Colors::DEFAULT . ' exists in ' . Colors::YELLOW . '/etc/bind/named.conf.options' . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
$ip = [];
|
||||
foreach ($nameservers as $nameserver) {
|
||||
if (!empty($nameserver->getA())) {
|
||||
|
@ -1847,8 +1841,8 @@ const VERSION = '{$versionSting}';
|
|||
foreach ($ip as $currentIp)
|
||||
echo "\t$currentIp;" . PHP_EOL;
|
||||
echo '};' . PHP_EOL;
|
||||
echo PHP_EOL . 'After the modification feel free to run ' . COLOR_YELLOW . 'named-checkconf' . COLOR_DEFAULT . ' to ensure there were no errors.' . PHP_EOL;
|
||||
echo PHP_EOL . 'Run ' . COLOR_YELLOW . 'rndc reload' . COLOR_DEFAULT . ' to activate the changes.' . PHP_EOL;
|
||||
echo PHP_EOL . 'After the modification feel free to run ' . Colors::YELLOW . 'named-checkconf' . Colors::DEFAULT . ' to ensure there were no errors.' . PHP_EOL;
|
||||
echo PHP_EOL . 'Run ' . Colors::YELLOW . 'rndc reload' . Colors::DEFAULT . ' to activate the changes.' . PHP_EOL;
|
||||
|
||||
|
||||
}
|
||||
|
@ -1864,10 +1858,10 @@ const VERSION = '{$versionSting}';
|
|||
{
|
||||
if (!$this->quiet) {
|
||||
if ($details) {
|
||||
echo COLOR_YELLOW . $details . COLOR_DEFAULT . PHP_EOL;
|
||||
echo Colors::YELLOW . $details . Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
echo 'This is no valid panel apikey. A valid key looks like this one:' . PHP_EOL;
|
||||
echo COLOR_YELLOW . 'A7hjZx52.u8Rzj2S5KUvqozPlQwh4k3eDCrLikL8ZYlcdPr488QkbOW2JaS6Hg5syNllgnNOpQv6TntNMzt62LiH5CTlrMovRQhMcwZzM5dOfLKzqEePFRv1y6qZ7CT9' . PHP_EOL;
|
||||
echo Colors::YELLOW . 'A7hjZx52.u8Rzj2S5KUvqozPlQwh4k3eDCrLikL8ZYlcdPr488QkbOW2JaS6Hg5syNllgnNOpQv6TntNMzt62LiH5CTlrMovRQhMcwZzM5dOfLKzqEePFRv1y6qZ7CT9' . PHP_EOL;
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
@ -1888,7 +1882,7 @@ const VERSION = '{$versionSting}';
|
|||
exit(1);
|
||||
}
|
||||
|
||||
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||
if (!$this->quiet) {
|
||||
echo "Updating DynDNS host: $hostName" . PHP_EOL;
|
||||
}
|
||||
|
||||
|
@ -1923,7 +1917,7 @@ const VERSION = '{$versionSting}';
|
|||
}
|
||||
|
||||
if ($result['header'] == 200) {
|
||||
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||
if (!$this->quiet) {
|
||||
$data = $result['data'];
|
||||
$decodedData = json_decode(json: $data, associative: true);
|
||||
echo $decodedData['message'] . PHP_EOL;
|
||||
|
@ -1947,7 +1941,7 @@ const VERSION = '{$versionSting}';
|
|||
|
||||
try {
|
||||
$key = sodium_bin2hex(string: sodium_crypto_secretbox_keygen());
|
||||
echo 'Suggested new key : "' . COLOR_YELLOW . $key . COLOR_DEFAULT . '".' . PHP_EOL;
|
||||
echo 'Suggested new key : "' . Colors::YELLOW . $key . Colors::DEFAULT . '".' . PHP_EOL;
|
||||
echo PHP_EOL;
|
||||
exit(0);
|
||||
} catch (SodiumException $e) {
|
||||
|
@ -1966,7 +1960,7 @@ const VERSION = '{$versionSting}';
|
|||
|
||||
foreach ($panels as $panel) {
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_DEFAULT . 'Checking panel ' . COLOR_YELLOW . $panel->getName() . COLOR_DEFAULT . PHP_EOL;
|
||||
echo Colors::DEFAULT . 'Checking panel ' . Colors::YELLOW . $panel->getName() . Colors::DEFAULT . PHP_EOL;
|
||||
$longestEntry = $this->domainRepository->getLongestEntry(field: 'name');
|
||||
}
|
||||
$encryptionKey = $this->configController->getConfig(configKey: 'encryptionKey');
|
||||
|
@ -2009,7 +2003,7 @@ const VERSION = '{$versionSting}';
|
|||
foreach ($domains as $domain) {
|
||||
$domainCount++;
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_YELLOW . ' ' . str_pad(string: $domain->domain, length: $longestEntry + 1, pad_type: STR_PAD_RIGHT);
|
||||
echo Colors::YELLOW . ' ' . str_pad(string: $domain->domain, length: $longestEntry + 1, pad_type: STR_PAD_RIGHT);
|
||||
}
|
||||
if ($currentDomain = $this->domainRepository->findByName(name: $domain->domain)) {
|
||||
$currentPanel = $currentDomain->getPanel();
|
||||
|
@ -2018,24 +2012,24 @@ const VERSION = '{$versionSting}';
|
|||
$currentDomain->setPanel(panel: $panelName);
|
||||
$this->domainRepository->update(domain: $currentDomain);
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_DEFAULT . ' updated to: ' . COLOR_YELLOW . $panelName;
|
||||
echo Colors::DEFAULT . ' updated to: ' . Colors::YELLOW . $panelName;
|
||||
}
|
||||
}
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_GREEN . ' OK' . COLOR_DEFAULT . PHP_EOL;
|
||||
echo Colors::GREEN . ' OK' . Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
} else {
|
||||
$newDomain = new Domain(name: $domain->domain, panel: $panel->getName());
|
||||
$result = $this->domainRepository->insert(domain: $newDomain);
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_DEFAULT . ' has been created with id ' . COLOR_YELLOW . $result . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
echo Colors::DEFAULT . ' has been created with id ' . Colors::YELLOW . $result . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
unset($currentDomains[$domain->domain]);
|
||||
}
|
||||
}
|
||||
if ($domainCount == 0) {
|
||||
echo 'No second level domains found.' . COLOR_DEFAULT . PHP_EOL;
|
||||
echo 'No second level domains found.' . Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
|
||||
//clean up stale domains
|
||||
|
@ -2057,31 +2051,29 @@ const VERSION = '{$versionSting}';
|
|||
|
||||
public function webmailCheck(): void
|
||||
{
|
||||
$quiet = $this->configController->getConfig(configKey: 'quiet');
|
||||
|
||||
if (empty($this->arguments[1])) {
|
||||
if (!$quiet) {
|
||||
echo COLOR_DEFAULT . 'You need to supply a domain name.' . PHP_EOL;
|
||||
if (!$this->quiet) {
|
||||
echo Colors::DEFAULT . 'You need to supply a domain name.' . PHP_EOL;
|
||||
}
|
||||
exit(1);
|
||||
} else {
|
||||
$domainName = $this->arguments[1];
|
||||
}
|
||||
|
||||
if (!$quiet) {
|
||||
echo COLOR_DEFAULT . 'Checking domain ' . COLOR_YELLOW . $domainName . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
if (!$this->quiet) {
|
||||
echo Colors::DEFAULT . 'Checking domain ' . Colors::YELLOW . $domainName . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
}
|
||||
|
||||
if (!$domain = $this->domainRepository->findByName(name: $domainName)) {
|
||||
if (!$quiet) {
|
||||
echo COLOR_DEFAULT . 'Domain ' . $domainName . ' not found on this server.' . PHP_EOL;
|
||||
if (!$this->quiet) {
|
||||
echo Colors::DEFAULT . 'Domain ' . $domainName . ' not found on this server.' . PHP_EOL;
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!$this->domainController->isMasterZone(domain: $domain)) {
|
||||
if (!$quiet) {
|
||||
echo 'This server is not responsible for ' . COLOR_YELLOW . $domainName . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
if (!$this->quiet) {
|
||||
echo 'This server is not responsible for ' . Colors::YELLOW . $domainName . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
@ -2094,8 +2086,8 @@ const VERSION = '{$versionSting}';
|
|||
$webmailDomain = 'webmail.' . $domainName;
|
||||
|
||||
if (!empty($panel->getAAAA())) {
|
||||
if (!$quiet) {
|
||||
echo 'Check using IPv6: ' . COLOR_YELLOW . $panel->getAaaa() . '.' . COLOR_DEFAULT . PHP_EOL;
|
||||
if (!$this->quiet) {
|
||||
echo 'Check using IPv6: ' . Colors::YELLOW . $panel->getAaaa() . '.' . Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
$result = $this->apiClient->sendCommand(
|
||||
requestType: 'GET',
|
||||
|
@ -2105,8 +2097,8 @@ const VERSION = '{$versionSting}';
|
|||
command: 'domains/name/' . $webmailDomain,
|
||||
serverType: 'panel');
|
||||
} else {
|
||||
if (!$quiet) {
|
||||
echo 'Check using IPv4: ' . COLOR_YELLOW . $panel->getA() . COLOR_DEFAULT . PHP_EOL;
|
||||
if (!$this->quiet) {
|
||||
echo 'Check using IPv4: ' . Colors::YELLOW . $panel->getA() . Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
$result = $this->apiClient->sendCommand(
|
||||
requestType: 'GET',
|
||||
|
@ -2118,58 +2110,58 @@ const VERSION = '{$versionSting}';
|
|||
}
|
||||
|
||||
if ($result['header'] === 404) {
|
||||
if (!$quiet) {
|
||||
echo 'The domain ' . COLOR_YELLOW . $webmailDomain . COLOR_DEFAULT . " doesn't exist." . PHP_EOL;
|
||||
if (!$this->quiet) {
|
||||
echo 'The domain ' . Colors::YELLOW . $webmailDomain . Colors::DEFAULT . " doesn't exist." . PHP_EOL;
|
||||
}
|
||||
exit(1);
|
||||
} else {
|
||||
if (!$quiet) {
|
||||
echo 'Found ' . COLOR_YELLOW . $webmailDomain . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
if (!$this->quiet) {
|
||||
echo 'Found ' . Colors::YELLOW . $webmailDomain . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
if ($v4 = dns_get_record(hostname: $webmailDomain, type: DNS_A)[0]) {
|
||||
if (!$quiet) {
|
||||
echo "Found IPv4 entry: " . COLOR_YELLOW . $v4['ip'] . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
if (!$this->quiet) {
|
||||
echo "Found IPv4 entry: " . Colors::YELLOW . $v4['ip'] . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
}
|
||||
$v4Test = $this->apiClient->fileGetContents(url: $webmailDomain, versionIP: 4);
|
||||
|
||||
if ($v4Test['error']) {
|
||||
if (!$quiet) {
|
||||
echo 'There was an error: ' . COLOR_YELLOW . $v4Test['errorMessage'] . COLOR_DEFAULT . '.';
|
||||
if (!$this->quiet) {
|
||||
echo 'There was an error: ' . Colors::YELLOW . $v4Test['errorMessage'] . Colors::DEFAULT . '.';
|
||||
}
|
||||
exit(1);
|
||||
} else {
|
||||
if (!$quiet) {
|
||||
echo 'Successfully connected to webserver via ' . COLOR_YELLOW . 'IPv4' . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
if (!$this->quiet) {
|
||||
echo 'Successfully connected to webserver via ' . Colors::YELLOW . 'IPv4' . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!$quiet) {
|
||||
echo "Found no IPv4 entry for " . COLOR_YELLOW . $webmailDomain . COLOR_DEFAULT . PHP_EOL;
|
||||
if (!$this->quiet) {
|
||||
echo "Found no IPv4 entry for " . Colors::YELLOW . $webmailDomain . Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($v6 = dns_get_record(hostname: $webmailDomain, type: DNS_AAAA)[0]) {
|
||||
if (!$quiet) {
|
||||
echo "Found IPv6 entry: " . COLOR_YELLOW . $v6['ipv6'] . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
if (!$this->quiet) {
|
||||
echo "Found IPv6 entry: " . Colors::YELLOW . $v6['ipv6'] . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
}
|
||||
$v6Test = $this->apiClient->fileGetContents(url: $webmailDomain, versionIP: 6);
|
||||
|
||||
if ($v6Test['error']) {
|
||||
if (!$quiet) {
|
||||
echo 'There was an error: ' . COLOR_YELLOW . $v6Test['errorMessage'] . COLOR_DEFAULT . '.';
|
||||
if (!$this->quiet) {
|
||||
echo 'There was an error: ' . Colors::YELLOW . $v6Test['errorMessage'] . Colors::DEFAULT . '.';
|
||||
}
|
||||
exit(1);
|
||||
} else {
|
||||
if (!$quiet) {
|
||||
echo 'Successfully connected to webserver via ' . COLOR_YELLOW . 'IPv6' . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
if (!$this->quiet) {
|
||||
echo 'Successfully connected to webserver via ' . Colors::YELLOW . 'IPv6' . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!$quiet) {
|
||||
echo "Found no IPv6 entry for " . COLOR_YELLOW . $webmailDomain . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
if (!$this->quiet) {
|
||||
echo "Found no IPv6 entry for " . Colors::YELLOW . $webmailDomain . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2181,12 +2173,12 @@ const VERSION = '{$versionSting}';
|
|||
$httpsDirectives = $apacheData->https_directives . PHP_EOL;
|
||||
|
||||
if (!str_contains(haystack: $httpsDirectives, needle: '# bindAPI - webmailer')) {
|
||||
if (!$quiet) {
|
||||
if (!$this->quiet) {
|
||||
echo 'Generated config is missing.' . PHP_EOL;
|
||||
}
|
||||
exit(1);
|
||||
} else {
|
||||
if (!$quiet) {
|
||||
if (!$this->quiet) {
|
||||
echo 'Generated config is valid.' . PHP_EOL;
|
||||
}
|
||||
exit(0);
|
||||
|
@ -2228,7 +2220,7 @@ const VERSION = '{$versionSting}';
|
|||
$action = $this->arguments[1];
|
||||
if ($action !== 'update') {
|
||||
if (!$this->quiet) {
|
||||
echo 'The only allowed argument is "' . COLOR_YELLOW . 'update' . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
echo 'The only allowed argument is "' . Colors::YELLOW . 'update' . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
@ -2338,23 +2330,23 @@ const VERSION = '{$versionSting}';
|
|||
if ($panelCount != 1) {
|
||||
if ($panelCount == 0) {
|
||||
echo 'No panel marked as this server.' . PHP_EOL;
|
||||
echo 'Use ' . COLOR_YELLOW . 'panels:update <ID> self=yes ' . COLOR_DEFAULT . 'to mark this panel.' . PHP_EOL;
|
||||
echo 'Use ' . Colors::YELLOW . 'panels:update <ID> self=yes ' . Colors::DEFAULT . 'to mark this panel.' . PHP_EOL;
|
||||
} else {
|
||||
echo 'Only one panel can be marked as self.' . PHP_EOL;
|
||||
echo 'Use ' . COLOR_YELLOW . 'panels:update <ID> self=no ' . COLOR_DEFAULT . 'to remove the stale panel' . PHP_EOL;
|
||||
echo 'Use ' . Colors::YELLOW . 'panels:update <ID> self=no ' . Colors::DEFAULT . 'to remove the stale panel' . PHP_EOL;
|
||||
}
|
||||
} else {
|
||||
if (!$this->quiet) {
|
||||
echo 'Only one panel is designated as our host' . COLOR_GREEN . ' OK' . COLOR_DEFAULT . PHP_EOL;
|
||||
echo 'Only one panel is designated as our host' . Colors::GREEN . ' OK' . Colors::DEFAULT . PHP_EOL;
|
||||
$self = $this->panelRepository->getSelf();
|
||||
$selfName = $self->getName();
|
||||
echo 'The panel is configured to be ' . COLOR_YELLOW . $selfName;
|
||||
echo 'The panel is configured to be ' . Colors::YELLOW . $selfName;
|
||||
$hostname = gethostname();
|
||||
if (strcmp(string1: $hostname, string2: $selfName) === 0) {
|
||||
echo COLOR_DEFAULT . ' and that seems to be valid.' . PHP_EOL;
|
||||
echo Colors::DEFAULT . ' and that seems to be valid.' . PHP_EOL;
|
||||
} else {
|
||||
echo PHP_EOL;
|
||||
echo $selfName . COLOR_DEFAULT . ' and ' . COLOR_YELLOW . $hostname . COLOR_DEFAULT . ' differ.' . PHP_EOL;
|
||||
echo $selfName . Colors::DEFAULT . ' and ' . Colors::YELLOW . $hostname . Colors::DEFAULT . ' differ.' . PHP_EOL;
|
||||
echo 'Name mismatch, maybe panel:self not set?' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
@ -2373,19 +2365,19 @@ const VERSION = '{$versionSting}';
|
|||
if (!$this->quiet) {
|
||||
echo 'No nameserver marked as this server.' . PHP_EOL;
|
||||
echo 'The setting is used to generate the default nameserver in SwaggerUI.' . PHP_EOL;
|
||||
echo 'Use ' . COLOR_YELLOW . 'nameservers:update <ID> self=yes ' . COLOR_DEFAULT . 'to mark this nameserver.' . PHP_EOL;
|
||||
echo 'Use ' . Colors::YELLOW . 'nameservers:update <ID> self=yes ' . Colors::DEFAULT . 'to mark this nameserver.' . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
if (!$this->quiet) {
|
||||
echo 'Only one nameserver should be marked as self.' . PHP_EOL;
|
||||
echo 'The setting is used to generate the default nameserver in SwaggerUI.' . PHP_EOL;
|
||||
echo 'Use ' . COLOR_YELLOW . 'nameservers:update <ID> self=no ' . COLOR_DEFAULT . 'to remove the stale nameserver' . PHP_EOL;
|
||||
echo 'Use ' . Colors::YELLOW . 'nameservers:update <ID> self=no ' . Colors::DEFAULT . 'to remove the stale nameserver' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!$this->quiet) {
|
||||
echo 'Only one nameserver is designated as our host' . COLOR_GREEN . ' OK' . COLOR_DEFAULT . PHP_EOL;
|
||||
echo 'Only one nameserver is designated as our host' . Colors::GREEN . ' OK' . Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2407,9 +2399,19 @@ const VERSION = '{$versionSting}';
|
|||
$nameservers = $this->nameserverRepository->findAll();
|
||||
foreach ($nameservers as $nameserver) {
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_YELLOW . $nameserver->getName();
|
||||
echo Colors::YELLOW . $nameserver->getName();
|
||||
$this->checkNameserverVersion(server: $nameserver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function checkCache()
|
||||
{
|
||||
if (function_exists(function: 'opcache_reset')) {
|
||||
opcache_reset();
|
||||
echo 'Cache cleared.' . PHP_EOL;
|
||||
} else {
|
||||
echo Color::RED . 'Errror: ' . Colors::DEFAULT . 'Missing function opcache_clear()' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace App\Controller\Commands;
|
||||
|
||||
use App\Utilities\Colors;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -31,17 +33,17 @@ class CommandGroup
|
|||
|
||||
public function printCommands(int $longestCommandLength): void
|
||||
{
|
||||
echo COLOR_YELLOW . str_pad(string: $this->name, length: $longestCommandLength + 1) . COLOR_WHITE . $this->description . COLOR_DEFAULT . PHP_EOL;
|
||||
echo Colors::YELLOW . str_pad(string: $this->name, length: $longestCommandLength + 1) . Colors::WHITE . $this->description . Colors::DEFAULT . PHP_EOL;
|
||||
foreach ($this->commands as $command) {
|
||||
echo COLOR_GREEN . str_pad(string: ' ', length: $longestCommandLength + 1, pad_type: STR_PAD_LEFT) . $this->name . ':' . $command->getName();
|
||||
echo Colors::GREEN . str_pad(string: ' ', length: $longestCommandLength + 1, pad_type: STR_PAD_LEFT) . $this->name . ':' . $command->getName();
|
||||
foreach ($command->getMandatoryParameters() as $optionals) {
|
||||
echo ' <' . $optionals . '>';
|
||||
}
|
||||
foreach ($command->getOptionalParameters() as $mandatory) {
|
||||
echo ' {' . $mandatory . '}';
|
||||
}
|
||||
echo COLOR_WHITE . ' ' . $command->getDescription();
|
||||
echo COLOR_DEFAULT . PHP_EOL;
|
||||
echo Colors::WHITE . ' ' . $command->getDescription();
|
||||
echo Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace App\Controller\Commands;
|
||||
|
||||
use App\Utilities\Colors;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -64,23 +66,23 @@ class CommandGroupContainer
|
|||
if ($group->exec(subcommand: $subcommand)) {
|
||||
exit(0);
|
||||
} else {
|
||||
echo COLOR_DEFAULT . 'Unknown subcommand ' . COLOR_YELLOW . $subcommand . COLOR_DEFAULT .' for ' . COLOR_YELLOW . $command . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
echo Colors::DEFAULT . 'Unknown subcommand ' . Colors::YELLOW . $subcommand . Colors::DEFAULT .' for ' . Colors::YELLOW . $command . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
echo COLOR_DEFAULT . 'Unknown command group ' . COLOR_YELLOW . $command . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
echo Colors::DEFAULT . 'Unknown command group ' . Colors::YELLOW . $command . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
// check for command group and print available commands
|
||||
foreach ($this->commandGroups as $group) {
|
||||
if ($group->getName() === $command) {
|
||||
echo 'Available subcommands for: ' . COLOR_YELLOW . $group->getName() . COLOR_DEFAULT . ':' . PHP_EOL;
|
||||
echo 'Available subcommands for: ' . Colors::YELLOW . $group->getName() . Colors::DEFAULT . ':' . PHP_EOL;
|
||||
$group->printCommands(strlen(string: $group->getName()));
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
echo COLOR_DEFAULT . 'Unknown command ' . COLOR_YELLOW . $command . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
echo Colors::DEFAULT . 'Unknown command ' . Colors::YELLOW . $command . Colors::DEFAULT . '.' . PHP_EOL;
|
||||
}
|
||||
}
|
|
@ -2,11 +2,14 @@
|
|||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Utilities\Colors;
|
||||
|
||||
class ConfigController
|
||||
{
|
||||
private array $config;
|
||||
private static $missingEncryptionShown = false;
|
||||
|
||||
public function __construct(bool $quiet, bool $test = false)
|
||||
public function __construct(private readonly bool $quiet, bool $test = false)
|
||||
{
|
||||
|
||||
if ($test) {
|
||||
|
@ -35,16 +38,23 @@ class ConfigController
|
|||
}
|
||||
$configJSON = file_get_contents(filename: $configFile);
|
||||
|
||||
if (json_decode(json: $configJSON) === null) {
|
||||
// first check if json is valid, after make the assignment
|
||||
if (json_decode(json: $configJSON, associative: true) === null) {
|
||||
echo 'Config file is not valid JSON.' . PHP_EOL;
|
||||
echo $configJSON . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$this->config = json_decode(json: $configJSON, associative: true);
|
||||
if (!ConfigController::$missingEncryptionShown) {
|
||||
if ($this->config['encryptionKey'] === '1bad::babe') {
|
||||
ConfigController::$missingEncryptionShown = true;
|
||||
if (!$this->quiet) {
|
||||
echo Colors::RED . 'Error: ' . Colors::DEFAULT . 'No encryption key, please run ' . Colors::YELLOW . './bin/console check:generatekey' . Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->config['quiet'] = (bool)$quiet;
|
||||
$this->config['test'] = (bool)$test;
|
||||
}
|
||||
|
||||
public function getConfig(string $configKey): string
|
||||
|
|
|
@ -7,6 +7,7 @@ use App\Repository\DomainRepository;
|
|||
use App\Repository\NameserverRepository;
|
||||
use App\Repository\PanelRepository;
|
||||
use App\Service\ApiClient;
|
||||
use App\Utilities\Colors;
|
||||
use Monolog\Logger;
|
||||
|
||||
error_reporting(error_level: E_ALL);
|
||||
|
@ -82,13 +83,13 @@ class DomainController
|
|||
foreach ($domains as $domain) {
|
||||
$zoneFile = $this->localZonesDir . $domain->getName();
|
||||
if (!$this->quiet) {
|
||||
echo ' ' . COLOR_YELLOW . str_pad(string: $domain->getName(), length: $longestEntry + 1, pad_string: " ", pad_type: STR_PAD_RIGHT) ;
|
||||
echo ' ' . Colors::YELLOW . str_pad(string: $domain->getName(), length: $longestEntry + 1, pad_string: " ", pad_type: STR_PAD_RIGHT) ;
|
||||
}
|
||||
|
||||
if (strcmp(string1: $self->getName(), string2: $domain->getPanel()) !== 0) {
|
||||
if (!file_exists(filename: $zoneFile)) {
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_GREEN . ' OK' . COLOR_DEFAULT . PHP_EOL;
|
||||
echo Colors::GREEN . ' OK' . Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
$this->createSlaveZoneFile(domain: $domain);
|
||||
} else {
|
||||
|
@ -100,19 +101,19 @@ class DomainController
|
|||
echo 'missing value: ' . $zoneFile;
|
||||
}
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_DEFAULT . 'Zone already exists.' . PHP_EOL;
|
||||
echo Colors::DEFAULT . 'Zone already exists.' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_DEFAULT . 'We are master for ' . COLOR_YELLOW . $domain->getName() . PHP_EOL;
|
||||
echo Colors::DEFAULT . 'We are master for ' . Colors::YELLOW . $domain->getName() . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
// remove stale zones
|
||||
foreach ($existingZones as $zone) {
|
||||
if (!$this->quiet) {
|
||||
echo 'Removing stale zone: ' . COLOR_YELLOW . $zone . COLOR_DEFAULT . PHP_EOL;
|
||||
echo 'Removing stale zone: ' . Colors::YELLOW . $zone . Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
echo $zone . PHP_EOL;
|
||||
unlink(filename: $zone);
|
||||
|
@ -190,12 +191,12 @@ class DomainController
|
|||
$uid = posix_geteuid();
|
||||
}
|
||||
if (!$this->quiet) {
|
||||
echo "UID:\t" . COLOR_YELLOW . $uid . PHP_EOL;
|
||||
echo "UID:\t" . Colors::YELLOW . $uid . PHP_EOL;
|
||||
}
|
||||
$pwuid = posix_getpwuid(user_id: $uid);
|
||||
$name = $pwuid['name'];
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_DEFAULT . "Name:\t" . COLOR_YELLOW . $name . PHP_EOL;
|
||||
echo Colors::DEFAULT . "Name:\t" . Colors::YELLOW . $name . PHP_EOL;
|
||||
}
|
||||
|
||||
if (!$bindGroup = posix_getgrnam(name: 'bind')) {
|
||||
|
@ -204,40 +205,40 @@ class DomainController
|
|||
$members = $bindGroup['members'] ?? [];
|
||||
if (in_array(needle: $name, haystack: $members)) {
|
||||
if (!$this->quiet) {
|
||||
echo "\t✅ $name" . COLOR_DEFAULT . ' is in group ' . COLOR_YELLOW . 'bind' . PHP_EOL;
|
||||
echo "\t✅ $name" . Colors::DEFAULT . ' is in group ' . Colors::YELLOW . 'bind' . PHP_EOL;
|
||||
}
|
||||
} else {
|
||||
$setupIsValid = false;
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_RED . "\t❌$name needs to be in group " . COLOR_YELLOW . 'bind' . COLOR_DEFAULT . '!' . PHP_EOL;
|
||||
echo Colors::RED . "\t❌$name needs to be in group " . Colors::YELLOW . 'bind' . Colors::DEFAULT . '!' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_DEFAULT . 'Checking ' . COLOR_YELLOW . $this->localZoneFile . PHP_EOL;
|
||||
echo Colors::DEFAULT . 'Checking ' . Colors::YELLOW . $this->localZoneFile . PHP_EOL;
|
||||
}
|
||||
$localZoneFilePermissions = @fileperms(filename: $this->localZoneFile);
|
||||
if ($localZoneFilePermissions & 0x0010) {
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_DEFAULT . "\t✅ Group has write access." . PHP_EOL;
|
||||
echo Colors::DEFAULT . "\t✅ Group has write access." . PHP_EOL;
|
||||
}
|
||||
} else {
|
||||
$setupIsValid = false;
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_RED . "\t❌Group needs write permission!" . COLOR_DEFAULT . PHP_EOL;
|
||||
echo Colors::RED . "\t❌Group needs write permission!" . Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
}
|
||||
if (!$this->quiet) {
|
||||
echo 'Checking ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL;
|
||||
echo 'Checking ' . Colors::YELLOW . $this->namedConfLocalFile . PHP_EOL;
|
||||
}
|
||||
if (file_exists(filename: $this->namedConfLocalFile) && $namedConfLocal = file_get_contents(filename: $this->namedConfLocalFile)) {
|
||||
if (!str_contains(haystack: $namedConfLocal, needle: $this->localZoneFile)) {
|
||||
$setupIsValid = false;
|
||||
if (!$this->quiet) {
|
||||
echo "\t❌ $this->localZoneFile" . COLOR_RED . ' needs to be included in ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL;
|
||||
echo "\t❌ $this->localZoneFile" . Colors::RED . ' needs to be included in ' . Colors::YELLOW . $this->namedConfLocalFile . PHP_EOL;
|
||||
}
|
||||
} else {
|
||||
if (!$this->quiet) {
|
||||
echo "\t✅ $this->localZoneFile" . COLOR_DEFAULT . ' is included in ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL;
|
||||
echo "\t✅ $this->localZoneFile" . Colors::DEFAULT . ' is included in ' . Colors::YELLOW . $this->namedConfLocalFile . PHP_EOL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -247,7 +248,7 @@ class DomainController
|
|||
}
|
||||
}
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_DEFAULT . 'Checking directory: ' . COLOR_YELLOW . $this->localZonesDir . PHP_EOL;
|
||||
echo Colors::DEFAULT . 'Checking directory: ' . Colors::YELLOW . $this->localZonesDir . PHP_EOL;
|
||||
}
|
||||
$localZoneDirPermissions = @fileperms(filename: $this->localZonesDir);
|
||||
if ($localZoneDirPermissions & 0x0010) {
|
||||
|
@ -257,7 +258,7 @@ class DomainController
|
|||
} else {
|
||||
$setupIsValid = false;
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_RED . "\t❌Group needs write permission!" . PHP_EOL;
|
||||
echo Colors::RED . "\t❌Group needs write permission!" . PHP_EOL;
|
||||
}
|
||||
}
|
||||
return $setupIsValid;
|
||||
|
@ -271,7 +272,7 @@ class DomainController
|
|||
{
|
||||
if (!file_exists(filename: $this->localZoneFile)) {
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_DEFAULT . 'Local Zone file ' . COLOR_YELLOW . $this->localZoneFile . COLOR_DEFAULT . ' does not exist.' . PHP_EOL;
|
||||
echo Colors::DEFAULT . 'Local Zone file ' . Colors::YELLOW . $this->localZoneFile . Colors::DEFAULT . ' does not exist.' . PHP_EOL;
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
@ -282,33 +283,33 @@ class DomainController
|
|||
foreach ($domains as $domain) {
|
||||
$idString = '(' . $domain->getId() . ') ';
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_YELLOW .
|
||||
echo Colors::YELLOW .
|
||||
str_pad(string: $domain->getName(), length: $maxNameLength + 1)
|
||||
. COLOR_DEFAULT
|
||||
. Colors::DEFAULT
|
||||
. str_pad(string: $idString, length: 7, pad_type: STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
$hasError = false;
|
||||
if ($this->isMasterZone(domain: $domain)) {
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_GREEN . 'Master Zone';
|
||||
echo Colors::GREEN . 'Master Zone';
|
||||
}
|
||||
} else {
|
||||
if (!str_contains(haystack: $localZones, needle: $domain->getName())) {
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_RED . 'is missing in ' . COLOR_YELLOW . $this->localZoneFile . COLOR_DEFAULT;
|
||||
echo Colors::RED . 'is missing in ' . Colors::YELLOW . $this->localZoneFile . Colors::DEFAULT;
|
||||
}
|
||||
$hasError = true;
|
||||
} else {
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_GREEN . 'OK';
|
||||
echo Colors::GREEN . 'OK';
|
||||
}
|
||||
}
|
||||
|
||||
$zoneFile = $this->localZonesDir . $domain->getName();
|
||||
|
||||
if (!file_exists(filename: $zoneFile)) {
|
||||
echo ' Missing zone file for ' . COLOR_YELLOW . $zoneFile . COLOR_DEFAULT;
|
||||
echo ' Missing zone file for ' . Colors::YELLOW . $zoneFile . Colors::DEFAULT;
|
||||
$hasError = true;
|
||||
}
|
||||
|
||||
|
@ -317,7 +318,7 @@ class DomainController
|
|||
}
|
||||
}
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_DEFAULT . PHP_EOL;
|
||||
echo Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -367,7 +368,7 @@ class DomainController
|
|||
return true;
|
||||
} else {
|
||||
if (!$this->quiet) {
|
||||
echo COLOR_RED . ' Error: ' . COLOR_DEFAULT . 'unable to create ' . COLOR_YELLOW . $this->localZonesDir . $domainName . COLOR_DEFAULT . PHP_EOL;
|
||||
echo Colors::RED . ' Error: ' . Colors::DEFAULT . 'unable to create ' . Colors::YELLOW . $this->localZonesDir . $domainName . Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Provider;
|
|||
//error_reporting(error_level: E_ALL);
|
||||
|
||||
|
||||
use App\Utilities\Colors;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use PHPUnit\Exception;
|
||||
|
@ -54,8 +55,8 @@ class DatabaseConnection
|
|||
$result = $statement->fetch();
|
||||
if (empty($result)) {
|
||||
// ALTER TABLE `domains` ADD `panel_id` INT NULL AFTER `id`;
|
||||
echo COLOR_RED . 'Error: ' . COLOR_DEFAULT . 'Cannot find tables.' . PHP_EOL;
|
||||
echo 'Run the migration: ' . COLOR_YELLOW . './bin/console migrations:migrate' . COLOR_DEFAULT . PHP_EOL;
|
||||
echo Colors::RED . 'Error: ' . Colors::DEFAULT . 'Cannot find tables.' . PHP_EOL;
|
||||
echo 'Run the migration: ' . Colors::YELLOW . './bin/console migrations:migrate' . Colors::DEFAULT . PHP_EOL;
|
||||
}
|
||||
} catch (PDOException $exception) {
|
||||
echo $exception->getMessage() . PHP_EOL;
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace App\Utilities;
|
||||
|
||||
class Colors
|
||||
{
|
||||
const RED = "\033[31m";
|
||||
const GREEN = "\033[32m";
|
||||
const YELLOW = "\033[33m";
|
||||
const BLUE = "\033[34m";
|
||||
const WHITE = "\033[37m";
|
||||
const DEFAULT = "\033[39m";
|
||||
}
|
Loading…
Reference in New Issue