Added the proper logging for #1706

This commit is contained in:
the-djmaze 2024-10-08 13:06:43 +02:00
parent ba85eda7f0
commit 28a8e3c157
6 changed files with 21 additions and 24 deletions

View File

@ -12,6 +12,7 @@ class CustomLoginMappingPlugin extends \RainLoop\Plugins\AbstractPlugin
public function Init() : void
{
// Happens only at DoLogin | ServiceSso | DoAccountSetup
$this->addHook('login.credentials', 'FilterLoginCredentials');
}
@ -29,18 +30,14 @@ class CustomLoginMappingPlugin extends \RainLoop\Plugins\AbstractPlugin
if (!empty($sMapping)) {
$aLines = \explode("\n", \preg_replace('/[\r\n\t\s]+/', "\n", $sMapping));
foreach ($aLines as $sLine) {
if (false !== \strpos($sLine, ':')) {
$aData = \explode(':', $sLine, 3);
if (\is_array($aData) && !empty($aData[0]) && isset($aData[1])) {
$aData = \array_map('trim', $aData);
if ($sEmail === $aData[0]) {
if (\strlen($aData[1])) {
$sImapUser = $aData[1];
}
if (isset($aData[2]) && \strlen($aData[2])) {
$sSmtpUser = $aData[2];
}
}
$aData = \explode(':', $sLine, 3);
if (\is_array($aData) && isset($aData[1]) && \trim($aData[0]) === $sEmail) {
$aData = \array_map('trim', $aData);
if (\strlen($aData[1])) {
$sImapUser = $aData[1];
}
if (isset($aData[2]) && \strlen($aData[2])) {
$sSmtpUser = $aData[2];
}
}
}

View File

@ -69,6 +69,7 @@ trait Accounts
}
/**
* Add/Edit additional account
* @throws \MailSo\RuntimeException
*/
public function DoAccountSetup(): array

View File

@ -207,6 +207,7 @@ trait UserAuth
// Test the login
$oImapClient = new \MailSo\Imap\ImapClient;
$oImapClient->SetLogger($this->Logger());
$this->imapConnect($oAccount, false, $oImapClient);
}
$this->SetAdditionalAuthToken($oAccount);

View File

@ -165,7 +165,8 @@ abstract class Account implements \JsonSerializable
// $aAccountHash['login'] = $oDomain->ImapSettings()->fixUsername($aAccountHash['login']);
$oAccount = new static;
$oAccount->sEmail = \SnappyMail\IDN::emailToAscii($aAccountHash['email']);
$oAccount->sImapUser = \SnappyMail\IDN::emailToAscii($aAccountHash['login']);
// $oAccount->sImapUser = \SnappyMail\IDN::emailToAscii($aAccountHash['login']);
$oAccount->sImapUser = $aAccountHash['login'];
$oAccount->setImapPass(new SensitiveString($aAccountHash['pass']));
$oAccount->oDomain = $oDomain;
$oActions->Plugins()->RunHook('filter.account', array($oAccount));
@ -286,7 +287,7 @@ abstract class Account implements \JsonSerializable
*/
/**
* @deprecated
* @deprecated since v2.36.1
*/
public function IncLogin() : string
{

View File

@ -106,7 +106,7 @@ class Domain implements \JsonSerializable
public function ValidateWhiteList(string $sEmail) : bool
{
$sW = \trim($this->whiteList);
$sW = $this->whiteList;
if (!$sW) {
return true;
}
@ -210,7 +210,7 @@ class Domain implements \JsonSerializable
$oDomain->SMTP->setSender = !empty($aDomain['smtp_set_sender']);
$oDomain->SMTP->usePhpMail = !empty($aDomain['smtp_php_mail']);
$oDomain->whiteList = \trim($aDomain['white_list'] ?? '');
$oDomain->whiteList = $aDomain['white_list'] ?? '';
$oDomain->Normalize();
}

View File

@ -6,15 +6,9 @@ use RainLoop\Exceptions\ClientException;
class Domain extends AbstractProvider
{
/**
* @var Domain\DomainInterface
*/
private $oDriver;
private Domain\DomainInterface $oDriver;
/**
* @var \RainLoop\Plugins\Manager
*/
private $oPlugins;
private \RainLoop\Plugins\Manager $oPlugins;
public function __construct(Domain\DomainInterface $oDriver, \RainLoop\Plugins\Manager $oPlugins)
{
@ -86,10 +80,13 @@ class Domain extends AbstractProvider
{
$oDomain = $this->Load(\MailSo\Base\Utils::getEmailAddressDomain($sEmail), true);
if (!$oDomain) {
$this->logWrite("{$sEmail} has no domain configuration", \LOG_INFO, 'domain');
throw new ClientException(Notifications::DomainNotAllowed);
}
if (!$oDomain->ValidateWhiteList($sEmail)) {
$this->logWrite("{$sEmail} not whitelisted in {$oDomain->Name()}", \LOG_WARNING, 'domain');
throw new ClientException(Notifications::AccountNotAllowed);
// throw new ClientException(Notifications::AccountNotAllowed, null, "{$sEmail} not whitelisted in {$oDomain->Name()}");
}
return $oDomain;
}