fixed marking oown panel bug

This commit is contained in:
tracer 2024-04-18 14:20:46 +02:00
parent eaa137291b
commit 2c65f743e7
8 changed files with 124 additions and 25 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": "341", "build_number": "342",
"authors": [ "authors": [
{ {
"name": "Micha Espey", "name": "Micha Espey",

View File

@ -4,6 +4,6 @@
"dbDatabase": "sampledb", "dbDatabase": "sampledb",
"dbUser": "sampleuser", "dbUser": "sampleuser",
"dbPassword": "secret", "dbPassword": "secret",
"encryptionKey": "12345678901234567890123456789012", "encryptionKey": "changeme",
"debug": false "debug": false
} }

View File

@ -0,0 +1,33 @@
<?php
use Phinx\Db\Adapter\MysqlAdapter;
class ConfigTable extends Phinx\Migration\AbstractMigration
{
public function change()
{
$this->table('config', [
'id' => false,
'engine' => 'InnoDB',
'encoding' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci',
'comment' => '',
'row_format' => 'DYNAMIC',
])
->addColumn('name', 'string', [
'null' => false,
'limit' => 256,
'collation' => 'utf8mb4_general_ci',
'encoding' => 'utf8mb4',
])
->addColumn('value', 'string', [
'null' => false,
'limit' => 256,
'collation' => 'utf8mb4_general_ci',
'encoding' => 'utf8mb4',
'after' => 'name',
])
->removeColumn('version')
->save();
}
}

View File

@ -112,23 +112,71 @@ return array (
), ),
'columns' => 'columns' =>
array ( array (
'version' => 'name' =>
array ( array (
'TABLE_CATALOG' => 'def', 'TABLE_CATALOG' => 'def',
'TABLE_NAME' => 'config', 'TABLE_NAME' => 'config',
'COLUMN_NAME' => 'version', 'COLUMN_NAME' => 'name',
'ORDINAL_POSITION' => 1, 'ORDINAL_POSITION' => 1,
'COLUMN_DEFAULT' => NULL, 'COLUMN_DEFAULT' => NULL,
'IS_NULLABLE' => 'NO', 'IS_NULLABLE' => 'NO',
'DATA_TYPE' => 'varchar', 'DATA_TYPE' => 'varchar',
'CHARACTER_MAXIMUM_LENGTH' => 11, 'CHARACTER_MAXIMUM_LENGTH' => 256,
'CHARACTER_OCTET_LENGTH' => 44, 'CHARACTER_OCTET_LENGTH' => 1024,
'NUMERIC_PRECISION' => NULL, 'NUMERIC_PRECISION' => NULL,
'NUMERIC_SCALE' => NULL, 'NUMERIC_SCALE' => NULL,
'DATETIME_PRECISION' => NULL, 'DATETIME_PRECISION' => NULL,
'CHARACTER_SET_NAME' => 'utf8mb4', 'CHARACTER_SET_NAME' => 'utf8mb4',
'COLLATION_NAME' => 'utf8mb4_general_ci', 'COLLATION_NAME' => 'utf8mb4_general_ci',
'COLUMN_TYPE' => 'varchar(11)', 'COLUMN_TYPE' => 'varchar(256)',
'COLUMN_KEY' => '',
'EXTRA' => '',
'PRIVILEGES' => 'select,insert,update,references',
'COLUMN_COMMENT' => '',
'IS_GENERATED' => 'NEVER',
'GENERATION_EXPRESSION' => NULL,
),
'value' =>
array (
'TABLE_CATALOG' => 'def',
'TABLE_NAME' => 'config',
'COLUMN_NAME' => 'value',
'ORDINAL_POSITION' => 2,
'COLUMN_DEFAULT' => NULL,
'IS_NULLABLE' => 'NO',
'DATA_TYPE' => 'varchar',
'CHARACTER_MAXIMUM_LENGTH' => 256,
'CHARACTER_OCTET_LENGTH' => 1024,
'NUMERIC_PRECISION' => NULL,
'NUMERIC_SCALE' => NULL,
'DATETIME_PRECISION' => NULL,
'CHARACTER_SET_NAME' => 'utf8mb4',
'COLLATION_NAME' => 'utf8mb4_general_ci',
'COLUMN_TYPE' => 'varchar(256)',
'COLUMN_KEY' => '',
'EXTRA' => '',
'PRIVILEGES' => 'select,insert,update,references',
'COLUMN_COMMENT' => '',
'IS_GENERATED' => 'NEVER',
'GENERATION_EXPRESSION' => NULL,
),
'fff' =>
array (
'TABLE_CATALOG' => 'def',
'TABLE_NAME' => 'config',
'COLUMN_NAME' => 'fff',
'ORDINAL_POSITION' => 3,
'COLUMN_DEFAULT' => NULL,
'IS_NULLABLE' => 'NO',
'DATA_TYPE' => 'int',
'CHARACTER_MAXIMUM_LENGTH' => NULL,
'CHARACTER_OCTET_LENGTH' => NULL,
'NUMERIC_PRECISION' => 10,
'NUMERIC_SCALE' => 0,
'DATETIME_PRECISION' => NULL,
'CHARACTER_SET_NAME' => NULL,
'COLLATION_NAME' => NULL,
'COLUMN_TYPE' => 'int(11)',
'COLUMN_KEY' => '', 'COLUMN_KEY' => '',
'EXTRA' => '', 'EXTRA' => '',
'PRIVILEGES' => 'select,insert,update,references', 'PRIVILEGES' => 'select,insert,update,references',

View File

@ -66,8 +66,6 @@ class CLIController
private bool $quiet private bool $quiet
) )
{ {
// FIXME needs to be elsewhere $this->runCheckSetup();
$this->commandGroupContainer = (new CommandGroupContainer()) $this->commandGroupContainer = (new CommandGroupContainer())
->addCommandGroup(commandGroup: (new CommandGroup(name: 'check', description: 'health checks the system can perform')) ->addCommandGroup(commandGroup: (new CommandGroup(name: 'check', description: 'health checks the system can perform'))
->addCommand(command: new Command( ->addCommand(command: new Command(
@ -81,7 +79,6 @@ class CLIController
callback: function () { callback: function () {
$this->checkPanel(); $this->checkPanel();
}, },
optionalParameters: ['ID', 'fix=xes'],
description: 'Validate setting for this panel')) description: 'Validate setting for this panel'))
->addCommand(command: new Command( ->addCommand(command: new Command(
name: 'panels', name: 'panels',
@ -144,7 +141,7 @@ class CLIController
$this->panelsUpdate(); $this->panelsUpdate();
}, },
mandatoryParameters: ['ID'], mandatoryParameters: ['ID'],
optionalParameters: ['name=<name>', 'A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>', 'self=<0|1>'])) optionalParameters: ['name=<name>', 'A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>', 'self=<yes|no>']))
->addCommand(command: new Command( ->addCommand(command: new Command(
name: 'delete', name: 'delete',
callback: function () { callback: function () {
@ -926,6 +923,7 @@ class CLIController
} else { } else {
$panel = new Panel(name: $name, id: $id, a: $a, aaaa: $aaaa, self: $self); $panel = new Panel(name: $name, id: $id, a: $a, aaaa: $aaaa, self: $self);
} }
var_dump($panel);
if ($this->panelRepository->update(panel: $panel) !== false) { if ($this->panelRepository->update(panel: $panel) !== false) {
echo 'Panel ' . COLOR_YELLOW . $id . COLOR_DEFAULT . ' has been updated' . PHP_EOL; echo 'Panel ' . COLOR_YELLOW . $id . COLOR_DEFAULT . ' has been updated' . PHP_EOL;
} else { } else {
@ -2021,8 +2019,8 @@ class CLIController
$phinx = new PhinxApplication('Phinx', '0.9.2'); $phinx = new PhinxApplication('Phinx', '0.9.2');
// use DI later when moving to symfony // use DI later when moving to symfony
$input = new \Symfony\Component\Console\Input\ArgvInput(); // $input = new \Symfony\Component\Console\Input\ArgvInput();
$output = new \Symfony\Component\Console\Output\ConsoleOutput(); // $output = new \Symfony\Component\Console\Output\ConsoleOutput();
echo 'show migration status' . PHP_EOL; echo 'show migration status' . PHP_EOL;
$command = $phinx->find(name: 'status'); // change 'migrate' to 'status' $command = $phinx->find(name: 'status'); // change 'migrate' to 'status'
@ -2044,6 +2042,7 @@ class CLIController
$arguments = [ $arguments = [
'command' => 'generate', 'command' => 'generate',
'--overwrite' => true,
]; ];
$output = new ConsoleOutput(); $output = new ConsoleOutput();
$returnCode = $phinx->run(input: new ArrayInput(parameters: $arguments), output: $output); $returnCode = $phinx->run(input: new ArrayInput(parameters: $arguments), output: $output);
@ -2073,10 +2072,10 @@ class CLIController
if ($panelCount != 1) { if ($panelCount != 1) {
if ($panelCount == 0) { if ($panelCount == 0) {
echo 'No panel marked as this server.' . PHP_EOL; echo 'No panel marked as this server.' . PHP_EOL;
echo 'Use ' . COLOR_YELLOW . 'panels:update <ID> self=1 ' . COLOR_DEFAULT . 'to mark this panel.' . PHP_EOL; echo 'Use ' . COLOR_YELLOW . 'panels:update <ID> self=yes ' . COLOR_DEFAULT . 'to mark this panel.' . PHP_EOL;
} else { } else {
echo 'Only one panel can be marked as self.' . PHP_EOL; echo 'Only one panel can be marked as self.' . PHP_EOL;
echo 'Use ' . COLOR_YELLOW . 'panels:update <ID> self=0 ' . COLOR_DEFAULT . 'to remove the stale panel' . PHP_EOL; echo 'Use ' . COLOR_YELLOW . 'panels:update <ID> self=no ' . COLOR_DEFAULT . 'to remove the stale panel' . PHP_EOL;
} }
} else { } else {
if (!$this->quiet) { if (!$this->quiet) {

View File

@ -68,7 +68,7 @@ class CommandGroupContainer
exit(1); exit(1);
} }
} else { } else {
echo COLOR_DEFAULT . 'Unknown subcommand ' . COLOR_YELLOW . $subcommand . COLOR_DEFAULT .' for ' . COLOR_YELLOW . $command . COLOR_DEFAULT . '.' . PHP_EOL; echo COLOR_DEFAULT . 'Unknown command group ' . COLOR_YELLOW . $command . COLOR_DEFAULT . '.' . PHP_EOL;
exit(1); exit(1);
} }
} else { } else {

View File

@ -72,24 +72,42 @@ class DomainController
{ {
$this->logger->debug(message: 'Delete all slave zones'); $this->logger->debug(message: 'Delete all slave zones');
$zones = glob(pattern: $this->localZonesDir . '*'); $existingZones = glob(pattern: $this->localZonesDir . '*');
foreach ($zones as $zone) {
unlink(filename: $zone);
}
$domains = $this->domainRepository->findAll(); $domains = $this->domainRepository->findAll();
$longestEntry = $this->domainRepository->getLongestEntry('name'); $longestEntry = $this->domainRepository->getLongestEntry(field: 'name');
foreach ($domains as $domain) { foreach ($domains as $domain) {
$zoneFile = $this->localZonesDir . $domain->getName();
if (!$this->quiet) { if (!$this->quiet) {
echo ' ' . COLOR_YELLOW . str_pad($domain->getName(), $longestEntry + 1, " ", STR_PAD_RIGHT) ; echo ' ' . COLOR_YELLOW . str_pad(string: $domain->getName(), length: $longestEntry + 1, pad_string: " ", pad_type: STR_PAD_RIGHT) ;
} }
if ($this->createSlaveZoneFile(domain: $domain)) {
if (!file_exists(filename: $zoneFile)) {
if (!$this->quiet) { if (!$this->quiet) {
echo COLOR_GREEN . ' OK' . COLOR_DEFAULT . PHP_EOL; echo COLOR_GREEN . ' OK' . COLOR_DEFAULT . PHP_EOL;
} }
$this->createSlaveZoneFile(domain: $domain);
} else {
if (($key = array_search(needle: $zoneFile, haystack: $existingZones)) !== false) {
if (isset($existingZones[$key])) {
unset($existingZones[$key]);
}
} else {
echo 'missing value: ' . $zoneFile;
}
if (!$this->quiet) {
echo COLOR_DEFAULT . 'Zone already exists.' . PHP_EOL;
}
} }
} }
// remove stale zones
foreach ($existingZones as $zone) {
if (!$this->quiet) {
echo 'Removing stale zone: ' . COLOR_YELLOW . $zone . COLOR_DEFAULT . PHP_EOL;
}
unlink(filename: $zone);
}
$this->createIncludeFile(); $this->createIncludeFile();
} }

View File

@ -162,6 +162,8 @@ class PanelRepository
$apikey = $panel->getApikey(); $apikey = $panel->getApikey();
$apikeyPrefix = $panel->getApikeyPrefix(); $apikeyPrefix = $panel->getApikeyPrefix();
$passphrase = $panel->getPassphrase(); $passphrase = $panel->getPassphrase();
$self = $panel->getSelf();
echo 'self: ' . $self;
$current = $this->findByID(id: $id); $current = $this->findByID(id: $id);
@ -185,7 +187,6 @@ class PanelRepository
$self = $current->getSelf(); $self = $current->getSelf();
} }
$sql = " $sql = "
UPDATE " . DatabaseConnection::TABLE_PANELS . " SET UPDATE " . DatabaseConnection::TABLE_PANELS . " SET
name = :name, name = :name,