|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
/** |
|
5
|
|
|
* This file is part of the mailserver-admin package. |
|
6
|
|
|
* (c) Jeffrey Boehm <https://github.com/jeboehm/mailserver-admin> |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace App\Command; |
|
12
|
|
|
|
|
13
|
|
|
use App\Entity\Domain; |
|
14
|
|
|
use Doctrine\Persistence\ManagerRegistry; |
|
15
|
|
|
use Symfony\Component\Console\Command\Command; |
|
16
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
20
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
|
21
|
|
|
|
|
22
|
|
|
class DKIMDisableCommand extends Command |
|
23
|
|
|
{ |
|
24
|
|
|
private ManagerRegistry $manager; |
|
25
|
|
|
|
|
26
|
|
|
public function __construct(ManagerRegistry $manager) |
|
27
|
|
|
{ |
|
28
|
|
|
parent::__construct(); |
|
29
|
|
|
|
|
30
|
|
|
$this->manager = $manager; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
protected function configure(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$this |
|
36
|
|
|
->setName('dkim:disable') |
|
37
|
|
|
->setDescription('Disables DKIM for a specific domain.') |
|
38
|
|
|
->addArgument('domain', InputArgument::REQUIRED, 'Domain-part (after @)'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
42
|
|
|
{ |
|
43
|
|
|
$name = $input->getArgument('domain'); |
|
44
|
|
|
/** @var Domain $domain */ |
|
45
|
|
|
$domain = $this->manager->getRepository(Domain::class)->findOneBy(['name' => $name]); |
|
46
|
|
|
|
|
47
|
|
|
if (!$domain) { |
|
|
|
|
|
|
48
|
|
|
$output->writeln(sprintf('<error>Domain "%s" was not found.</error>', $name)); |
|
49
|
|
|
|
|
50
|
|
|
return 1; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** @var QuestionHelper $questionHelper */ |
|
54
|
|
|
$questionHelper = $this->getHelper('question'); |
|
55
|
|
|
$result = $questionHelper->ask( |
|
56
|
|
|
$input, |
|
57
|
|
|
$output, |
|
58
|
|
|
new ConfirmationQuestion(sprintf('Do you want to disable DKIM for domain "%s"?', $domain->getName())) |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
if (!$result) { |
|
62
|
|
|
$output->writeln('Aborting.'); |
|
63
|
|
|
|
|
64
|
|
|
return 1; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$domain->setDkimEnabled(false); |
|
68
|
|
|
|
|
69
|
|
|
$this->manager->getManager()->flush(); |
|
70
|
|
|
|
|
71
|
|
|
$output->writeln('Done.'); |
|
72
|
|
|
|
|
73
|
|
|
return 0; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|