some bugfixes
This commit is contained in:
parent
02cdc70e9b
commit
3a29039bde
4
TODO
4
TODO
|
@ -1,6 +1,6 @@
|
||||||
check:config *validate if all required fields are set, sanity checks.
|
|
||||||
API Endpoint cleanup
|
API Endpoint cleanup
|
||||||
check keytype of panel/bindApi
|
check keytype of panel
|
||||||
|
check keytype of 1bindApi
|
||||||
check:configkey => update config.json
|
check:configkey => update config.json
|
||||||
more UNIT tests
|
more UNIT tests
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,11 @@ if (php_sapi_name() !== 'cli') {
|
||||||
|
|
||||||
// check php version (must be >= 8.1)
|
// check php version (must be >= 8.1)
|
||||||
/** @noinspection PhpArgumentWithoutNamedIdentifierInspection */
|
/** @noinspection PhpArgumentWithoutNamedIdentifierInspection */
|
||||||
if (version_compare(PHP_VERSION, '8.1.0', '<')) {
|
if (version_compare(PHP_VERSION, '8.2.0', '<')) {
|
||||||
echo 'This application requires PHP 8.1 or newer. You are running ' . PHP_VERSION . PHP_EOL;
|
echo 'This application requires PHP 8.2 or newer. You are running ' . PHP_VERSION . PHP_EOL;
|
||||||
echo 'If you are using KeyHelp, use keyhelp-php81 ' . $argv[0] . ' instead.' . PHP_EOL;
|
echo 'If you are using KeyHelp, use keyhelp-php82 ' . $argv[0] . ' instead.' . PHP_EOL;
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @noinspection PhpArgumentWithoutNamedIdentifierInspection */
|
/** @noinspection PhpArgumentWithoutNamedIdentifierInspection */
|
||||||
require dirname(__DIR__, 1) . '/src/Util/Console.php';
|
require dirname(__DIR__, 1) . '/src/Utilities/Console.php';
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"name": "tracer/bindapi",
|
"name": "tracer/bindapi",
|
||||||
"description": "manage Bind9 client zones for KeyHelp",
|
"description": "manage Bind9 client zones for KeyHelp",
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"build_number": "379",
|
"build_number": "380",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Micha Espey",
|
"name": "Micha Espey",
|
||||||
|
|
|
@ -318,13 +318,13 @@ class CLIController
|
||||||
|
|
||||||
$this->commandGroupContainer = (new CommandGroupContainer())
|
$this->commandGroupContainer = (new CommandGroupContainer())
|
||||||
->addCommandGroup(commandGroup: $apikeyGroup)
|
->addCommandGroup(commandGroup: $apikeyGroup)
|
||||||
->addCommandGroup($cronGroup)
|
->addCommandGroup(commandGroup: $cronGroup)
|
||||||
->addCommandGroup($panelsGroup)
|
->addCommandGroup(commandGroup: $panelsGroup)
|
||||||
->addCommandGroup($domainsGroup)
|
->addCommandGroup(commandGroup: $domainsGroup)
|
||||||
->addCommandGroup($nameserversGroup)
|
->addCommandGroup(commandGroup: $nameserversGroup)
|
||||||
->addCommandGroup($dyndnsGroup)
|
->addCommandGroup(commandGroup: $dyndnsGroup)
|
||||||
->addCommandGroup($checkGroup)
|
->addCommandGroup(commandGroup: $checkGroup)
|
||||||
->addCommandGroup($migrationsGroup);
|
->addCommandGroup(commandGroup: $migrationsGroup);
|
||||||
|
|
||||||
|
|
||||||
// ->addCommandGroup(commandGroup: (new CommandGroup(name: 'webmail', description: 'manage webmail setup'))
|
// ->addCommandGroup(commandGroup: (new CommandGroup(name: 'webmail', description: 'manage webmail setup'))
|
||||||
|
@ -369,6 +369,8 @@ class CLIController
|
||||||
$this->logger->debug(message: "runCommand()");
|
$this->logger->debug(message: "runCommand()");
|
||||||
|
|
||||||
|
|
||||||
|
$this->checkConfig();
|
||||||
|
|
||||||
if (str_contains(haystack: $arguments[0], needle: ':')) {
|
if (str_contains(haystack: $arguments[0], needle: ':')) {
|
||||||
[$command, $subcommand] = explode(separator: ':', string: $arguments[0]);
|
[$command, $subcommand] = explode(separator: ':', string: $arguments[0]);
|
||||||
} else {
|
} else {
|
||||||
|
@ -792,12 +794,12 @@ class CLIController
|
||||||
break;
|
break;
|
||||||
case 401:
|
case 401:
|
||||||
if (!$this->quiet) {
|
if (!$this->quiet) {
|
||||||
echo Color::RED . ' Error: ' . Colors::YELLOW . $result['data'] . Colors::DEFAULT . PHP_EOL;
|
echo Colors::RED . ' Error: ' . Colors::YELLOW . $result['data'] . Colors::DEFAULT . PHP_EOL;
|
||||||
}
|
}
|
||||||
exit(1);
|
exit(1);
|
||||||
case 404:
|
case 404:
|
||||||
if (!$this->quiet) {
|
if (!$this->quiet) {
|
||||||
echo Color::RED . ' ' . $result['header'] . Colors::DEFAULT;
|
echo Colors::RED . ' ' . $result['header'] . Colors::DEFAULT;
|
||||||
}
|
}
|
||||||
if (!empty($this->arguments['fix']) && $this->arguments['fix'] == 'yes') {
|
if (!empty($this->arguments['fix']) && $this->arguments['fix'] == 'yes') {
|
||||||
if (!$this->quiet) {
|
if (!$this->quiet) {
|
||||||
|
@ -2310,7 +2312,7 @@ const VERSION = '{$versionSting}';
|
||||||
{
|
{
|
||||||
$phinx = new PhinxApplication();
|
$phinx = new PhinxApplication();
|
||||||
|
|
||||||
$phinx->add(new GenerateCommand());
|
$phinx->add(command: new GenerateCommand());
|
||||||
|
|
||||||
$arguments = [
|
$arguments = [
|
||||||
'command' => 'generate',
|
'command' => 'generate',
|
||||||
|
@ -2436,4 +2438,49 @@ const VERSION = '{$versionSting}';
|
||||||
echo 'Created new bootsrap.php' . PHP_EOL;
|
echo 'Created new bootsrap.php' . PHP_EOL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function checkConfig(): void
|
||||||
|
{
|
||||||
|
echo 'checking config.' . PHP_EOL;
|
||||||
|
$error = [];
|
||||||
|
$env = $this->configController->getConfig(configKey: 'env');
|
||||||
|
switch ($env) {
|
||||||
|
case 'prod':
|
||||||
|
$configFile = $this->baseDir . 'config.json';
|
||||||
|
break;
|
||||||
|
case 'test':
|
||||||
|
$configFile = $this->baseDir . 'config.json.test';
|
||||||
|
break;
|
||||||
|
case 'dev':
|
||||||
|
// currently both dev and test use config.json
|
||||||
|
$configFile = $this->baseDir . 'config.json';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (!$this->quiet) {
|
||||||
|
echo Colors::RED . 'Error: ' . Colors::DEFAULT . 'unknown environment: env = ' . Colors::YELLOW . $env . Colors::DEFAULT . PHP_EOL;
|
||||||
|
}
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->quiet) {
|
||||||
|
echo Colors::DEFAULT . 'Checking config file ' . Colors::YELLOW . $configFile . Colors::DEFAULT . '.' . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
$config = file_get_contents(filename: $configFile);
|
||||||
|
$configValues = json_decode(json: $config);
|
||||||
|
|
||||||
|
// db settings are mandatory, but already checked while invoking DatabaseConnection.
|
||||||
|
$encryptionKey = $configValues->encryptionKey;
|
||||||
|
if (strlen(string: $encryptionKey) != 64) {
|
||||||
|
echo Colors::RED . 'Error: ' . Colors::DEFAULT . 'This is no valid encryption key.' . PHP_EOL;
|
||||||
|
echo 'Run ' . Colors::YELLOW . './bin/console check:generatekey ' . Colors::DEFAULT . 'to create a new one' . PHP_EOL;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$binKey = sodium_hex2bin(string: $encryptionKey);
|
||||||
|
} catch (SodiumException $exception) {
|
||||||
|
echo Colors::RED . 'Error: ' . Colors::YELLOW . $exception->getMessage() . Colors::DEFAULT;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,19 +47,24 @@ class ConfigController
|
||||||
|
|
||||||
$this->config = json_decode(json: $configJSON, associative: true);
|
$this->config = json_decode(json: $configJSON, associative: true);
|
||||||
if (!ConfigController::$missingEncryptionShown) {
|
if (!ConfigController::$missingEncryptionShown) {
|
||||||
if ($this->config['encryptionKey'] === '1bad::babe') {
|
if (!isset($this->config['encryptionKey']) || ($this->config['encryptionKey'] === '1bad::babe')) {
|
||||||
ConfigController::$missingEncryptionShown = true;
|
ConfigController::$missingEncryptionShown = true;
|
||||||
if (!$this->quiet) {
|
if (!$this->quiet) {
|
||||||
echo Colors::RED . 'Error: ' . Colors::DEFAULT . 'No encryption key, please run ' . Colors::YELLOW . './bin/console check:generatekey' . Colors::DEFAULT . PHP_EOL;
|
echo Colors::RED . 'Error: ' . Colors::DEFAULT . 'No encryption key, please run ' . Colors::YELLOW . './bin/console check:generatekey' . Colors::DEFAULT . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getConfig(string $configKey): string
|
public function getConfig(string $configKey): ?string
|
||||||
{
|
{
|
||||||
|
if (isset($this->config[$configKey])) {
|
||||||
return $this->config[$configKey];
|
return $this->config[$configKey];
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ class EncryptionController
|
||||||
|
|
||||||
$plain = sodium_crypto_secretbox_open(ciphertext: $ciphertext, nonce: $nonce, key: $binKey);
|
$plain = sodium_crypto_secretbox_open(ciphertext: $ciphertext, nonce: $nonce, key: $binKey);
|
||||||
if ($plain === false) {
|
if ($plain === false) {
|
||||||
throw new Exception(message: ' Incorrect key.');
|
throw new Exception(message: ' Incorrect key.' . PHP_EOL);
|
||||||
}
|
}
|
||||||
sodium_memzero(string: $ciphertext);
|
sodium_memzero(string: $ciphertext);
|
||||||
sodium_memzero(string: $key);
|
sodium_memzero(string: $key);
|
||||||
|
|
|
@ -28,11 +28,29 @@ class DatabaseConnection
|
||||||
|
|
||||||
public function __construct(private readonly ConfigController $configController)
|
public function __construct(private readonly ConfigController $configController)
|
||||||
{
|
{
|
||||||
$dbHost = $this->configController->getConfig(configKey: 'dbHost');
|
$errors = [];
|
||||||
$dbPort = $this->configController->getConfig(configKey: 'dbPort');
|
if (!$dbHost = $this->configController->getConfig(configKey: 'dbHost')) {
|
||||||
$dbDatabase = $this->configController->getConfig(configKey: 'dbDatabase');
|
$errors[] = Colors::RED . 'Error: ' . Colors::DEFAULT . 'Missing config: dbHost' . PHP_EOL;
|
||||||
$dbUser = $this->configController->getConfig(configKey: 'dbUser');
|
}
|
||||||
$dbPassword = $this->configController->getConfig(configKey: 'dbPassword');
|
if (!$dbPort = $this->configController->getConfig(configKey: 'dbPort')) {
|
||||||
|
$errors[] = Colors::RED . 'Error: ' . Colors::DEFAULT . 'Missing config: dbPort}' . PHP_EOL;
|
||||||
|
}
|
||||||
|
if (!$dbDatabase = $this->configController->getConfig(configKey: 'dbDatabase')) {
|
||||||
|
$errors[] = Colors::RED . 'Error: ' . Colors::DEFAULT . 'Missing config: dbDatabase' . PHP_EOL;
|
||||||
|
}
|
||||||
|
if (!$dbUser = $this->configController->getConfig(configKey: 'dbUser')) {
|
||||||
|
$errors[] = Colors::RED . 'Error: ' . Colors::DEFAULT . 'Missing config: dbUser' . PHP_EOL;
|
||||||
|
}
|
||||||
|
if (!$dbPassword = $this->configController->getConfig(configKey: 'dbPassword')) {
|
||||||
|
$errors[] = Colors::RED . 'Error: ' . Colors::DEFAULT . 'Missing config: dbPassword' . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($errors) {
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
echo $error;
|
||||||
|
}
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->dbConnection = new PDO(
|
$this->dbConnection = new PDO(
|
||||||
|
@ -72,6 +90,7 @@ class DatabaseConnection
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function generatePassword(int $length = 8): string
|
function generatePassword(int $length = 8): string
|
||||||
{
|
{
|
||||||
$chars = '23456789bcdfhkmnprstvzBCDFHJKLMNPRSTVZ';
|
$chars = '23456789bcdfhkmnprstvzBCDFHJKLMNPRSTVZ';
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Service\BindAPI;
|
use App\Service\BindAPI;
|
||||||
|
use App\Utilities\Colors;
|
||||||
|
|
||||||
error_reporting(error_level: E_ALL & ~E_DEPRECATED);
|
error_reporting(error_level: E_ALL & ~E_DEPRECATED);
|
||||||
|
|
||||||
if (!is_file(filename: dirname(path: __DIR__, levels: 2) . '/vendor/autoload.php')) {
|
if (!is_file(filename: dirname(path: __DIR__, levels: 2) . '/vendor/autoload.php')) {
|
||||||
echo 'Required runtime components are missing. Try running "' . COLOR_YELLOW . 'composer install' . COLOR_DEFAULT . '".' . PHP_EOL;
|
echo 'Required runtime components are missing. Try running "' . Colors::YELLOW . 'composer install' . Colors::DEFAULT . '".' . PHP_EOL;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue