Compare commits

..

14 Commits

16 changed files with 126 additions and 67 deletions

View File

@ -4,9 +4,25 @@ $finder = PhpCsFixer\Finder::create()
->in(__DIR__)
;
$fileHeaderComment = <<<EOF
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
EOF;
$config = new PhpCsFixer\Config();
return $config->setRules([
'@PHP73Migration' => true,
'header_comment' => [
'header' => $fileHeaderComment,
'comment_type' => 'PHPDoc',
'location' => 'after_open'
],
'@PHP80Migration' => true,
'@PSR12' => true
])
->setFinder($finder)

View File

@ -26,7 +26,32 @@ use OxidEsales\Eshop\Core\Registry;
class MailConfigCheck extends AdminDetailsController
{
protected $_sThisTemplate = '@'.Constants::OXID_MODULE_ID.'/admin/mailConfigCheck';
protected string $testMailAddress = 'test@example.com';
protected string $testMailAddress;
public function __construct()
{
parent::__construct();
try {
$infoMail = Registry::getConfig()->getActiveShop()->getFieldData( 'oxinfoemail' );
Assert::that($infoMail)->email();
$re = '/.*(@.*$)/m';
$subst = "noreply$1";
$this->testMailAddress = preg_replace($re, $subst, $infoMail);
} catch (InvalidArgumentException) {
$this->testMailAddress = 'test@example.tld';
}
$this->setSmtpCredentials();
}
protected function setSmtpCredentials(): void
{
$shop = Registry::getConfig()->getActiveShop();
$this->addTplParam('smtpHost', $shop->getFieldData('oxsmtp'));
$this->addTplParam('smtpUser', $shop->getFieldData('oxsmtpuser'));
}
public function render(): string
{
@ -74,7 +99,6 @@ class MailConfigCheck extends AdminDetailsController
{
try {
$shop = Registry::getConfig()->getActiveShop();
$config = Registry::getConfig();
$mail = oxNew(Email::class);
$mail->setRecipient(
@ -83,8 +107,7 @@ class MailConfigCheck extends AdminDetailsController
$mail->setBody('.');
$mail->setFrom($shop->getFieldData('oxowneremail'));
$currentDebug = $config->getConfigParam('iDebug');
$config->setConfigParam('iDebug', 6);
$mail->set("SMTPDebug", true); // don't set via iDebug = 6 because different handling
$mail->setSmtp();
ob_start();
@ -95,12 +118,13 @@ class MailConfigCheck extends AdminDetailsController
$re = '/(^|\<br\>)(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\s)/m';
$subst = "$1";
$communication = preg_replace($re, $subst, $communication);
$config->setConfigParam('iDebug', $currentDebug);
$this->addTplParam('mailer', $mail->getMailer());
$this->addTplParam('communication', $communication);
} catch (Exception $e) {
ob_end_clean();
Registry::getUtilsView()->addErrorToDisplay($e);
}
restore_error_handler();
}
}

View File

@ -46,7 +46,7 @@ class MailTester extends AdminDetailsController
$mail->setFrom($from);
$mail->sendEmail($to, $subject, $body);
$this->addTplParam('success', true);
} catch ( Exception $e) {
} catch (Exception $e) {
Registry::getUtilsView()->addErrorToDisplay(nl2br($e->getMessage()));
}
}

View File

