Inherit logger as Trait

This commit is contained in:
the-djmaze 2023-04-11 10:56:28 +02:00
parent b5b1d5f88a
commit 0a3effc6ba
27 changed files with 157 additions and 199 deletions

View file

@ -113,8 +113,8 @@ trait Messages
if (FetchResponse::isValidImapResponse($oResponse)) {
if (FetchResponse::hasUidAndSize($oResponse)) {
yield new FetchResponse($oResponse);
} else if ($this->oLogger) {
$this->oLogger->Write('Skipped Imap Response! ['.$oResponse.']', \LOG_NOTICE);
} else {
$this->logWrite('Skipped Imap Response! ['.$oResponse.']', \LOG_NOTICE);
}
}
}

View file

@ -154,7 +154,7 @@ class ImapClient extends \MailSo\Net\NetClient
$sAuthzid = $this->getResponseValue($this->SendRequestGetResponse('AUTHENTICATE', array($type)), Enumerations\ResponseType::CONTINUATION);
$this->sendRaw($SASL->authenticate($sLogin, $sPassword/*, $sAuthzid*/), true);
$sChallenge = $SASL->challenge($this->getResponseValue($this->getResponse(), Enumerations\ResponseType::CONTINUATION));
$this->oLogger && $this->oLogger->AddSecret($sChallenge);
$this->logMask($sChallenge);
$this->sendRaw($sChallenge);
$oResponse = $this->getResponse();
$SASL->verify($this->getResponseValue($oResponse));
@ -162,16 +162,16 @@ class ImapClient extends \MailSo\Net\NetClient
else if ('CRAM-MD5' === $type)
{
$sChallenge = $this->getResponseValue($this->SendRequestGetResponse('AUTHENTICATE', array($type)), Enumerations\ResponseType::CONTINUATION);
$this->oLogger->Write('challenge: '.\base64_decode($sChallenge));
$this->logWrite('challenge: '.\base64_decode($sChallenge));
$sAuth = $SASL->authenticate($sLogin, $sPassword, $sChallenge);
$this->oLogger && $this->oLogger->AddSecret($sAuth);
$this->logMask($sAuth);
$this->sendRaw($sAuth);
$oResponse = $this->getResponse();
}
else if ('PLAIN' === $type || 'OAUTHBEARER' === $type /*|| 'PLAIN-CLIENTTOKEN' === $type*/)
{
$sAuth = $SASL->authenticate($sLogin, $sPassword);
$this->oLogger && $this->oLogger->AddSecret($sAuth);
$this->logMask($sAuth);
if ($this->hasCapability('SASL-IR')) {
$oResponse = $this->SendRequestGetResponse('AUTHENTICATE', array($type, $sAuth));
} else {
@ -187,8 +187,7 @@ class ImapClient extends \MailSo\Net\NetClient
$oR = $oResponse->getLast();
if ($oR && Enumerations\ResponseType::CONTINUATION === $oR->ResponseType) {
if (!empty($oR->ResponseList[1]) && preg_match('/^[a-zA-Z0-9=+\/]+$/', $oR->ResponseList[1])) {
$this->Logger()->Write(\base64_decode($oR->ResponseList[1]),
\LOG_WARNING);
$this->logWrite(\base64_decode($oR->ResponseList[1]), \LOG_WARNING);
}
$this->sendRaw('');
$oResponse = $this->getResponse();
@ -200,14 +199,14 @@ class ImapClient extends \MailSo\Net\NetClient
$this->sendRaw($SASL->authenticate($sLogin, $sPassword, $sB64), true);
$this->getResponse();
$sPass = $SASL->challenge(''/*UGFzc3dvcmQ6*/);
$this->oLogger && $this->oLogger->AddSecret($sPass);
$this->logMask($sPass);
$this->sendRaw($sPass);
$oResponse = $this->getResponse();
}
else
{
$sPassword = $this->EscapeString(\mb_convert_encoding($sPassword, 'ISO-8859-1', 'UTF-8'));
$this->oLogger && $this->oLogger->AddSecret($sPassword);
$this->logMask($sPassword);
$oResponse = $this->SendRequestGetResponse('LOGIN',
array(
$this->EscapeString($sLogin),

View file

@ -0,0 +1,52 @@
<?php
/*
* This file is part of MailSo.
*
* (c) 2014 Usenko Timur
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MailSo\Log;
/**
* @category MailSo
* @package Log
*/
trait Inherit
{
protected ?Logger $oLogger = null;
public function Logger(): ?Logger
{
return $this->oLogger;
}
public function SetLogger(?Logger $oLogger): void
{
$this->oLogger = $oLogger;
}
public function logWrite(string $sDesc, int $iType = \LOG_INFO,
string $sName = '', bool $bSearchSecretWords = true, bool $bDiplayCrLf = false): bool
{
return $this->oLogger && $this->oLogger->Write($sDesc, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
}
public function logException(\Throwable $oException, int $iType = \LOG_NOTICE, string $sName = ''): void
{
$this->oLogger && $this->oLogger->WriteException($oException, $iType, $sName);
}
public function logMask(string $sWord): void
{
$this->oLogger && $this->oLogger->AddSecret($sWord);
}
/*
public function logWriteDump($mValue, int $iType = \LOG_INFO, string $sName = '') : bool
public function logWriteExceptionShort(\Throwable $oException, int $iType = \LOG_NOTICE, string $sName = '') : void
*/
}

View file

@ -26,7 +26,7 @@ use MailSo\Mime\Enumerations\Parameter as MimeParameter;
*/
class MailClient
{
private ?\MailSo\Log\Logger $oLogger = null;
use \MailSo\Log\Inherit;
private \MailSo\Imap\ImapClient $oImapClient;
@ -400,17 +400,13 @@ class MailClient
"ThreadsMapSorted/{$sSearch}/{$sFolderName}/{$oMessageCollection->FolderInfo->etag}";
// "ThreadsMapSorted/{$sSearch}/{$iThreadLimit}/{$sFolderName}/{$oMessageCollection->FolderInfo->etag}";
if ($this->oLogger) {
$this->oLogger->Write($sSerializedHashKey);
}
$this->logWrite($sSerializedHashKey);
$sSerializedUids = $oCacher->Get($sSerializedHashKey);
if (!empty($sSerializedUids)) {
$aSerializedUids = \json_decode($sSerializedUids, true);
if (isset($aSerializedUids['ThreadsUids']) && \is_array($aSerializedUids['ThreadsUids'])) {
if ($this->oLogger) {
$this->oLogger->Write('Get Serialized Thread UIDS from cache ("'.$sFolderName.'" / '.$sSearch.') [count:'.\count($aSerializedUids['ThreadsUids']).']');
}
$this->logWrite('Get Serialized Thread UIDS from cache ("'.$sFolderName.'" / '.$sSearch.') [count:'.\count($aSerializedUids['ThreadsUids']).']');
return $aSerializedUids['ThreadsUids'];
}
}
@ -439,9 +435,7 @@ class MailClient
'ThreadsUids' => $aResult
)));
if ($this->oLogger) {
$this->oLogger->Write('Save Serialized Thread UIDS to cache ("'.$sFolderName.'" / '.$sSearch.') [count:'.\count($aResult).']');
}
$this->logWrite('Save Serialized Thread UIDS to cache ("'.$sFolderName.'" / '.$sSearch.') [count:'.\count($aResult).']');
}
return $aResult;
@ -571,9 +565,7 @@ class MailClient
$sFolderHash === $aSerialized['FolderHash'] &&
\is_array($aSerialized['Uids'])
) {
if ($this->oLogger) {
$this->oLogger->Write('Get Serialized '.($bReturnUid?'UIDS':'IDS').' from cache ('.$sSerializedLog.') [count:'.\count($aSerialized['Uids']).']');
}
$this->logWrite('Get Serialized '.($bReturnUid?'UIDS':'IDS').' from cache ('.$sSerializedLog.') [count:'.\count($aSerialized['Uids']).']');
return $aSerialized['Uids'];
}
}
@ -606,9 +598,7 @@ class MailClient
'Uids' => $aResultUids
)));
if ($this->oLogger) {
$this->oLogger->Write('Save Serialized '.($bReturnUid?'UIDS':'IDS').' to cache ('.$sSerializedLog.') [count:'.\count($aResultUids).']');
}
$this->logWrite('Save Serialized '.($bReturnUid?'UIDS':'IDS').' to cache ('.$sSerializedLog.') [count:'.\count($aResultUids).']');
}
return $aResultUids;
@ -664,9 +654,7 @@ class MailClient
// || (!$this->oImapClient->hasCapability('SORT') && !$this->oImapClient->CapabilityValue('THREAD'))) {
// Don't use THREAD for speed
$oMessageCollection->Limited = true;
if ($this->oLogger) {
$this->oLogger->Write('List optimization (count: '.$oInfo->MESSAGES.', limit:'.$message_list_limit.')');
}
$this->logWrite('List optimization (count: '.$oInfo->MESSAGES.', limit:'.$message_list_limit.')');
if (\strlen($sSearch)) {
// Don't use SORT for speed
$aUids = $this->GetUids($oParams, $sSearch, $oInfo->etag/*, $bUseSort*/);
@ -746,8 +734,8 @@ class MailClient
$aUids = \array_slice($aUids, $oParams->iOffset, $oParams->iLimit);
$this->MessageListByRequestIndexOrUids($oMessageCollection, new SequenceSet($aUids), $aAllThreads);
}
} else if ($this->oLogger) {
$this->oLogger->Write('No messages in '.$oMessageCollection->FolderName);
} else {
$this->logWrite('No messages in '.$oMessageCollection->FolderName);
}
return $oMessageCollection;
@ -775,7 +763,7 @@ class MailClient
}
if ($bUseListSubscribeStatus && !$this->oImapClient->hasCapability('LIST-EXTENDED')) {
// $this->oLogger && $this->oLogger->Write('RFC5258 not supported, using LSUB');
// $this->logWrite('RFC5258 not supported, using LSUB');
// \SnappyMail\Log::warning('IMAP', 'RFC5258 not supported, using LSUB');
try
{
@ -916,7 +904,7 @@ class MailClient
/**
* @throws \InvalidArgumentException
*/
public function SetLogger(\MailSo\Log\Logger $oLogger) : void
public function SetLogger(?\MailSo\Log\Logger $oLogger) : void
{
$this->oLogger = $oLogger;
$this->oImapClient->SetLogger($oLogger);

View file

@ -17,6 +17,8 @@ namespace MailSo\Net;
*/
abstract class NetClient
{
use \MailSo\Log\Inherit;
/**
* @var resource
*/
@ -34,11 +36,6 @@ abstract class NetClient
private float $iStartConnectTime = 0;
/**
* @var \MailSo\Log\Logger
*/
protected $oLogger = null;
public ConnectSettings $Settings;
public function __destruct()
@ -295,34 +292,22 @@ abstract class NetClient
protected function writeLog(string $sDesc, int $iDescType = \LOG_INFO) : void
{
$this->oLogger && $this->oLogger->Write($sDesc, $iDescType, $this->getLogName());
$this->logWrite($sDesc, $iDescType, $this->getLogName());
}
protected function writeLogWithCrlf(string $sDesc) : void
{
$this->oLogger && $this->oLogger->Write($sDesc, \LOG_INFO, $this->getLogName(), true, true);
$this->logWrite($sDesc, \LOG_INFO, $this->getLogName(), true, true);
}
protected function writeLogException(\Throwable $oException, int $iDescType = \LOG_NOTICE, bool $bThrowException = true) : void
{
if ($this->oLogger) {
if ($oException instanceof Exceptions\SocketCanNotConnectToHostException) {
$this->oLogger->Write('Socket: ['.$oException->getSocketCode().'] '.$oException->getSocketMessage(), $iDescType, $this->getLogName());
}
$this->oLogger->WriteException($oException, $iDescType, $this->getLogName());
if ($oException instanceof Exceptions\SocketCanNotConnectToHostException) {
$this->logWrite('Socket: ['.$oException->getSocketCode().'] '.$oException->getSocketMessage(), $iDescType, $this->getLogName());
}
$this->logException($oException, $iDescType, $this->getLogName());
if ($bThrowException) {
throw $oException;
}
}
public function SetLogger(\MailSo\Log\Logger $oLogger) : void
{
$this->oLogger = $oLogger;
}
public function Logger() : ?\MailSo\Log\Logger
{
return $this->oLogger;
}
}

View file

@ -117,7 +117,7 @@ class SieveClient extends \MailSo\Net\NetClient
$sAuthzid = $this->getResponseValue($this->SendRequestGetResponse('AUTHENTICATE', array($type)), \MailSo\Imap\Enumerations\ResponseType::CONTINUATION);
$this->sendRaw($SASL->authenticate($sLogin, $sPassword/*, $sAuthzid* /), true);
$sChallenge = $SASL->challenge($this->getResponseValue($this->getResponse(), \MailSo\Imap\Enumerations\ResponseType::CONTINUATION));
$this->oLogger && $this->oLogger->AddSecret($sChallenge);
$this->logMask($sChallenge);
$this->sendRaw($sChallenge);
$oResponse = $this->getResponse();
$SASL->verify($this->getResponseValue($oResponse));
@ -126,7 +126,7 @@ class SieveClient extends \MailSo\Net\NetClient
else if ('PLAIN' === $type || 'OAUTHBEARER' === $type || 'XOAUTH2' === $type)
{
$sAuth = $SASL->authenticate($sLogin, $sPassword, $sLoginAuthKey);
$this->oLogger && $this->oLogger->AddSecret($sAuth);
$this->logMask($sAuth);
if ($oSettings->authPlainLiteral) {
$this->sendRaw("AUTHENTICATE \"{$type}\" {".\strlen($sAuth).'+}');
@ -143,7 +143,7 @@ class SieveClient extends \MailSo\Net\NetClient
{
$sLogin = $SASL->authenticate($sLogin, $sPassword);
$sPassword = $SASL->challenge('');
$this->oLogger && $this->oLogger->AddSecret($sPassword);
$this->logMask($sPassword);
$this->sendRaw('AUTHENTICATE "LOGIN"');
$this->sendRaw('{'.\strlen($sLogin).'+}');

View file

@ -166,7 +166,7 @@ class SmtpClient extends \MailSo\Net\NetClient
// RFC 5802
$sResult = $this->sendRequestWithCheck($SASL->authenticate($sLogin, $sPassword, $sResult), 234, '');
$sChallenge = $SASL->challenge($sResult);
$this->oLogger && $this->oLogger->AddSecret($sChallenge);
$this->logMask($sChallenge);
$SASL->verify($this->sendRequestWithCheck($sChallenge, 235, '', true));
} else switch ($type) {
// RFC 4616
@ -174,14 +174,14 @@ class SmtpClient extends \MailSo\Net\NetClient
case 'XOAUTH2':
case 'OAUTHBEARER':
$sAuth = $SASL->authenticate($sLogin, $sPassword);
$this->oLogger && $this->oLogger->AddSecret($sAuth);
$this->logMask($sAuth);
$this->sendRequestWithCheck($sAuth, 235, '', true);
break;
case 'LOGIN':
$sResult = $this->sendRequestWithCheck($SASL->authenticate($sLogin, $sPassword, $sResult), 334, '');
$sPassword = $SASL->challenge($sResult);
$this->oLogger && $this->oLogger->AddSecret($sPassword);
$this->logMask($sPassword);
$this->sendRequestWithCheck($sPassword, 235, '', true);
break;

View file

@ -12,6 +12,8 @@ class Actions
use Actions\Localization;
use Actions\Themes;
use \MailSo\Log\Inherit;
const AUTH_MAILTO_TOKEN_KEY = 'smmailtoauth';
/**
@ -56,11 +58,6 @@ class Actions
*/
protected $oPlugins = null;
/**
* @var \MailSo\Log\Logger
*/
protected $oLogger = null;
/**
* @var \MailSo\Log\Logger
*/
@ -140,7 +137,7 @@ class Actions
$oHttp = $this->Http();
$this->oLogger->Write(
$this->logWrite(
'[SM:' . APP_VERSION . '][IP:'
. $oHttp->GetClientIp($this->oConfig->Get('labs', 'http_client_ip_check_proxy', false))
. '][PID:' . (\MailSo\Base\Utils::FunctionCallable('getmypid') ? \getmypid() : 'unknown')
@ -560,11 +557,6 @@ class Actions
return $this->oPlugins;
}
public function Logger(): \MailSo\Log\Logger
{
return $this->oLogger;
}
public function LoggerAuth(): \MailSo\Log\Logger
{
if (!$this->oLoggerAuth) {
@ -1130,7 +1122,7 @@ class Actions
public function Location(string $sUrl, int $iStatus = 302): void
{
$this->oLogger->Write("{$iStatus} Location: {$sUrl}");
$this->logWrite("{$iStatus} Location: {$sUrl}");
\MailSo\Base\Http::Location($sUrl, $iStatus);
}

View file

@ -108,7 +108,7 @@ trait AdminDomains
}
catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException)
{
$this->Logger()->WriteException($oException, \LOG_ERR);
$this->logException($oException, \LOG_ERR);
$sImapErrorDesc = $oException->getSocketMessage();
if (empty($sImapErrorDesc)) {
$sImapErrorDesc = $oException->getMessage();
@ -116,7 +116,7 @@ trait AdminDomains
}
catch (\Throwable $oException)
{
$this->Logger()->WriteException($oException, \LOG_ERR);
$this->logException($oException, \LOG_ERR);
$sImapErrorDesc = $oException->getMessage();
}
@ -146,7 +146,7 @@ trait AdminDomains
}
catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException)
{
$this->Logger()->WriteException($oException, \LOG_ERR);
$this->logException($oException, \LOG_ERR);
$sSmtpErrorDesc = $oException->getSocketMessage();
if (empty($sSmtpErrorDesc)) {
$sSmtpErrorDesc = $oException->getMessage();
@ -154,7 +154,7 @@ trait AdminDomains
}
catch (\Throwable $oException)
{
$this->Logger()->WriteException($oException, \LOG_ERR);
$this->logException($oException, \LOG_ERR);
$sSmtpErrorDesc = $oException->getMessage();
}
}
@ -179,7 +179,7 @@ trait AdminDomains
}
catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException)
{
$this->Logger()->WriteException($oException, \LOG_ERR);
$this->logException($oException, \LOG_ERR);
$sSieveErrorDesc = $oException->getSocketMessage();
if (empty($sSieveErrorDesc)) {
$sSieveErrorDesc = $oException->getMessage();
@ -187,7 +187,7 @@ trait AdminDomains
}
catch (\Throwable $oException)
{
$this->Logger()->WriteException($oException, \LOG_ERR);
$this->logException($oException, \LOG_ERR);
$sSieveErrorDesc = $oException->getMessage();
}
} else {

View file

@ -258,7 +258,7 @@ trait Contacts
if (\is_resource($rFile) && $oAddressBookProvider && $oAddressBookProvider->IsActive()) {
try
{
$this->Logger()->Write('Import contacts from vcf');
$this->logWrite('Import contacts from vcf');
foreach (\RainLoop\Providers\AddressBook\Utils::VcfStreamToContacts($rFile) as $oContact) {
if ($oAddressBookProvider->ContactSave($oContact)) {
++$iCount;
@ -267,7 +267,7 @@ trait Contacts
}
catch (\Throwable $oExc)
{
$this->Logger()->WriteException($oExc);
$this->logException($oExc);
}
}
return $iCount;
@ -280,7 +280,7 @@ trait Contacts
if (\is_resource($rFile) && $oAddressBookProvider && $oAddressBookProvider->IsActive()) {
try
{
$this->Logger()->Write('Import contacts from csv');
$this->logWrite('Import contacts from csv');
$sDelimiter = ((int)\strpos($sFileStart, ',') > (int)\strpos($sFileStart, ';')) ? ',' : ';';
foreach (\RainLoop\Providers\AddressBook\Utils::CsvStreamToContacts($rFile, $sDelimiter) as $oContact) {
if ($oAddressBookProvider->ContactSave($oContact)) {
@ -290,7 +290,7 @@ trait Contacts
}
catch (\Throwable $oExc)
{
$this->Logger()->WriteException($oExc);
$this->logException($oExc);
}
}
return $iCount;

View file

@ -299,7 +299,7 @@ trait Folders
}
catch (\Throwable $oException)
{
$this->Logger()->WriteException($oException);
$this->logException($oException);
}
}
}

View file

@ -196,7 +196,7 @@ trait Messages
}
catch (\Throwable $oException)
{
$this->Logger()->WriteException($oException, \LOG_ERR);
$this->logException($oException, \LOG_ERR);
}
}
@ -253,7 +253,7 @@ trait Messages
}
catch (\Throwable $oException)
{
$this->Logger()->WriteException($oException, \LOG_ERR);
$this->logException($oException, \LOG_ERR);
}
}
@ -297,7 +297,7 @@ trait Messages
}
catch (\Throwable $oException)
{
$this->Logger()->WriteException($oException);
$this->logException($oException);
}
return $this->TrueResponse();

View file

@ -156,7 +156,7 @@ trait Raw
$self->cacheByKey($sRawKey);
$self->Logger()->Write(\print_r([
$self->logWrite(\print_r([
$sFileName,
$sContentType,
$sFileNameIn,

View file

@ -60,7 +60,7 @@ trait Response
$sErrorMessage = $oException->getCode().' - '.$oException->getMessage();
}
$this->Logger()->WriteException($oException->getPrevious() ?: $oException);
$this->logException($oException->getPrevious() ?: $oException);
return $this->DefaultResponse(false, [
'ErrorCode' => $iErrorCode,

View file

@ -38,7 +38,7 @@ trait User
$sPassword = $this->GetActionParam('Password', '');
$bSignMe = !empty($this->GetActionParam('signMe', 0));
$this->Logger()->AddSecret($sPassword);
$this->logMask($sPassword);
try {
$oAccount = $this->LoginProcess($sEmail, $sPassword, $bSignMe);
@ -116,17 +116,17 @@ trait User
}
if ($bMainCache) {
$this->Logger()->Write('Cacher GC: Begin');
$this->logWrite('Cacher GC: Begin');
$this->Cacher()->GC(48);
$this->Logger()->Write('Cacher GC: End');
$this->logWrite('Cacher GC: End');
$this->Logger()->Write('Storage GC: Begin');
$this->logWrite('Storage GC: Begin');
$this->StorageProvider()->GC();
$this->Logger()->Write('Storage GC: End');
$this->logWrite('Storage GC: End');
} else if ($bFilesCache) {
$this->Logger()->Write('Files GC: Begin');
$this->logWrite('Files GC: Begin');
$this->FilesProvider()->GC(48);
$this->Logger()->Write('Files GC: End');
$this->logWrite('Files GC: End');
}
$this->Plugins()->RunHook('service.app-delay-start-end');

View file

@ -32,13 +32,13 @@ trait UserAuth
}
if (!\str_contains($sEmail, '@')) {
$this->Logger()->Write('The email address "' . $sEmail . '" is not complete', \LOG_INFO, 'LOGIN');
$this->logWrite('The email address "' . $sEmail . '" is not complete', \LOG_INFO, 'LOGIN');
$bAdded = false;
if ($this->Config()->Get('login', 'determine_user_domain', false)) {
$sUserHost = \trim($this->Http()->GetHost(true, true));
$this->Logger()->Write('Determined user domain: ' . $sUserHost, \LOG_INFO, 'LOGIN');
$this->logWrite('Determined user domain: ' . $sUserHost, \LOG_INFO, 'LOGIN');
$aDomainParts = \explode('.', $sUserHost);
$iLimit = \min(\count($aDomainParts), 14);
@ -50,13 +50,13 @@ trait UserAuth
$oDomain = $oDomainProvider->Load($sLine, false);
if ($oDomain) {
$bAdded = true;
$this->Logger()->Write('Check "' . $sLine . '": OK (' . $sEmail . ' > ' . $sEmail . '@' . $sLine . ')',
$this->logWrite('Check "' . $sLine . '": OK (' . $sEmail . ' > ' . $sEmail . '@' . $sLine . ')',
\LOG_INFO, 'LOGIN');
$sEmail .= '@' . $sLine;
break;
} else {
$this->Logger()->Write('Check "' . $sLine . '": NO', \LOG_INFO, 'LOGIN');
$this->logWrite('Check "' . $sLine . '": NO', \LOG_INFO, 'LOGIN');
}
\array_shift($aDomainParts);
@ -66,17 +66,17 @@ trait UserAuth
$oDomain = $oDomainProvider->Load($sUserHost, true);
if ($oDomain) {
$bAdded = true;
$this->Logger()->Write('Check "' . $sUserHost . '" with wildcard: OK (' . $sEmail . ' > ' . $sEmail . '@' . $sUserHost . ')',
$this->logWrite('Check "' . $sUserHost . '" with wildcard: OK (' . $sEmail . ' > ' . $sEmail . '@' . $sUserHost . ')',
\LOG_INFO, 'LOGIN');
$sEmail .= '@' . $sUserHost;
} else {
$this->Logger()->Write('Check "' . $sUserHost . '" with wildcard: NO', \LOG_INFO, 'LOGIN');
$this->logWrite('Check "' . $sUserHost . '" with wildcard: NO', \LOG_INFO, 'LOGIN');
}
}
if (!$bAdded) {
$this->Logger()->Write('Domain was not found!', \LOG_INFO, 'LOGIN');
$this->logWrite('Domain was not found!', \LOG_INFO, 'LOGIN');
}
}
@ -88,12 +88,12 @@ trait UserAuth
} else if ('gethostname' === $sDefDomain) {
$sDefDomain = \gethostname();
}
$this->Logger()->Write('Default domain "' . $sDefDomain . '" was used. (' . $sEmail . ' > ' . $sEmail . '@' . $sDefDomain . ')',
$this->logWrite('Default domain "' . $sDefDomain . '" was used. (' . $sEmail . ' > ' . $sEmail . '@' . $sDefDomain . ')',
\LOG_INFO, 'LOGIN');
$sEmail .= '@' . $sDefDomain;
} else {
$this->Logger()->Write('Default domain not configured.', \LOG_INFO, 'LOGIN');
$this->logWrite('Default domain not configured.', \LOG_INFO, 'LOGIN');
}
}
}
@ -105,9 +105,9 @@ trait UserAuth
$sLogin = \mb_strtolower($sLogin);
}
$this->Logger()->AddSecret($sPassword);
$this->logMask($sPassword);
$this->Plugins()->RunHook('login.credentials', array(&$sEmail, &$sLogin, &$sPassword));
$this->Logger()->AddSecret($sPassword);
$this->logMask($sPassword);
}
/**

View file

@ -105,7 +105,7 @@ class ActionsAdmin extends Actions
$sLogin = trim($this->GetActionParam('Login', ''));
$sPassword = $this->GetActionParam('Password', '');
$this->Logger()->AddSecret($sPassword);
$this->logMask($sPassword);
$totp = $this->Config()->Get('security', 'admin_totp', '');
@ -172,11 +172,11 @@ class ActionsAdmin extends Actions
$oConfig = $this->Config();
$sPassword = $this->GetActionParam('Password', '');
$this->Logger()->AddSecret($sPassword);
$this->logMask($sPassword);
$sNewPassword = $this->GetActionParam('newPassword', '');
if (\strlen($sNewPassword)) {
$this->Logger()->AddSecret($sNewPassword);
$this->logMask($sNewPassword);
}
$passfile = APP_PRIVATE_DATA.'admin_password.txt';

View file

@ -4,6 +4,8 @@ namespace RainLoop\Common;
abstract class PdoAbstract
{
use \MailSo\Log\Inherit;
/**
* @var \PDO
*/
@ -19,11 +21,6 @@ abstract class PdoAbstract
*/
protected $bSqliteCollate = true;
/**
* @var \MailSo\Log\Logger
*/
protected $oLogger;
/**
* @var string
*/
@ -34,11 +31,6 @@ abstract class PdoAbstract
return !!\class_exists('PDO');
}
public function SetLogger(?\MailSo\Log\Logger $oLogger)
{
$this->oLogger = $oLogger;
}
protected function getPdoAccessData() : array
{
return array('', '', '', '');
@ -98,7 +90,7 @@ abstract class PdoAbstract
// $bCaseFunc = true;
// }
// }
// $this->oLogger->Write('PDO:'.$sPdoType.($bCaseFunc ? '/SQLITE_NOCASE_UTF8' : ''));
// $this->logWrite('PDO:'.$sPdoType.($bCaseFunc ? '/SQLITE_NOCASE_UTF8' : ''));
$this->oPDO = $oPdo;
return $oPdo;

View file

@ -190,18 +190,18 @@ abstract class Account implements \JsonSerializable
if (isset($aAccountHash['name'])) {
$oAccount->sName = $aAccountHash['name'];
}
$oActions->Logger()->AddSecret($oAccount->sPassword);
$oActions->logMask($oAccount->sPassword);
// init smtp user/password
if (isset($aAccountHash['smtp'])) {
$oAccount->sSmtpLogin = $aAccountHash['smtp']['user'];
$oAccount->sSmtpPassword = $aAccountHash['smtp']['pass'];
$oActions->Logger()->AddSecret($oAccount->sSmtpPassword);
$oActions->logMask($oAccount->sSmtpPassword);
}
// init proxy user/password
if (isset($aAccountHash['proxy'])) {
$oAccount->sProxyAuthUser = $aAccountHash['proxy']['user'];
$oAccount->sProxyAuthPassword = $aAccountHash['proxy']['pass'];
$oActions->Logger()->AddSecret($oAccount->sProxyAuthPassword);
$oActions->logMask($oAccount->sProxyAuthPassword);
}
}
}

View file

@ -4,6 +4,8 @@ namespace RainLoop\Plugins;
class Manager
{
use \MailSo\Log\Inherit;
/**
* @var \RainLoop\Actions
*/
@ -21,14 +23,8 @@ class Manager
private bool $bIsEnabled;
/**
* @var \MailSo\Log\Logger
*/
private $oLogger;
public function __construct(\RainLoop\Actions $oActions)
{
$this->oLogger = null;
$this->oActions = $oActions;
$oConfig = $oActions->Config();
@ -121,8 +117,7 @@ class Manager
}
}
} else {
$this->oActions->Logger()->Write('Cannot get installed plugins from '.APP_PLUGINS_PATH,
\LOG_ERR);
$this->oActions->logWrite('Cannot get installed plugins from '.APP_PLUGINS_PATH, \LOG_ERR);
}
return $aList;
@ -478,24 +473,13 @@ class Manager
return $this->bIsEnabled ? \count($this->aPlugins) : 0;
}
public function SetLogger(\MailSo\Log\Logger $oLogger) : self
{
$this->oLogger = $oLogger;
return $this;
}
public function WriteLog(string $sDesc, int $iType = \LOG_INFO) : void
{
if ($this->oLogger) {
$this->oLogger->Write($sDesc, $iType, 'PLUGIN');
}
$this->logWrite($sDesc, $iType, 'PLUGIN');
}
public function WriteException(string $sDesc, int $iType = \LOG_INFO) : void
{
if ($this->oLogger) {
$this->oLogger->WriteException($sDesc, $iType, 'PLUGIN');
}
$this->logException($sDesc, $iType, 'PLUGIN');
}
}

