From f82309c9e21bfb495d3c516b83d926fc2ddc6394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Sun, 7 Aug 2022 09:55:34 +0200 Subject: [PATCH] Log dropped spam messages --- .../Classes/Controller/AjaxFormController.php | 13 ++++++++++--- .../ext/ep_events/Classes/Domain/Model/Inquiry.php | 9 +++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/public/typo3conf/ext/ep_events/Classes/Controller/AjaxFormController.php b/public/typo3conf/ext/ep_events/Classes/Controller/AjaxFormController.php index 1772838e..cf1b2b74 100644 --- a/public/typo3conf/ext/ep_events/Classes/Controller/AjaxFormController.php +++ b/public/typo3conf/ext/ep_events/Classes/Controller/AjaxFormController.php @@ -31,11 +31,14 @@ use EP\EpEvents\Domain\Model\Inquiry; use EP\EpEvents\Service\ConfigurationService; use EP\EpEvents\Service\EmailService; use EP\EpEvents\Service\SpamProtectService; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerAwareTrait; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; -class AjaxFormController extends ActionController +class AjaxFormController extends ActionController implements LoggerAwareInterface { + use LoggerAwareTrait; /** * @var EmailService @@ -70,7 +73,9 @@ class AjaxFormController extends ActionController */ public function processInquiryFormAction(Inquiry $inquiry) { - if (false === $this->spamProtectService->isSpamEmail($inquiry->getEmail())) { + if (true === $this->spamProtectService->isSpamEmail($inquiry->getEmail())) { + $this->logger->warning('Dropped potential SPAM', $inquiry->toArray()); + } else { $this->emailService->send([ 'toEmail' => $this->settings['inquiryToEmail'], 'toName' => $this->settings['inquiryToName'], @@ -90,7 +95,9 @@ class AjaxFormController extends ActionController */ public function processConfiguratorFormAction(Inquiry $inquiry) { - if (false === $this->spamProtectService->isSpamEmail($inquiry->getEmail())) { + if (true === $this->spamProtectService->isSpamEmail($inquiry->getEmail())) { + $this->logger->warning('Dropped potential SPAM', $inquiry->toArray()); + } else { $this->emailService->send([ 'toEmail' => $this->settings['inquiryToEmail'], 'toName' => $this->settings['inquiryToName'], diff --git a/public/typo3conf/ext/ep_events/Classes/Domain/Model/Inquiry.php b/public/typo3conf/ext/ep_events/Classes/Domain/Model/Inquiry.php index d533d965..51ae432b 100644 --- a/public/typo3conf/ext/ep_events/Classes/Domain/Model/Inquiry.php +++ b/public/typo3conf/ext/ep_events/Classes/Domain/Model/Inquiry.php @@ -459,4 +459,13 @@ class Inquiry extends AbstractValueObject $this->pageUrl = $pageUrl; } + public function toArray() + { + return [ + 'name' => $this->name, + 'email' => $this->email, + 'message' => $this->message, + 'pageUrl' => $this->pageUrl, + ]; + } }