reworked most of the check commands
This commit is contained in:
parent
d115a5d775
commit
43698c0fae
|
@ -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": "332",
|
"build_number": "333",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Micha Espey",
|
"name": "Micha Espey",
|
||||||
|
|
|
@ -53,7 +53,8 @@ class BindAPI
|
||||||
ConfigController::class => autowire()
|
ConfigController::class => autowire()
|
||||||
->constructorParameter(parameter: 'quiet', value: $quiet),
|
->constructorParameter(parameter: 'quiet', value: $quiet),
|
||||||
CLIController::class => autowire()
|
CLIController::class => autowire()
|
||||||
->constructorParameter(parameter: 'logger', value: $this->logger),
|
->constructorParameter(parameter: 'logger', value: $this->logger)
|
||||||
|
->constructorParameter(parameter: 'quiet', value: $quiet),
|
||||||
DomainController::class => autowire()
|
DomainController::class => autowire()
|
||||||
->constructorParameter(parameter: 'logger', value: $this->logger)
|
->constructorParameter(parameter: 'logger', value: $this->logger)
|
||||||
->constructorParameter(parameter: 'quiet', value: $quiet),
|
->constructorParameter(parameter: 'quiet', value: $quiet),
|
||||||
|
|
|
@ -1,51 +1,51 @@
|
||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
error_reporting(error_level: E_ALL);
|
error_reporting(error_level: E_ALL);
|
||||||
|
|
||||||
define(constant_name: 'COLOR_RED', value: "\033[31m");
|
define(constant_name: 'COLOR_RED', value: "\033[31m");
|
||||||
define(constant_name: 'COLOR_GREEN', value: "\033[32m");
|
define(constant_name: 'COLOR_GREEN', value: "\033[32m");
|
||||||
define(constant_name: 'COLOR_YELLOW', value: "\033[33m");
|
define(constant_name: 'COLOR_YELLOW', value: "\033[33m");
|
||||||
define(constant_name: 'COLOR_BLUE', value: "\033[34m");
|
define(constant_name: 'COLOR_BLUE', value: "\033[34m");
|
||||||
define(constant_name: 'COLOR_WHITE', value: "\033[37m");
|
define(constant_name: 'COLOR_WHITE', value: "\033[37m");
|
||||||
define(constant_name: 'COLOR_DEFAULT', value: "\033[39m");
|
define(constant_name: 'COLOR_DEFAULT', value: "\033[39m");
|
||||||
|
|
||||||
use App\Controller\Commands\Command;
|
use App\Controller\Commands\Command;
|
||||||
use App\Controller\Commands\CommandGroup;
|
use App\Controller\Commands\CommandGroup;
|
||||||
use App\Controller\Commands\CommandGroupContainer;
|
use App\Controller\Commands\CommandGroupContainer;
|
||||||
use App\Entity\Apikey;
|
use App\Entity\Apikey;
|
||||||
use App\Entity\Domain;
|
use App\Entity\Domain;
|
||||||
use App\Entity\DynDNS;
|
use App\Entity\DynDNS;
|
||||||
use App\Entity\KeyHelp\KeyHelpDomain;
|
use App\Entity\KeyHelp\KeyHelpDomain;
|
||||||
use App\Entity\Nameserver;
|
use App\Entity\Nameserver;
|
||||||
use App\Entity\Panel;
|
use App\Entity\Panel;
|
||||||
use App\Repository\ApikeyRepository;
|
use App\Repository\ApikeyRepository;
|
||||||
use App\Repository\DomainRepository;
|
use App\Repository\DomainRepository;
|
||||||
use App\Repository\DynDNSRepository;
|
use App\Repository\DynDNSRepository;
|
||||||
use App\Repository\NameserverRepository;
|
use App\Repository\NameserverRepository;
|
||||||
use App\Repository\PanelRepository;
|
use App\Repository\PanelRepository;
|
||||||
use Arubacao\TldChecker\Validator;
|
use Arubacao\TldChecker\Validator;
|
||||||
use Exception;
|
use Exception;
|
||||||
use JsonMapper;
|
use JsonMapper;
|
||||||
use JsonMapper_Exception;
|
use JsonMapper_Exception;
|
||||||
use LucidFrame\Console\ConsoleTable;
|
use LucidFrame\Console\ConsoleTable;
|
||||||
use Odan\Migration\Command\GenerateCommand;
|
use Odan\Migration\Command\GenerateCommand;
|
||||||
use Phinx\Console\PhinxApplication;
|
use Phinx\Console\PhinxApplication;
|
||||||
use SodiumException;
|
use SodiumException;
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
use Symfony\Component\Console\Input\ArrayInput;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
if (php_sapi_name() !== 'cli') {
|
if (php_sapi_name() !== 'cli') {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class CLIController
|
class CLIController
|
||||||
{
|
{
|
||||||
private array $arguments;
|
private array $arguments;
|
||||||
private CommandGroupContainer $commandGroupContainer;
|
private CommandGroupContainer $commandGroupContainer;
|
||||||
|
|
||||||
|
@ -62,133 +62,135 @@
|
||||||
private readonly PanelRepository $panelRepository,
|
private readonly PanelRepository $panelRepository,
|
||||||
private readonly ConfigController $configController,
|
private readonly ConfigController $configController,
|
||||||
private readonly EncryptionController $encryptionController,
|
private readonly EncryptionController $encryptionController,
|
||||||
private $logger)
|
private $logger,
|
||||||
|
private bool $quiet
|
||||||
|
)
|
||||||
{
|
{
|
||||||
// FIXME needs to be elsewhere $this->runCheckSetup();
|
// 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(
|
||||||
name : 'permissions',
|
name: 'permissions',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->checkPermissions();
|
$this->checkPermissions();
|
||||||
},
|
},
|
||||||
description: 'check file permissions'))
|
description: 'check file permissions'))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'panels',
|
name: 'panels',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->checkPanels();
|
$this->checkPanels();
|
||||||
},
|
},
|
||||||
optionalParameters: ['ID', 'fix=xes']))
|
optionalParameters: ['ID', 'fix=xes']))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'domains',
|
name: 'domains',
|
||||||
callback: function () {
|
callback: function () {
|
||||||
$this->checkDomains();
|
$this->checkDomains();
|
||||||
}))
|
}))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'mail',
|
name: 'mail',
|
||||||
callback: function () {
|
callback: function () {
|
||||||
$this->checkMail();
|
$this->checkMail();
|
||||||
}))
|
}))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'showincludes',
|
name: 'showincludes',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->checkShowIncludes();
|
$this->checkShowIncludes();
|
||||||
},
|
},
|
||||||
description: 'Shows needed setting on panels'))
|
description: 'Shows needed setting on panels'))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'generatekey',
|
name: 'generatekey',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->checkGenerateKey();
|
$this->checkGenerateKey();
|
||||||
},
|
},
|
||||||
description: 'Generates a a new key for encryption'))
|
description: 'Generates a a new key for encryption'))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'setup',
|
name: 'setup',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->checkSetup();
|
$this->checkSetup();
|
||||||
},
|
},
|
||||||
mandatoryParameters: ['username'],
|
mandatoryParameters: ['username'],
|
||||||
description : 'Adapt filesystem permissions (requires elaborated permissions)'))
|
description: 'Adapt filesystem permissions (requires elaborated permissions)'))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'version',
|
name: 'version',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->checksVersion();
|
$this->checksVersion();
|
||||||
},
|
},
|
||||||
optionalParameters: ['major:minor:patch'],
|
optionalParameters: ['major:minor:patch'],
|
||||||
description : 'Read or set the bindApi version in the database')))
|
description: 'Read or set the bindApi version in the database')))
|
||||||
->addCommandGroup(commandGroup: (new CommandGroup(name: 'panels', description: 'all KeyHelp systems configured'))
|
->addCommandGroup(commandGroup: (new CommandGroup(name: 'panels', description: 'all KeyHelp systems configured'))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'list',
|
name: 'list',
|
||||||
callback: function () {
|
callback: function () {
|
||||||
$this->panelsList();
|
$this->panelsList();
|
||||||
}))
|
}))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'create',
|
name: 'create',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->panelsCreate();
|
$this->panelsCreate();
|
||||||
},
|
},
|
||||||
mandatoryParameters: ['name'],
|
mandatoryParameters: ['name'],
|
||||||
optionalParameters : ['A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>']))
|
optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>']))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'update',
|
name: 'update',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$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=<0|1>']))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'delete',
|
name: 'delete',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->panelsDelete();
|
$this->panelsDelete();
|
||||||
},
|
},
|
||||||
mandatoryParameters: ['ID']))
|
mandatoryParameters: ['ID']))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'apiping',
|
name: 'apiping',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->apiPing(type: 'panel');
|
$this->apiPing(type: 'panel');
|
||||||
},
|
},
|
||||||
optionalParameters: ['ID'])))
|
optionalParameters: ['ID'])))
|
||||||
->addCommandGroup(commandGroup: (new CommandGroup(name: 'nameservers', description: 'available nameservers'))
|
->addCommandGroup(commandGroup: (new CommandGroup(name: 'nameservers', description: 'available nameservers'))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'list',
|
name: 'list',
|
||||||
callback: function () {
|
callback: function () {
|
||||||
$this->nameserversList();
|
$this->nameserversList();
|
||||||
}))
|
}))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'create',
|
name: 'create',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->nameserversCreate();
|
$this->nameserversCreate();
|
||||||
},
|
},
|
||||||
mandatoryParameters: ['name'],
|
mandatoryParameters: ['name'],
|
||||||
optionalParameters : ['A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>']))
|
optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>']))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'update',
|
name: 'update',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->nameserversUpdate();
|
$this->nameserversUpdate();
|
||||||
},
|
},
|
||||||
mandatoryParameters: ['ID'],
|
mandatoryParameters: ['ID'],
|
||||||
optionalParameters : ['name=<name>', 'A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>']))
|
optionalParameters: ['name=<name>', 'A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>']))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'delete',
|
name: 'delete',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->nameserversDelete();
|
$this->nameserversDelete();
|
||||||
},
|
},
|
||||||
mandatoryParameters: ['ID']))
|
mandatoryParameters: ['ID']))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'apiping',
|
name: 'apiping',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->apiPing(type: 'nameserver');
|
$this->apiPing(type: 'nameserver');
|
||||||
},
|
},
|
||||||
optionalParameters: ['ID'])))
|
optionalParameters: ['ID'])))
|
||||||
->addCommandGroup(commandGroup: (new CommandGroup(name: 'domains', description: 'configured domains'))
|
->addCommandGroup(commandGroup: (new CommandGroup(name: 'domains', description: 'configured domains'))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'list',
|
name: 'list',
|
||||||
callback: function () {
|
callback: function () {
|
||||||
$this->domainsList();
|
$this->domainsList();
|
||||||
}))
|
}))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'refresh',
|
name: 'refresh',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->domainsRefresh();
|
$this->domainsRefresh();
|
||||||
},
|
},
|
||||||
// mandatoryParameters: ['name'],
|
// mandatoryParameters: ['name'],
|
||||||
|
@ -196,74 +198,74 @@
|
||||||
description: 'Refresh domains')))
|
description: 'Refresh domains')))
|
||||||
->addCommandGroup(commandGroup: (new CommandGroup(name: 'dyndns', description: 'handle DynDNS entries'))
|
->addCommandGroup(commandGroup: (new CommandGroup(name: 'dyndns', description: 'handle DynDNS entries'))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'list',
|
name: 'list',
|
||||||
callback: function () {
|
callback: function () {
|
||||||
$this->dynDnsList();
|
$this->dynDnsList();
|
||||||
}))
|
}))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'create',
|
name: 'create',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->dynDnsCreate();
|
$this->dynDnsCreate();
|
||||||
},
|
},
|
||||||
mandatoryParameters: ['hostname.example.com', 'password'],
|
mandatoryParameters: ['hostname.example.com', 'password'],
|
||||||
optionalParameters : ['A=<IPv4>', 'AAAA=<IPv6>'],
|
optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>'],
|
||||||
description : 'FQDN within a domain where this server is master'))
|
description: 'FQDN within a domain where this server is master'))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'update',
|
name: 'update',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->dynDnyUpdate();
|
$this->dynDnyUpdate();
|
||||||
},
|
},
|
||||||
mandatoryParameters: ['hostname.example.com',],
|
mandatoryParameters: ['hostname.example.com',],
|
||||||
optionalParameters : ['password=<password>', 'A=<IPv4>', 'AAAA=<IPv6>']))
|
optionalParameters: ['password=<password>', 'A=<IPv4>', 'AAAA=<IPv6>']))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'delete',
|
name: 'delete',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->dynDnsDelete();
|
$this->dynDnsDelete();
|
||||||
},
|
},
|
||||||
mandatoryParameters: ['ID'])))
|
mandatoryParameters: ['ID'])))
|
||||||
->addCommandGroup(commandGroup: (new CommandGroup(name: 'apikeys', description: 'API keys to access this bindAPI'))
|
->addCommandGroup(commandGroup: (new CommandGroup(name: 'apikeys', description: 'API keys to access this bindAPI'))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'list',
|
name: 'list',
|
||||||
callback: function () {
|
callback: function () {
|
||||||
$this->apikeysList();
|
$this->apikeysList();
|
||||||
}))
|
}))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'create',
|
name: 'create',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->apikeysCreate();
|
$this->apikeysCreate();
|
||||||
},
|
},
|
||||||
optionalParameters: ['name=<name>']))
|
optionalParameters: ['name=<name>']))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'update',
|
name: 'update',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->apikeysUpdate();
|
$this->apikeysUpdate();
|
||||||
},
|
},
|
||||||
mandatoryParameters: ['ID',],
|
mandatoryParameters: ['ID',],
|
||||||
optionalParameters : ['name=<name>']))
|
optionalParameters: ['name=<name>']))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'delete',
|
name: 'delete',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->apikeysDelete();
|
$this->apikeysDelete();
|
||||||
},
|
},
|
||||||
mandatoryParameters: ['ID'])))
|
mandatoryParameters: ['ID'])))
|
||||||
->addCommandGroup(commandGroup: (new CommandGroup(name: 'migrations', description: 'maintain database migrations'))
|
->addCommandGroup(commandGroup: (new CommandGroup(name: 'migrations', description: 'maintain database migrations'))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'status',
|
name: 'status',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->migrationsStatus();
|
$this->migrationsStatus();
|
||||||
},
|
},
|
||||||
description: 'List information about migrations'
|
description: 'List information about migrations'
|
||||||
))
|
))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'make',
|
name: 'make',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->migrationsMake();
|
$this->migrationsMake();
|
||||||
},
|
},
|
||||||
description: 'Build a new migration file'
|
description: 'Build a new migration file'
|
||||||
))
|
))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name : 'migrate',
|
name: 'migrate',
|
||||||
callback : function () {
|
callback: function () {
|
||||||
$this->migrationsMigrate();
|
$this->migrationsMigrate();
|
||||||
},
|
},
|
||||||
description: 'Apply a new migration file'
|
description: 'Apply a new migration file'
|
||||||
|
@ -490,7 +492,9 @@
|
||||||
echo "Unknown panel ID $id" . PHP_EOL;
|
echo "Unknown panel ID $id" . PHP_EOL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (!$this->quiet) {
|
||||||
echo "check all …" . PHP_EOL;
|
echo "check all …" . PHP_EOL;
|
||||||
|
}
|
||||||
$panels = $this->panelRepository->findAll();
|
$panels = $this->panelRepository->findAll();
|
||||||
foreach ($panels as $panel) {
|
foreach ($panels as $panel) {
|
||||||
$this->checkSinglePanel(panel: $panel);
|
$this->checkSinglePanel(panel: $panel);
|
||||||
|
@ -509,30 +513,34 @@
|
||||||
{
|
{
|
||||||
$this->logger->debug(message: "checkSinglePanel()");
|
$this->logger->debug(message: "checkSinglePanel()");
|
||||||
|
|
||||||
|
if (!$this->quiet) {
|
||||||
echo COLOR_DEFAULT . 'KeyHelp-Panel: ' . COLOR_YELLOW . $panel->getName() . COLOR_DEFAULT;
|
echo COLOR_DEFAULT . 'KeyHelp-Panel: ' . COLOR_YELLOW . $panel->getName() . COLOR_DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
$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);
|
||||||
|
|
||||||
$f = $panel->getA();
|
$f = $panel->getA();
|
||||||
|
if (!$this->quiet) {
|
||||||
echo COLOR_DEFAULT . ' IPv4: ' . COLOR_YELLOW . $f . COLOR_DEFAULT;
|
echo COLOR_DEFAULT . ' IPv4: ' . COLOR_YELLOW . $f . COLOR_DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($panel->getA())) {
|
if (!empty($panel->getA())) {
|
||||||
$panelRequest = $this->apiController->sendCommand(
|
$panelRequest = $this->apiController->sendCommand(
|
||||||
requestType: 'GET',
|
requestType: 'GET',
|
||||||
serverName : $panel->getName(),
|
serverName: $panel->getName(),
|
||||||
versionIP : 4,
|
versionIP: 4,
|
||||||
apiKey : $decryptedKey,
|
apiKey: $decryptedKey,
|
||||||
command : '/server',
|
command: '/server',
|
||||||
serverType : 'panel');
|
serverType: 'panel');
|
||||||
} else {
|
} else {
|
||||||
$panelRequest = $this->apiController->sendCommand(
|
$panelRequest = $this->apiController->sendCommand(
|
||||||
requestType: 'GET',
|
requestType: 'GET',
|
||||||
serverName : $panel->getName(),
|
serverName: $panel->getName(),
|
||||||
versionIP : 6,
|
versionIP: 6,
|
||||||
apiKey : $decryptedKey,
|
apiKey: $decryptedKey,
|
||||||
command : '/server',
|
command: '/server',
|
||||||
serverType : 'panel');
|
serverType: 'panel');
|
||||||
}
|
}
|
||||||
$panelData = json_decode(json: $panelRequest['data']);
|
$panelData = json_decode(json: $panelRequest['data']);
|
||||||
if (!empty($panelData)) {
|
if (!empty($panelData)) {
|
||||||
|
@ -542,35 +550,41 @@
|
||||||
$panelVersion = 'n/a';
|
$panelVersion = 'n/a';
|
||||||
$responseTime = 'n/a';
|
$responseTime = 'n/a';
|
||||||
}
|
}
|
||||||
|
if (!$this->quiet) {
|
||||||
echo COLOR_DEFAULT . ' KeyHelp version: ' . $panelVersion . " ($responseTime seconds)" . PHP_EOL;
|
echo COLOR_DEFAULT . ' KeyHelp version: ' . $panelVersion . " ($responseTime seconds)" . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($panel->getA())) {
|
if (empty($panel->getA())) {
|
||||||
$result = $this->apiController->sendCommand(
|
$result = $this->apiController->sendCommand(
|
||||||
requestType: 'GET',
|
requestType: 'GET',
|
||||||
serverName : $panel->getName(),
|
serverName: $panel->getName(),
|
||||||
versionIP : 6,
|
versionIP: 6,
|
||||||
apiKey : $decryptedKey,
|
apiKey: $decryptedKey,
|
||||||
command : 'domains?sort=domain&subdomains=false',
|
command: 'domains?sort=domain&subdomains=false',
|
||||||
serverType : 'panel'
|
serverType: 'panel'
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$result = $this->apiController->sendCommand(
|
$result = $this->apiController->sendCommand(
|
||||||
requestType: 'GET',
|
requestType: 'GET',
|
||||||
serverName : $panel->getName(),
|
serverName: $panel->getName(),
|
||||||
versionIP : 4,
|
versionIP: 4,
|
||||||
apiKey : $decryptedKey,
|
apiKey: $decryptedKey,
|
||||||
command : 'domains?sort=domain&subdomains=false',
|
command: 'domains?sort=domain&subdomains=false',
|
||||||
serverType : 'panel');
|
serverType: 'panel');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($result['error'])) {
|
if (!empty($result['error'])) {
|
||||||
|
if (!$this->quiet) {
|
||||||
echo $result['data'] . PHP_EOL;
|
echo $result['data'] . PHP_EOL;
|
||||||
|
}
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (!empty($result['data'])) {
|
if (!empty($result['data'])) {
|
||||||
$domains = json_decode(json: $result['data']);
|
$domains = json_decode(json: $result['data']);
|
||||||
} else {
|
} else {
|
||||||
|
if (!$this->quiet) {
|
||||||
echo 'No domains found' . PHP_EOL;
|
echo 'No domains found' . PHP_EOL;
|
||||||
|
}
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,7 +611,9 @@
|
||||||
|
|
||||||
$domainCount = 0;
|
$domainCount = 0;
|
||||||
foreach ($tmpDomainList as $domain) {
|
foreach ($tmpDomainList as $domain) {
|
||||||
|
if (!$this->quiet) {
|
||||||
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);
|
||||||
|
@ -606,9 +622,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($domainCount == 0) {
|
if ($domainCount == 0) {
|
||||||
|
if (!$this->quiet) {
|
||||||
echo 'No second level domains found.' . COLOR_DEFAULT . PHP_EOL;
|
echo 'No second level domains found.' . COLOR_DEFAULT . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (!$this->quiet) {
|
||||||
echo PHP_EOL;
|
echo PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sodium_memzero(string: $decryptedKey);
|
sodium_memzero(string: $decryptedKey);
|
||||||
|
@ -704,31 +724,37 @@
|
||||||
$encryptionKey = $this->configController->getConfig(configKey: 'encryptionKey');
|
$encryptionKey = $this->configController->getConfig(configKey: 'encryptionKey');
|
||||||
$decryptedKey = $this->encryptionController->safeDecrypt(encrypted: $nameserver->getApikey(), key: $encryptionKey);
|
$decryptedKey = $this->encryptionController->safeDecrypt(encrypted: $nameserver->getApikey(), key: $encryptionKey);
|
||||||
|
|
||||||
|
if (!$this->quiet) {
|
||||||
echo COLOR_YELLOW . ' ' . $nameserver->getName();
|
echo COLOR_YELLOW . ' ' . $nameserver->getName();
|
||||||
|
}
|
||||||
if (!empty($nameserver->getName())) {
|
if (!empty($nameserver->getName())) {
|
||||||
$result = $this->apiController->sendCommand(
|
$result = $this->apiController->sendCommand(
|
||||||
requestType: 'GET',
|
requestType: 'GET',
|
||||||
serverName : $nameserver->getName(),
|
serverName: $nameserver->getName(),
|
||||||
versionIP : 6,
|
versionIP: 6,
|
||||||
apiKey : $decryptedKey,
|
apiKey: $decryptedKey,
|
||||||
command : 'domains/name/' . $domainName,
|
command: 'domains/name/' . $domainName,
|
||||||
serverType : 'nameserver');
|
serverType: 'nameserver');
|
||||||
} else {
|
} else {
|
||||||
$result = $this->apiController->sendCommand(
|
$result = $this->apiController->sendCommand(
|
||||||
requestType: 'GET',
|
requestType: 'GET',
|
||||||
serverName : $nameserver->getName(),
|
serverName: $nameserver->getName(),
|
||||||
versionIP : 4,
|
versionIP: 4,
|
||||||
apiKey : $decryptedKey(),
|
apiKey: $decryptedKey(),
|
||||||
command : 'domains/name/',
|
command: 'domains/name/',
|
||||||
serverType : 'nameserver' . $domainName);
|
serverType: 'nameserver' . $domainName);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($result['header']) {
|
switch ($result['header']) {
|
||||||
case 200:
|
case 200:
|
||||||
|
if (!$this->quiet) {
|
||||||
echo COLOR_GREEN . ' OK';
|
echo COLOR_GREEN . ' OK';
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 404:
|
case 404:
|
||||||
|
if (!$this->quiet) {
|
||||||
echo COLOR_RED . ' ' . $result['header'] . COLOR_DEFAULT;
|
echo COLOR_RED . ' ' . $result['header'] . COLOR_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) {
|
||||||
echo ' trying to fix …';
|
echo ' trying to fix …';
|
||||||
|
@ -743,37 +769,43 @@
|
||||||
if (!empty($nameserver->getAaaa())) {
|
if (!empty($nameserver->getAaaa())) {
|
||||||
$create = $this->apiController->sendCommand(
|
$create = $this->apiController->sendCommand(
|
||||||
requestType: 'POST',
|
requestType: 'POST',
|
||||||
serverName : $nameserver->getName(),
|
serverName: $nameserver->getName(),
|
||||||
versionIP : 6,
|
versionIP: 6,
|
||||||
apiKey : $decryptedKey,
|
apiKey: $decryptedKey,
|
||||||
command : 'domains',
|
command: 'domains',
|
||||||
serverType : 'nameserver',
|
serverType: 'nameserver',
|
||||||
body : $body);
|
body: $body);
|
||||||
} else {
|
} else {
|
||||||
$create = $this->apiController->sendCommand(
|
$create = $this->apiController->sendCommand(
|
||||||
requestType: 'POST',
|
requestType: 'POST',
|
||||||
serverName : $nameserver->getName(),
|
serverName: $nameserver->getName(),
|
||||||
versionIP : 4,
|
versionIP: 4,
|
||||||
apiKey : $decryptedKey(),
|
apiKey: $decryptedKey(),
|
||||||
command : 'domains',
|
command: 'domains',
|
||||||
serverType : 'nameserver',
|
serverType: 'nameserver',
|
||||||
body : $body);
|
body: $body);
|
||||||
}
|
}
|
||||||
if ($create['header'] != 201) {
|
if ($create['header'] != 201) {
|
||||||
print_r(value: $create);
|
print_r(value: $create);
|
||||||
die("make error handling");
|
die("make error handling");
|
||||||
} else {
|
} else {
|
||||||
|
if (!$this->quiet) {
|
||||||
echo COLOR_GREEN . 'OK' . COLOR_DEFAULT;
|
echo COLOR_GREEN . 'OK' . COLOR_DEFAULT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
if (!$this->quiet) {
|
||||||
echo 'Server error' . PHP_EOL;
|
echo 'Server error' . PHP_EOL;
|
||||||
|
}
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!$this->quiet) {
|
||||||
echo PHP_EOL;
|
echo PHP_EOL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $arguments
|
* @param array $arguments
|
||||||
|
@ -1032,11 +1064,11 @@
|
||||||
}
|
}
|
||||||
if ($result = $this->apiController->sendCommand(
|
if ($result = $this->apiController->sendCommand(
|
||||||
requestType: 'GET',
|
requestType: 'GET',
|
||||||
serverName : $server->getName(),
|
serverName: $server->getName(),
|
||||||
versionIP : 4,
|
versionIP: 4,
|
||||||
apiKey : $decryptedKey,
|
apiKey: $decryptedKey,
|
||||||
command : 'ping',
|
command: 'ping',
|
||||||
serverType : $type)) {
|
serverType: $type)) {
|
||||||
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||||
if ($result['data'] == 'pong') {
|
if ($result['data'] == 'pong') {
|
||||||
echo ' ' . COLOR_GREEN . $result['data'];
|
echo ' ' . COLOR_GREEN . $result['data'];
|
||||||
|
@ -1059,11 +1091,11 @@
|
||||||
}
|
}
|
||||||
if ($result = $this->apiController->sendCommand(
|
if ($result = $this->apiController->sendCommand(
|
||||||
requestType: 'GET',
|
requestType: 'GET',
|
||||||
serverName : $server->getName(),
|
serverName: $server->getName(),
|
||||||
versionIP : 6,
|
versionIP: 6,
|
||||||
apiKey : $decryptedKey,
|
apiKey: $decryptedKey,
|
||||||
command : 'ping',
|
command: 'ping',
|
||||||
serverType : $type)) {
|
serverType: $type)) {
|
||||||
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||||
if ($result['data'] == 'pong') {
|
if ($result['data'] == 'pong') {
|
||||||
echo ' ' . COLOR_GREEN . $result['data'];
|
echo ' ' . COLOR_GREEN . $result['data'];
|
||||||
|
@ -1655,19 +1687,19 @@
|
||||||
if (!empty($panel->getAaaa())) {
|
if (!empty($panel->getAaaa())) {
|
||||||
$result = $this->apiController->sendCommand(
|
$result = $this->apiController->sendCommand(
|
||||||
requestType: 'POST',
|
requestType: 'POST',
|
||||||
serverName : $panel->getName(),
|
serverName: $panel->getName(),
|
||||||
versionIP : 6,
|
versionIP: 6,
|
||||||
apiKey : $decryptedKey,
|
apiKey: $decryptedKey,
|
||||||
command : 'dyndns/' . $hostName,
|
command: 'dyndns/' . $hostName,
|
||||||
serverType : 'nameserver');
|
serverType: 'nameserver');
|
||||||
} else {
|
} else {
|
||||||
$result = $this->apiController->sendCommand(
|
$result = $this->apiController->sendCommand(
|
||||||
requestType: 'POST',
|
requestType: 'POST',
|
||||||
serverName : $panel->getName(),
|
serverName: $panel->getName(),
|
||||||
versionIP : 4,
|
versionIP: 4,
|
||||||
apiKey : $decryptedKey(),
|
apiKey: $decryptedKey(),
|
||||||
command : 'dyndns/' . $hostName,
|
command: 'dyndns/' . $hostName,
|
||||||
serverType : 'nameserver');
|
serverType: 'nameserver');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($result['header'] == 200) {
|
if ($result['header'] == 200) {
|
||||||
|
@ -1713,30 +1745,32 @@
|
||||||
|
|
||||||
|
|
||||||
foreach ($panels as $panel) {
|
foreach ($panels as $panel) {
|
||||||
|
if (!$this->quiet) {
|
||||||
echo COLOR_DEFAULT . 'Checking panel ' . COLOR_YELLOW . $panel->getName() . COLOR_DEFAULT . PHP_EOL;
|
echo COLOR_DEFAULT . 'Checking panel ' . COLOR_YELLOW . $panel->getName() . COLOR_DEFAULT . PHP_EOL;
|
||||||
|
$longestEntry = $this->domainRepository->getLongestEntry(field: 'name');
|
||||||
|
}
|
||||||
$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);
|
||||||
|
|
||||||
$currentDomains = $this->domainRepository->findByPanel(name: $panel->getName());
|
$currentDomains = $this->domainRepository->findByPanel(name: $panel->getName());
|
||||||
var_dump($currentDomains);
|
|
||||||
|
|
||||||
if (empty($panel->getA())) {
|
if (empty($panel->getA())) {
|
||||||
$result = $this->apiController->sendCommand(
|
$result = $this->apiController->sendCommand(
|
||||||
requestType: 'GET',
|
requestType: 'GET',
|
||||||
serverName : $panel->getName(),
|
serverName: $panel->getName(),
|
||||||
versionIP : 6,
|
versionIP: 6,
|
||||||
apiKey : $decryptedKey,
|
apiKey: $decryptedKey,
|
||||||
command : 'domains?sort=domain&subdomains=false',
|
command: 'domains?sort=domain&subdomains=false',
|
||||||
serverType : 'panel'
|
serverType: 'panel'
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$result = $this->apiController->sendCommand(
|
$result = $this->apiController->sendCommand(
|
||||||
requestType: 'GET',
|
requestType: 'GET',
|
||||||
serverName : $panel->getName(),
|
serverName: $panel->getName(),
|
||||||
versionIP : 4,
|
versionIP: 4,
|
||||||
apiKey : $decryptedKey,
|
apiKey: $decryptedKey,
|
||||||
command : 'domains?sort=domain&subdomains=false',
|
command: 'domains?sort=domain&subdomains=false',
|
||||||
serverType : 'panel');
|
serverType: 'panel');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($result['error'])) {
|
if (!empty($result['error'])) {
|
||||||
|
@ -1754,24 +1788,29 @@
|
||||||
if (count($domains) > 0) {
|
if (count($domains) > 0) {
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
$domainCount++;
|
$domainCount++;
|
||||||
echo COLOR_YELLOW . ' ' . $domain->domain;
|
if (!$this->quiet) {
|
||||||
echo PHP_EOL;
|
echo COLOR_YELLOW . ' ' .str_pad(string: $domain->domain, length: $longestEntry + 1, pad_type: STR_PAD_RIGHT);
|
||||||
|
}
|
||||||
if ($domain = $this->domainRepository->findByName(name: $domain->domain)) {
|
if ($domain = $this->domainRepository->findByName(name: $domain->domain)) {
|
||||||
$currentPanel = $domain->getPanel();
|
$currentPanel = $domain->getPanel();
|
||||||
$panelName = $panel->getName();
|
$panelName = $panel->getName();
|
||||||
echo 'current Panel: ' . $panelName . PHP_EOL;
|
|
||||||
echo 'panel name: ' . $panelName . PHP_EOL;
|
|
||||||
if (strcmp(string1: $currentPanel, string2: $panelName)) {
|
if (strcmp(string1: $currentPanel, string2: $panelName)) {
|
||||||
$domain->setPanel(panel: $panelName);
|
$domain->setPanel(panel: $panelName);
|
||||||
}
|
|
||||||
$this->domainRepository->update(domain: $domain);
|
$this->domainRepository->update(domain: $domain);
|
||||||
|
if (!$this->quiet) {
|
||||||
echo COLOR_DEFAULT . ' updated to: ' . COLOR_YELLOW . $panelName;
|
echo COLOR_DEFAULT . ' updated to: ' . COLOR_YELLOW . $panelName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$this->quiet) {
|
||||||
echo COLOR_GREEN . ' OK' . COLOR_DEFAULT . PHP_EOL;
|
echo COLOR_GREEN . ' OK' . COLOR_DEFAULT . PHP_EOL;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$newDomain = new Domain(name: $domain->getName(), panel: $panel->getName());
|
$newDomain = new Domain(name: $domain->getName(), panel: $panel->getName());
|
||||||
$result = $this->domainRepository->insert(domain: $newDomain);
|
$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 COLOR_DEFAULT . ' has been created with id ' . COLOR_YELLOW . $result . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
unset($currentDomains[$domain->getName()]);
|
unset($currentDomains[$domain->getName()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1789,6 +1828,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (!$this->quiet) {
|
||||||
|
echo 'Creating slave zone files' . PHP_EOL;
|
||||||
|
}
|
||||||
$this->domainController->updateSlaveZones();
|
$this->domainController->updateSlaveZones();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1837,22 +1879,22 @@
|
||||||
}
|
}
|
||||||
$result = $this->apiController->sendCommand(
|
$result = $this->apiController->sendCommand(
|
||||||
requestType: 'GET',
|
requestType: 'GET',
|
||||||
serverName : $panel->getName(),
|
serverName: $panel->getName(),
|
||||||
versionIP : 6,
|
versionIP: 6,
|
||||||
apiKey : $decryptedKey,
|
apiKey: $decryptedKey,
|
||||||
command : 'domains/name/' . $webmailDomain,
|
command: 'domains/name/' . $webmailDomain,
|
||||||
serverType : 'panel');
|
serverType: 'panel');
|
||||||
} else {
|
} else {
|
||||||
if (!$quiet) {
|
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(
|
||||||
requestType: 'GET',
|
requestType: 'GET',
|
||||||
serverName : $panel->getName(),
|
serverName: $panel->getName(),
|
||||||
versionIP : 4,
|
versionIP: 4,
|
||||||
apiKey : $decryptedKey,
|
apiKey: $decryptedKey,
|
||||||
command : 'domains/name/' . $webmailDomain,
|
command: 'domains/name/' . $webmailDomain,
|
||||||
serverType : 'panel');
|
serverType: 'panel');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($result['header'] === 404) {
|
if ($result['header'] === 404) {
|
||||||
|
@ -2025,4 +2067,4 @@
|
||||||
$phinxOutput = new ConsoleOutput();
|
$phinxOutput = new ConsoleOutput();
|
||||||
$returnCode = $command->run(input: new ArrayInput(parameters: $arguments), output: $phinxOutput);
|
$returnCode = $command->run(input: new ArrayInput(parameters: $arguments), output: $phinxOutput);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,12 +78,17 @@ class DomainController
|
||||||
}
|
}
|
||||||
|
|
||||||
$domains = $this->domainRepository->findAll();
|
$domains = $this->domainRepository->findAll();
|
||||||
|
$longestEntry = $this->domainRepository->getLongestEntry('name');
|
||||||
|
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
if (!$this->quiet) {
|
if (!$this->quiet) {
|
||||||
echo 'Create zone: ' . $domain->getName() . PHP_EOL;
|
echo ' ' . COLOR_YELLOW . str_pad($domain->getName(), $longestEntry + 1, " ", STR_PAD_RIGHT) ;
|
||||||
|
}
|
||||||
|
if ($this->createSlaveZoneFile(domain: $domain)) {
|
||||||
|
if (!$this->quiet) {
|
||||||
|
echo COLOR_GREEN . ' OK' . COLOR_DEFAULT . PHP_EOL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->createSlaveZoneFile(domain: $domain);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->createIncludeFile();
|
$this->createIncludeFile();
|
||||||
|
@ -234,7 +239,9 @@ class DomainController
|
||||||
function checkDomains(): void
|
function checkDomains(): void
|
||||||
{
|
{
|
||||||
if (!file_exists(filename: $this->localZoneFile)) {
|
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 COLOR_DEFAULT . 'Local Zone file ' . COLOR_YELLOW . $this->localZoneFile . COLOR_DEFAULT . ' does not exist.' . PHP_EOL;
|
||||||
|
}
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
$localZones = file_get_contents(filename: $this->localZoneFile);
|
$localZones = file_get_contents(filename: $this->localZoneFile);
|
||||||
|
@ -243,20 +250,28 @@ class DomainController
|
||||||
|
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
$idString = '(' . $domain->getId() . ') ';
|
$idString = '(' . $domain->getId() . ') ';
|
||||||
|
if (!$this->quiet) {
|
||||||
echo COLOR_YELLOW .
|
echo COLOR_YELLOW .
|
||||||
str_pad(string: $domain->getName(), length: $maxNameLength + 1)
|
str_pad(string: $domain->getName(), length: $maxNameLength + 1)
|
||||||
. COLOR_DEFAULT
|
. COLOR_DEFAULT
|
||||||
. str_pad(string: $idString, length: 7, pad_type: STR_PAD_LEFT);
|
. str_pad(string: $idString, length: 7, pad_type: STR_PAD_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
$hasError = false;
|
$hasError = false;
|
||||||
if ($this->isMasterZone(domain: $domain)) {
|
if ($this->isMasterZone(domain: $domain)) {
|
||||||
echo 'Master Zone lies on this panel.';
|
if (!$this->quiet) {
|
||||||
|
echo COLOR_GREEN . 'Master Zone';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!str_contains(haystack: $localZones, needle: $domain->getName())) {
|
if (!str_contains(haystack: $localZones, needle: $domain->getName())) {
|
||||||
|
if (!$this->quiet) {
|
||||||
echo COLOR_RED . 'is missing in ' . COLOR_YELLOW . $this->localZoneFile . COLOR_DEFAULT;
|
echo COLOR_RED . 'is missing in ' . COLOR_YELLOW . $this->localZoneFile . COLOR_DEFAULT;
|
||||||
|
}
|
||||||
$hasError = true;
|
$hasError = true;
|
||||||
} else {
|
} else {
|
||||||
|
if (!$this->quiet) {
|
||||||
echo COLOR_GREEN . 'OK';
|
echo COLOR_GREEN . 'OK';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$zoneFile = $this->localZonesDir . $domain->getName();
|
$zoneFile = $this->localZonesDir . $domain->getName();
|
||||||
|
@ -270,8 +285,10 @@ class DomainController
|
||||||
echo " Update zone (Domain) to create it.";
|
echo " Update zone (Domain) to create it.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!$this->quiet) {
|
||||||
echo COLOR_DEFAULT . PHP_EOL;
|
echo COLOR_DEFAULT . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +298,7 @@ class DomainController
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function createSlaveZoneFile(Domain $domain): void
|
public function createSlaveZoneFile(Domain $domain): bool
|
||||||
{
|
{
|
||||||
$domainName = $domain->getName();
|
$domainName = $domain->getName();
|
||||||
$this->logger->info(message: "createZoneFile($domainName)");
|
$this->logger->info(message: "createZoneFile($domainName)");
|
||||||
|
@ -289,14 +306,16 @@ class DomainController
|
||||||
// check if we're a master zone
|
// check if we're a master zone
|
||||||
if ($this->isMasterZone(domain: $domain)) {
|
if ($this->isMasterZone(domain: $domain)) {
|
||||||
//echo 'We are zone master for ' . $domainName . PHP_EOL;
|
//echo 'We are zone master for ' . $domainName . PHP_EOL;
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($zoneFile = fopen(filename: $this->localZonesDir . $domainName, mode: 'w')) {
|
if ($zoneFile = fopen(filename: $this->localZonesDir . $domainName, mode: 'w')) {
|
||||||
$panelName = $domain->getPanel();
|
$panelName = $domain->getPanel();
|
||||||
if (!$panel = $this->panelRepository->findByName(name: $panelName)) {
|
if (!$panel = $this->panelRepository->findByName(name: $panelName)) {
|
||||||
|
if (!$this->quiet) {
|
||||||
echo "Error: Panel $panelName doesn't exist." . PHP_EOL;
|
echo "Error: Panel $panelName doesn't exist." . PHP_EOL;
|
||||||
exit(1);
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
$a = $panel->getA();
|
$a = $panel->getA();
|
||||||
$aaaa = $panel->getAaaa();
|
$aaaa = $panel->getAaaa();
|
||||||
|
@ -312,6 +331,12 @@ class DomainController
|
||||||
}
|
}
|
||||||
fputs(stream: $zoneFile, data: "\t};" . PHP_EOL);
|
fputs(stream: $zoneFile, data: "\t};" . PHP_EOL);
|
||||||
fputs(stream: $zoneFile, data: "};" . PHP_EOL);
|
fputs(stream: $zoneFile, data: "};" . PHP_EOL);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
if (!$this->quiet) {
|
||||||
|
echo COLOR_RED . ' Error: ' . COLOR_DEFAULT . 'unable to create ' . COLOR_YELLOW . $this->localZonesDir . $domainName . COLOR_DEFAULT . PHP_EOL;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -219,6 +219,7 @@ readonly class DomainRepository
|
||||||
$domainName = $domain->getName();
|
$domainName = $domain->getName();
|
||||||
$this->logger->debug(message: "delete($domainName)");
|
$this->logger->debug(message: "delete($domainName)");
|
||||||
|
|
||||||
|
// FIXME, add force parameter, reject deletion if domains left on panel
|
||||||
$sql = "
|
$sql = "
|
||||||
DELETE FROM " . DatabaseConnection::TABLE_DOMAINS . "
|
DELETE FROM " . DatabaseConnection::TABLE_DOMAINS . "
|
||||||
WHERE id = :id";
|
WHERE id = :id";
|
||||||
|
|
Loading…
Reference in New Issue