initial
This commit is contained in:
40
Application/Controller/Admin/MailCheckBase.php
Normal file
40
Application/Controller/Admin/MailCheckBase.php
Normal 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();
|
||||
}
|
||||
}
|
33
Application/Controller/Admin/MailCheckMenu.php
Normal file
33
Application/Controller/Admin/MailCheckMenu.php
Normal 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();
|
||||
}
|
||||
}
|
154
Application/Controller/Admin/MailConfigCheck.php
Normal file
154
Application/Controller/Admin/MailConfigCheck.php
Normal 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'),
|
||||
]
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
23
Application/Controller/Admin/MailTester.php
Normal file
23
Application/Controller/Admin/MailTester.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?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 OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController;
|
||||
|
||||
class MailTester extends AdminDetailsController
|
||||
{
|
||||
protected $_sThisTemplate = 'mailTester.tpl';
|
||||
}
|
@ -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();
|
||||
|
Reference in New Issue
Block a user