@ -44,7 +44,18 @@ class SmtpChecker extends AdminDetailsController
{
parent::__construct();
/** @var Shop $activeShop */
$this->setSmtpCredentials();
$this->from = Registry::getRequest()->getRequestEscapedParameter('from') ?: '';
$this->addTplParam('from', $this->from);
$this->to = Registry::getRequest()->getRequestEscapedParameter('to') ?: '';
$this->addTplParam('recipient', $this->to);
$this->addTplParam('sendMail', Registry::getRequest()->getRequestEscapedParameter('sendmail'));
$this->addTplParam('smtpLog', $this->log);
}
protected function setSmtpCredentials(): void
{
$activeShop = Registry::getConfig()->getActiveShop();
if ($localHost = Registry::getRequest()->getRequestEscapedParameter('smtpHost')) {
@ -53,20 +64,13 @@ class SmtpChecker extends AdminDetailsController
['host' => $shopHost, 'port' => $shopPort] = parse_url(trim($activeShop->getFieldData('oxsmtp')));
}
$this->host = $shopHost;
$this->host = $shopHost ?? '';
$this->addTplParam('smtpHost', Registry::getRequest()->getRequestEscapedParameter('smtpHost'));
$this->port = $shopPort;
$this->port = $shopPort ?? 587;
$this->user = Registry::getRequest()->getRequestEscapedParameter('smtpUser') ?: $activeShop->getFieldData('oxsmtpuser');
$this->addTplParam('smtpUser', $this->user);
$this->pwd = Registry::getRequest()->getRequestEscapedParameter('smtpPwd') ?: $activeShop->getFieldData('oxsmtppwd');
$this->addTplParam('smtpPwd', $this->pwd);
$this->from = Registry::getRequest()->getRequestEscapedParameter('from') ?: '';
$this->addTplParam('from', $this->from);
$this->to = Registry::getRequest()->getRequestEscapedParameter('to') ?: '';
$this->addTplParam('recipient', $this->to);
$this->addTplParam('sendMail', Registry::getRequest()->getRequestEscapedParameter('sendmail'));
$this->addTplParam('smtpLog', $this->log);
}
public function getTemplateName(): string

View File

