✨ feat(Command/Mail): Ajoute commande pour contrôler la configuration du serveur mail.
Ajoute une commande pour vérifier et notifier la configuration du serveur mail, incluant les enregistrements A, PTR et TLSA.
This commit is contained in:
@@ -214,7 +214,13 @@
|
||||
hour: "21"
|
||||
job: "php {{ path }}/bin/console mainframe:cron:customer"
|
||||
user: root
|
||||
|
||||
- name: "Cron Task purge customer delete"
|
||||
cron:
|
||||
name: "Mainframe - Check Server mail"
|
||||
minute: "0"
|
||||
hour: "6,16"
|
||||
job: "php {{ path }}/bin/console mainframe:mailserver:check"
|
||||
user: root
|
||||
- name: "Cron Task purge email delete"
|
||||
cron:
|
||||
name: "Mainframe - Purge customer"
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
"nelmio/api-doc-bundle": "^5.4",
|
||||
"nelmio/cors-bundle": "^2.5",
|
||||
"ovh/ovh": "*",
|
||||
"pear/net_dns2": "*",
|
||||
"phpdocumentor/reflection-docblock": "^5.6.2",
|
||||
"phpoffice/phpspreadsheet": "*",
|
||||
"phpstan/phpdoc-parser": "^2.2",
|
||||
|
||||
65
composer.lock
generated
65
composer.lock
generated
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "41f067f09246c6e7314d4e7164c2a358",
|
||||
"content-hash": "1daefc9419bbfdfa4b4f286a2a26b1b2",
|
||||
"packages": [
|
||||
{
|
||||
"name": "async-aws/core",
|
||||
@@ -5794,6 +5794,69 @@
|
||||
},
|
||||
"time": "2025-09-24T15:06:41+00:00"
|
||||
},
|
||||
{
|
||||
"name": "pear/net_dns2",
|
||||
"version": "v2.0.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mikepultz/netdns2.git",
|
||||
"reference": "515b064665ca740df5da672d5204e34ac3921c31"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/mikepultz/netdns2/zipball/515b064665ca740df5da672d5204e34ac3921c31",
|
||||
"reference": "515b064665ca740df5da672d5204e34ac3921c31",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^10"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-curl": "Used for DNS over HTTPS (DoH)",
|
||||
"ext-hash": "Used for TSIG authentication.",
|
||||
"ext-intl": "Used for decoding Unicode domain names.",
|
||||
"ext-openssl": "Used for DNS over TLS (DoT), and some DNSSEC verification."
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"NetDNS2\\": "src/NetDNS2/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Mike Pultz",
|
||||
"email": "mike@mikepultz.com",
|
||||
"homepage": "https://mikepultz.com/",
|
||||
"role": "lead"
|
||||
}
|
||||
],
|
||||
"description": "PHP DNS Resolver and Updater Library",
|
||||
"homepage": "https://netdns2.com/",
|
||||
"keywords": [
|
||||
"DNSSEC",
|
||||
"dns",
|
||||
"network"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/mikepultz/netdns2/issues",
|
||||
"source": "https://github.com/mikepultz/netdns2"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/mikepultz",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2025-09-21T19:33:49+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpdocumentor/reflection-common",
|
||||
"version": "2.2.0",
|
||||
|
||||
104
src/Command/ControlMailServerConfigurationCommand.php
Normal file
104
src/Command/ControlMailServerConfigurationCommand.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Service\Mailer\Mailer;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
#[AsCommand(name: 'mainframe:mailserver:check')]
|
||||
class ControlMailServerConfigurationCommand extends Command
|
||||
{
|
||||
private bool $mailEsyWebDevA_valid;
|
||||
private bool $mailEsyWebDevTLSA_valid;
|
||||
private bool $mailEsyWebDevPTR_valid;
|
||||
private bool $mailEsyWeb_valid;
|
||||
private string $currentTLSA;
|
||||
private string $currentPTR;
|
||||
private string $currentA;
|
||||
|
||||
public function __construct(private readonly Mailer $mailer,?string $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$rDnsClient = new \NetDNS2\Resolver([ 'nameservers' => [ '1.1.1.1' ]]);
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$io->title("Control mail server configuration");
|
||||
$io->info("Configuration mail.esy-web.dev");
|
||||
$this->mailEsyWebDevA_valid = false;
|
||||
$this->mailEsyWebDevTLSA_valid = false;
|
||||
$this->mailEsyWebDevPTR_valid = false;
|
||||
$this->mailEsyWeb_valid = true;
|
||||
$this->currentA = "";
|
||||
$this->currentPTR = "";
|
||||
$this->currentTLSA = "";
|
||||
try {
|
||||
$mailEsyWebDevA = $rDnsClient->query('mail.esy-web.dev', 'A');
|
||||
/** @var \NetDNS2\Data\IPv4 $mailEsyWebDevAResponse */
|
||||
$mailEsyWebDevAResponse = $mailEsyWebDevA->answer[0]->address;
|
||||
$this->currentA = $mailEsyWebDevAResponse->value();
|
||||
if($mailEsyWebDevAResponse->value() == "5.39.73.151") {
|
||||
$this->mailEsyWebDevA_valid = true;
|
||||
}
|
||||
}catch (\Exception $exception) {
|
||||
$this->mailEsyWeb_valid = false;
|
||||
}
|
||||
try {
|
||||
$mailEsyWebDevPTR = $rDnsClient->query('151.73.39.5.in-addr.arpa', 'PTR');
|
||||
/** @var \NetDNS2\Data\Domain $mailEsyWebDevPTRResponse */
|
||||
$mailEsyWebDevPTRResponse = $mailEsyWebDevPTR->answer[0]->ptrdname;
|
||||
$this->currentPTR = $mailEsyWebDevPTRResponse->value();
|
||||
|
||||
if($mailEsyWebDevPTRResponse->value() == "mail.esy-web.dev") {
|
||||
$this->mailEsyWebDevPTR_valid = true;
|
||||
}
|
||||
}catch (\Exception $exception) {
|
||||
$this->mailEsyWeb_valid = false;
|
||||
}
|
||||
try {
|
||||
$mailEsyWebDevTLSA = $rDnsClient->query('_25._tcp.mail.esy-web.dev', 'TLSA');
|
||||
$mailEsyWebDevTLSAResponse = $mailEsyWebDevTLSA->answer[0]->certificate;
|
||||
$this->currentTLSA = $mailEsyWebDevTLSAResponse;
|
||||
|
||||
if($mailEsyWebDevTLSAResponse == "ae7b5c43b79965b059200c209ba810600a98344de02a6688423826a7d4c774b3") {
|
||||
$this->mailEsyWebDevTLSA_valid = true;
|
||||
}
|
||||
}catch (\Exception $exception) {
|
||||
$this->mailEsyWeb_valid = false;
|
||||
}
|
||||
if($this->mailEsyWeb_valid) {
|
||||
$io->success("Mail server configuration is valid");
|
||||
$this->mailer->sendMulti(['legrand@siteconseil.fr','jovann@siteconseil.fr'],"Configuration mail.esy-web.dev - VALIDE","mails/mailserver.twig",[
|
||||
'A' => '5.39.73.151',
|
||||
'ACurrent' => $this->currentA,
|
||||
'PTR' => 'mail.esy-web.dev',
|
||||
'PTRCurrent' => $this->currentPTR,
|
||||
'TLSA' => 'ae7b5c43b79965b059200c209ba810600a98344de02a6688423826a7d4c774b3',
|
||||
'TLSACurrent' => $this->currentTLSA,
|
||||
'isValid' => $this->mailEsyWeb_valid,
|
||||
]);
|
||||
} else {
|
||||
$io->error("Mail server configuration is not valid");
|
||||
$this->mailer->sendMulti(['legrand@siteconseil.fr','jovann@siteconseil.fr'],"Configuration mail.esy-web.dev - INVALID","mails/mailserver.twig",[
|
||||
'A' => '5.39.73.151',
|
||||
'ACurrent' => $this->currentA,
|
||||
'PTR' => 'mail.esy-web.dev',
|
||||
'PTRCurrent' => $this->currentPTR,
|
||||
'TLSA' => 'ae7b5c43b79965b059200c209ba810600a98344de02a6688423826a7d4c774b3',
|
||||
'TLSACurrent' => $this->currentTLSA,
|
||||
'isValid' => $this->mailEsyWeb_valid,
|
||||
]);
|
||||
}
|
||||
$io->info("started control all domain register");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
30
templates/mails/mailserver.twig
Normal file
30
templates/mails/mailserver.twig
Normal file
@@ -0,0 +1,30 @@
|
||||
{% extends 'mails/base.twig' %}
|
||||
|
||||
{% block content %}
|
||||
<mj-text font-size="16px" line-height="24px">
|
||||
Bonjour,<br/><br/>
|
||||
Voici le résultat de la vérification de configuration mail pour <strong>mail.esy-web.dev</strong> :<br/><br/>
|
||||
|
||||
{% if datas.isValid %}
|
||||
<span style="color:green; font-weight:bold;">Configuration VALIDÉE ✔️</span>
|
||||
{% else %}
|
||||
<span style="color:red; font-weight:bold;">Configuration INVALIDÉE ❌</span>
|
||||
{% endif %}
|
||||
|
||||
<br/><br/>
|
||||
<strong>Détails des enregistrements DNS :</strong><br/>
|
||||
<ul>
|
||||
<li><strong>A:</strong> {{ datas.A }}</li>
|
||||
<li><strong>IP actuelle:</strong> {{ datas.ACurrent }}</li>
|
||||
<li><strong>PTR:</strong> {{ datas.PTR }}</li>
|
||||
<li><strong>PTR actuel:</strong> {{ datas.PTRCurrent }}</li>
|
||||
<li><strong>TLSA:</strong> {{ datas.TLSA }}</li>
|
||||
<li><strong>TLSA actuel:</strong> {{ datas.TLSACurrent }}</li>
|
||||
</ul>
|
||||
|
||||
<br/>
|
||||
N'hésitez pas à nous contacter en cas de questions.<br/><br/>
|
||||
Cordialement,<br/>
|
||||
L'équipe SARL SITECONSEIL
|
||||
</mj-text>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user