Merge Actions::getAdditionalLogParamsByUserLogin() into Actions::LoggerAuthHelper()

This commit is contained in:
the-djmaze 2024-03-08 02:49:41 +01:00
parent f32f5347a7
commit 9fc4d8f953
3 changed files with 17 additions and 17 deletions

View file

@ -532,8 +532,22 @@ class Actions
return $this->oPlugins;
}
protected function LoggerAuthHelper(?Model\Account $oAccount = null, array $aAdditionalParams = array(), bool $admin = false): void
protected function LoggerAuthHelper(?Model\Account $oAccount = null, string $sLogin, bool $admin = false): void
{
if ($sLogin) {
$sHost = $admin ? $this->Http()->GetHost(true, true) : \MailSo\Base\Utils::GetDomainFromEmail($sLogin);
$aAdditionalParams = array(
'{imap:login}' => $sLogin,
'{imap:host}' => $sHost,
'{smtp:login}' => $sLogin,
'{smtp:host}' => $sHost,
'{user:email}' => $sLogin,
'{user:login}' => $admin ? $sLogin : \MailSo\Base\Utils::GetAccountNameFromEmail($sLogin),
'{user:domain}' => $sHost,
);
} else {
$aAdditionalParams = array();
}
$sLine = $this->oConfig->Get('logs', 'auth_logging_format', '');
if (!empty($sLine)) {
if (!$this->oLoggerAuth) {
@ -808,20 +822,6 @@ class Actions
}
}
protected function getAdditionalLogParamsByUserLogin(string $sLogin, bool $bAdmin = false): array
{
$sHost = $bAdmin ? $this->Http()->GetHost(true, true) : \MailSo\Base\Utils::GetDomainFromEmail($sLogin);
return array(
'{imap:login}' => $sLogin,
'{imap:host}' => $sHost,
'{smtp:login}' => $sLogin,
'{smtp:host}' => $sHost,
'{user:email}' => $sLogin,
'{user:login}' => $bAdmin ? $sLogin : \MailSo\Base\Utils::GetAccountNameFromEmail($sLogin),
'{user:domain}' => $sHost,
);
}
public function DoPing(): array
{
return $this->DefaultResponse('Pong');

View file

@ -136,7 +136,7 @@ trait UserAuth
throw new ClientException(Notifications::AuthError);
}
} catch (\Throwable $oException) {
$this->LoggerAuthHelper($oAccount, $this->getAdditionalLogParamsByUserLogin($sInputEmail));
$this->LoggerAuthHelper($oAccount, $sInputEmail);
throw $oException;
}

View file

@ -124,7 +124,7 @@ class ActionsAdmin extends Actions
!$this->Config()->ValidatePassword($oPassword)
|| ($totp && !\SnappyMail\TOTP::Verify($totp, $this->GetActionParam('TOTP', ''))))
{
$this->LoggerAuthHelper(null, $this->getAdditionalLogParamsByUserLogin($sLogin, true), true);
$this->LoggerAuthHelper(null, $sLogin, true);
$this->loginErrorDelay();
throw new ClientException(Notifications::AuthError);
}