@ -81,7 +81,7 @@ class SpfChecker extends AdminDetailsController
function ($mailAddress) {
$mailAddress = trim($mailAddress);
try {
if ( ! str_contains( $mailAddress, '@' ) ) {
if (! str_contains($mailAddress, '@')) {
throw oxNew(InvalidArgumentException::class);
}
$addressChunks = explode('@', $mailAddress);
@ -107,7 +107,7 @@ class SpfChecker extends AdminDetailsController
$query = new Query('', $domain);
$result = $checker->getResult($query);
$status = match ( $result->getResult() ) {
$status = match ($result->getResult()) {
Result::FAIL, Result::NEUTRAL, Result::PASS, Result::SOFTFAIL => SpfResult::SET,
Result::NONE => SpfResult::MISSING,
default => SpfResult::ERROR,
@ -122,7 +122,7 @@ class SpfChecker extends AdminDetailsController
public function getSpfStatusColor(SpfResult $result): string
{
return match ( $result->getStatus() ) {
return match ($result->getStatus()) {
SpfResult::SET => 'success',
SpfResult::ERROR => 'warning',
default => 'danger',
@ -136,21 +136,21 @@ class SpfChecker extends AdminDetailsController
$query = new Query('', $domain);
$record = $check->getResult($query)->getRecord();
$status = match ( $record->getRejectPolicy()->getValue() ) {
$status = match ($record->getRejectPolicy()->getValue()) {
DMARCResult::REJECT_QUARANTINE, DMARCResult::REJECT_REJECT => OxDmarcResult::SET,
DMARCResult::REJECT_NONE => OxDmarcResult::MISSING,
default => OxDmarcResult::ERROR,
};
$summarize[$domain] = oxNew( OxDmarcResult::class, $status, $record->getRawRecord());
} catch ( LogicException) {
$summarize[$domain] = oxNew( OxDmarcResult::class, OxDmarcResult::MISSING, '');
$summarize[$domain] = oxNew(OxDmarcResult::class, $status, $record->getRawRecord());
} catch (LogicException) {
$summarize[$domain] = oxNew(OxDmarcResult::class, OxDmarcResult::MISSING, '');
}
}
public function getDmarcStatusColor(OxDmarcResult $result): string
{
return match ( $result->getStatus() ) {
return match ($result->getStatus()) {
SpfResult::SET => 'success',
SpfResult::ERROR => 'warning',
default => 'danger',

View File

@ -21,8 +21,8 @@ class DmarcResult
public const MISSING = 'missing';
public const ERROR = 'error';
protected $status;
protected $record;
protected string $status;
protected ?string $record;
public function __construct(string $status, ?string $record = null)
{

View File

@ -27,7 +27,7 @@ class d3TranslatableLazyAssertionException extends LazyAssertionException
$i = 1;
foreach ($errors as $error) {
$message .= sprintf("%d) %s: %s\n", $i ++, $error->getPropertyPath(), $error->getMessage());
$message .= sprintf("%d) %s: %s\n", $i++, $error->getPropertyPath(), $error->getMessage());
}
return new LazyAssertionException($message, $errors);

View File

@ -30,8 +30,8 @@ return [
'D3_MAILCHECKER_ASSERTIONS_NOTSET' => 'ist nicht (richtig) gesetzt',
'D3_MAILCHECKER_ASSERTIONS_NOPORT' => 'fehlende oder falsche Port-Angabe (587 oder 2525)',
'D3_MAILCHECKER_CFGCHECK_SHOPSEND' => 'Der Shop verschickt Mails über',
'D3_MAILCHECKER_CFGCHECK_SHOPSEND_PHPMAILER' => 'PhpMailer',
'D3_MAILCHECKER_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_MAILCHECKER_CFGCHECK_SHOPSEND_PHPMAILER' => 'PHP Mailfunktion',
'D3_MAILCHECKER_CFGCHECK_SHOPSEND_PHPMAILER_DESC' => 'Der Versand über die PHP-eigene Mailfunktion 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_MAILCHECKER_CFGCHECK_SHOPSEND_SMTP' => 'SMTP',
'D3_MAILCHECKER_CFGCHECK_SHOPSEND_SMTP_DESC' => 'Alles in bester Ordnung. Bitte prüfen Sie noch die nötigen Einstellungen im Tab "Authorisierung Check" für Ihre Domain(s).',
'D3_MAILCHECKER_CFGCHECK_STARTCHECK' => 'Konfiguration testen',

View File

@ -25,8 +25,8 @@ return [
"D3_MAILCHECKER_ASSERTIONS_NOTSET" => "is not (correctly) set",
"D3_MAILCHECKER_ASSERTIONS_NOPORT" => "missing or incorrect port information (587 or 2525)",
"D3_MAILCHECKER_CFGCHECK_SHOPSEND" => "The shop sends emails via",
"D3_MAILCHECKER_CFGCHECK_SHOPSEND_PHPMAILER" => "PhpMailer",
"D3_MAILCHECKER_CFGCHECK_SHOPSEND_PHPMAILER_DESC" => "Sending via PhpMailer should be avoided as such emails are usually classified as spam. Once you have entered all SMTP data, check possible login problems in the SMTP check.",
"D3_MAILCHECKER_CFGCHECK_SHOPSEND_PHPMAILER" => "PHP mail function",
"D3_MAILCHECKER_CFGCHECK_SHOPSEND_PHPMAILER_DESC" => "Sending via PHP's integrated mail function should be avoided as such emails are usually classified as spam. Once you have entered all SMTP data, check possible login problems in the SMTP check.",
"D3_MAILCHECKER_CFGCHECK_SHOPSEND_SMTP" => "SMTP",
"D3_MAILCHECKER_CFGCHECK_SHOPSEND_SMTP_DESC" => "Everything is fine. Please check the necessary settings for your domain(s) in the \"Authentication Check\" tab .",
"D3_MAILCHECKER_CFGCHECK_STARTCHECK" => "Test configuration",
@ -62,8 +62,8 @@ return [
'D3_MAILCHECKER_DMARCRESULT_HL' => 'DMARC (Reject policy and reporting)',
'D3_MAILCHECKER_DMARCRESULT_DESC' => 'The DMARC entry defines how to deal with mails for which the authentication checks have failed. Mail addresses for reports can also be specified there.',
'D3_MAILCHECKER_DMARCRESULT_SET' => 'A DMARC entry is set, the behaviour is not set to ignore.',
'D3_MAILCHECKER_DMARCRESULT_MISSING' => 'No DMARC entry is set or configured with ignore. This should be changed urgently.',
'D3_MAILCHECKER_DMARCRESULT_SET' => 'A DMARC entry is set, the behaviour is not set to "ignore".',
'D3_MAILCHECKER_DMARCRESULT_MISSING' => 'No DMARC entry is set or configured with "ignore". This should be changed urgently.',
'D3_MAILCHECKER_DMARCRESULT_ERROR' => 'The DMARC record cannot be checked',
'D3_MAILCHECKER_DMARCRESULT_LINKS' => 'Related Links',
'D3_MAILCHECKER_DMARCRESULT_LINK_ANALYSIS' => 'DMARC analysis',

View File

@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased](https://git.d3data.de/D3Public/MyModule/compare/3.0.1.0...rel_3.x)
### Added
- improve extendability for OAuth support
### Changed
- use SMTP debug instead of iDebug = 6
- use a non RFC 2606 blocked test mail address
### Fixed
- clean output buffer in case of thrown exception
## [3.0.1.0](https://git.d3data.de/D3Public/MailConfigChecker/compare/3.0.0.0...3.0.1.0) - 2024-07-10
### Added

View File

@ -39,7 +39,6 @@
"beberlei/assert": "^3.3"
},
"require-dev": {
"php": "^8",
"friendsofphp/php-cs-fixer": "^3.9",
"phpstan/phpstan": "^1.8",
"boxblinkracer/phpunuhi": "^1.12"
@ -50,6 +49,7 @@
}
},
"scripts": {
"php-cs-fixer": "./vendor/bin/php-cs-fixer fix --config=vendor/d3/mailconfigchecker/.php-cs-fixer.php",
"phpstan": "./vendor/bin/phpstan --configuration=./vendor/d3/mailconfigchecker/phpstan.neon",
"phpunuhi": "./vendor/bin/phpunuhi --configuration=vendor/d3/mailconfigchecker/phpunuhi.xml validate"
}

View File

@ -28,12 +28,14 @@
<div class="col-12 col-md-6 col-lg-4 mb-4">
<div>
<label class="col-4 form-label" for="oxshops__oxsmtp">[{oxmultilang ident="SHOP_MAIN_SMTPSERVER"}]</label>
<input type="text" class="col-7 editinput" size="35" maxlength="[{$shop->oxshops__oxsmtp->fldmax_length}]" id="oxshops__oxsmtp" value="[{$shop->getFieldData('oxsmtp')}]" [{$readonly}]>
<input type="text" class="col-7 editinput" size="35" maxlength="[{$shop->oxshops__oxsmtp->fldmax_length}]" id="oxshops__oxsmtp" value="[{$smtpHost}]" [{$readonly}]>
</div>
[{block name="smtp_credentials"}]
<div>
<label class="col-4 form-label" for="oxshops__oxsmtpuser">[{oxmultilang ident="SHOP_MAIN_SMTPUSER"}]</label>
<input type="text" class="col-7 editinput" size="35" maxlength="[{$shop->oxshops__oxsmtpuser->fldmax_length}]" id="oxshops__oxsmtpuser" value="[{$shop->getFieldData('oxsmtpuser')}]" [{$readonly}]>
<input type="text" class="col-7 editinput" size="35" maxlength="[{$shop->oxshops__oxsmtpuser->fldmax_length}]" id="oxshops__oxsmtpuser" value="[{$smtpUser}]" [{$readonly}]>
</div>
[{/block}]
<div>
<label class="col-4 form-label" for="oxshops__oxinfoemail">[{oxmultilang ident="SHOP_MAIN_INFOEMAIL"}]</label>
<input type="text" class="col-7 editinput" size="35" maxlength="[{$shop->oxshops__oxinfoemail->fldmax_length}]" id="oxshops__oxinfoemail" value="[{$shop->getFieldData('oxinfoemail')}]" [{$readonly}]>

View File

@ -43,6 +43,7 @@
<label class="col-4 form-label" for="oxshops__oxsmtp">[{oxmultilang ident="SHOP_MAIN_SMTPSERVER"}]</label>
<input type="text" class="col-7 editinput" size="35" maxlength="[{$shop->oxshops__oxsmtp->fldmax_length}]" id="oxshops__oxsmtp" name="smtpHost" value="[{if $smtpHost}][{$smtpHost}][{else}][{$shop->getFieldData('oxsmtp')}][{/if}]">
</div>
[{block name="smtp_credentials"}]
<div>
<label class="col-4 form-label" for="oxshops__oxsmtpuser">[{oxmultilang ident="SHOP_MAIN_SMTPUSER"}]</label>
<input type="text" class="col-7 editinput" size="35" maxlength="[{$shop->oxshops__oxsmtpuser->fldmax_length}]" id="oxshops__oxsmtpuser" name="smtpUser" value="[{if $smtpUser}][{$smtpUser}][{else}][{$shop->getFieldData('oxsmtpuser')}][{/if}]">
@ -51,6 +52,7 @@
<label class="col-4 form-label" for="oxshops__oxsmtppwd">[{oxmultilang ident="SHOP_MAIN_SMTPPASSWORD"}]</label>
<input type="password" class="col-7 editinput" size="35" maxlength="[{$shop->oxshops__oxsmtppwd->fldmax_length}]" id="oxshops__oxsmtppwd" name="smtpPwd" value="[{if $smtpPwd}][{$smtpPwd}][{else}][{$shop->getFieldData('oxsmtppwd')}][{/if}]">
</div>
[{/block}]
<div>
<label class="col-4 form-label" for="sender">[{oxmultilang ident="D3_MAILCHECKER_SMTPCHECK_SENDER"}]</label>
<select name="from" class="col-7 editinput" id="sender">

View File

@ -28,12 +28,14 @@
<div class="col-12 col-md-6 col-lg-4 mb-4">
<div>
<label class="col-4 form-label" for="oxshops__oxsmtp">{{ translate({ ident: "SHOP_MAIN_SMTPSERVER" }) }}</label>
<input type="text" class="col-7 editinput" size="35" maxlength="{{ shop.oxshops__oxsmtp.fldmax_length }}" id="oxshops__oxsmtp" value="{{ shop.getFieldData('oxsmtp') }}" {{ readonly }}>
<input type="text" class="col-7 editinput" size="35" maxlength="{{ shop.oxshops__oxsmtp.fldmax_length }}" id="oxshops__oxsmtp" value="{{ smtpHost }}" {{ readonly }}>
</div>
{% block smtp_credentials %}
<div>
<label class="col-4 form-label" for="oxshops__oxsmtpuser">{{ translate({ ident: "SHOP_MAIN_SMTPUSER" }) }}</label>
<input type="text" class="col-7 editinput" size="35" maxlength="{{ shop.oxshops__oxsmtpuser.fldmax_length }}" id="oxshops__oxsmtpuser" value="{{ shop.getFieldData('oxsmtpuser') }}" {{ readonly }}>
<input type="text" class="col-7 editinput" size="35" maxlength="{{ shop.oxshops__oxsmtpuser.fldmax_length }}" id="oxshops__oxsmtpuser" value="{{ smtpUser }}" {{ readonly }}>
</div>
{% endblock %}
<div>
<label class="col-4 form-label" for="oxshops__oxinfoemail">{{ translate({ ident: "SHOP_MAIN_INFOEMAIL" }) }}</label>
<input type="text" class="col-7 editinput" size="35" maxlength="{{ shop.oxshops__oxinfoemail.fldmax_length }}" id="oxshops__oxinfoemail" value="{{ shop.getFieldData('oxinfoemail') }}" {{ readonly }}>

View File

@ -43,6 +43,7 @@
<label class="col-4 form-label" for="oxshops__oxsmtp">{{ translate({ ident: "SHOP_MAIN_SMTPSERVER" }) }}</label>
<input type="text" class="col-7 editinput" size="35" maxlength="{{ shop.oxshops__oxsmtp.fldmax_length }}" id="oxshops__oxsmtp" name="smtpHost" value="{% if smtpHost %}{{ smtpHost }}{% else %}{{ shop.getFieldData('oxsmtp') }}{% endif %}">
</div>
{% block smtp_credentials %}
<div>
<label class="col-4 form-label" for="oxshops__oxsmtpuser">{{ translate({ ident: "SHOP_MAIN_SMTPUSER" }) }}</label>
<input type="text" class="col-7 editinput" size="35" maxlength="{{ shop.oxshops__oxsmtpuser.fldmax_length }}" id="oxshops__oxsmtpuser" name="smtpUser" value="{% if smtpUser %}{{ smtpUser }}{% else %}{{ shop.getFieldData('oxsmtpuser') }}{% endif %}">
@ -51,6 +52,7 @@
<label class="col-4 form-label" for="oxshops__oxsmtppwd">{{ translate({ ident: "SHOP_MAIN_SMTPPASSWORD" }) }}</label>
<input type="password" class="col-7 editinput" size="35" maxlength="{{ shop.oxshops__oxsmtppwd.fldmax_length }}" id="oxshops__oxsmtppwd" name="smtpPwd" value="{% if smtpPwd %}{{ smtpPwd }}{% else %}{{ shop.getFieldData('oxsmtppwd') }}{% endif %}">
</div>
{% endblock %}
<div>
<label class="col-4 form-label" for="sender">{{ translate({ ident: "D3_MAILCHECKER_SMTPCHECK_SENDER" }) }}</label>
<select name="from" class="col-7 editinput" id="sender">