View file

@ -4,16 +4,13 @@ namespace RainLoop\Providers;
abstract class AbstractProvider
{
use \MailSo\Log\Inherit;
/**
* @var \RainLoop\Model\Account
*/
protected $oAccount;
/**
* @var \MailSo\Log\Logger
*/
protected $oLogger = null;
public function IsActive() : bool
{
return false;
@ -23,14 +20,4 @@ abstract class AbstractProvider
{
$this->oAccount = $oAccount;
}
public function SetLogger(?\MailSo\Log\Logger $oLogger)
{
$this->oLogger = $oLogger;
}
public function Logger() : ?\MailSo\Log\Logger
{
return $this->oLogger;
}
}

View file

@ -36,7 +36,7 @@ trait CardDAV
}
catch (\Throwable $oException)
{
$this->oLogger->WriteException($oException);
$this->logException($oException);
}
/**
@ -88,7 +88,7 @@ trait CardDAV
{
\MailSo\Base\Utils::ResetTimeLimit();
$this->oLogger->Write($sCmd.' '.$sUrl.(('PUT' === $sCmd || 'POST' === $sCmd) && null !== $mData ? ' ('.\strlen($mData).')' : ''),
$this->logWrite($sCmd.' '.$sUrl.(('PUT' === $sCmd || 'POST' === $sCmd) && null !== $mData ? ' ('.\strlen($mData).')' : ''),
\LOG_INFO, 'DAV');
try
@ -105,7 +105,7 @@ trait CardDAV
}
catch (\Throwable $oException)
{
$this->oLogger->WriteException($oException);
$this->logException($oException);
}
return null;
@ -124,7 +124,7 @@ trait CardDAV
}
catch (\Throwable $oException)
{
$this->oLogger->WriteException($oException);
$this->logException($oException);
}
return null;
@ -271,7 +271,7 @@ trait CardDAV
}
catch (\Throwable $oException)
{
$this->oLogger->WriteException($oException);
$this->logException($oException);
}
$bGood = false;
@ -316,7 +316,7 @@ trait CardDAV
'password' => $sPassword
);
$this->oLogger->AddSecret($sPassword);
$this->logMask($sPassword);
if (!empty($sProxy)) {
$aSettings['proxy'] = $sProxy;
@ -327,7 +327,7 @@ trait CardDAV
$oClient->__UrlPath__ = $aUrl['path'];
$this->oLogger->Write('DavClient: User: '.$aSettings['userName'].', Url: '.$sUrl, \LOG_INFO, 'DAV');
$this->logWrite('DavClient: User: '.$aSettings['userName'].', Url: '.$sUrl, \LOG_INFO, 'DAV');
return $oClient;
}
@ -398,7 +398,7 @@ trait CardDAV
$bGood = $sNewPath && $this->checkContactsPath($oClient, $sNewPath);
if (!$bGood) {
$this->oLogger->Write('Contacts path not found at: '.$sPath, \LOG_INFO, 'DAV');
$this->logWrite('Contacts path not found at: '.$sPath, \LOG_INFO, 'DAV');
}
}

View file

@ -275,10 +275,8 @@ class PdoAddressBook
try {
$oVCard = \Sabre\VObject\Reader::read($sBody);
} catch (\Throwable $oExc) {
if ($this->oLogger) {
$this->oLogger->WriteException($oExc);
$this->oLogger->WriteDump($sBody);
}
$this->logException($oExc);
$this->oLogger && $this->oLogger->WriteDump($sBody);
}
}
}
@ -341,7 +339,7 @@ class PdoAddressBook
}
}
} catch (\Throwable $oExc) {
$this->oLogger && $this->oLogger->WriteException($oExc);
$this->logException($oExc);
}
}
}

View file

@ -4,12 +4,9 @@ namespace RainLoop\Providers\Filters;
class SieveStorage implements FiltersInterface
{
const SIEVE_FILE_NAME = 'rainloop.user';
use \MailSo\Log\Inherit;
/**
* @var \MailSo\Log\Logger
*/
private $oLogger;
const SIEVE_FILE_NAME = 'rainloop.user';
/**
* @var \RainLoop\Plugins\Manager
@ -23,8 +20,6 @@ class SieveStorage implements FiltersInterface
public function __construct($oPlugins, $oConfig)
{
$this->oLogger = null;
$this->oPlugins = $oPlugins;
$this->oConfig = $oConfig;
}
@ -123,9 +118,4 @@ class SieveStorage implements FiltersInterface
}
return false;
}
public function SetLogger(?\MailSo\Log\Logger $oLogger)
{
$this->oLogger = $oLogger;
}
}

View file

@ -6,6 +6,8 @@ use RainLoop\Providers\Storage\Enumerations\StorageType;
class FileStorage implements \RainLoop\Providers\Storage\IStorage
{
use \MailSo\Log\Inherit;
/**
* @var string
*/
@ -16,16 +18,10 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
*/
private $bLocal;
/**
* @var \MailSo\Log\Logger
*/
protected $oLogger;
public function __construct(string $sStoragePath, bool $bLocal = false)
{
$this->sDataPath = \rtrim(\trim($sStoragePath), '\\/');
$this->bLocal = $bLocal;
$this->oLogger = null;
}
/**
@ -169,11 +165,6 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
return $sFilePath;
}
public function SetLogger(?\MailSo\Log\Logger $oLogger)
{
$this->oLogger = $oLogger;
}
public function GC() : void
{
\clearstatcache();

View file

@ -47,7 +47,7 @@ class Suggestions extends \RainLoop\Providers\AbstractProvider
}
catch (\Throwable $oException)
{
$this->oLogger && $this->oLogger->WriteException($oException);
$this->logException($oException);
}
// Extensions/Plugins
@ -67,7 +67,7 @@ class Suggestions extends \RainLoop\Providers\AbstractProvider
}
}
} catch (\Throwable $oException) {
$this->oLogger && $this->oLogger->WriteException($oException);
$this->logException($oException);
}
}

View file

@ -20,7 +20,7 @@ class Sync
$this->oImapSource->TAG_PREFIX = 'S';
$this->oImapTarget->TAG_PREFIX = 'T';
// $this->oImapTarget->Logger()->Write('Get oImapTarget->FolderList');
// $this->oImapTarget->logWrite('Get oImapTarget->FolderList');
\SnappyMail\Log::notice('SYNC', 'Get oImapTarget->FolderList');
$aTargetFolders = $this->oImapTarget->FolderList($sParent, $sListPattern);
if (!$aTargetFolders) {