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

View file

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

View file

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

View file

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

View file

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

View file

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