mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-27 02:59:21 +03:00
Solve the massive logger bloat by simplifying it to be RFC 5424
As it confused people and #552
This commit is contained in:
parent
2056600a72
commit
87d01c8bde
40 changed files with 330 additions and 799 deletions
|
|
@ -66,13 +66,13 @@ class ChangePasswordHMailServerDriver
|
|||
$oHmailAccount->Save();
|
||||
$bResult = true;
|
||||
} else {
|
||||
$this->oLogger && $this->oLogger->Write('hMailServer: Unknown account ('.$sEmail.')', \MailSo\Log\Enumerations\Type::ERROR);
|
||||
$this->oLogger && $this->oLogger->Write('hMailServer: Unknown account ('.$sEmail.')', \LOG_ERROR);
|
||||
}
|
||||
} else {
|
||||
$this->oLogger && $this->oLogger->Write('hMailServer: Unknown domain ('.$sDomain.')', \MailSo\Log\Enumerations\Type::ERROR);
|
||||
$this->oLogger && $this->oLogger->Write('hMailServer: Unknown domain ('.$sDomain.')', \LOG_ERROR);
|
||||
}
|
||||
} else {
|
||||
$this->oLogger && $this->oLogger->Write('hMailServer: Auth error', \MailSo\Log\Enumerations\Type::ERROR);
|
||||
$this->oLogger && $this->oLogger->Write('hMailServer: Auth error', \LOG_ERROR);
|
||||
}
|
||||
}
|
||||
catch (\Exception $oException)
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class ChangePasswordPoppassdDriver extends \MailSo\Net\NetClient
|
|||
if ($this->bIsLoggined) {
|
||||
$this->writeLogException(
|
||||
new \RuntimeException('Already authenticated for this session'),
|
||||
\MailSo\Log\Enumerations\Type::ERROR, true);
|
||||
\LOG_ERR, true);
|
||||
}
|
||||
|
||||
try
|
||||
|
|
@ -63,7 +63,7 @@ class ChangePasswordPoppassdDriver extends \MailSo\Net\NetClient
|
|||
}
|
||||
catch (\Throwable $oException)
|
||||
{
|
||||
$this->writeLogException($oException, \MailSo\Log\Enumerations\Type::NOTICE, true);
|
||||
$this->writeLogException($oException, \LOG_NOTICE, true);
|
||||
}
|
||||
|
||||
$this->bIsLoggined = true;
|
||||
|
|
@ -73,7 +73,7 @@ class ChangePasswordPoppassdDriver extends \MailSo\Net\NetClient
|
|||
} else {
|
||||
$this->writeLogException(
|
||||
new \RuntimeException('Required login'),
|
||||
\MailSo\Log\Enumerations\Type::ERROR, true);
|
||||
\LOG_ERR, true);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -125,9 +125,7 @@ class ChangePasswordPoppassdDriver extends \MailSo\Net\NetClient
|
|||
{
|
||||
$sCommand = \trim($sCommand);
|
||||
if (!\strlen($sCommand)) {
|
||||
$this->writeLogException(
|
||||
new \MailSo\Base\Exceptions\InvalidArgumentException(),
|
||||
\MailSo\Log\Enumerations\Type::ERROR, true);
|
||||
$this->writeLogException(new \MailSo\Base\Exceptions\InvalidArgumentException(), \LOG_ERR, true);
|
||||
}
|
||||
|
||||
$this->IsConnected(true);
|
||||
|
|
@ -158,13 +156,10 @@ class ChangePasswordPoppassdDriver extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
if (!$bResult) {
|
||||
$this->writeLogException(
|
||||
new \MailSo\Base\Exceptions\Exception(),
|
||||
\MailSo\Log\Enumerations\Type::WARNING, true);
|
||||
$this->writeLogException(new \MailSo\Base\Exceptions\Exception(), \LOG_WARNING, true);
|
||||
}
|
||||
|
||||
$this->writeLog((\microtime(true) - $this->iRequestTime),
|
||||
\MailSo\Log\Enumerations\Type::TIME);
|
||||
$this->writeLog((\microtime(true) - $this->iRequestTime), \LOG_DEBUG);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class ChangePasswordDriverLDAP
|
|||
if (!\ldap_set_option($oCon, LDAP_OPT_PROTOCOL_VERSION, 3)) {
|
||||
$this->oLogger->Write(
|
||||
'Failed to set LDAP Protocol version to 3, TLS not supported.',
|
||||
\MailSo\Log\Enumerations\Type::WARNING,
|
||||
\LOG_WARNING,
|
||||
'LDAP'
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ class ChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
if ($oLogger) {
|
||||
$oLogger->Write("ERROR: {$name} password change for {$oAccount->Email()} failed");
|
||||
$oLogger->WriteException($oException);
|
||||
// $oLogger->WriteException($oException, \MailSo\Log\Enumerations\Type::WARNING, $name);
|
||||
// $oLogger->WriteException($oException, \LOG_WARNING, $name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ class ExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
$this->Manager()->IsEnabled() : bool
|
||||
$this->Manager()->Count() : int
|
||||
$this->Manager()->SetLogger(\MailSo\Log\Logger $oLogger) : self
|
||||
$this->Manager()->WriteLog(string $sDesc, int $iType = \MailSo\Log\Enumerations\Type::INFO) : void
|
||||
$this->Manager()->WriteException(string $sDesc, int $iType = \MailSo\Log\Enumerations\Type::INFO) : void
|
||||
$this->Manager()->WriteLog(string $sDesc, int $iType = \LOG_INFO) : void
|
||||
$this->Manager()->WriteException(string $sDesc, int $iType = \LOG_INFO) : void
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
|
|||
$oCon = @\ldap_connect($this->sLdapUri);
|
||||
if ($oCon)
|
||||
{
|
||||
$this->oLogger->Write('ldap_connect: connected', \MailSo\Log\Enumerations\Type::INFO, 'LDAP');
|
||||
$this->oLogger->Write('ldap_connect: connected', \LOG_INFO, 'LDAP');
|
||||
|
||||
@\ldap_set_option($oCon, LDAP_OPT_PROTOCOL_VERSION, 3);
|
||||
|
||||
|
|
@ -268,7 +268,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
|
|||
$sFilter .= (1 < count($aItems) ? '(|' : '').$sSubFilter.(1 < count($aItems) ? ')' : '');
|
||||
$sFilter .= ')';
|
||||
|
||||
$this->oLogger->Write('ldap_search: start: '.$sBaseDn.' / '.$sFilter, \MailSo\Log\Enumerations\Type::INFO, 'LDAP');
|
||||
$this->oLogger->Write('ldap_search: start: '.$sBaseDn.' / '.$sFilter, \LOG_INFO, 'LDAP');
|
||||
$oS = @\ldap_search($oCon, $sBaseDn, $sFilter, $aItems, 0, 30, 30);
|
||||
if ($oS)
|
||||
{
|
||||
|
|
@ -343,7 +343,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
|
|||
$iErrno = $oCon ? @\ldap_errno($oCon) : 0;
|
||||
|
||||
$this->oLogger->Write($sCmd.' error: '.$sError.' ('.$iErrno.')',
|
||||
\MailSo\Log\Enumerations\Type::WARNING, 'LDAP');
|
||||
\LOG_WARNING, 'LDAP');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
<?php
|
||||
|
||||
use MailSo\Log\Enumerations\Type;
|
||||
use MailSo\Log\Logger;
|
||||
use RainLoop\Model\Account;
|
||||
use RainLoop\Model\Identity;
|
||||
|
|
@ -40,7 +39,7 @@ class LdapIdentities implements IIdentities
|
|||
// Check if LDAP is available
|
||||
if (!extension_loaded('ldap') || !function_exists('ldap_connect')) {
|
||||
$this->ldapAvailable = false;
|
||||
$logger->Write("The LDAP extension is not available!", Type::WARNING, self::LOG_KEY);
|
||||
$logger->Write("The LDAP extension is not available!", \LOG_WARNING, self::LOG_KEY);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -77,10 +76,10 @@ class LdapIdentities implements IIdentities
|
|||
}
|
||||
|
||||
if (count($userResults) < 1) {
|
||||
$this->logger->Write("Could not find user $username", Type::NOTICE, self::LOG_KEY);
|
||||
$this->logger->Write("Could not find user $username", \LOG_NOTICE, self::LOG_KEY);
|
||||
return [];
|
||||
} else if (count($userResults) > 1) {
|
||||
$this->logger->Write("Found multiple matches for user $username", Type::WARNING, self::LOG_KEY);
|
||||
$this->logger->Write("Found multiple matches for user $username", \LOG_WARNING, self::LOG_KEY);
|
||||
}
|
||||
|
||||
$userResult = $userResults[0];
|
||||
|
|
@ -219,7 +218,7 @@ class LdapIdentities implements IIdentities
|
|||
$errorMsg = @ldap_error($this->ldap);
|
||||
|
||||
$message = empty($op) ? "LDAP Error: {$errorMsg} ({$errorNo})" : "LDAP Error during {$op}: {$errorMsg} ({$errorNo})";
|
||||
$this->logger->Write($message, Type::ERROR, self::LOG_KEY);
|
||||
$this->logger->Write($message, \LOG_ERR, self::LOG_KEY);
|
||||
throw new LdapException($message, $errorNo);
|
||||
}
|
||||
|
||||
|
|
@ -279,14 +278,14 @@ class LdapIdentities implements IIdentities
|
|||
{
|
||||
if (!isset($entry[$attribute])) {
|
||||
if ($required)
|
||||
$this->logger->Write("Attribute $attribute not found on object {$entry['dn']} while required", Type::NOTICE, self::LOG_KEY);
|
||||
$this->logger->Write("Attribute $attribute not found on object {$entry['dn']} while required", \LOG_NOTICE, self::LOG_KEY);
|
||||
|
||||
return $single ? "" : [];
|
||||
}
|
||||
|
||||
if ($single) {
|
||||
if ($entry[$attribute]["count"] > 1)
|
||||
$this->logger->Write("Attribute $attribute is multivalues while only a single value is expected", Type::NOTICE, self::LOG_KEY);
|
||||
$this->logger->Write("Attribute $attribute is multivalues while only a single value is expected", \LOG_NOTICE, self::LOG_KEY);
|
||||
|
||||
return $entry[$attribute][0];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
<?php
|
||||
|
||||
use \MailSo\Log\Enumerations\Type;
|
||||
use \RainLoop\Enumerations\PluginPropertyType;
|
||||
use \RainLoop\Plugins\AbstractPlugin;
|
||||
use RainLoop\Enumerations\PluginPropertyType;
|
||||
use RainLoop\Plugins\AbstractPlugin;
|
||||
use RainLoop\Plugins\Property;
|
||||
|
||||
class LDAPLoginMappingPlugin extends AbstractPlugin
|
||||
|
|
@ -87,7 +86,7 @@ class LDAPLoginMappingPlugin extends AbstractPlugin
|
|||
*/
|
||||
public function FilterLoginСredentials(&$sEmail, &$sLogin, &$sPassword)
|
||||
{
|
||||
$this->oLogger = \MailSo\Log\Logger::SingletonInstance();
|
||||
$this->oLogger = \RainLoop\Api::Logger();
|
||||
|
||||
$this->aDomains = explode(',', $this->Config()->Get('plugin', 'domains', ''));
|
||||
$this->sSearchDomain = trim($this->Config()->Get('plugin', 'search_domain', ''));
|
||||
|
|
@ -100,13 +99,13 @@ class LDAPLoginMappingPlugin extends AbstractPlugin
|
|||
|
||||
if (0 < \strlen($this->sObjectClass) && 0 < \strlen($this->sEmailField))
|
||||
{
|
||||
$sIP = $_SERVER['REMOTE_ADDR'];
|
||||
$sResult = $this->ldapSearch($sEmail);
|
||||
$sIP = $_SERVER['REMOTE_ADDR'];
|
||||
$sResult = $this->ldapSearch($sEmail);
|
||||
if ( is_array($sResult) ) {
|
||||
$sLogin = $sResult['login'];
|
||||
$sEmail = $sResult['email'];
|
||||
}
|
||||
syslog(LOG_WARNING, "plugins/ldap-login-mapping/index.php:FilterLoginСredentials() auth try: $sIP/$sEmail, resolved as $sLogin/$sEmail");
|
||||
syslog(LOG_WARNING, "plugins/ldap-login-mapping/index.php:FilterLoginСredentials() auth try: $sIP/$sEmail, resolved as $sLogin/$sEmail");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -163,7 +162,7 @@ class LDAPLoginMappingPlugin extends AbstractPlugin
|
|||
$bFound = FALSE;
|
||||
foreach ( $this->aDomains as $sDomain ) {
|
||||
$sRegex = '/^[a-z0-9._-]+@' . preg_quote(trim($sDomain)) . '$/i';
|
||||
$this->oLogger->Write('DEBUG regex ' . $sRegex, Type::INFO, 'LDAP');
|
||||
$this->oLogger->Write('DEBUG regex ' . $sRegex, \LOG_INFO, 'LDAP');
|
||||
if ( preg_match($sRegex, $sEmail) === 1) {
|
||||
$bFound = TRUE;
|
||||
break;
|
||||
|
|
@ -172,18 +171,18 @@ class LDAPLoginMappingPlugin extends AbstractPlugin
|
|||
if ( !$bFound ) {
|
||||
$this->oLogger->Write(
|
||||
'preg_match: no match in "' . $sEmail . '" for /^[a-z0-9._-]+@{configured-domains}$/i',
|
||||
Type::INFO,
|
||||
\LOG_INFO,
|
||||
'LDAP');
|
||||
return FALSE;
|
||||
}
|
||||
$sLogin = \MailSo\Base\Utils::GetAccountNameFromEmail($sEmail);
|
||||
|
||||
$this->oLogger->Write('ldap_connect: trying...', Type::INFO, 'LDAP');
|
||||
$this->oLogger->Write('ldap_connect: trying...', \LOG_INFO, 'LDAP');
|
||||
|
||||
$oCon = @\ldap_connect($this->sHostName, $this->iHostPort);
|
||||
if (!$oCon) return FALSE;
|
||||
|
||||
$this->oLogger->Write('ldap_connect: connected', Type::INFO, 'LDAP');
|
||||
$this->oLogger->Write('ldap_connect: connected', \LOG_INFO, 'LDAP');
|
||||
|
||||
@\ldap_set_option($oCon, LDAP_OPT_PROTOCOL_VERSION, 3);
|
||||
|
||||
|
|
@ -199,7 +198,7 @@ class LDAPLoginMappingPlugin extends AbstractPlugin
|
|||
} else {
|
||||
$sFilter = '(&(objectclass='.$this->sObjectClass.')(|('.$this->sEmailField.'='.$sEmail.')('.$this->sLoginField.'='.$sLogin.')))';
|
||||
}
|
||||
$this->oLogger->Write('ldap_search: start: '.$sSearchDn.' / '.$sFilter, Type::INFO, 'LDAP');
|
||||
$this->oLogger->Write('ldap_search: start: '.$sSearchDn.' / '.$sFilter, \LOG_INFO, 'LDAP');
|
||||
$oS = @\ldap_search($oCon, $sSearchDn, $sFilter, $aItems, 0, 30, 30);
|
||||
if (!$oS) {
|
||||
$this->logLdapError($oCon, 'ldap_search');
|
||||
|
|
@ -246,7 +245,7 @@ class LDAPLoginMappingPlugin extends AbstractPlugin
|
|||
$iErrno = $oCon ? @\ldap_errno($oCon) : 0;
|
||||
|
||||
$this->oLogger->Write($sCmd.' error: '.$sError.' ('.$iErrno.')',
|
||||
Type::WARNING, 'LDAP');
|
||||
\LOG_WARNING, 'LDAP');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ class LoginOAuth2Plugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
}
|
||||
catch (\Exception $oException)
|
||||
{
|
||||
$oActions->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR);
|
||||
$oActions->Logger()->WriteException($oException, \LOG_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -292,7 +292,7 @@ class LoginOAuth2Plugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
}
|
||||
catch (\Exception $oException)
|
||||
{
|
||||
$oActions->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR);
|
||||
$oActions->Logger()->WriteException($oException, \LOG_ERR);
|
||||
}
|
||||
|
||||
$oActions = \RainLoop::Actions();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue