get($installToolPassword, 'BE'); // @todo: This code should check required hash updates and update the hash if needed $validPassword = $hashInstance->checkPassword($password, $installToolPassword); } catch (InvalidPasswordHashException $e) { $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); $logger->error( 'Invalid install tool password hash specified in "BE/installToolPassword" configuration.', ['exceptionMessage' => $e->getMessage()] ); } } if ($validPassword) { $session->setAuthorized(); $this->sendLoginSuccessfulMail($request); return true; } $this->sendLoginFailedMail($request); return false; } /** * If install tool login mail is set, send a mail for a successful login. */ protected function sendLoginSuccessfulMail(ServerRequestInterface $request): void { $warningEmailAddress = $GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr']; if (!$warningEmailAddress) { return; } $email = $this->emailFactory->createWithOverrides( [20 => 'EXT:install/Resources/Private/Templates/Email/'], [], [], $request, ); $email ->to($warningEmailAddress) ->subject('Install Tool Login at \'' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . '\'') ->from(new Address($this->getSenderEmailAddress(), $this->getSenderEmailName())) ->setTemplate('Security/InstallToolLogin'); $this->sendEmail($email); } /** * If install tool login mail is set, send a mail for a failed login. */ protected function sendLoginFailedMail(ServerRequestInterface $request): void { $warningEmailAddress = $GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr']; if (!$warningEmailAddress) { return; } $formValues = $request->getParsedBody()['install'] ?? $request->getQueryParams()['install'] ?? null; $email = $this->emailFactory->createWithOverrides( [20 => 'EXT:install/Resources/Private/Templates/Email/'], [], [], $request, ); $email ->to($warningEmailAddress) ->subject('Install Tool Login ATTEMPT at \'' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . '\'') ->from(new Address($this->getSenderEmailAddress(), $this->getSenderEmailName())) ->setTemplate('Security/InstallToolLoginAttempt'); $this->sendEmail($email); } /** * Sends an email and gracefully logs if the mail could not be sent due to configuration errors. * * @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface */ protected function sendEmail(RawMessage $email): void { try { $this->mailer->send($email); } catch (TransportException $e) { $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); $logger->warning('Could not send notification email to ' . $this->getSenderEmailAddress() . ' due to mailer settings error', [ 'recipientList' => $this->getSenderEmailAddress(), 'exception' => $e, ]); } catch (RfcComplianceException $e) { $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); $logger->warning('Could not send notification email to ' . $this->getSenderEmailAddress() . ' due to invalid email address', [ 'recipientList' => $this->getSenderEmailAddress(), 'exception' => $e, ]); } } /** * Get sender address from configuration * ['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'] * If this setting is empty fall back to 'no-reply@example.com' * * @return string Returns an email address */ protected function getSenderEmailAddress() { return MailUtility::getSystemFromAddress(); } /** * Gets sender name from configuration * ['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'] * If this setting is empty, it falls back to a default string. * * @return string */ protected function getSenderEmailName() { return MailUtility::getSystemFromName() ?: 'TYPO3 CMS install tool'; } }