Bugfix: don't log admin auth fail attempts twice

This commit is contained in:
the-djmaze 2022-02-12 00:05:35 +01:00
parent cb15085dc6
commit 182aee6bb8
3 changed files with 10 additions and 11 deletions

View file

@ -626,19 +626,18 @@ class Actions
return $this->oLoggerAuth;
}
public function LoggerAuthHelper(?Model\Account $oAccount = null, array $aAdditionalParams = array()): void
protected function LoggerAuthHelper(?Model\Account $oAccount = null, array $aAdditionalParams = array(), bool $admin = false): void
{
$sLine = $this->oConfig->Get('logs', 'auth_logging_format', '');
if (!empty($sLine)) {
$this->LoggerAuth()->Write($this->compileLogParams($sLine, $oAccount, false, $aAdditionalParams));
}
$this->SysLogAuth($this->compileLogParams('Auth failed: ip={request:ip} user={imap:login}', $oAccount, false, $aAdditionalParams));
}
protected function SysLogAuth(string $message): void
{
if ($this->oConfig->Get('logs', 'auth_logging', false) && \openlog('snappymail', 0, \LOG_AUTHPRIV)) {
\syslog(\LOG_ERR, $message);
if (($this->oConfig->Get('logs', 'auth_logging', false) || $this->oConfig->Get('logs', 'auth_syslog', false))
&& \openlog('snappymail', 0, \LOG_AUTHPRIV)) {
\syslog(\LOG_ERR, $this->compileLogParams(
$admin ? 'Admin Auth failed: ip={request:ip} user={user:login}' : 'Auth failed: ip={request:ip} user={imap:login}',
$oAccount, false, $aAdditionalParams
));
\closelog();
}
}

View file

@ -212,8 +212,7 @@ trait Admin
!$this->Config()->ValidatePassword($sPassword)
|| ($totp && !\SnappyMail\TOTP::Verify($totp, $this->GetActionParam('TOTP', ''))))
{
$this->SysLogAuth($this->compileLogParams('Admin Auth failed: ip={request:ip} user={user:login}'));
$this->LoggerAuthHelper(null, $this->getAdditionalLogParamsByUserLogin($sLogin, true));
$this->LoggerAuthHelper(null, $this->getAdditionalLogParamsByUserLogin($sLogin, true), true);
$this->loginErrorDelay();
throw new ClientException(Notifications::AuthError);
}

View file

@ -299,7 +299,8 @@ Examples:
'auth_logging' => array(false, 'Enable auth logging in a separate file (for fail2ban)'),
'auth_logging_filename' => array('fail2ban/auth-{date:Y-m-d}.txt'),
'auth_logging_format' => array('[{date:Y-m-d H:i:s}] Auth failed: ip={request:ip} user={imap:login} host={imap:host} port={imap:port}')
'auth_logging_format' => array('[{date:Y-m-d H:i:s}] Auth failed: ip={request:ip} user={imap:login} host={imap:host} port={imap:port}'),
'auth_syslog' => array(false, 'Enable auth logging to syslog for fail2ban')
),
'debug' => array(