This commit is contained in:
Daniel Seifert 2023-12-09 13:32:01 +01:00
parent 7b2d9cf296
commit 2f1d4caba4
Signed by: DanielS
GPG Key ID: 8A7C4C6ED1915C6F
6 changed files with 390 additions and 55 deletions

View File

@ -22,14 +22,20 @@ use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController;
use OxidEsales\Eshop\Application\Model\Shop;
use OxidEsales\Eshop\Core\Registry;
use PEAR;
use PEAR_Error;
class SmtpChecker extends AdminDetailsController
{
protected bool $debug = true;
protected string $host;
protected string $user;
protected string $from;
protected string $to;
protected Net_SMTP $smtp;
protected string $action;
protected array $log = [];
public function __construct()
{
@ -38,47 +44,61 @@ class SmtpChecker extends AdminDetailsController
/** @var Shop $activeShop */
$activeShop = Registry::getConfig()->getActiveShop();
$this->host = Registry::getRequest()->getRequestEscapedParameter('') ?? $activeShop->getFieldData('oxsmtp');
list('host' => $shopHost, 'port' => $shopPort) = parse_url($activeShop->getFieldData('oxsmtp'));
$this->host = Registry::getRequest()->getRequestEscapedParameter('smtpHost') ?: $shopHost;
$this->addTplParam('smtpHost', Registry::getRequest()->getRequestEscapedParameter('smtpHost'));
$this->port = Registry::getRequest()->getRequestEscapedParameter('smtpHost') ? (Registry::getRequest()->getRequestEscapedParameter('smtpPort') ?: null) : $shopPort;
$this->addTplParam('smtpPort', Registry::getRequest()->getRequestEscapedParameter('smtpPort'));
$this->user = Registry::getRequest()->getRequestEscapedParameter('smtpUser') ?: $activeShop->getFieldData('oxsmtpuser');
$this->addTplParam('smtpUser', Registry::getRequest()->getRequestEscapedParameter('smtpUser'));
$this->pwd = Registry::getRequest()->getRequestEscapedParameter('smtpPwd') ?: $activeShop->getFieldData('oxsmtppwd');
$this->addTplParam('smtpPwd', Registry::getRequest()->getRequestEscapedParameter('smtpPwd'));
$this->from = Registry::getRequest()->getRequestEscapedParameter('from') ?: Registry::getRequest()->getRequestEscapedParameter('fromCust') ?: '';
$this->addTplParam('from', Registry::getRequest()->getRequestEscapedParameter('from'));
$this->addTplParam('fromCust', Registry::getRequest()->getRequestEscapedParameter('fromCust'));
$this->to = Registry::getRequest()->getRequestEscapedParameter('to') ?: '';
$this->addTplParam('smtpLog', $this->log);
}
public function getTemplateName()
{
return 'smtpCheck.tpl';
}
public function getMailAddressList()
{
$shop = Registry::getConfig()->getActiveShop();
return array_filter(
array_unique(
[
$shop->getFieldData('oxinfoemail'),
$shop->getFieldData('oxorderemail'),
$shop->getFieldData('oxowneremail'),
]
)
);
}
public function sendMail()
{
try {
$this->checkDataAreSet();
$this->hostIsAvailable();
/*
//$host = 'cloud1-vm279.de-nserver.de:587';
$from = 'mail@ds.data-develop.de';
$rcpt = array('test@ds.data-develop.de', 'test@daniel-seifert.com', 'recipient2@example.com');
//$rcpt = array('test@ds.data-develop.de');
$rcpt = array('test@daniel-seifert.com');
$subj = "Subject: Test Message\n";
$body = "Body Line 1\nBody Line 2";
if ( PEAR::isError( $e = $smtp->connect())) {
dumpvar(__METHOD__.__LINE__.PHP_EOL);
die($e->getMessage() . "\n");
$this->connect();
$this->auth();
$this->setFrom();
$this->setRecipient();
$this->sendContent();
} catch (InvalidArgumentException $e) {
Registry::getUtilsView()->addErrorToDisplay($e);
} finally {
$this->disconnect();
}
if ( PEAR::isError( $smtp->mailFrom( $from))) {
die("Unable to set sender to $from\n");
}
foreach ($rcpt as $to) {
dumpvar($to.PHP_EOL);
if ( PEAR::isError( $res = $smtp->rcptTo( $to))) {
die("Unable to add recipient $to: " . $res->getMessage() . "\n");
}
}
/* Set the body of the message. */
/*
if ( PEAR::isError( $res = $smtp->data( $subj . "\r\n" . $body))) {
dumpvar($res->getMessage());
die("Unable to send data\n");
}
/* Disconnect from the SMTP server. */
/*
$smtp->disconnect();
*/
$this->addTplParam('smtpLog', $this->log);
}
protected function checkDataAreSet()
@ -91,20 +111,85 @@ class SmtpChecker extends AdminDetailsController
*/
protected function hostIsAvailable()
{
$this->host = 'test.example.dev';
Assert::that(( $this->smtp = new Net_SMTP( $this->host ) ))->true('Unable to instantiate SMTP object');
$this->smtp->setDebug($this->debug);
$this->action = __FUNCTION__;
Assert::that(( $this->smtp = new Net_SMTP( $this->host, $this->port ) ))
->isInstanceOf(Net_SMTP::class, 'Unable to instantiate SMTP object');
$this->smtp->setDebug($this->debug, [$this, 'dumpDebug']);
}
protected function foo()
protected function connect()
{
PEAR::isError( $e = $this->smtp->connect());
dumpvar(get_class($e));
die();
Assert::that(PEAR::isError( $e = $this->smtp->connect()))->false($e->getMessage());
{
dumpvar(__METHOD__.__LINE__.PHP_EOL);
die($e->getMessage() . "\n");
$this->action = __FUNCTION__;
Assert::that($this->smtp->connect())
->notIsInstanceOf(PEAR_Error::class, [$this, 'formatMessage'], 'can not connect');
}
/**
* @throws InvalidArgumentException
* @return void
*/
protected function auth()
{
$this->action = __FUNCTION__;
Assert::that($this->smtp->auth($this->user, $this->pwd))
->notIsInstanceOf(PEAR_Error::class, [$this, 'formatMessage'], 'auth failed');
}
protected function setFrom()
{
$this->action = __FUNCTION__;
Assert::that($this->smtp->mailFrom($this->from))
->notIsInstanceOf(PEAR_Error::class, [$this, 'formatMessage'], 'unable to set sender "'.$this->from.'"');
}
protected function setRecipient()
{
$this->action = __FUNCTION__;
Assert::that(( $this->smtp->rcptTo( $this->to)))
->notIsInstanceOf(PEAR_Error::class, [$this, 'formatMessage'], 'unable to set recipient "'.$this->to.'"');
}
protected function sendContent()
{
if (!Registry::getRequest()->getRequestEscapedParameter('sendMail')) {
return;
}
$this->action = __FUNCTION__;
$subj = "Subject: Test Message\n";
$body = "Body Line 1\nBody Line 2";
Assert::that($this->smtp->data( $subj . "\r\n" . $body))
->notIsInstanceOf(PEAR_Error::class, [$this, 'formatMessage'], 'unable to send content');
}
protected function disconnect()
{
$this->action = __FUNCTION__;
Assert::that($this->smtp->disconnect())
->notIsInstanceOf(PEAR_Error::class, [$this, 'formatMessage'], 'unable to disconnect');
}
public function dumpDebug($smtp, $message)
{
unset($smtp);
if (!isset($this->log[$this->action])) {
$this->log[$this->action] = [];
}
$this->log[$this->action][] = trim(htmlentities($message));
}
public function formatMessage(array $arguments)
{
/** @var PEAR_Error|true $response */
$response = $arguments['value'];
$propertyPath = $arguments['propertyPath'];
if (PEAR::isError($response)) {
return ($propertyPath ? $propertyPath .' - ' : '').
$response->getMessage() .
($response->getCode() ? ': '.$response->getCode() : '');
}
return null;
}
}

View File

@ -0,0 +1,228 @@
[{include file="headitem.tpl" title="GENERAL_ADMIN_TITLE"|oxmultilangassign}]
<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>SMTP Test</h3>
<div class="col-6">
<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="sendMail">
<label for="smtpHost">Host</label>
<input id="smtpHost" type="text" name="smtpHost" value="[{$smtpHost}]">
<label for="smtpPort">Port</label>
<input id="smtpPort" type="text" name="smtpPort" value="[{$smtpPort}]">
<br>
<label for="smtpUser">User</label>
<input id="smtpUser" type="text" name="smtpUser" value="[{$smtpUser}]">
<label for="smtpPwd">Passwort</label>
<input id="smtpPwd" type="password" name="smtpPwd" value="[{$smtpPwd}]">
<br>
<label for="from">From</label>
<select name="from" id="from">
[{foreach from=$oView->getMailAddressList() item="address"}]
<option>[{$address}]</option>
[{/foreach}]
</select>
<label for="fromCust">From Cust</label>
<input id="fromCust" type="text" name="fromCust">
<br>
<label for="to">To</label>
<input id="to" type="text" name="to" value="test@daniel-seifert.com">
<br>
<label for="sendMail">send mail</label>
<input id="sendMail" type="checkbox" name="sendMail" value="1">
<br>
<input type="submit">
</form>
</div>
<div class="col-6">
[{foreach from=$smtpLog key="action" item="logItems" name="actionList"}]
<dl>
<dt>[{$smarty.foreach.actionList.iteration}] - [{$action}]</dt>
<dd>
<ul>
[{foreach from=$logItems item="logItem"}]
<li>
[{$logItem}]
</li>
[{/foreach}]
</ul>
</dd>
</dl>
[{/foreach}]
</div>
[{*<form name="myedit" id="myedit" action="[{$oViewConf->getSelfLink()}]" method="post" style="padding: 0;margin: 0;height:0;">*}]
[{* [{$oViewConf->getHiddenSid()}]*}]
[{* <input type="hidden" name="cl" value="[{$oViewConf->getActiveClassName()}]">*}]
[{* <input type="hidden" name="fnc" value="">*}]
[{* <input type="hidden" name="oxid" value="[{$oxid}]">*}]
[{* <input type="hidden" name="voxid" value="[{$oxid}]">*}]
[{* <input type="hidden" name="editval[[{$edit->d3GetFieldLongName('oxid')}]]" value="[{$oxid}]">*}]
[{* <table style="width:98%; padding: 0; border: none">*}]
[{* [{if $edit->getId() && !$edit->getLicenseActive()}]*}]
[{* <tr>*}]
[{* <td style="vertical-align:top;" colspan="2">*}]
[{* <div class="extension_warning">[{oxmultilang ident="D3_ORDERMANAGER_ERROR_IEXECJOBSLIMIT"}]</div>*}]
[{* </td>*}]
[{* </tr>*}]
[{* [{/if}]*}]
[{* <tr>*}]
[{* <td class="edittext" colspan="2">*}]
[{* <details>*}]
[{* <summary>[{oxmultilang ident="D3_GENERAL_ORDERMANAGER_DESCRIPTION"}]</summary>*}]
[{* [{oxmultilang ident="d3tbclordermanager_items_main_desc"}]*}]
[{* </details>*}]
[{* </td>*}]
[{* </tr>*}]
[{* [{if $edit->getBasicRestrictionSettings()}]*}]
[{* <tr>*}]
[{* <td class="restrictioninfo" colspan="2">*}]
[{* [{oxmultilang ident="D3_GENERAL_ORDERMANAGER_BASICRESTRICTIONS"}]*}]
[{* </td>*}]
[{* </tr>*}]
[{* [{/if}]*}]
[{* <tr>*}]
[{* <td class="edittext" style="text-align:left; vertical-align:top; height:99%;padding-left:5px;padding-bottom:30px;padding-top:10px;">*}]
[{* <table style="border: none; padding: 0;">*}]
[{* <tr>*}]
[{* <td class="edittext">*}]
[{* <label for="MainTitle">[{oxmultilang ident="D3_MODPROFILE_MAIN_TITLE"}]</label>&nbsp;*}]
[{* </td>*}]
[{* <td class="edittext">*}]
[{* <input id="MainTitle" type="text" class="editinput" size="50" maxlength="[{$edit->d3getFieldMaxLength('oxtitle')}]" name="editval[[{$edit->d3GetFieldLongName('oxtitle')}]]" value="[{$edit->getFieldData('oxtitle')}]" [{$readonly}]>*}]
[{* </td>*}]
[{* </tr>*}]
[{* <tr>*}]
[{* <td class="edittext">*}]
[{* <label for="MainShortDesc">[{oxmultilang ident="D3_MODPROFILE_MAIN_SHORTDESC"}]</label>&nbsp;*}]
[{* </td>*}]
[{* <td class="edittext">*}]
[{* <textarea id="MainShortDesc" name="editval[[{$edit->d3GetFieldLongName('oxshortdesc')}]]" class="editinput" maxlength="[{$edit->d3getFieldMaxLength('oxshortdesc')}]" cols="50" rows="5" [{$readonly}]>[{$edit->getFieldData('oxshortdesc')}]</textarea>*}]
[{* </td>*}]
[{* </tr>*}]
[{* <tr>*}]
[{* <td class="edittext">*}]
[{* <label for="MainSort">[{oxmultilang ident="D3_MODPROFILE_MAIN_SORT"}]</label>&nbsp;*}]
[{* </td>*}]
[{* <td class="edittext">*}]
[{* <input id="MainSort" type="text" class="editinput" size="32" maxlength="[{$edit->d3getFieldMaxLength('oxsort')}]" name="editval[[{$edit->d3GetFieldLongName('oxsort')}]]" value="[{$edit->getFieldData('oxsort')}]" [{$readonly}]>*}]
[{* [{oxinputhelp ident="D3_ORDERMANAGER_MAIN_SORT_DESC"}]*}]
[{* </td>*}]
[{* </tr>*}]
[{* <tr>*}]
[{* <td class="edittext">*}]
[{* <label for="MainFolder">[{oxmultilang ident="D3_MODPROFILE_MAIN_FOLDER"}]</label>&nbsp;*}]
[{* </td>*}]
[{* <td class="edittext">*}]
[{* <select id="MainFolder" class="editinput" size="1" name="editval[[{$edit->d3GetFieldLongName('oxfolder')}]]" [{$readonly}]>*}]
[{* <option value="" [{if '' == $edit->getFieldData('oxfolder')}] selected[{/if}]>[{oxmultilang ident="D3_MODPROFILE_MAIN_NOFOLDER"}]</option>*}]
[{* [{foreach from=$oView->getFolderList() key="sMLItem" item="sTranslation"}]*}]
[{* <option value="[{$sMLItem}]" [{if $sMLItem == $edit->getFieldData('oxfolder')}] selected[{/if}]>[{$sTranslation}]</option>*}]
[{* [{/foreach}]*}]
[{* </select>*}]
[{* [{oxinputhelp ident="D3_ORDERMANAGER_MAIN_FOLDER_DESC"}]*}]
[{* </td>*}]
[{* </tr>*}]
[{* <tr>*}]
[{* <td class="edittext">*}]
[{* [{oxmultilang ident="D3_ORDERMANAGER_MAIN_LASTEXEC"}]&nbsp;*}]
[{* </td>*}]
[{* <td class="edittext">*}]
[{* [{$edit->getValue('iLastExecDate')|date_format:"%Y-%m-%d %H:%M:%S"}]*}]
[{* </td>*}]
[{* </tr>*}]
[{* [{if $blShowLangSwitch}]*}]
[{* <tr>*}]
[{* <td class="edittext" colspan="2"><br>*}]
[{* [{include file="language_edit.tpl"}]<br>*}]
[{* </td>*}]
[{* </tr>*}]
[{* [{/if}]*}]
[{* </table>*}]
[{* <table style="border: none; padding: 0;">*}]
[{* [{include file="d3_modprofile_actionbuttons.tpl"}]*}]
[{* </table>*}]
[{* </td>*}]
[{* <!-- Anfang rechte Seite -->*}]
[{* <td style="vertical-align: top; padding-top:10px;padding-left:10px;">*}]
[{* <fieldset>*}]
[{* <legend>[{oxmultilang ident="D3_ORDERMANAGER_MAIN_FIELDSET_EXECUTION"}]</legend>*}]
[{* <table style="border: none; padding: 0;">*}]
[{* <tr>*}]
[{* <td class="edittext" style="*}]
[{* [{if ($edit->getFieldData('oxactive') == 1 OR*}]
[{* ($blUseTimeCheck && ($edit->getFieldData('oxactivefrom') != '0000-00-00 00:00:00' AND $edit->getFieldData('oxactiveto') != '0000-00-00 00:00:00')))*}]
[{* AND !$edit->getValue('blItemExecute') AND !$edit->getValue('blItemMailSend')}]*}]
[{* font-weight: bold; background-color: darkred; color: white;*}]
[{* [{/if}]">*}]
[{* <label for="MainExecute">[{oxmultilang ident="D3_ORDERMANAGER_MAIN_EXECUTE2"}][{if $oSet->hasDebugMode()}]<br><span id="debugnote">[{oxmultilang ident="D3_ORDERMANAGER_MAIN_EXECUTE_DEBUG"}]</span>[{/if}]</label>*}]
[{* </td>*}]
[{* <td class="edittext">*}]
[{* <input type="hidden" name="value[blItemExecute]" value="1">*}]
[{* <input id="MainExecute" type="checkbox" [{if $oSet->hasDebugMode()}]disabled[{/if}] class="edittext ext_edittext" name="value[blItemExecute]" value="0" [{if false == $edit->getValue('blItemExecute')}]checked[{/if}] [{$readonly}]>*}]
[{* [{oxinputhelp ident="D3_ORDERMANAGER_MAIN_EXECUTE_DESC"}]*}]
[{* </td>*}]
[{* </tr>*}]
[{* <tr>*}]
[{* <td class="edittext" style="*}]
[{* [{if ($edit->getFieldData('oxactive') == 1 OR*}]
[{* ($blUseTimeCheck && ($edit->getFieldData('oxactivefrom') != '0000-00-00 00:00:00' AND $edit->getFieldData('oxactiveto') != '0000-00-00 00:00:00')))*}]
[{* AND !$edit->getValue('blItemExecute') AND !$edit->getValue('blItemMailSend')}]*}]
[{* font-weight: bold; background-color: darkred; color: white;*}]
[{* [{/if}]">*}]
[{* <label for="MainMailsend">[{oxmultilang ident="D3_ORDERMANAGER_MAIN_MAILSEND"}]</label>&nbsp;*}]
[{* </td>*}]
[{* <td class="edittext">*}]
[{* <input type="hidden" name="value[blItemMailSend]" value="0">*}]
[{* <input id="MainMailsend" type="checkbox" class="edittext ext_edittext" name="value[blItemMailSend]" value="1" [{if $edit->getValue('blItemMailSend')}]checked[{/if}] [{$readonly}]>*}]
[{* [{oxinputhelp ident="D3_ORDERMANAGER_MAIN_MAILSEND_DESC"}]*}]
[{* </td>*}]
[{* </tr>*}]
[{* <tr>*}]
[{* <td class="edittext">*}]
[{* <label for="AddHistory">[{oxmultilang ident="D3_ORDERMANAGER_MAIN_ADDHISTORYITEM"}]</label>*}]
[{* </td>*}]
[{* <td class="edittext">*}]
[{* <input type="hidden" name="value[blAddHistory]" value="0">*}]
[{* <input id="AddHistory" type="checkbox" class="edittext ext_edittext" name="value[blAddHistory]" value="1" [{if $edit->getValue('blAddHistory')}]checked[{/if}] [{$readonly}]>*}]
[{* [{oxinputhelp ident="D3_ORDERMANAGER_MAIN_ADDHISTORYITEM_DESC"}]*}]
[{* </td>*}]
[{* </tr>*}]
[{* </table>*}]
[{* </fieldset>*}]
[{* </td>*}]
[{* <!-- Ende rechte Seite -->*}]
[{* </tr>*}]
[{* </table>*}]
[{*</form>*}]
[{include file="bottomnaviitem.tpl"}]
[{include file="bottomitem.tpl"}]

View File

@ -1,6 +1,6 @@
{
"name": "d3/smtpchecker",
"description": "SMTP checker",
"name": "d3/mailconfigchecker",
"description": "Mail configuration check tool",
"type": "oxideshop-module",
"keywords": [
"oxid",
@ -46,12 +46,12 @@
"*.xml",
"*.neon"
],
"target-directory": "d3/smtpchecker"
"target-directory": "d3/mailconfigchecker"
}
},
"autoload": {
"psr-4": {
"D3\\SmtpChecker\\": "../../../source/modules/d3/smtpchecker"
"D3\\MailConfigChecker\\": "../../../source/modules/d3/mailconfigchecker"
}
},
"scripts": {

18
de/translations.php Normal file
View File

@ -0,0 +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
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com
*/
return [
'MXMAILCHECK' => "Mail Check"
];

View File

@ -2,7 +2,11 @@
<OX>
<OXMENU id="NAVIGATION_ESHOPADMIN">
<MAINMENU id="mxservice">
<SUBMENU id="MXSMTPCHECKER" cl="d3smtpchecker" />
<SUBMENU id="D3_MENU_MAILCHECKER" cl="d3mailchecker" list="d3mailchecker_menu">
<TAB id="D3_TAB_CONFIGCHECK" cl="d3mailconfigcheck" />
<TAB id="D3_TAB_SMTPCHECK" cl="d3smtpcheck" />
<TAB id="D3_TAB_TESTMAIL" cl="d3testmail" />
</SUBMENU>
</MAINMENU>
</OXMENU>
</OX>

View File

@ -17,7 +17,7 @@ use D3\SmtpChecker\Application\Controller\Admin\SmtpChecker;
$sMetadataVersion = '2.1';
$sModuleId = 'd3smtpchecker';
$sModuleId = 'd3mailconfigchecker';
$logo = '<img src="https://logos.oxidmodule.com/d3logo.svg" alt="(D3)" style="height:1em;width:1em">';
/**
@ -25,7 +25,7 @@ $logo = '<img src="https://logos.oxidmodule.com/d3logo.svg" alt="(D3)" style="he
*/
$aModule = [
'id' => $sModuleId,
'title' => $logo.' SMTP Checker',
'title' => $logo.' Mail Configuration Checker',
'description' => [
'de' => '',
'en' => '',
@ -46,7 +46,7 @@ $aModule = [
// 'onDeactivate' => '\D3\ThisModule\Setup\Events::onDeactivate',
],
'templates' => [
// 'd3TemplateAlias.tpl' => 'd3/thismodule/Application/views/admin/tpl/d3Template.tpl',
'smtpCheck.tpl' => 'd3/smtpchecker/Application/views/admin/tpl/smtpCheck.tpl',
// 'flow_theme' => [
// 'd3FlowTemplateAlias.tpl' => 'd3/thismodule/Application/views/tpl/d3FlowTheme.tpl',
// ],