diff --git a/Application/Controller/Admin/MailConfigCheck.php b/Application/Controller/Admin/MailConfigCheck.php index 57dcc69..f18817b 100644 --- a/Application/Controller/Admin/MailConfigCheck.php +++ b/Application/Controller/Admin/MailConfigCheck.php @@ -18,10 +18,7 @@ namespace D3\MailConfigChecker\Application\Controller\Admin; use Assert\Assert; use Assert\InvalidArgumentException; use D3\MailConfigChecker\Application\Model\Exception\d3TranslatableLazyAssertionException; -use Mika56\SPFCheck\DNS\DNSRecordGetter; -use Mika56\SPFCheck\Model\Query; -use Mika56\SPFCheck\Model\Result; -use Mika56\SPFCheck\SPFCheck; +use Exception; use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController; use OxidEsales\Eshop\Application\Model\Shop; use OxidEsales\Eshop\Core\Email; @@ -30,6 +27,7 @@ use OxidEsales\Eshop\Core\Registry; class MailConfigCheck extends AdminDetailsController { protected $_sThisTemplate = 'mailConfigCheck.tpl'; + protected $testMailAddress = 'test@example.com'; public function render() { @@ -51,9 +49,6 @@ class MailConfigCheck extends AdminDetailsController ->that( $shop->getFieldData( 'oxsmtp' ), $lang->translateString('SHOP_MAIN_SMTPSERVER') ) ->notBlank( $lang->translateString('D3_ASSERTIONS_NOTSET') ) ->regex( '/.*:(587|2525)$/m', $lang->translateString('D3_ASSERTIONS_NOPORT') ) - ->that( 'cloud1-vm279.de-nserver.de:5', $lang->translateString('SHOP_MAIN_SMTPSERVER') ) - ->notBlank( $lang->translateString('D3_ASSERTIONS_NOTSET') ) - ->regex( '/.*:(587|2525)$/m', $lang->translateString('D3_ASSERTIONS_NOPORT') ) ->that( $shop->getFieldData( 'oxsmtpuser' ), $lang->translateString('SHOP_MAIN_SMTPUSER') ) ->notBlank( $lang->translateString('D3_ASSERTIONS_NOTSET') ) ->that( $shop->getFieldData( 'oxsmtppwd' ), $lang->translateString('SHOP_MAIN_SMTPPASSWORD') ) @@ -72,83 +67,19 @@ class MailConfigCheck extends AdminDetailsController public function checkConfiguration() { - dumpvar(''); - dumpvar(''); - dumpvar(''); - dumpVar(''); - $this->useSmtp(); - $this->checkSpf(); + $this->getCurrentMailer(); } - protected function useSmtp() + protected function getCurrentMailer() { try { - echo "

Mailer Check

"; $mail = oxNew( Email::class ); - $mail->setRecipient( 'test@example.com' ); + $mail->setRecipient( $this->testMailAddress ); $mail->setBody('.'); $mail->send(); - dumpvar( 'Shop sendet ueber '.ucfirst($mail->getMailer()) ); - } catch (\Exception $e) { - dumpvar($e->getMessage()); + $this->addTplParam('mailer', $mail->getMailer()); + } catch ( Exception $e) { + Registry::getUtilsView()->addErrorToDisplay($e); } } - - protected function checkSpf() - { - echo "

SPF Check

"; - $mailDomains = $this->getMailDomains(); - array_walk( - $mailDomains, - function($domain) { - dumpvar(''.$domain.''); - $this->checkSpfByDomain($domain); - } - ); - } - - protected function checkSpfByDomain($domain) - { - $checker = new SPFCheck(new DNSRecordGetter()); - $query = new Query('', $domain); - - $result = $checker->getResult($query); - if (in_array( - $result->getResult(), - [Result::FAIL, Result::NEUTRAL, Result::PASS, Result::SOFTFAIL] - )) { - dumpvar('SPF is set'); - } elseif (Result::NONE) { - dumpvar('SPF missing'); - } else { - dumpvar('error determine SPF record'); - } - - if ($record = $result->getRecord()) { - dumpvar($record->getRawRecord()); - } - } - - protected function getMailDomains() - { - return - array_filter( - array_unique( - array_map( - function($mailAddress) { - $mailAddress = trim($mailAddress); - return strstr($mailAddress, '@') ? - array_pop(explode('@', $mailAddress)) : - ''; - }, - [ - Registry::getConfig()->getActiveShop()->getFieldData('oxinfoemail'), - Registry::getConfig()->getActiveShop()->getFieldData('oxorderemail'), - Registry::getConfig()->getActiveShop()->getFieldData('oxowneremail'), - ] - ) - ) - ); - - } } \ No newline at end of file diff --git a/Application/Controller/Admin/SpfChecker.php b/Application/Controller/Admin/SpfChecker.php new file mode 100644 index 0000000..6fab6f2 --- /dev/null +++ b/Application/Controller/Admin/SpfChecker.php @@ -0,0 +1,117 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +namespace D3\MailConfigChecker\Application\Controller\Admin; + +use Assert\Assert; +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 Net_SMTP; +use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController; +use OxidEsales\Eshop\Application\Model\Shop; +use OxidEsales\Eshop\Core\Registry; +use PEAR; +use PEAR_Error; + +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, + function($domain) use (&$result) { + $this->checkSpfByDomain($domain, $result); + } + ); + + $this->addTplParam('result', $result); + } + + protected function getMailDomains() + { + return + array_filter( + array_unique( + array_map( + function($mailAddress) { + $mailAddress = trim($mailAddress); + return strstr($mailAddress, '@') ? + array_pop(explode('@', $mailAddress)) : + ''; + }, + [ + Registry::getConfig()->getActiveShop()->getFieldData('oxinfoemail'), + Registry::getConfig()->getActiveShop()->getFieldData('oxorderemail'), + Registry::getConfig()->getActiveShop()->getFieldData('oxowneremail'), + ] + ) + ) + ); + + } + + 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'; + } + } +} \ No newline at end of file diff --git a/Application/Model/Exception/d3TranslatableLazyAssertionException.php b/Application/Model/Exception/d3TranslatableLazyAssertionException.php index e34e75c..b102e98 100644 --- a/Application/Model/Exception/d3TranslatableLazyAssertionException.php +++ b/Application/Model/Exception/d3TranslatableLazyAssertionException.php @@ -1,18 +1,18 @@ - * @link http://www.oxidmodule.com + * @author D3 Data Development - Daniel Seifert + * @link https://www.oxidmodule.com */ +declare(strict_types=1); + namespace D3\MailConfigChecker\Application\Model\Exception; use Assert\LazyAssertionException; diff --git a/Application/Model/SpfResult.php b/Application/Model/SpfResult.php new file mode 100644 index 0000000..a6176d7 --- /dev/null +++ b/Application/Model/SpfResult.php @@ -0,0 +1,41 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +namespace D3\MailConfigChecker\Application\Model; +class SpfResult +{ + const SET = 'set'; + const MISSING = 'missing'; + const ERROR = 'error'; + + protected string $status; + protected ?string $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; + } +} \ No newline at end of file diff --git a/Application/views/admin/tpl/inc/bootstrap.tpl b/Application/views/admin/tpl/inc/bootstrap.tpl new file mode 100644 index 0000000..07a1a31 --- /dev/null +++ b/Application/views/admin/tpl/inc/bootstrap.tpl @@ -0,0 +1,10 @@ + + \ No newline at end of file diff --git a/Application/views/admin/tpl/mailconfigcheck.tpl b/Application/views/admin/tpl/mailconfigcheck.tpl index 615238e..fe73d77 100644 --- a/Application/views/admin/tpl/mailconfigcheck.tpl +++ b/Application/views/admin/tpl/mailconfigcheck.tpl @@ -1,21 +1,14 @@ [{include file="headitem.tpl" title="d3mxd3cleartmp"|oxmultilangassign}] +[{include file="inc_bootstrap.tpl"}] - -[{*[{if $readonly}]*}] - [{assign var="readonly" value="readonly disabled"}] -[{*[{else}]*}] -[{* [{assign var="readonly" value=""}]*}] -[{*[{/if}]*}] +[{assign var="readonly" value="readonly disabled"}] +
[{$oViewConf->getHiddenSid()}] @@ -23,56 +16,52 @@
- - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - -
- - - -
- - - -
- - - -
-
-
- [{$oViewConf->getHiddenSid()}] - - - -
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ [{if $mailer}] +
+ [{oxmultilang ident="D3_CFGCHECK_SHOPSEND" suffix="COLON"}] + [{if $mailer == 'mail'}] +
+ [{oxmultilang ident="D3_CFGCHECK_SHOPSEND_PHPMAILER_DESC"}] + [{else}] + [{oxmultilang ident="D3_CFGCHECK_SHOPSEND_SMTP"}]
+ [{oxmultilang ident="D3_CFGCHECK_SHOPSEND_SMTP_DESC"}] + [{/if}] +
+ [{else}] +
+ [{$oViewConf->getHiddenSid()}] + + + +
+ [{/if}] +
+
[{include file="bottomnaviitem.tpl"}] - [{include file="bottomitem.tpl"}] \ No newline at end of file diff --git a/Application/views/admin/tpl/spfCheck.tpl b/Application/views/admin/tpl/spfCheck.tpl new file mode 100644 index 0000000..dd8fe19 --- /dev/null +++ b/Application/views/admin/tpl/spfCheck.tpl @@ -0,0 +1,43 @@ +[{include file="headitem.tpl" title="GENERAL_ADMIN_TITLE"|oxmultilangassign}] +[{include file="inc_bootstrap.tpl"}] + + + +
+ [{$oViewConf->getHiddenSid()}] + + + + +
+ +

[{oxmultilang ident="D3_TAB_SPFCHECK"}]

+ +
+ [{foreach from=$result key="domain" item="spf"}] +
+
+
+ [{$domain}] +
+
+ [{oxmultilang ident="D3_SPFRESULT_"|cat:$spf->getStatus()|upper}]
+ [{if $spf->getRecord()}] +
+ + [{/if}] +
+
+
+ [{/foreach}] +
+ +[{include file="bottomnaviitem.tpl"}] + +[{include file="bottomitem.tpl"}] diff --git a/Application/views/de/translations.php b/Application/views/de/translations.php index cca307c..fbfceb5 100644 --- a/Application/views/de/translations.php +++ b/Application/views/de/translations.php @@ -10,4 +10,14 @@ return [ 'D3_ASSERTIONS_FAILED' => 'Die folgenden %d Prüfungen schlugen fehl:', 'D3_ASSERTIONS_NOTSET' => 'ist nicht (richtig) gesetzt', 'D3_ASSERTIONS_NOPORT' => 'fehlende oder falsche Port-Angabe (587 oder 2525)', + 'D3_CFGCHECK_SHOPSEND' => 'Der Shop verschickt Mails über', + 'D3_CFGCHECK_SHOPSEND_PHPMAILER' => 'PhpMailer', + 'D3_CFGCHECK_SHOPSEND_PHPMAILER_DESC' => 'Der Versand über den PhpMailer sollte dringend vermieden werden, da solche Mails meist als Spam eingestuft werden. Wenn Sie alle SMTP-Daten eingegeben haben, prüfen Sie mögliche Anmeldeprobleme im SMTP-Check.', + 'D3_CFGCHECK_SHOPSEND_SMTP' => 'SMTP', + 'D3_CFGCHECK_SHOPSEND_SMTP_DESC' => 'Alles in bester Ordnung. Bitte prüfen Sie noch die nötigen SPF-Einträge für Ihre Domain(s).', + 'D3_CFGCHECK_STARTCHECK' => 'Konfiguration testen', + + 'D3_SPFRESULT_SET' => 'SPF-Eintrag gesetzt', + 'D3_SPFRESULT_MISSING' => 'SPF-Eintrag fehlt, dieser sollte dringend nachgetragen werden', + 'D3_SPFRESULT_ERROR' => 'SPF-Eintrag kann nicht geprüft werden', ]; diff --git a/metadata.php b/metadata.php index 0d2c02c..7bed776 100644 --- a/metadata.php +++ b/metadata.php @@ -17,7 +17,8 @@ use D3\MailConfigChecker\Application\Controller\Admin\MailCheckBase; use D3\MailConfigChecker\Application\Controller\Admin\MailCheckMenu; use D3\MailConfigChecker\Application\Controller\Admin\MailConfigCheck; use D3\MailConfigChecker\Application\Controller\Admin\MailTester; -use D3\SmtpChecker\Application\Controller\Admin\SmtpChecker; +use D3\MailConfigChecker\Application\Controller\Admin\SpfChecker; +use D3\MailConfigChecker\Application\Controller\Admin\SmtpChecker; $sMetadataVersion = '2.1'; @@ -40,11 +41,12 @@ $aModule = [ 'email' => 'support@shopmodule.com', 'url' => 'https://www.oxidmodule.com/', 'controllers' => [ - 'd3mailcheck' => MailCheckBase::class, + 'd3mailcheck' => MailCheckBase::class, 'd3mailcheckmenu' => MailCheckMenu::class, - 'd3mailconfigcheck' => MailConfigCheck::class, - 'd3smtpchecker' => SmtpChecker::class, - 'd3mailtester' => MailTester::class, + 'd3mailconfigcheck' => MailConfigCheck::class, + 'd3smtpchecker' => SmtpChecker::class, + 'd3spfchecker' => SpfChecker::class, + 'd3mailtester' => MailTester::class, ], 'extend' => [ // \OxidEsales\Eshop\Core\ShopControl::class => \D3\ThisModule\Modules\Core\ShopControl_MyModule::class @@ -56,9 +58,12 @@ $aModule = [ 'templates' => [ 'mailCheckBase.tpl' => 'd3/mailconfigchecker/Application/views/admin/tpl/mailcheckbase.tpl', 'mailCheckMenu.tpl' => 'd3/mailconfigchecker/Application/views/admin/tpl/mailcheckmenu.tpl', - 'mailConfigCheck.tpl' => 'd3/mailconfigchecker/Application/views/admin/tpl/mailconfigcheck.tpl', + 'mailConfigCheck.tpl' => 'd3/mailconfigchecker/Application/views/admin/tpl/mailconfigcheck.tpl', 'smtpCheck.tpl' => 'd3/mailconfigchecker/Application/views/admin/tpl/smtpCheck.tpl', + 'spfCheck.tpl' => 'd3/mailconfigchecker/Application/views/admin/tpl/spfCheck.tpl', 'mailTester.tpl' => 'd3/mailconfigchecker/Application/views/admin/tpl/mailTester.tpl', + + 'inc_bootstrap.tpl' => 'd3/mailconfigchecker/Application/views/admin/tpl/inc/bootstrap.tpl', // 'flow_theme' => [ // 'd3FlowTemplateAlias.tpl' => 'd3/thismodule/Application/views/tpl/d3FlowTheme.tpl', // ],