Assign zone to a domain command, remove and add domain commands, (un)active zone version
This commit is contained in:
parent
89045402a7
commit
67eabe7b3a
|
@ -4,8 +4,6 @@ namespace Deblan\PowerDNS\Command;
|
||||||
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
|
||||||
class AboutCommand extends Command
|
class AboutCommand extends Command
|
||||||
|
@ -20,11 +18,11 @@ class AboutCommand extends Command
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$output->writeln(<<<EOF
|
$output->writeln(<<<EOF
|
||||||
<info>PDNS-CONSOLE</info>
|
<info>PDNS-CONSOLE</info>
|
||||||
|
|
||||||
PDNS-Console provided a CLI to manage PowerDNS application and improved it by
|
PDNS-Console provided a CLI to manage PowerDNS application and improved it by
|
||||||
adding a powerfull DNS zone versionning.
|
adding a powerfull DNS zone versionning.
|
||||||
|
|
||||||
<info>AUTHOR</info>
|
<info>AUTHOR</info>
|
||||||
|
|
||||||
|
|
|
@ -30,13 +30,13 @@ class DomainAddCommand extends AbstractCommand
|
||||||
parent::execute($input, $output);
|
parent::execute($input, $output);
|
||||||
|
|
||||||
$name = $this->getInput()->getOption('name');
|
$name = $this->getInput()->getOption('name');
|
||||||
|
$master = $this->getInput()->getOption('master');
|
||||||
|
$type = $this->getInput()->getOption('type');
|
||||||
|
|
||||||
while (null === $name || trim($name) === '') {
|
while (null === $name || trim($name) === '') {
|
||||||
$name = $this->getHelper('dialog')->ask($this->getOutput(), 'Name: ', null);
|
$name = $this->getHelper('dialog')->ask($this->getOutput(), 'Name: ', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
$master = $this->getInput()->getOption('master');
|
|
||||||
|
|
||||||
if ($master === 'null') {
|
if ($master === 'null') {
|
||||||
$master = null;
|
$master = null;
|
||||||
} elseif (null === $master || trim($master) === '') {
|
} elseif (null === $master || trim($master) === '') {
|
||||||
|
@ -44,8 +44,6 @@ class DomainAddCommand extends AbstractCommand
|
||||||
$master = empty($response) ? null : $response;
|
$master = empty($response) ? null : $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = $this->getInput()->getOption('type');
|
|
||||||
|
|
||||||
if ($type === 'null') {
|
if ($type === 'null') {
|
||||||
$type = null;
|
$type = null;
|
||||||
} elseif (null === $type) {
|
} elseif (null === $type) {
|
||||||
|
|
|
@ -45,7 +45,7 @@ class DomainRemoveCommand extends AbstractCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $domain) {
|
if (null === $domain) {
|
||||||
$this->getOutput()->writeln('<error>No domain found.</error>');
|
$this->getOutput()->writeln('<error>Domain not found.</error>');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
52
src/Deblan/PowerDNS/Command/ZoneAssignCommand.php
Normal file
52
src/Deblan/PowerDNS/Command/ZoneAssignCommand.php
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Deblan\PowerDNS\Command;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Deblan\Console\Command\AbstractCommand;
|
||||||
|
use Deblan\PowerDNS\Model\Domain;
|
||||||
|
use Deblan\PowerDNS\Model\DomainQuery;
|
||||||
|
use Deblan\PowerDNS\Model\ZoneQuery;
|
||||||
|
|
||||||
|
class ZoneAssignCommand extends AbstractCommand
|
||||||
|
{
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
parent::configure();
|
||||||
|
|
||||||
|
$this
|
||||||
|
->setName('zone:assign')
|
||||||
|
->setDescription('Add a domain')
|
||||||
|
->addArgument('zone_id', InputArgument::REQUIRED, 'ZONE_ID')
|
||||||
|
->addArgument('domain_id', InputArgument::REQUIRED, 'ZONE_ID')
|
||||||
|
->setHelp("The <info>%command.name%</info> ");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
parent::execute($input, $output);
|
||||||
|
|
||||||
|
$zoneId = (int) $this->getInput()->getArgument('zone_id');
|
||||||
|
$zone = ZoneQuery::create()->findOneById($zoneId);
|
||||||
|
$domain = DomainQuery::create()->findOneById((int) $this->getInput()->getArgument('domain_id'));
|
||||||
|
|
||||||
|
if ($zoneId !== 0 && null === $zone) {
|
||||||
|
$this->getOutput()->writeln('<error>Zone not found.</error>');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null === $domain) {
|
||||||
|
$this->getOutput()->writeln('<error>Domain not found.</error>');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$domain->setZone($zone)->save();
|
||||||
|
|
||||||
|
$this->getOutput()->writeln('<info>Domain zone updated.</info>');
|
||||||
|
}
|
||||||
|
}
|
56
src/Deblan/PowerDNS/Command/ZoneVersionActiveCommand.php
Normal file
56
src/Deblan/PowerDNS/Command/ZoneVersionActiveCommand.php
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Deblan\PowerDNS\Command;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Deblan\Console\Command\AbstractCommand;
|
||||||
|
use Deblan\PowerDNS\Model\ZoneVersionQuery;
|
||||||
|
|
||||||
|
class ZoneVersionActiveCommand extends AbstractCommand
|
||||||
|
{
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
parent::configure();
|
||||||
|
|
||||||
|
$this
|
||||||
|
->setName('zone:version:active')
|
||||||
|
->setDescription('Active a zone version')
|
||||||
|
->addArgument('zone_id', InputArgument::REQUIRED, 'ZONE_ID')
|
||||||
|
->addArgument('version', InputArgument::REQUIRED, 'VERSION')
|
||||||
|
->setHelp("The <info>%command.name%</info> ");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
parent::execute($input, $output);
|
||||||
|
|
||||||
|
$zoneId = (int) $this->getInput()->getArgument('zone_id');
|
||||||
|
$version = (int) $this->getInput()->getArgument('version');
|
||||||
|
|
||||||
|
$zoneVersionCount = ZoneVersionQuery::create()
|
||||||
|
->filterByZoneId($zoneId)
|
||||||
|
->filterByVersion($version)
|
||||||
|
->count();
|
||||||
|
|
||||||
|
if (0 === $zoneVersionCount) {
|
||||||
|
$this->getOutput()->writeln('<error>Zone version not found.</error>');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (ZoneVersionQuery::create()->findByZoneId($zoneId) as $zoneVersion) {
|
||||||
|
if ($zoneVersion->getVersion() === $version) {
|
||||||
|
$zoneVersion->setIsActive(true);
|
||||||
|
} else {
|
||||||
|
$zoneVersion->setIsActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
$zoneVersion->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->getOutput()->writeln('<info>Zone version activated.</info>');
|
||||||
|
}
|
||||||
|
}
|
48
src/Deblan/PowerDNS/Command/ZoneVersionUnactiveCommand.php
Normal file
48
src/Deblan/PowerDNS/Command/ZoneVersionUnactiveCommand.php
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Deblan\PowerDNS\Command;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Deblan\Console\Command\AbstractCommand;
|
||||||
|
use Deblan\PowerDNS\Model\ZoneVersionQuery;
|
||||||
|
|
||||||
|
class ZoneVersionUnactiveCommand extends AbstractCommand
|
||||||
|
{
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
parent::configure();
|
||||||
|
|
||||||
|
$this
|
||||||
|
->setName('zone:version:unactive')
|
||||||
|
->setDescription('Unactive a zone version')
|
||||||
|
->addArgument('zone_id', InputArgument::REQUIRED, 'ZONE_ID')
|
||||||
|
->addArgument('version', InputArgument::REQUIRED, 'VERSION')
|
||||||
|
->setHelp("The <info>%command.name%</info> ");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
parent::execute($input, $output);
|
||||||
|
|
||||||
|
$zoneId = (int) $this->getInput()->getArgument('zone_id');
|
||||||
|
$version = (int) $this->getInput()->getArgument('version');
|
||||||
|
|
||||||
|
$zoneVersion = ZoneVersionQuery::create()
|
||||||
|
->filterByZoneId($zoneId)
|
||||||
|
->filterByVersion($version)
|
||||||
|
->findOne();
|
||||||
|
|
||||||
|
if (null === $zoneVersion) {
|
||||||
|
$this->getOutput()->writeln('<error>Zone version not found.</error>');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$zoneVersion->setIsActive(false)->save();
|
||||||
|
|
||||||
|
$this->getOutput()->writeln('<info>Zone version unactivated.</info>');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue