This commit is contained in:
Daniel Seifert 2023-12-11 10:38:59 +01:00
parent 2f1d4caba4
commit 3cf5ca84f5
Signed by: DanielS
GPG Key ID: 8A7C4C6ED1915C6F
18 changed files with 459 additions and 10 deletions

View File

@ -0,0 +1,40 @@
<?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.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\MailConfigChecker\Application\Controller\Admin;
use OxidEsales\Eshop\Application\Controller\Admin\AdminController;
class MailCheckBase extends AdminController
{
protected $_sThisTemplate = 'mailCheckBase.tpl';
/**
* @return string
*/
public function render(): string
{
$this->addTplParam('sListClass', MailCheckMenu::class);
$this->addTplParam('sMainClass', setMainController::class);
$this->_hasListItems = false;
return parent::render();
}
}

View File

@ -0,0 +1,33 @@
<?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.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\MailConfigChecker\Application\Controller\Admin;
use OxidEsales\Eshop\Application\Controller\Admin\AdminListController;
class MailCheckMenu extends AdminListController
{
protected $_sThisTemplate = 'mailCheckMenu.tpl';
public function render()
{
$this->addTplParam('noOXIDCheck', true);
return parent::render();
}
}

View File

@ -0,0 +1,154 @@
<?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
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com
*/
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 OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController;
use OxidEsales\Eshop\Application\Model\Shop;
use OxidEsales\Eshop\Core\Email;
use OxidEsales\Eshop\Core\Registry;
class MailConfigCheck extends AdminDetailsController
{
protected $_sThisTemplate = 'mailConfigCheck.tpl';
public function render()
{
$this->checkDataAreSet();
$this->addTplParam('shop', Registry::getConfig()->getActiveShop());
return parent::render();
}
protected function checkDataAreSet()
{
try {
/** @var Shop $shop */
$shop = Registry::getConfig()->getActiveShop();
$lang = Registry::getLang();
Assert::lazy()
->setExceptionClass(d3TranslatableLazyAssertionException::class)
->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') )
->notBlank( $lang->translateString('D3_ASSERTIONS_NOTSET') )
->that( $shop->getFieldData( 'oxinfoemail' ), $lang->translateString('SHOP_MAIN_INFOEMAIL') )
->email( $lang->translateString('D3_ASSERTIONS_NOTSET') )
->that( $shop->getFieldData( 'oxorderemail' ), $lang->translateString('SHOP_MAIN_ORDEREMAIL') )
->email( $lang->translateString('D3_ASSERTIONS_NOTSET') )
->that( $shop->getFieldData( 'oxowneremail' ), $lang->translateString('SHOP_MAIN_OWNEREMAIL') )
->email( $lang->translateString('D3_ASSERTIONS_NOTSET') )
->verifyNow();
} catch (InvalidArgumentException $e) {
Registry::getUtilsView()->addErrorToDisplay(nl2br($e->getMessage()));
}
}
public function checkConfiguration()
{
dumpvar('');
dumpvar('');
dumpvar('');
dumpVar('');
$this->useSmtp();
$this->checkSpf();
}
protected function useSmtp()
{
try {
echo "<h3>Mailer Check</h3>";
$mail = oxNew( Email::class );
$mail->setRecipient( 'test@example.com' );
$mail->setBody('.');
$mail->send();
dumpvar( 'Shop sendet ueber '.ucfirst($mail->getMailer()) );
} catch (\Exception $e) {
dumpvar($e->getMessage());
}
}
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'),
]
)
)
);
}
}

View File

@ -13,6 +13,11 @@
* @link http://www.oxidmodule.com
*/
return [
'MXMAILCHECK' => "Mail Check"
];
namespace D3\MailConfigChecker\Application\Controller\Admin;
use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController;
class MailTester extends AdminDetailsController
{
protected $_sThisTemplate = 'mailTester.tpl';
}

View File

@ -13,7 +13,7 @@
declare(strict_types=1);
namespace D3\SmtpChecker\Application\Controller\Admin;
namespace D3\MailConfigChecker\Application\Controller\Admin;
use Assert\Assert;
use Assert\InvalidArgumentException;
@ -85,7 +85,6 @@ class SmtpChecker extends AdminDetailsController
public function sendMail()
{
try {
$this->checkDataAreSet();
$this->hostIsAvailable();
$this->connect();
$this->auth();

View File

@ -0,0 +1,35 @@
<?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
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com
*/
namespace D3\MailConfigChecker\Application\Model\Exception;
use Assert\LazyAssertionException;
use OxidEsales\Eshop\Core\Registry;
class d3TranslatableLazyAssertionException extends LazyAssertionException
{
public static function fromErrors(array $errors): self
{
$text = Registry::getLang()->translateString('D3_ASSERTIONS_FAILED');
$message = \sprintf($text, \count($errors))."\n";
$i = 1;
foreach ($errors as $error) {
$message .= \sprintf("%d) %s: %s\n", $i++, $error->getPropertyPath(), $error->getMessage());
}
return new static($message, $errors);
}
}

View File

@ -0,0 +1,5 @@
<?php
return [
'charset' => 'UTF-8',
];

View File

@ -0,0 +1,19 @@
[{include file="headitem.tpl" title="d3mxd3cleartmp"|oxmultilangassign}]
[{if $readonly}]
[{assign var="readonly" value="readonly disabled"}]
[{else}]
[{assign var="readonly" value=""}]
[{/if}]
<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()}]">
</form>
...
[{include file="bottomnaviitem.tpl"}]
[{include file="bottomitem.tpl"}]

View File

@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>[{oxmultilang ident="GENERAL_ADMIN_TITLE"}]</title>
</head>
<!-- frames -->
<frameset rows="10%,*" style="border: none" onload="top.loadEditFrame('[{$oViewConf->getSelfLink()|oxaddparams:$editurl}][{if $oxid}]&oxid=[{$oxid}][{/if}]');">
<frame src="[{$oViewConf->getSelfLink()|oxaddparams:$listurl}][{if $oxid}]&oxid=[{$oxid}][{/if}]" name="list" id="list" style="border: none" frameborder="0" scrolling="Auto" noresize marginwidth="0" marginheight="0">
<frame src="" name="edit" id="edit" style="border: none" frameborder="0" scrolling="Auto" noresize marginwidth="0" marginheight="0">
</frameset>
</html>

View File

@ -0,0 +1,39 @@
[{include file="headitem.tpl" title="GENERAL_ADMIN_TITLE"|oxmultilangassign box="list"}]
[{if $readonly}]
[{assign var="readonly" value="readonly disabled"}]
[{else}]
[{assign var="readonly" value=""}]
[{/if}]
<script type="text/javascript">
<!--
window.onload = function ()
{
[{if $updatenav}]
var oTransfer = top.basefrm.edit.document.getElementById( "transfer" );
oTransfer.updatenav.value = 1;
oTransfer.cl.value = '[{$default_edit}]';
[{/if}]
top.reloadEditFrame();
}
//-->
</script>
<form name="search" id="search" action="[{$oViewConf->getSelfLink()}]" method="post">
[{include file="_formparams.tpl" cl=$oViewConf->getActiveClassName() lstrt=$lstrt actedit=$actedit oxid=$oxid fnc="" language=$actlang editlanguage=$actlang}]
</form>
[{include file="pagetabsnippet.tpl"}]
<script type="text/javascript">
if (parent.parent != null && parent.parent.setTitle )
{ parent.parent.sShopTitle = "[{$actshopobj->oxshops__oxname->getRawValue()|oxaddslashes}]";
parent.parent.sMenuItem = "[{oxmultilang ident="SHOP_LIST_MENUITEM"}]";
parent.parent.sMenuSubItem = "[{oxmultilang ident="SHOP_LIST_MENUSUBITEM"}]";
parent.parent.sWorkArea = "[{$_act}]";
parent.parent.setTitle();
}
</script>
</body>
</html>

View File

@ -0,0 +1,78 @@
[{include file="headitem.tpl" title="d3mxd3cleartmp"|oxmultilangassign}]
<link rel="stylesheet" href="[{$oViewConf->getModuleUrl('d3mailconfigchecker', 'out/src/css/bootstrap.min.css')}]">
<style>
* {
font-size: 12px;
}
a {
color: inherit;
text-decoration: inherit;
}
</style>
[{*[{if $readonly}]*}]
[{assign var="readonly" value="readonly disabled"}]
[{*[{else}]*}]
[{* [{assign var="readonly" value=""}]*}]
[{*[{/if}]*}]
<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()}]">
</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>
[{include file="bottomnaviitem.tpl"}]
[{include file="bottomitem.tpl"}]

View File

@ -2,4 +2,12 @@
return [
'charset' => 'UTF-8',
'D3_MENU_MAILCHECKER' => 'E-Mail Prüfung',
'D3_TAB_CONFIGCHECK' => 'Konfigurationsprüfung',
'D3_TAB_SMTPCHECK' => 'SMTP Check',
'D3_TAB_SPFCHECK' => 'SPF Check',
'D3_TAB_TESTMAIL' => 'Testmail',
'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)',
];

View File

@ -28,6 +28,7 @@
"php": ">=7.3",
"oxid-esales/oxideshop-ce": "6.8 - 6.14",
"pear/net_smtp": "^1.11",
"mika56/spfcheck": "^1.1.7|^2.1.1",
"beberlei/assert": "^3.3"
},
"require-dev": {
@ -43,7 +44,6 @@
"*.md",
"composer.json",
".php-cs-fixer.php",
"*.xml",
"*.neon"
],
"target-directory": "d3/mailconfigchecker"

View File

@ -2,10 +2,11 @@
<OX>
<OXMENU id="NAVIGATION_ESHOPADMIN">
<MAINMENU id="mxservice">
<SUBMENU id="D3_MENU_MAILCHECKER" cl="d3mailchecker" list="d3mailchecker_menu">
<SUBMENU id="D3_MENU_MAILCHECKER" cl="d3mailcheck" list="d3mailcheckmenu">
<TAB id="D3_TAB_CONFIGCHECK" cl="d3mailconfigcheck" />
<TAB id="D3_TAB_SMTPCHECK" cl="d3smtpcheck" />
<TAB id="D3_TAB_TESTMAIL" cl="d3testmail" />
<TAB id="D3_TAB_SMTPCHECK" cl="d3smtpchecker" />
<TAB id="D3_TAB_SPFCHECK" cl="d3spfchecker" />
<TAB id="D3_TAB_TESTMAIL" cl="d3mailtester" />
</SUBMENU>
</MAINMENU>
</OXMENU>

View File

@ -13,6 +13,10 @@
declare(strict_types=1);
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;
$sMetadataVersion = '2.1';
@ -36,7 +40,11 @@ $aModule = [
'email' => 'support@shopmodule.com',
'url' => 'https://www.oxidmodule.com/',
'controllers' => [
'd3mailcheck' => MailCheckBase::class,
'd3mailcheckmenu' => MailCheckMenu::class,
'd3mailconfigcheck' => MailConfigCheck::class,
'd3smtpchecker' => SmtpChecker::class,
'd3mailtester' => MailTester::class,
],
'extend' => [
// \OxidEsales\Eshop\Core\ShopControl::class => \D3\ThisModule\Modules\Core\ShopControl_MyModule::class
@ -46,7 +54,11 @@ $aModule = [
// 'onDeactivate' => '\D3\ThisModule\Setup\Events::onDeactivate',
],
'templates' => [
'smtpCheck.tpl' => 'd3/smtpchecker/Application/views/admin/tpl/smtpCheck.tpl',
'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',
'smtpCheck.tpl' => 'd3/mailconfigchecker/Application/views/admin/tpl/smtpCheck.tpl',
'mailTester.tpl' => 'd3/mailconfigchecker/Application/views/admin/tpl/mailTester.tpl',
// 'flow_theme' => [
// 'd3FlowTemplateAlias.tpl' => 'd3/thismodule/Application/views/tpl/d3FlowTheme.tpl',
// ],

7
out/src/css/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long