add DMARC check

# Conflicts:
#	Application/Controller/Admin/SpfChecker.php
#	Application/views/admin/tpl/mailTester.tpl
#	Application/views/admin/tpl/mailconfigcheck.tpl
#	Application/views/admin/tpl/mailinfopage.tpl
#	Application/views/admin/tpl/smtpCheck.tpl
#	Application/views/admin/tpl/spfCheck.tpl
This commit is contained in:
2024-06-04 14:20:20 +02:00
parent c414117143
commit 860de39a79
6 changed files with 181 additions and 12 deletions

View File

@ -16,6 +16,10 @@ declare(strict_types=1);
namespace D3\MailConfigChecker\Application\Controller\Admin;
use Assert\InvalidArgumentException;
use D3\MailAuthenticationCheck\DMARCCheck;
use D3\MailAuthenticationCheck\Model\DMARCResult;
use D3\MailConfigChecker\Application\Model\Constants;
use D3\MailConfigChecker\Application\Model\DmarcResult as OxDmarcResult;
use D3\MailConfigChecker\Application\Model\SpfResult;
use Mika56\SPFCheck\DNS\DNSRecordGetter;
use Mika56\SPFCheck\Model\Query;
@ -32,6 +36,7 @@ class SpfChecker extends AdminDetailsController
public function render()
{
$this->checkSpf();
$this->checkDmarc();
return parent::render();
}
@ -46,10 +51,24 @@ class SpfChecker extends AdminDetailsController
}
);
$this->addTplParam('result', $result);
$this->addTplParam('spf_result', $result);
}
protected function getMailDomains()
protected function checkDmarc()
{
$result = [];
$mailDomains = $this->getMailDomains();
array_walk(
$mailDomains,
function ($domain) use (&$result) {
$this->checkDmarcByDomain($domain, $result);
}
);
$this->addTplParam('dmarc_result', $result);
}
protected function getMailDomains(): array
{
/** @var Shop $shop */
$shop = Registry::getConfig()->getActiveShop();
@ -119,4 +138,41 @@ class SpfChecker extends AdminDetailsController
return 'danger';
}
}
public function checkDmarcByDomain($domain, &$summarize)
{
try {
$check = new DMARCCheck(new DNSRecordGetter());
$query = new Query('', $domain);
$record = $check->getResult($query)->getRecord();
switch ( $record->getRejectPolicy()->getValue() ) {
case DMARCResult::REJECT_QUARANTINE:
case DMARCResult::REJECT_REJECT:
$status = OxDmarcResult::SET;
break;
case DMARCResult::REJECT_NONE:
$status = OxDmarcResult::MISSING;
break;
default:
$status = OxDmarcResult::ERROR;
}
$summarize[$domain] = oxNew( OxDmarcResult::class, $status, $record->getRawRecord());
} catch (\LogicException) {
$summarize[$domain] = oxNew( OxDmarcResult::class, OxDmarcResult::MISSING, '');
}
}
public function getDmarcStatusColor(OxDmarcResult $result)
{
switch ($result->getStatus()) {
case SpfResult::SET:
return 'success';
case SpfResult::ERROR:
return 'warning';
default:
return 'danger';
}
}
}