8
0
Dieser Commit ist enthalten in:
Daniel Seifert 2023-12-11 15:48:31 +01:00
Ursprung 3cf5ca84f5
Commit e40614aa0e
Signiert von: DanielS
GPG-Schlüssel-ID: 8A7C4C6ED1915C6F
9 geänderte Dateien mit 299 neuen und 153 gelöschten Zeilen

Datei anzeigen

@ -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 "<h3>Mailer Check</h3>";
$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 "<h3>SPF Check</h3>";
$mailDomains = $this->getMailDomains();
array_walk(
$mailDomains,
function($domain) {
dumpvar('<b>'.$domain.'</b>');
$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'),
]
)
)
);
}
}

Datei anzeigen

@ -0,0 +1,117 @@
<?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\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';
}
}
}

Datei anzeigen

@ -1,18 +1,18 @@
<?php
/**
* This Software is the property of Data Development and is protected
* by copyright law - it is NOT Freeware.
* Any unauthorized use of this software without a valid license
* is a violation of the license agreement and will be prosecuted by
* civil and criminal law.
* http://www.shopmodule.com
* 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 <support@shopmodule.com>
* @link http://www.oxidmodule.com
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\MailConfigChecker\Application\Model\Exception;
use Assert\LazyAssertionException;

Datei anzeigen

@ -0,0 +1,41 @@
<?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\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;
}
}

Datei anzeigen

@ -0,0 +1,10 @@
<link rel="stylesheet" href="[{$oViewConf->getModuleUrl('d3mailconfigchecker', 'out/src/css/bootstrap.min.css')}]">
<style>
* {
font-size: 12px;
}
a {
color: inherit;
text-decoration: inherit;
}
</style>

Datei anzeigen

@ -1,21 +1,14 @@
[{include file="headitem.tpl" title="d3mxd3cleartmp"|oxmultilangassign}]
[{include file="inc_bootstrap.tpl"}]
<link rel="stylesheet" href="[{$oViewConf->getModuleUrl('d3mailconfigchecker', 'out/src/css/bootstrap.min.css')}]">
<style>
* {
font-size: 12px;
}
a {
color: inherit;
text-decoration: inherit;
span.btn {
cursor: default;
}
</style>
[{*[{if $readonly}]*}]
[{assign var="readonly" value="readonly disabled"}]
[{*[{else}]*}]
[{* [{assign var="readonly" value=""}]*}]
[{*[{/if}]*}]
[{assign var="readonly" value="readonly disabled"}]
<form name="transfer" id="transfer" action="[{$oViewConf->getSelfLink()}]" method="post">
[{$oViewConf->getHiddenSid()}]
<input type="hidden" name="oxid" value="[{$oxid}]">
@ -23,56 +16,52 @@
<input type="hidden" name="cl" value="[{$oViewConf->getActiveClassName()}]">
</form>
<table style="margin-left: 300px;">
<tr>
<td class="edittext" >
<label for="oxshops__oxsmtp">[{oxmultilang ident="SHOP_MAIN_SMTPSERVER"}]</label>
</td>
<td class="edittext">
<input type="text" class="editinput" size="35" maxlength="[{$shop->oxshops__oxsmtp->fldmax_length}]" id="oxshops__oxsmtp" value="[{$shop->getFieldData('oxsmtp')}]" [{$readonly}]>
</td>
</tr>
<tr>
<td class="edittext" >
<label for="oxshops__oxsmtpuser">[{oxmultilang ident="SHOP_MAIN_SMTPUSER"}]</label>
</td>
<td class="edittext">
<input type="text" class="editinput" size="35" maxlength="[{$shop->oxshops__oxsmtpuser->fldmax_length}]" id="oxshops__oxsmtpuser" value="[{$shop->getFieldData('oxsmtpuser')}]" [{$readonly}]>
</td>
</tr>
<tr>
<td class="edittext" >
<label for="oxshops__oxinfoemail">[{oxmultilang ident="SHOP_MAIN_INFOEMAIL"}]</label>
</td>
<td class="edittext">
<input type="text" class="editinput" size="35" maxlength="[{$shop->oxshops__oxinfoemail->fldmax_length}]" id="oxshops__oxinfoemail" value="[{$shop->getFieldData('oxinfoemail')}]" [{$readonly}]>
</td>
</tr>
<tr>
<td class="edittext" >
<label for="oxshops__oxorderemail">[{oxmultilang ident="SHOP_MAIN_ORDEREMAIL"}]</label>
</td>
<td class="edittext">
<input type="text" class="editinput" size="35" maxlength="[{$shop->oxshops__oxorderemail->fldmax_length}]" id="oxshops__oxorderemail" value="[{$shop->getFieldData('oxorderemail')}]" [{$readonly}]>
</td>
</tr>
<tr>
<td class="edittext" >
<label for="oxshops__oxowneremail">[{oxmultilang ident="SHOP_MAIN_OWNEREMAIL"}]</label>
</td>
<td class="edittext">
<input type="text" class="editinput" size="35" maxlength="[{$shop->oxshops__oxowneremail->fldmax_length}]" id="oxshops__oxowneremail" value="[{$shop->getFieldData('oxowneremail')}]" [{$readonly}]>
</td>
</tr>
</table>
<hr>
<form style="margin-left: 300px;" name="myedit" id="myedit" action="[{$oViewConf->getSelfLink()}]" method="post">
[{$oViewConf->getHiddenSid()}]
<input type="hidden" name="cl" value="[{$oViewConf->getActiveClassName()}]">
<input type="hidden" name="fnc" value="checkConfiguration">
<button type="submit" class="btn btn-primary">Konfiguration testen</button>
</form>
<div class="row">
<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}]>
</div>
<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}]>
</div>
<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}]>
</div>
<div>
<label class="col-4 form-label" for="oxshops__oxorderemail">[{oxmultilang ident="SHOP_MAIN_ORDEREMAIL"}]</label>
<input type="text" class="col-7 editinput" size="35" maxlength="[{$shop->oxshops__oxorderemail->fldmax_length}]" id="oxshops__oxorderemail" value="[{$shop->getFieldData('oxorderemail')}]" [{$readonly}]>
</div>
<div>
<label class="col-4 form-label" for="oxshops__oxowneremail">[{oxmultilang ident="SHOP_MAIN_OWNEREMAIL"}]</label>
<input type="text" class="col-7 editinput" size="35" maxlength="[{$shop->oxshops__oxowneremail->fldmax_length}]" id="oxshops__oxowneremail" value="[{$shop->getFieldData('oxowneremail')}]" [{$readonly}]>
</div>
</div>
<div class="col-12 col-md-6 col-lg-4">
[{if $mailer}]
<div>
[{oxmultilang ident="D3_CFGCHECK_SHOPSEND" suffix="COLON"}]
[{if $mailer == 'mail'}]
<button type="button" class="btn btn-danger">[{oxmultilang ident="D3_CFGCHECK_SHOPSEND_PHPMAILER"}]</button><br>
[{oxmultilang ident="D3_CFGCHECK_SHOPSEND_PHPMAILER_DESC"}]
[{else}]
<span class="btn btn-success">[{oxmultilang ident="D3_CFGCHECK_SHOPSEND_SMTP"}]</span><br>
[{oxmultilang ident="D3_CFGCHECK_SHOPSEND_SMTP_DESC"}]
[{/if}]
</div>
[{else}]
<form name="myedit" id="myedit" action="[{$oViewConf->getSelfLink()}]" method="post">
[{$oViewConf->getHiddenSid()}]
<input type="hidden" name="cl" value="[{$oViewConf->getActiveClassName()}]">
<input type="hidden" name="fnc" value="checkConfiguration">
<button type="submit" class="btn btn-primary">[{oxmultilang ident="D3_CFGCHECK_STARTCHECK"}]</button>
</form>
[{/if}]
</div>
</div>
[{include file="bottomnaviitem.tpl"}]
[{include file="bottomitem.tpl"}]

Datei anzeigen

@ -0,0 +1,43 @@
[{include file="headitem.tpl" title="GENERAL_ADMIN_TITLE"|oxmultilangassign}]
[{include file="inc_bootstrap.tpl"}]
<style type="text/css">
.col-6 {
float: left;
width: 48%;
padding: 15px;
}
</style>
<form name="transfer" id="transfer" action="[{$oViewConf->getSelfLink()}]" method="post">
[{$oViewConf->getHiddenSid()}]
<input type="hidden" name="oxid" value="[{$oxid}]">
<input type="hidden" name="oxidCopy" value="[{$oxid}]">
<input type="hidden" name="cl" value="[{$oViewConf->getActiveClassName()}]">
<input type="hidden" name="editlanguage" value="[{$editlanguage}]">
</form>
<h3>[{oxmultilang ident="D3_TAB_SPFCHECK"}]</h3>
<div class="row">
[{foreach from=$result key="domain" item="spf"}]
<div class="col-lg-3 col-md-6">
<div class="card mb-3">
<div class="card-header text-white bg-[{$oView->getSpfStatusColor($spf)}]">
[{$domain}]
</div>
<div class="card-body">
[{oxmultilang ident="D3_SPFRESULT_"|cat:$spf->getStatus()|upper}]<br>
[{if $spf->getRecord()}]
<br>
<input type="text" value="[{$spf->getRecord()}]" readonly disabled>
[{/if}]
</div>
</div>
</div>
[{/foreach}]
</div>
[{include file="bottomnaviitem.tpl"}]
[{include file="bottomitem.tpl"}]

Datei anzeigen

@ -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',
];

Datei anzeigen

@ -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',
// ],