2023-12-11 15:48:31 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace D3\MailConfigChecker\Application\Controller\Admin;
|
|
|
|
|
|
|
|
use Assert\InvalidArgumentException;
|
|
|
|
use D3\MailConfigChecker\Application\Model\SpfResult;
|
|
|
|
use Mika56\SPFCheck\DNS\DNSRecordGetter;
|
|
|
|
use Mika56\SPFCheck\Model\Query;
|
|
|
|
use Mika56\SPFCheck\Model\Result;
|
|
|
|
use Mika56\SPFCheck\SPFCheck;
|
|
|
|
use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController;
|
2023-12-12 11:43:46 +01:00
|
|
|
use OxidEsales\Eshop\Application\Model\Shop;
|
2023-12-11 15:48:31 +01:00
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
|
|
|
|
class SpfChecker extends AdminDetailsController
|
|
|
|
{
|
|
|
|
protected $_sThisTemplate = 'spfCheck.tpl';
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
$this->checkSpf();
|
|
|
|
return parent::render();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function checkSpf()
|
|
|
|
{
|
|
|
|
$result = [];
|
|
|
|
$mailDomains = $this->getMailDomains();
|
|
|
|
array_walk(
|
|
|
|
$mailDomains,
|
2023-12-12 11:50:41 +01:00
|
|
|
function ($domain) use (&$result) {
|
2023-12-11 15:48:31 +01:00
|
|
|
$this->checkSpfByDomain($domain, $result);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->addTplParam('result', $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getMailDomains()
|
|
|
|
{
|
2023-12-12 11:43:46 +01:00
|
|
|
/** @var Shop $shop */
|
|
|
|
$shop = Registry::getConfig()->getActiveShop();
|
|
|
|
|
2023-12-11 15:48:31 +01:00
|
|
|
return
|
|
|
|
array_filter(
|
|
|
|
array_unique(
|
|
|
|
array_map(
|
2023-12-12 11:50:41 +01:00
|
|
|
function ($mailAddress) {
|
2023-12-11 15:48:31 +01:00
|
|
|
$mailAddress = trim($mailAddress);
|
2023-12-12 11:28:18 +01:00
|
|
|
try {
|
2023-12-12 11:50:41 +01:00
|
|
|
if (! strstr($mailAddress, '@')) {
|
|
|
|
throw oxNew(InvalidArgumentException::class);
|
2023-12-12 11:28:18 +01:00
|
|
|
}
|
2023-12-12 11:50:41 +01:00
|
|
|
$addressChunks = explode('@', $mailAddress);
|
2023-12-12 11:28:18 +01:00
|
|
|
|
2023-12-12 11:50:41 +01:00
|
|
|
return array_pop($addressChunks);
|
2023-12-12 11:28:18 +01:00
|
|
|
} catch (InvalidArgumentException $e) {
|
|
|
|
return '';
|
|
|
|
}
|
2023-12-11 15:48:31 +01:00
|
|
|
},
|
|
|
|
[
|
2023-12-12 11:43:46 +01:00
|
|
|
$shop->getFieldData('oxinfoemail'),
|
|
|
|
$shop->getFieldData('oxorderemail'),
|
|
|
|
$shop->getFieldData('oxowneremail'),
|
2023-12-11 15:48:31 +01:00
|
|
|
]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function checkSpfByDomain($domain, &$summarize)
|
|
|
|
{
|
|
|
|
$checker = new SPFCheck(new DNSRecordGetter());
|
|
|
|
$query = new Query('', $domain);
|
|
|
|
|
|
|
|
$result = $checker->getResult($query);
|
|
|
|
switch ($result->getResult()) {
|
|
|
|
case Result::FAIL:
|
|
|
|
case Result::NEUTRAL:
|
|
|
|
case Result::PASS:
|
|
|
|
case Result::SOFTFAIL:
|
|
|
|
$status = SpfResult::SET;
|
|
|
|
break;
|
|
|
|
case Result::NONE:
|
|
|
|
$status = SpfResult::MISSING;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$status = SpfResult::ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
$rawRecord = ($record = $result->getRecord()) ?
|
|
|
|
$record->getRawRecord() :
|
|
|
|
null;
|
|
|
|
|
|
|
|
$summarize[$domain] = oxNew(SpfResult::class, $status, $rawRecord);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSpfStatusColor(SpfResult $result)
|
|
|
|
{
|
|
|
|
switch ($result->getStatus()) {
|
|
|
|
case SpfResult::SET:
|
|
|
|
return 'success';
|
|
|
|
case SpfResult::ERROR:
|
|
|
|
return 'warning';
|
|
|
|
default:
|
|
|
|
return 'danger';
|
|
|
|
}
|
|
|
|
}
|
2023-12-12 11:50:41 +01:00
|
|
|
}
|