diff --git a/Application/Controller/Admin/SpfChecker.php b/Application/Controller/Admin/SpfChecker.php index 798ac38..a87534f 100644 --- a/Application/Controller/Admin/SpfChecker.php +++ b/Application/Controller/Admin/SpfChecker.php @@ -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'; + } + } } diff --git a/Application/Model/DmarcResult.php b/Application/Model/DmarcResult.php new file mode 100644 index 0000000..5d6e0a4 --- /dev/null +++ b/Application/Model/DmarcResult.php @@ -0,0 +1,42 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +namespace D3\MailConfigChecker\Application\Model; + +class DmarcResult +{ + public const SET = 'set'; + public const MISSING = 'missing'; + public const ERROR = 'error'; + + protected $status; + protected $record; + + public function __construct(string $status, ?string $record = null) + { + $this->status = $status; + $this->record = $record; + } + + public function getStatus() + { + return $this->status; + } + + public function getRecord() + { + return $this->record; + } +} diff --git a/Application/Model/SpfResult.php b/Application/Model/SpfResult.php index 6cd9b8d..e8e1cfe 100644 --- a/Application/Model/SpfResult.php +++ b/Application/Model/SpfResult.php @@ -17,7 +17,7 @@ namespace D3\MailConfigChecker\Application\Model; class SpfResult { - public const SET = 'set'; + public const SET = 'set'; public const MISSING = 'missing'; public const ERROR = 'error'; diff --git a/Application/views/admin/tpl/spfCheck.tpl b/Application/views/admin/tpl/spfCheck.tpl index 9301fd4..3cca203 100644 --- a/Application/views/admin/tpl/spfCheck.tpl +++ b/Application/views/admin/tpl/spfCheck.tpl @@ -10,15 +10,16 @@
[{oxmultilang ident="D3_MAILCHECKER_SPFRESULT_"|cat:$spf->getStatus()|upper}]
[{if $spf->getRecord()}]- - + +
[{/if}] @@ -45,7 +46,6 @@ [{oxmultilang ident="D3_MAILCHECKER_SPFRESULT_LINK_GENERATOR"}] - [{/if}][{oxmultilang ident="D3_MAILCHECKER_DMARCRESULT_"|cat:$dmarc->getStatus()|upper}]
+ [{if $dmarc->getRecord()}] ++ + +
+ [{/if}] + +