Privacy/GDPR friendly version (removed: Social, Gravatar, Facebook, Google, Twitter, DropBox, OwnCloud)

Also removed: POP3, OAuth2 and update feature
Added: admin password_hash/password_verify
Requires: PHP 7.3+
Replaced: CRLF with LF
Replaced: pclZip with ZipArchive
This commit is contained in:
djmaze 2020-03-09 17:04:17 +01:00
parent 15ceddc202
commit 2cada68f41
293 changed files with 23728 additions and 85420 deletions

View file

@ -8,37 +8,25 @@ abstract class AbstractProvider
* @var \RainLoop\Model\Account
*/
protected $oAccount;
/**
* @var \MailSo\Log\Logger
*/
protected $oLogger = null;
/**
* @return bool
*/
public function IsActive()
public function IsActive() : bool
{
return false;
}
/**
* @param \RainLoop\Model\Account $oAccount
*/
public function SetAccount($oAccount)
public function SetAccount(\RainLoop\Model\Account $oAccount)
{
$this->oAccount = $oAccount;
}
/**
* @param \MailSo\Log\Logger $oLogger
*/
public function SetLogger($oLogger)
public function SetLogger(?\MailSo\Log\Logger $oLogger)
{
if ($oLogger instanceof \MailSo\Log\Logger)
{
$this->oLogger = $oLogger;
}
$this->oLogger = $oLogger;
}
/**

View file

@ -12,171 +12,93 @@ class AddressBook extends \RainLoop\Providers\AbstractProvider
private $oDriver;
/**
* @param \RainLoop\Providers\AddressBook\Interface $oDriver
*
* @return void
*/
public function __construct($oDriver)
public function __construct(?\RainLoop\Providers\AddressBook\AddressBookInterface $oDriver)
{
$this->oDriver = null;
if ($oDriver instanceof \RainLoop\Providers\AddressBook\AddressBookInterface)
{
$this->oDriver = $oDriver;
}
$this->oDriver = $oDriver;
}
/**
* @return string
*/
public function Test()
public function Test() : string
{
\sleep(1);
return $this->oDriver instanceof \RainLoop\Providers\AddressBook\AddressBookInterface ?
$this->oDriver->Test() : 'Personal address book driver is not allowed';
}
/**
* @return bool
*/
public function IsActive()
public function IsActive() : bool
{
return $this->oDriver instanceof \RainLoop\Providers\AddressBook\AddressBookInterface &&
$this->oDriver->IsSupported();
}
/**
* @return bool
*/
public function IsSupported()
public function IsSupported() : bool
{
return $this->oDriver instanceof \RainLoop\Providers\AddressBook\AddressBookInterface &&
$this->oDriver->IsSupported();
}
/**
* @return bool
*/
public function IsSharingAllowed()
public function IsSharingAllowed() : bool
{
return $this->oDriver instanceof \RainLoop\Providers\AddressBook\AddressBookInterface &&
$this->oDriver->IsSharingAllowed();
}
/**
* @param string $sEmail
* @param string $sUrl
* @param string $sUser
* @param string $sPassword
*
* @return bool
*/
public function Sync($sEmail, $sUrl, $sUser, $sPassword)
public function Sync(string $sEmail, string $sUrl, string $sUser, string $sPassword) : bool
{
return $this->IsActive() ? $this->oDriver->Sync($sEmail, $sUrl, $sUser, $sPassword) : false;
}
/**
* @param string $sEmail
* @param string $sType = 'vcf'
*
* @return bool
*/
public function Export($sEmail, $sType = 'vcf')
public function Export(string $sEmail, string $sType = 'vcf') : bool
{
return $this->IsActive() ? $this->oDriver->Export($sEmail, $sType) : false;
}
/**
* @param string $sEmail
* @param \RainLoop\Providers\AddressBook\Classes\Contact $oContact
*
* @return bool
*/
public function ContactSave($sEmail, &$oContact)
public function ContactSave(string $sEmail, \RainLoop\Providers\AddressBook\Classes\Contact $oContact) : bool
{
return $this->IsActive() ? $this->oDriver->ContactSave($sEmail, $oContact) : false;
}
/**
* @param string $sEmail
* @param array $aContactIds
*
* @return bool
*/
public function DeleteContacts($sEmail, $aContactIds)
public function DeleteContacts(string $sEmail, array $aContactIds) : bool
{
return $this->IsActive() ? $this->oDriver->DeleteContacts($sEmail, $aContactIds) : false;
}
/**
* @param string $sEmail
*
* @return bool
*/
public function DeleteAllContacts($sEmail)
public function DeleteAllContacts(string $sEmail) : bool
{
return $this->IsActive() ? $this->oDriver->DeleteAllContacts($sEmail) : false;
}
/**
* @param string $sEmail
* @param int $iOffset = 0
* @param type $iLimit = 20
* @param string $sSearch = ''
* @param int $iResultCount = 0
*
* @return array
*/
public function GetContacts($sEmail, $iOffset = 0, $iLimit = 20, $sSearch = '', &$iResultCount = 0)
public function GetContacts(string $sEmail, int $iOffset = 0, int $iLimit = 20, string $sSearch = '', int &$iResultCount = 0) : array
{
return $this->IsActive() ? $this->oDriver->GetContacts($sEmail,
$iOffset, $iLimit, $sSearch, $iResultCount) : array();
}
/**
* @param string $sEmail
* @param string $mID
* @param bool $bIsStrID = false
*
* @return \RainLoop\Providers\AddressBook\Classes\Contact|null
*/
public function GetContactByID($sEmail, $mID, $bIsStrID = false)
public function GetContactByID(string $sEmail, $mID, bool $bIsStrID = false)
{
return $this->IsActive() ? $this->oDriver->GetContactByID($sEmail, $mID, $bIsStrID) : null;
}
/**
* @param string $sEmail
* @param string $sSearch
* @param int $iLimit = 20
*
* @return array
*
* @throws \InvalidArgumentException
*/
public function GetSuggestions($sEmail, $sSearch, $iLimit = 20)
public function GetSuggestions(string $sEmail, string $sSearch, int $iLimit = 20) : array
{
return $this->IsActive() ? $this->oDriver->GetSuggestions($sEmail, $sSearch, $iLimit) : array();
}
/**
* @param string $sEmail
* @param array $aEmails
* @param bool $bCreateAuto = true
*
* @return bool
*/
public function IncFrec($sEmail, $aEmails, $bCreateAuto = true)
public function IncFrec(string $sEmail, array $aEmails, bool $bCreateAuto = true) : bool
{
return $this->IsActive() ? $this->oDriver->IncFrec($sEmail, $aEmails, $bCreateAuto) : false;
}
/**
* @param string $sCsvName
*
* @return int
*/
private function csvNameToTypeConvertor($sCsvName)
private function csvNameToTypeConvertor(string $sCsvName) : int
{
static $aMap = null;
if (null === $aMap)
@ -256,13 +178,7 @@ class AddressBook extends \RainLoop\Providers\AbstractProvider
return !empty($sCsvNameLower) && isset($aMap[$sCsvNameLower]) ? $aMap[$sCsvNameLower] : PropertyType::UNKNOWN;
}
/**
* @param string $sEmail
* @param array $aCsvData
*
* @return int
*/
public function ImportCsvArray($sEmail, $aCsvData)
public function ImportCsvArray(string $sEmail, array $aCsvData) : int
{
$iCount = 0;
if ($this->IsActive() && \is_array($aCsvData) && 0 < \count($aCsvData))
@ -311,13 +227,7 @@ class AddressBook extends \RainLoop\Providers\AbstractProvider
return $iCount;
}
/**
* @param string $sEmail
* @param string $sVcfData
*
* @return int
*/
public function ImportVcfFile($sEmail, $sVcfData)
public function ImportVcfFile(string $sEmail, string $sVcfData) : int
{
$iCount = 0;
@ -334,7 +244,7 @@ class AddressBook extends \RainLoop\Providers\AbstractProvider
{
$oVCardSplitter = new \SabreForRainLoop\VObject\Splitter\VCard($sVcfData);
}
catch (\Exception $oExc)
catch (\Throwable $oExc)
{
$this->Logger()->WriteException($oExc);
}

View file

@ -4,8 +4,5 @@ namespace RainLoop\Providers\AddressBook;
interface AddressBookInterface
{
/**
* @return bool
*/
public function IsSupported();
}
public function IsSupported() : bool;
}

View file

@ -66,7 +66,7 @@ class Contact
$this->Etag = '';
}
public function PopulateDisplayAndFullNameValue($bForceFullNameReplace = false)
public function PopulateDisplayAndFullNameValue(bool $bForceFullNameReplace = false)
{
$sFullName = '';
$sLastName = '';
@ -161,19 +161,13 @@ class Contact
$this->PopulateDisplayAndFullNameValue();
}
/**
* @return array
*/
public function RegenerateContactStr()
public function RegenerateContactStr() : array
{
$this->IdContactStr = \class_exists('SabreForRainLoop\DAV\Client') ?
\SabreForRainLoop\DAV\UUIDUtil::getUUID() : \MailSo\Base\Utils::Md5Rand();
}
/**
* @return array
*/
public function GetEmails()
public function GetEmails() : array
{
$aResult = array();
foreach ($this->Properties as /* @var $oProperty \RainLoop\Providers\AddressBook\Classes\Property */ &$oProperty)
@ -187,18 +181,12 @@ class Contact
return \array_unique($aResult);
}
/**
* @return string
*/
public function CardDavNameUri()
public function CardDavNameUri() : string
{
return $this->IdContactStr.'.vcf';
}
/**
* @return string
*/
public function ToVCard($sPreVCard = '', $oLogger = null)
public function ToVCard(string $sPreVCard = '', $oLogger = null) : string
{
$this->UpdateDependentValues();
@ -219,7 +207,7 @@ class Contact
{
$oVCard = \SabreForRainLoop\VObject\Reader::read($sPreVCard);
}
catch (\Exception $oExc)
catch (\Throwable $oExc)
{
if ($oLogger)
{
@ -309,10 +297,7 @@ class Contact
return (string) $oVCard->serialize();
}
/**
* @return string
*/
public function ToCsv($bWithHeader = false)
public function ToCsv(bool $bWithHeader = false) : string
{
$aData = array();
if ($bWithHeader)
@ -470,10 +455,8 @@ class Contact
/**
* @param mixed $oProp
* @param bool $bOldVersion
* @return string
*/
private function getPropertyValueHelper($oProp, $bOldVersion)
private function getPropertyValueHelper($oProp, bool $bOldVersion) : string
{
$sValue = \trim($oProp);
if ($bOldVersion && !isset($oProp->parameters['CHARSET']))
@ -495,10 +478,8 @@ class Contact
/**
* @param mixed $oProp
* @param bool $bOldVersion
* @return string
*/
private function addArrayPropertyHelper(&$aProperties, $oArrayProp, $iType)
private function addArrayPropertyHelper(array &$aProperties, $oArrayProp, int $iType) : string
{
foreach ($oArrayProp as $oProp)
{
@ -520,7 +501,7 @@ class Contact
}
}
public function PopulateByVCard($sUid, $sVCard, $sEtag = '', $oLogger = null)
public function PopulateByVCard(string $sUid, string $sVCard, string $sEtag = '', $oLogger = null)
{
if ("\xef\xbb\xbf" === \substr($sVCard, 0, 3))
{
@ -545,7 +526,7 @@ class Contact
{
$oVCard = \SabreForRainLoop\VObject\Reader::read($sVCard);
}
catch (\Exception $oExc)
catch (\Throwable $oExc)
{
if ($oLogger)
{
@ -559,14 +540,10 @@ class Contact
// $oLogger->WriteDump($sVCard);
// }
$bOwnCloud = false;
$aProperties = array();
if ($oVCard)
{
$bOwnCloud = empty($oVCard->PRODID) ? false :
false !== \strpos(\strtolower($oVCard->PRODID), 'owncloud');
$bOldVersion = empty($oVCard->VERSION) ? false :
\in_array((string) $oVCard->VERSION, array('2.1', '2.0', '1.0'));

View file

@ -65,51 +65,33 @@ class Property
$this->Frec = 0;
}
/**
* @return bool
*/
public function IsName()
public function IsName() : bool
{
return \in_array($this->Type, array(PropertyType::FULLNAME, PropertyType::FIRST_NAME,
PropertyType::LAST_NAME, PropertyType::MIDDLE_NAME, PropertyType::NICK_NAME));
}
/**
* @return bool
*/
public function IsEmail()
public function IsEmail() : bool
{
return PropertyType::EMAIl === $this->Type;
}
/**
* @return bool
*/
public function IsPhone()
public function IsPhone() : bool
{
return PropertyType::PHONE === $this->Type;
}
/**
* @return bool
*/
public function IsWeb()
public function IsWeb() : bool
{
return PropertyType::WEB_PAGE === $this->Type;
}
/**
* @return bool
*/
public function IsValueForLower()
public function IsValueForLower() : bool
{
return $this->IsEmail() || $this->IsName() || $this->IsWeb();
}
/**
* @return bool
*/
public function TypesAsArray()
public function TypesAsArray() : bool
{
$aResult = array();
if (!empty($this->TypeStr))
@ -121,10 +103,7 @@ class Property
return $aResult;
}
/**
* @return array
*/
public function TypesUpperAsArray()
public function TypesUpperAsArray() : array
{
return \array_map('strtoupper', $this->TypesAsArray());
}

View file

@ -28,7 +28,7 @@ class PdoAddressBook
*/
private $sPassword;
public function __construct($sDsn, $sUser = '', $sPassword = '', $sDsnType = 'mysql')
public function __construct(string $sDsn, string $sUser = '', string $sPassword = '', string $sDsnType = 'mysql')
{
$this->sDsn = $sDsn;
$this->sUser = $sUser;
@ -38,31 +38,25 @@ class PdoAddressBook
$this->bExplain = false; // debug
}
/**
* @return bool
*/
public function IsSupported()
public function IsSupported() : bool
{
$aDrivers = \class_exists('PDO') ? \PDO::getAvailableDrivers() : array();
return \is_array($aDrivers) ? \in_array($this->sDsnType, $aDrivers) : false;
}
/**
* @return bool
*/
public function IsSharingAllowed()
public function IsSharingAllowed() : bool
{
return $this->IsSupported() && false; // TODO
}
private function flushDeletedContacts($iUserID)
private function flushDeletedContacts(int $iUserID)
{
return !!$this->prepareAndExecute('DELETE FROM rainloop_ab_contacts WHERE id_user = :id_user AND deleted = 1', array(
':id_user' => array($iUserID, \PDO::PARAM_INT)
));
}
private function updateContactEtagAndTime($iUserID, $mID, $sEtag, $iChanged)
private function updateContactEtagAndTime(int $iUserID, int $mID, string $sEtag, int $iChanged)
{
return !!$this->prepareAndExecute('UPDATE rainloop_ab_contacts SET changed = :changed, etag = :etag '.
'WHERE id_user = :id_user AND id_contact = :id_contact', array(
@ -74,7 +68,7 @@ class PdoAddressBook
);
}
private function prepearDatabaseSyncData($iUserID)
private function prepearDatabaseSyncData(int $iUserID)
{
$aResult = array();
$oStmt = $this->prepareAndExecute('SELECT id_contact, id_contact_str, changed, deleted, etag FROM rainloop_ab_contacts WHERE id_user = :id_user', array(
@ -110,7 +104,7 @@ class PdoAddressBook
return $aResult;
}
private function prepearRemoteSyncData($oClient, $sPath)
private function prepearRemoteSyncData($oClient, string $sPath)
{
$mResult = false;
$aResponse = null;
@ -126,7 +120,7 @@ class PdoAddressBook
// $this->oLogger->WriteDump($aResponse);
}
catch (\Exception $oException)
catch (\Throwable $oException)
{
$this->oLogger->WriteException($oException);
}
@ -181,7 +175,7 @@ class PdoAddressBook
return $mResult;
}
private function davClientRequest($oClient, $sCmd, $sUrl, $mData = null)
private function davClientRequest($oClient, string $sCmd, string $sUrl, $mData = null)
{
\MailSo\Base\Utils::ResetTimeLimit();
@ -212,7 +206,7 @@ class PdoAddressBook
// $this->oLogger->WriteDump($oResponse, \MailSo\Log\Enumerations\Type::INFO, 'DAV');
// }
}
catch (\Exception $oException)
catch (\Throwable $oException)
{
$this->oLogger->WriteException($oException);
}
@ -220,13 +214,7 @@ class PdoAddressBook
return $oResponse;
}
/**
* @param \SabreForRainLoop\DAV\Client $oClient
* @param string $sPath
*
* @return bool
*/
private function detectionPropFind($oClient, $sPath)
private function detectionPropFind(\SabreForRainLoop\DAV\Client $oClient, string $sPath) : bool
{
$aResponse = null;
@ -243,7 +231,7 @@ class PdoAddressBook
// $this->oLogger->WriteDump($aResponse);
}
catch (\Exception $oException)
catch (\Throwable $oException)
{
$this->oLogger->WriteException($oException);
}
@ -251,15 +239,7 @@ class PdoAddressBook
return $aResponse;
}
/**
* @param \SabreForRainLoop\DAV\Client $oClient
* @param string $sUser
* @param string $sPassword
* @param string $sProxy = ''
*
* @return array
*/
private function getContactsPaths(&$oClient, $sUser, $sPassword, $sProxy = '')
private function getContactsPaths(\SabreForRainLoop\DAV\Client &$oClient, string $sUser, string $sPassword, string $sProxy = '') : array
{
$aContactsPaths = array();
@ -445,13 +425,7 @@ class PdoAddressBook
return $aContactsPaths;
}
/**
* @param \SabreForRainLoop\DAV\Client $oClient
* @param string $sPath
*
* @return bool
*/
private function checkContactsPath(&$oClient, $sPath)
private function checkContactsPath(\SabreForRainLoop\DAV\Client &$oClient, string $sPath) : bool
{
if (!$oClient)
{
@ -469,7 +443,7 @@ class PdoAddressBook
// $this->oLogger->WriteDump($aResponse);
}
catch (\Exception $oException)
catch (\Throwable $oException)
{
$this->oLogger->WriteException($oException);
}
@ -501,7 +475,7 @@ class PdoAddressBook
return $bGood;
}
public function getDavClientFromUrl($sUrl, $sUser, $sPassword, $sProxy = '')
public function getDavClientFromUrl(string $sUrl, string $sUser, string $sPassword, string $sProxy = '')
{
if (!\preg_match('/^http[s]?:\/\//i', $sUrl))
{
@ -553,16 +527,7 @@ class PdoAddressBook
return $oClient;
}
/**
* @param string $sEmail
* @param string $sUrl
* @param string $sUser
* @param string $sPassword
* @param string $sProxy = ''
*
* @return bool
*/
public function getDavClient($sUrl, $sUser, $sPassword, $sProxy = '')
public function getDavClient(string $sUrl, string $sUser, string $sPassword, string $sProxy = '') : bool
{
if (!\class_exists('SabreForRainLoop\DAV\Client'))
{
@ -655,16 +620,7 @@ class PdoAddressBook
return $oClient;
}
/**
* @param string $sEmail
* @param string $sUrl
* @param string $sUser
* @param string $sPassword
* @param string $sProxy = ''
*
* @return bool
*/
public function Sync($sEmail, $sUrl, $sUser, $sPassword, $sProxy = '')
public function Sync(string $sEmail, string $sUrl, string $sUser, string $sPassword, string $sProxy = '') : bool
{
$this->SyncDatabase();
@ -815,13 +771,7 @@ class PdoAddressBook
return true;
}
/**
* @param string $sEmail
* @param string $sType = 'vcf'
*
* @return bool
*/
public function Export($sEmail, $sType = 'vcf')
public function Export(string $sEmail, string $sType = 'vcf') : bool
{
$this->SyncDatabase();
@ -861,14 +811,7 @@ class PdoAddressBook
return true;
}
/**
* @param string $sEmail
* @param \RainLoop\Providers\AddressBook\Classes\Contact $oContact
* @param bool $bSyncDb = true
*
* @return bool
*/
public function ContactSave($sEmail, &$oContact, $bSyncDb = true)
public function ContactSave(string $sEmail, \RainLoop\Providers\AddressBook\Classes\Contact $oContact, bool $bSyncDb = true) : bool
{
if ($bSyncDb)
{
@ -973,7 +916,7 @@ class PdoAddressBook
}
}
}
catch (\Exception $oException)
catch (\Throwable $oException)
{
throw $oException;
}
@ -981,14 +924,7 @@ class PdoAddressBook
return 0 < $iIdContact;
}
/**
* @param string $sEmail
* @param array $aContactIds
* @param bool $bSyncDb = true
*
* @return bool
*/
public function DeleteContacts($sEmail, $aContactIds, $bSyncDb = true)
public function DeleteContacts(string $sEmail, array $aContactIds, bool $bSyncDb = true) : bool
{
if ($bSyncDb)
{
@ -1023,13 +959,7 @@ class PdoAddressBook
return true;
}
/**
* @param string $sEmail
* @param bool $bSyncDb = true
*
* @return bool
*/
public function DeleteAllContacts($sEmail, $bSyncDb = true)
public function DeleteAllContacts(string $sEmail, bool $bSyncDb = true) : bool
{
if ($bSyncDb)
{
@ -1046,16 +976,7 @@ class PdoAddressBook
return true;
}
/**
* @param string $sEmail
* @param int $iOffset = 0
* @param int $iLimit = 20
* @param string $sSearch = ''
* @param int $iResultCount = 0
*
* @return array
*/
public function GetContacts($sEmail, $iOffset = 0, $iLimit = 20, $sSearch = '', &$iResultCount = 0)
public function GetContacts(string $sEmail, int $iOffset = 0, int $iLimit = 20, string $sSearch = '', int &$iResultCount = 0) : array
{
$this->SyncDatabase();
@ -1246,13 +1167,11 @@ class PdoAddressBook
}
/**
* @param string $sEmail
* @param string $mID
* @param bool $bIsStrID = false
* @param mixed $mID
*
* @return \RainLoop\Providers\AddressBook\Classes\Contact|null
*/
public function GetContactByID($sEmail, $mID, $bIsStrID = false)
public function GetContactByID(string $sEmail, $mID, bool $bIsStrID = false)
{
$mID = \trim($mID);
@ -1350,15 +1269,9 @@ class PdoAddressBook
}
/**
* @param string $sEmail
* @param string $sSearch
* @param int $iLimit = 20
*
* @return array
*
* @throws \InvalidArgumentException
*/
public function GetSuggestions($sEmail, $sSearch, $iLimit = 20)
public function GetSuggestions(string $sEmail, string $sSearch, int $iLimit = 20) : array
{
$sSearch = \trim($sSearch);
if (0 === \strlen($sSearch))
@ -1553,14 +1466,7 @@ class PdoAddressBook
return array();
}
/**
* @param string $sEmail
* @param array $aEmails
* @param bool $bCreateAuto = true
*
* @return bool
*/
public function IncFrec($sEmail, $aEmails, $bCreateAuto = true)
public function IncFrec(string $sEmail, array $aEmails, bool $bCreateAuto = true) : bool
{
$self = $this;
$aEmailsObjects = \array_map(function ($mItem) {
@ -1569,7 +1475,7 @@ class PdoAddressBook
{
$oResult = \MailSo\Mime\Email::Parse(\trim($mItem));
}
catch (\Exception $oException) { unset($oException); }
catch (\Throwable $oException) { unset($oException); }
return $oResult;
}, $aEmails);
@ -1721,10 +1627,7 @@ class PdoAddressBook
));
}
/**
* @return string
*/
public function Test()
public function Test() : string
{
$sResult = '';
try
@ -1735,7 +1638,7 @@ class PdoAddressBook
$sResult = 'Unknown database error';
}
}
catch (\Exception $oException)
catch (\Throwable $oException)
{
$sResult = $oException->getMessage();
if (!empty($sResult) && !\MailSo\Base\Utils::IsAscii($sResult) && !\MailSo\Base\Utils::IsUtf8($sResult))
@ -1752,7 +1655,7 @@ class PdoAddressBook
return $sResult;
}
private function getInitialTablesArray($sDbType)
private function getInitialTablesArray(string $sDbType)
{
switch ($sDbType)
{
@ -1876,10 +1779,7 @@ SQLITEINITIAL;
return $aResult;
}
/**
* @return bool
*/
public function SyncDatabase()
public function SyncDatabase() : bool
{
static $mCache = null;
if (null !== $mCache)
@ -1926,12 +1826,7 @@ SQLITEINITIAL;
return $mCache;
}
/**
* @param int $iUserID
* @param int $iIdContact
* @return array
*/
private function getContactFreq($iUserID, $iIdContact)
private function getContactFreq(int $iUserID, int $iIdContact) : array
{
$aResult = array();
@ -1961,25 +1856,13 @@ SQLITEINITIAL;
return $aResult;
}
/**
* @param string $sSearch
* @param string $sEscapeSign = '='
*
* @return string
*/
private function specialConvertSearchValue($sSearch, $sEscapeSign = '=')
private function specialConvertSearchValue(string $sSearch, string $sEscapeSign = '=') : string
{
return '%'.\str_replace(array($sEscapeSign, '_', '%'),
array($sEscapeSign.$sEscapeSign, $sEscapeSign.'_', $sEscapeSign.'%'), $sSearch).'%';
}
/**
* @param string $sSearch
* @param string $sEscapeSign = '='
*
* @return string
*/
private function specialConvertSearchValueLower($sSearch, $sEscapeSign = '=')
private function specialConvertSearchValueLower(string $sSearch, string $sEscapeSign = '=') : string
{
if (!\MailSo\Base\Utils::FunctionExistsAndEnabled('mb_strtolower'))
{
@ -1991,22 +1874,14 @@ SQLITEINITIAL;
(string) @\mb_strtolower($sSearch, 'UTF-8')).'%';
}
/**
* @param string $sSearch
*
* @return string
*/
private function specialConvertSearchValueCustomPhone($sSearch)
private function specialConvertSearchValueCustomPhone(string $sSearch) : string
{
$sResult = '%'.\preg_replace('/[^\d]/', '', $sSearch).'%';
return '%%' === $sResult ? '' : $sResult;
}
/**
* @return array
*/
protected function getPdoAccessData()
protected function getPdoAccessData() : array
{
return array($this->sDsnType, $this->sDsn, $this->sUser, $this->sPassword);
}
}
}

View file

@ -19,42 +19,24 @@ class ChangePassword extends \RainLoop\Providers\AbstractProvider
*/
private $bCheckWeak;
/**
* @param \RainLoop\Actions $oActions
* @param \RainLoop\Providers\ChangePassword\ChangePasswordInterface|null $oDriver = null
* @param bool $bCheckWeak = true
*
* @return void
*/
public function __construct($oActions, $oDriver = null, $bCheckWeak = true)
public function __construct(\RainLoop\Actions $oActions, ?\RainLoop\Providers\ChangePassword\ChangePasswordInterface $oDriver = null, bool $bCheckWeak = true)
{
$this->oActions = $oActions;
$this->oDriver = $oDriver;
$this->bCheckWeak = !!$bCheckWeak;
$this->bCheckWeak = $bCheckWeak;
}
/**
* @param \RainLoop\Account $oAccount
*
* @return bool
*/
public function PasswordChangePossibility($oAccount)
public function PasswordChangePossibility(\RainLoop\Model\Account $oAccount) : bool
{
return $this->IsActive() &&
$oAccount instanceof \RainLoop\Account &&
$this->oDriver && $this->oDriver->PasswordChangePossibility($oAccount)
;
}
/**
* @param \RainLoop\Account $oAccount
* @param string $sPrevPassword
* @param string $sNewPassword
*/
public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
public function ChangePassword(\RainLoop\Model\Account $oAccount, string $sPrevPassword, string $sNewPassword)
{
$mResult = false;
if ($this->oDriver instanceof \RainLoop\Providers\ChangePassword\ChangePasswordInterface &&
$this->PasswordChangePossibility($oAccount))
{
@ -92,10 +74,7 @@ class ChangePassword extends \RainLoop\Providers\AbstractProvider
return $mResult;
}
/**
* @return bool
*/
public function IsActive()
public function IsActive() : bool
{
return $this->oDriver instanceof \RainLoop\Providers\ChangePassword\ChangePasswordInterface;
}

View file

@ -4,19 +4,7 @@ namespace RainLoop\Providers\ChangePassword;
interface ChangePasswordInterface
{
/**
* @param \RainLoop\Account $oAccount
*
* @return bool
*/
public function PasswordChangePossibility($oAccount);
public function PasswordChangePossibility(\RainLoop\Model\Account $oAccount) : bool;
/**
* @param \RainLoop\Account $oAccount
* @param string $sPrevPassword
* @param string $sNewPassword
*
* @return bool
*/
public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword);
public function ChangePassword(\RainLoop\Model\Account $oAccount, string $sPrevPassword, string $sNewPassword) : bool;
}

View file

@ -19,11 +19,6 @@ class Domain extends \RainLoop\Providers\AbstractProvider
*/
private $bAdmin;
/**
* @param \RainLoop\Providers\Domain\DomainInterface $oDriver
*
* @return void
*/
public function __construct(\RainLoop\Providers\Domain\DomainInterface $oDriver,
\RainLoop\Plugins\Manager $oPlugins)
{
@ -32,23 +27,15 @@ class Domain extends \RainLoop\Providers\AbstractProvider
$this->bAdmin = $this->oDriver instanceof \RainLoop\Providers\Domain\DomainAdminInterface;
}
/**
* @return bool
*/
public function IsAdmin()
public function IsAdmin() : bool
{
return $this->bAdmin;
}
/**
* @param string $sName
* @param bool $bFindWithWildCard = false
* @param bool $bCheckDisabled = true
* @param bool $bCheckAliases = true
*
* @return \RainLoop\Model\Domain|null
*/
public function Load($sName, $bFindWithWildCard = false, $bCheckDisabled = true, $bCheckAliases = true)
public function Load(string $sName, bool $bFindWithWildCard = false, bool $bCheckDisabled = true, bool $bCheckAliases = true)
{
$oDomain = $this->oDriver->Load($sName, $bFindWithWildCard, $bCheckDisabled, $bCheckAliases);
if ($oDomain instanceof \RainLoop\Model\Domain)
@ -59,23 +46,12 @@ class Domain extends \RainLoop\Providers\AbstractProvider
return $oDomain;
}
/**
* @param \RainLoop\Model\Domain $oDomain
*
* @return bool
*/
public function Save(\RainLoop\Model\Domain $oDomain)
public function Save(\RainLoop\Model\Domain $oDomain) : bool
{
return $this->bAdmin ? $this->oDriver->Save($oDomain) : false;
}
/**
* @param string $sName
* @param string $sAlias
*
* @return bool
*/
public function SaveAlias($sName, $sAlias)
public function SaveAlias(string $sName, string $sAlias) : bool
{
if ($this->Load($sName, false, false))
{
@ -85,36 +61,17 @@ class Domain extends \RainLoop\Providers\AbstractProvider
return $this->bAdmin ? $this->oDriver->SaveAlias($sName, $sAlias) : false;
}
/**
* @param string $sName
*
* @return bool
*/
public function Delete($sName)
public function Delete(string $sName) : bool
{
return $this->bAdmin ? $this->oDriver->Delete($sName) : false;
}
/**
* @param string $sName
* @param bool $bDisabled
*
* @return bool
*/
public function Disable($sName, $bDisabled)
public function Disable(string $sName, bool $bDisabled) : bool
{
return $this->bAdmin ? $this->oDriver->Disable($sName, $bDisabled) : false;
}
/**
* @param int $iOffset = 0
* @param int $iLimit = 20
* @param string $sSearch = ''
* @param bool $bIncludeAliases = true
*
* @return array
*/
public function GetList($iOffset = 0, $iLimit = 20, $sSearch = '', $bIncludeAliases = true)
public function GetList(int $iOffset = 0, int $iLimit = 20, string $sSearch = '', bool $bIncludeAliases = true) : array
{
$sSearch = \trim($sSearch);
@ -131,23 +88,15 @@ class Domain extends \RainLoop\Providers\AbstractProvider
return $this->bAdmin ? $this->oDriver->GetList($iOffset, $iLimit, $sSearch, $bIncludeAliases) : array();
}
/**
* @param string $sSearch = ''
*
* @return int
*/
public function Count($sSearch = '')
public function Count(string $sSearch = '') : int
{
return $this->oDriver->Count($sSearch);
}
/**
* @param \RainLoop\Actions $oActions
* @param string $sNameForTest = ''
*
* @return \RainLoop\Model\Domain | null
*/
public function LoadOrCreateNewFromAction(\RainLoop\Actions $oActions, $sNameForTest = '')
public function LoadOrCreateNewFromAction(\RainLoop\Actions $oActions, string $sNameForTest = '')
{
$oDomain = null;
@ -215,12 +164,9 @@ class Domain extends \RainLoop\Providers\AbstractProvider
}
/**
* @param \RainLoop\Actions $oActions
* @param string $sNameForTest = ''
*
* @return \RainLoop\Model\Domain | null
*/
public function CreateNewAliasFromAction(\RainLoop\Actions $oActions, $sNameForTest = '')
public function CreateNewAliasFromAction(\RainLoop\Actions $oActions, string $sNameForTest = '')
{
$oDomain = null;
@ -287,11 +233,8 @@ class Domain extends \RainLoop\Providers\AbstractProvider
return $oDomain;
}
/**
* @return bool
*/
public function IsActive()
public function IsActive() : bool
{
return $this->oDriver instanceof \RainLoop\Providers\Domain\DomainInterface;
}
}
}

View file

@ -1,410 +1,325 @@
<?php
namespace RainLoop\Providers\Domain;
class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
{
/**
* @var string
*/
protected $sDomainPath;
/**
* @var \MailSo\Cache\CacheClient
*/
protected $oCacher;
/**
* @param string $sDomainPath
* @param \MailSo\Cache\CacheClient $oCacher = null
*
* @return void
*/
public function __construct($sDomainPath, $oCacher = null)
{
$this->sDomainPath = \rtrim(\trim($sDomainPath), '\\/');
$this->oCacher = $oCacher;
}
/**
* @param string $sName
* @param bool $bBack = false
*
* @return string
*/
public function codeFileName($sName, $bBack = false)
{
if ($bBack && 'default' === $sName)
{
return '*';
}
else if (!$bBack && '*' === $sName)
{
return 'default';
}
if ($bBack)
{
$sName = \MailSo\Base\Utils::IdnToUtf8($sName, true);
}
else
{
$sName = \MailSo\Base\Utils::IdnToAscii($sName, true);
}
return $bBack ? \str_replace('_wildcard_', '*', $sName) : \str_replace('*', '_wildcard_', $sName);
}
/**
* @return string
*/
private function wildcardDomainsCacheKey()
{
return '/WildCard/DomainCache/'.\md5(APP_VERSION.APP_PRIVATE_DATA_NAME).'/';
}
/**
* @return string
*/
private function getWildcardDomainsLine()
{
if ($this->oCacher)
{
$sResult = $this->oCacher->Get($this->wildcardDomainsCacheKey());
if (0 < \strlen($sResult))
{
return $sResult;
}
}
$sResult = '';
$aNames = array();
$aList = \glob($this->sDomainPath.'/*.ini');
foreach ($aList as $sFile)
{
$sName = \substr(\basename($sFile), 0, -4);
if ('default' === $sName || false !== \strpos($sName, '_wildcard_'))
{
$aNames[] = $this->codeFileName($sName, true);
}
}
if (0 < \count($aNames))
{
\rsort($aNames, SORT_STRING);
$sResult = \implode(' ', $aNames);
}
if ($this->oCacher)
{
$this->oCacher->Set($this->wildcardDomainsCacheKey(), $sResult);
}
return $sResult;
}
/**
* @param string $sName
* @param bool $bFindWithWildCard = false
* @param bool $bCheckDisabled = true
* @param bool $bCheckAliases = true
*
* @return \RainLoop\Model\Domain|null
*/
public function Load($sName, $bFindWithWildCard = false, $bCheckDisabled = true, $bCheckAliases = true)
{
$mResult = null;
$sDisabled = '';
$sFoundedValue = '';
$sRealFileName = $this->codeFileName($sName);
if (\file_exists($this->sDomainPath.'/disabled'))
{
$sDisabled = @\file_get_contents($this->sDomainPath.'/disabled');
}
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini') &&
(!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.\MailSo\Base\Utils::IdnToAscii($sName, true).',')))
{
$aDomain = \RainLoop\Utils::CustomParseIniFile($this->sDomainPath.'/'.$sRealFileName.'.ini');
// if ($bCheckAliases && !empty($aDomain['alias']))
// {
// $oDomain = $this->Load($aDomain['alias'], false, false, false);
// if ($oDomain && $oDomain instanceof \RainLoop\Model\Domain)
// {
// $oDomain->SetAliasName($sName);
// }
//
// return $oDomain;
// }
// fix misspellings (#119)
if (\is_array($aDomain))
{
if (isset($aDomain['smpt_host']))
{
$aDomain['smtp_host'] = $aDomain['smpt_host'];
}
if (isset($aDomain['smpt_port']))
{
$aDomain['smtp_port'] = $aDomain['smpt_port'];
}
if (isset($aDomain['smpt_secure']))
{
$aDomain['smtp_secure'] = $aDomain['smpt_secure'];
}
if (isset($aDomain['smpt_auth']))
{
$aDomain['smtp_auth'] = $aDomain['smpt_auth'];
}
}
//---
$mResult = \RainLoop\Model\Domain::NewInstanceFromDomainConfigArray($sName, $aDomain);
}
else if ($bCheckAliases && \file_exists($this->sDomainPath.'/'.$sRealFileName.'.alias') &&
(!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.\MailSo\Base\Utils::IdnToAscii($sName, true).',')))
{
$sAlias = \trim(\file_get_contents($this->sDomainPath.'/'.$sRealFileName.'.alias'));
if (!empty($sAlias))
{
$oDomain = $this->Load($sAlias, false, false, false);
if ($oDomain && $oDomain instanceof \RainLoop\Model\Domain)
{
$oDomain->SetAliasName($sName);
}
return $oDomain;
}
}
else if ($bFindWithWildCard)
{
$sNames = $this->getWildcardDomainsLine();
if (0 < \strlen($sNames))
{
if (\RainLoop\Plugins\Helper::ValidateWildcardValues(
\MailSo\Base\Utils::IdnToUtf8($sName, true), $sNames, $sFoundedValue) && 0 < \strlen($sFoundedValue))
{
if (!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.$sFoundedValue.','))
{
$mResult = $this->Load($sFoundedValue, false);
}
}
}
}
return $mResult;
}
/**
* @param \RainLoop\Model\Domain $oDomain
*
* @return bool
*/
public function Save(\RainLoop\Model\Domain $oDomain)
{
$sRealFileName = $this->codeFileName($oDomain->Name());
if ($this->oCacher)
{
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
}
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.ini', $oDomain->ToIniString());
return \is_int($mResult) && 0 < $mResult;
}
/**
* @param string $sName
* @param string $sAlias
*
* @return bool
*/
public function SaveAlias($sName, $sAlias)
{
$sRealFileName = $this->codeFileName($sName);
if ($this->oCacher)
{
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
}
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.alias', $sAlias);
return \is_int($mResult) && 0 < $mResult;
}
/**
* @param string $sName
* @param bool $bDisable
*
* @return bool
*/
public function Disable($sName, $bDisable)
{
$sName = \MailSo\Base\Utils::IdnToAscii($sName, true);
$sFile = '';
if (\file_exists($this->sDomainPath.'/disabled'))
{
$sFile = @\file_get_contents($this->sDomainPath.'/disabled');
}
$aResult = array();
$aNames = \explode(',', $sFile);
if ($bDisable)
{
\array_push($aNames, $sName);
$aResult = $aNames;
}
else
{
foreach ($aNames as $sItem)
{
if ($sName !== $sItem)
{
$aResult[] = $sItem;
}
}
}
$aResult = \array_unique($aResult);
return false !== \file_put_contents($this->sDomainPath.'/disabled', \trim(\implode(',', $aResult), ', '));
}
/**
* @param string $sName
*
* @return bool
*/
public function Delete($sName)
{
$bResult = true;
$sRealFileName = $this->codeFileName($sName);
if (0 < \strlen($sName))
{
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini'))
{
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.ini');
}
else if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.alias'))
{
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.alias');
}
}
if ($bResult)
{
$this->Disable($sName, false);
}
if ($this->oCacher)
{
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
}
return $bResult;
}
/**
* @param int $iOffset = 0
* @param int $iLimit = 20
* @param int $sSearch = ''
* @param bool $bIncludeAliases = true
*
* @return array
*/
public function GetList($iOffset = 0, $iLimit = 20, $sSearch = '', $bIncludeAliases = true)
{
$aResult = array();
$aWildCards = array();
$aAliases = array();
// $aList = \glob($this->sDomainPath.'/*.{ini,alias}', GLOB_BRACE);
$aList = @\array_diff(\scandir($this->sDomainPath), array('.', '..'));
if (\is_array($aList))
{
foreach ($aList as $sFile)
{
$sName = $sFile;
if ('.ini' === \substr($sName, -4) || '.alias' === \substr($sName, -6))
{
$bAlias = '.alias' === \substr($sName, -6);
$sName = \preg_replace('/\.(ini|alias)$/', '', $sName);
$sName = $this->codeFileName($sName, true);
if ($bAlias)
{
if ($bIncludeAliases)
{
$aAliases[] = $sName;
}
}
else if (false !== \strpos($sName, '*'))
{
$aWildCards[] = $sName;
}
else
{
$aResult[] = $sName;
}
}
}
}
\sort($aResult, SORT_STRING);
\sort($aAliases, SORT_STRING);
\rsort($aWildCards, SORT_STRING);
$aResult = \array_merge($aResult, $aAliases, $aWildCards);
$iOffset = (0 > $iOffset) ? 0 : $iOffset;
$iLimit = (0 > $iLimit) ? 0 : ((999 < $iLimit) ? 999 : $iLimit);
$aResult = \array_slice($aResult, $iOffset, $iLimit);
$aDisabledNames = array();
if (0 < \count($aResult) && \file_exists($this->sDomainPath.'/disabled'))
{
$sDisabled = @\file_get_contents($this->sDomainPath.'/disabled');
if (false !== $sDisabled && 0 < strlen($sDisabled))
{
$aDisabledNames = \explode(',', $sDisabled);
$aDisabledNames = \array_unique($aDisabledNames);
foreach ($aDisabledNames as $iIndex => $sValue)
{
$aDisabledNames[$iIndex] = \MailSo\Base\Utils::IdnToUtf8($sValue, true);
}
}
}
$aReturn = array();
foreach ($aResult as $sName)
{
$aReturn[$sName] = array(
!\in_array($sName, $aDisabledNames),
\in_array($sName, $aAliases)
);
}
return $aReturn;
}
/**
* @param string $sSearch = ''
* @param bool $bIncludeAliases = true
*
* @return int
*/
public function Count($sSearch = '', $bIncludeAliases = true)
{
return \count($this->GetList(0, 999, $sSearch, $bIncludeAliases));
}
}
<?php
namespace RainLoop\Providers\Domain;
class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
{
/**
* @var string
*/
protected $sDomainPath;
/**
* @var \MailSo\Cache\CacheClient
*/
protected $oCacher;
public function __construct(string $sDomainPath, ?\MailSo\Cache\CacheClient $oCacher = null)
{
$this->sDomainPath = \rtrim(\trim($sDomainPath), '\\/');
$this->oCacher = $oCacher;
}
public function codeFileName(string $sName, bool $bBack = false) : string
{
if ($bBack && 'default' === $sName)
{
return '*';
}
else if (!$bBack && '*' === $sName)
{
return 'default';
}
if ($bBack)
{
$sName = \MailSo\Base\Utils::IdnToUtf8($sName, true);
}
else
{
$sName = \MailSo\Base\Utils::IdnToAscii($sName, true);
}
return $bBack ? \str_replace('_wildcard_', '*', $sName) : \str_replace('*', '_wildcard_', $sName);
}
private function wildcardDomainsCacheKey() : string
{
return '/WildCard/DomainCache/'.\md5(APP_VERSION.APP_PRIVATE_DATA_NAME).'/';
}
private function getWildcardDomainsLine() : string
{
if ($this->oCacher)
{
$sResult = $this->oCacher->Get($this->wildcardDomainsCacheKey());
if (0 < \strlen($sResult))
{
return $sResult;
}
}
$sResult = '';
$aNames = array();
$aList = \glob($this->sDomainPath.'/*.ini');
foreach ($aList as $sFile)
{
$sName = \substr(\basename($sFile), 0, -4);
if ('default' === $sName || false !== \strpos($sName, '_wildcard_'))
{
$aNames[] = $this->codeFileName($sName, true);
}
}
if (0 < \count($aNames))
{
\rsort($aNames, SORT_STRING);
$sResult = \implode(' ', $aNames);
}
if ($this->oCacher)
{
$this->oCacher->Set($this->wildcardDomainsCacheKey(), $sResult);
}
return $sResult;
}
/**
* @return \RainLoop\Model\Domain|null
*/
public function Load(string $sName, bool $bFindWithWildCard = false, bool $bCheckDisabled = true, bool $bCheckAliases = true)
{
$mResult = null;
$sDisabled = '';
$sFoundedValue = '';
$sRealFileName = $this->codeFileName($sName);
if (\file_exists($this->sDomainPath.'/disabled'))
{
$sDisabled = @\file_get_contents($this->sDomainPath.'/disabled');
}
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini') &&
(!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.\MailSo\Base\Utils::IdnToAscii($sName, true).',')))
{
$aDomain = \RainLoop\Utils::CustomParseIniFile($this->sDomainPath.'/'.$sRealFileName.'.ini');
// if ($bCheckAliases && !empty($aDomain['alias']))
// {
// $oDomain = $this->Load($aDomain['alias'], false, false, false);
// if ($oDomain && $oDomain instanceof \RainLoop\Model\Domain)
// {
// $oDomain->SetAliasName($sName);
// }
//
// return $oDomain;
// }
$mResult = \RainLoop\Model\Domain::NewInstanceFromDomainConfigArray($sName, $aDomain);
}
else if ($bCheckAliases && \file_exists($this->sDomainPath.'/'.$sRealFileName.'.alias') &&
(!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.\MailSo\Base\Utils::IdnToAscii($sName, true).',')))
{
$sAlias = \trim(\file_get_contents($this->sDomainPath.'/'.$sRealFileName.'.alias'));
if (!empty($sAlias))
{
$oDomain = $this->Load($sAlias, false, false, false);
if ($oDomain && $oDomain instanceof \RainLoop\Model\Domain)
{
$oDomain->SetAliasName($sName);
}
return $oDomain;
}
}
else if ($bFindWithWildCard)
{
$sNames = $this->getWildcardDomainsLine();
if (0 < \strlen($sNames))
{
if (\RainLoop\Plugins\Helper::ValidateWildcardValues(
\MailSo\Base\Utils::IdnToUtf8($sName, true), $sNames, $sFoundedValue) && 0 < \strlen($sFoundedValue))
{
if (!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.$sFoundedValue.','))
{
$mResult = $this->Load($sFoundedValue, false);
}
}
}
}
return $mResult;
}
public function Save(\RainLoop\Model\Domain $oDomain) : bool
{
$sRealFileName = $this->codeFileName($oDomain->Name());
if ($this->oCacher)
{
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
}
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.ini', $oDomain->ToIniString());
return \is_int($mResult) && 0 < $mResult;
}
public function SaveAlias(string $sName, string $sAlias) : bool
{
$sRealFileName = $this->codeFileName($sName);
if ($this->oCacher)
{
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
}
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.alias', $sAlias);
return \is_int($mResult) && 0 < $mResult;
}
public function Disable(string $sName, bool $bDisable) : bool
{
$sName = \MailSo\Base\Utils::IdnToAscii($sName, true);
$sFile = '';
if (\file_exists($this->sDomainPath.'/disabled'))
{
$sFile = @\file_get_contents($this->sDomainPath.'/disabled');
}
$aResult = array();
$aNames = \explode(',', $sFile);
if ($bDisable)
{
\array_push($aNames, $sName);
$aResult = $aNames;
}
else
{
foreach ($aNames as $sItem)
{
if ($sName !== $sItem)
{
$aResult[] = $sItem;
}
}
}
$aResult = \array_unique($aResult);
return false !== \file_put_contents($this->sDomainPath.'/disabled', \trim(\implode(',', $aResult), ', '));
}
public function Delete(string $sName) : bool
{
$bResult = true;
$sRealFileName = $this->codeFileName($sName);
if (0 < \strlen($sName))
{
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini'))
{
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.ini');
}
else if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.alias'))
{
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.alias');
}
}
if ($bResult)
{
$this->Disable($sName, false);
}
if ($this->oCacher)
{
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
}
return $bResult;
}
public function GetList(int $iOffset = 0, int $iLimit = 20, string $sSearch = '', bool $bIncludeAliases = true) : array
{
$aResult = array();
$aWildCards = array();
$aAliases = array();
// $aList = \glob($this->sDomainPath.'/*.{ini,alias}', GLOB_BRACE);
$aList = @\array_diff(\scandir($this->sDomainPath), array('.', '..'));
if (\is_array($aList))
{
foreach ($aList as $sFile)
{
$sName = $sFile;
if ('.ini' === \substr($sName, -4) || '.alias' === \substr($sName, -6))
{
$bAlias = '.alias' === \substr($sName, -6);
$sName = \preg_replace('/\.(ini|alias)$/', '', $sName);
$sName = $this->codeFileName($sName, true);
if ($bAlias)
{
if ($bIncludeAliases)
{
$aAliases[] = $sName;
}
}
else if (false !== \strpos($sName, '*'))
{
$aWildCards[] = $sName;
}
else
{
$aResult[] = $sName;
}
}
}
}
\sort($aResult, SORT_STRING);
\sort($aAliases, SORT_STRING);
\rsort($aWildCards, SORT_STRING);
$aResult = \array_merge($aResult, $aAliases, $aWildCards);
$iOffset = (0 > $iOffset) ? 0 : $iOffset;
$iLimit = (0 > $iLimit) ? 0 : ((999 < $iLimit) ? 999 : $iLimit);
$aResult = \array_slice($aResult, $iOffset, $iLimit);
$aDisabledNames = array();
if (0 < \count($aResult) && \file_exists($this->sDomainPath.'/disabled'))
{
$sDisabled = @\file_get_contents($this->sDomainPath.'/disabled');
if (false !== $sDisabled && 0 < strlen($sDisabled))
{
$aDisabledNames = \explode(',', $sDisabled);
$aDisabledNames = \array_unique($aDisabledNames);
foreach ($aDisabledNames as $iIndex => $sValue)
{
$aDisabledNames[$iIndex] = \MailSo\Base\Utils::IdnToUtf8($sValue, true);
}
}
}
$aReturn = array();
foreach ($aResult as $sName)
{
$aReturn[$sName] = array(
!\in_array($sName, $aDisabledNames),
\in_array($sName, $aAliases)
);
}
return $aReturn;
}
public function Count(string $sSearch = '', bool $bIncludeAliases = true) : int
{
return \count($this->GetList(0, 999, $sSearch, $bIncludeAliases));
}
}

View file

@ -5,52 +5,18 @@ namespace RainLoop\Providers\Domain;
interface DomainAdminInterface extends DomainInterface
{
/**
* @param string $sName
* @param bool $bDisable
*
* @return bool
*/
public function Disable($sName, $bDisable);
public function Disable(string $sName, bool $bDisable) : bool;
/**
* @param string $sName
* @param bool $bFindWithWildCard = false
* @param bool $bCheckDisabled = true
*
* @return \RainLoop\Model\Domain|null
*/
public function Load($sName, $bFindWithWildCard = false, $bCheckDisabled = true);
public function Load(string $sName, bool $bFindWithWildCard = false, bool $bCheckDisabled = true);
/**
* @param \RainLoop\Model\Domain $oDomain
*
* @return bool
*/
public function Save(\RainLoop\Model\Domain $oDomain);
public function Save(\RainLoop\Model\Domain $oDomain) : bool;
/**
* @param string $sName
*
* @return bool
*/
public function Delete($sName);
public function Delete(string $sName) : bool;
/**
* @param int $iOffset = 0
* @param int $iLimit = 20
* @param int $sSearch = ''
* @param bool $bIncludeAliases = true
*
* @return array
*/
public function GetList($iOffset = 0, $iLimit = 20, $sSearch = '', $bIncludeAliases = true);
public function GetList(int $iOffset = 0, int $iLimit = 20, string $sSearch = '', bool $bIncludeAliases = true) : array;
/**
* @param string $sSearch = ''
* @param bool $bIncludeAliases = true
*
* @return int
*/
public function Count($sSearch = '', $bIncludeAliases = true);
}
public function Count(string $sSearch = '', bool $bIncludeAliases = true) : int;
}

View file

@ -9,128 +9,72 @@ class Files extends \RainLoop\Providers\AbstractProvider
*/
private $oDriver;
/**
* @return void
*/
public function __construct(\RainLoop\Providers\Files\IFiles $oDriver)
{
$this->oDriver = $oDriver;
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
* @param resource $rSource
*
* @return bool
*/
public function PutFile($oAccount, $sKey, $rSource)
public function PutFile(\RainLoop\Model\Account $oAccount, string $sKey, resource $rSource) : bool
{
return $this->oDriver->PutFile($oAccount, $sKey, $rSource);
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
* @param string $sSource
*
* @return bool
*/
public function MoveUploadedFile($oAccount, $sKey, $sSource)
public function MoveUploadedFile(\RainLoop\Model\Account $oAccount, string $sKey, string $sSource) : bool
{
return $this->oDriver->MoveUploadedFile($oAccount, $sKey, $sSource);
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
* @param string $sOpenMode = 'rb'
*
* @return resource|bool
*/
public function GetFile($oAccount, $sKey, $sOpenMode = 'rb')
public function GetFile(\RainLoop\Model\Account $oAccount, string $sKey, string $sOpenMode = 'rb')
{
return $this->oDriver->GetFile($oAccount, $sKey, $sOpenMode);
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
*
* @return string | bool
*/
public function GetFileName($oAccount, $sKey)
public function GetFileName(\RainLoop\Model\Account $oAccount, string $sKey)
{
return $this->oDriver->GetFileName($oAccount, $sKey);
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
*
* @return bool
*/
public function Clear($oAccount, $sKey)
public function Clear(\RainLoop\Model\Account $oAccount, string $sKey) : bool
{
return $this->oDriver->Clear($oAccount, $sKey);
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
*
* @return int|bool
*/
public function FileSize($oAccount, $sKey)
public function FileSize(\RainLoop\Model\Account $oAccount, string $sKey)
{
return $this->oDriver->FileSize($oAccount, $sKey);
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
*
* @return bool
*/
public function FileExists($oAccount, $sKey)
public function FileExists(\RainLoop\Model\Account $oAccount, string $sKey) : bool
{
return $this->oDriver->FileExists($oAccount, $sKey);
}
/**
* @param int $iTimeToClearInHours = 24
*
* @return bool
*/
public function GC($iTimeToClearInHours = 24)
public function GC(int $iTimeToClearInHours = 24) : bool
{
return $this->oDriver ? $this->oDriver->GC($iTimeToClearInHours) : false;
}
/**
* @return bool
*/
public function CloseAllOpenedFiles()
public function CloseAllOpenedFiles() : bool
{
return $this->oDriver && \method_exists($this->oDriver, 'CloseAllOpenedFiles') ?
$this->oDriver->CloseAllOpenedFiles() : false;
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
*
* @return string
*/
public function GenerateLocalFullFileName($oAccount, $sKey)
public function GenerateLocalFullFileName(\RainLoop\Model\Account $oAccount, string $sKey) : string
{
return $this->oDriver ? $this->oDriver->GenerateLocalFullFileName($oAccount, $sKey) : '';
}
/**
* @return bool
*/
public function IsActive()
public function IsActive() : bool
{
return $this->oDriver instanceof \RainLoop\Providers\Files\IFiles;
}

View file

@ -14,36 +14,18 @@ class FileStorage implements \RainLoop\Providers\Files\IFiles
*/
private $sDataPath;
/**
* @param string $sStoragePath
*
* @return void
*/
public function __construct($sStoragePath)
public function __construct(string $sStoragePath)
{
$this->aResources = array();
$this->sDataPath = \rtrim(\trim($sStoragePath), '\\/');
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
*
* @return string
*/
public function GenerateLocalFullFileName($oAccount, $sKey)
public function GenerateLocalFullFileName(\RainLoop\Model\Account $oAccount, string $sKey) : string
{
return $this->generateFullFileName($oAccount, $sKey, true);
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
* @param resource $rSource
*
* @return bool
*/
public function PutFile($oAccount, $sKey, $rSource)
public function PutFile(\RainLoop\Model\Account $oAccount, string $sKey, resource $rSource) : bool
{
$bResult = false;
if ($rSource)
@ -58,27 +40,16 @@ class FileStorage implements \RainLoop\Providers\Files\IFiles
return $bResult;
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
* @param string $sSource
*
* @return bool
*/
public function MoveUploadedFile($oAccount, $sKey, $sSource)
public function MoveUploadedFile(\RainLoop\Model\Account $oAccount, string $sKey, string $sSource) : bool
{
return @\move_uploaded_file($sSource,
$this->generateFullFileName($oAccount, $sKey, true));
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
* @param string $sOpenMode = 'rb'
*
* @return resource|bool
*/
public function GetFile($oAccount, $sKey, $sOpenMode = 'rb')
public function GetFile(\RainLoop\Model\Account $oAccount, string $sKey, string $sOpenMode = 'rb')
{
$mResult = false;
$bCreate = !!\preg_match('/[wac]/', $sOpenMode);
@ -98,12 +69,9 @@ class FileStorage implements \RainLoop\Providers\Files\IFiles
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
*
* @return string|bool
*/
public function GetFileName($oAccount, $sKey)
public function GetFileName(\RainLoop\Model\Account $oAccount, string $sKey)
{
$mResult = false;
$sFileName = $this->generateFullFileName($oAccount, $sKey);
@ -115,13 +83,7 @@ class FileStorage implements \RainLoop\Providers\Files\IFiles
return $mResult;
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
*
* @return bool
*/
public function Clear($oAccount, $sKey)
public function Clear(\RainLoop\Model\Account $oAccount, string $sKey) : bool
{
$mResult = true;
$sFileName = $this->generateFullFileName($oAccount, $sKey);
@ -139,12 +101,9 @@ class FileStorage implements \RainLoop\Providers\Files\IFiles
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
*
* @return int|bool
*/
public function FileSize($oAccount, $sKey)
public function FileSize(\RainLoop\Model\Account $oAccount, string $sKey)
{
$mResult = false;
$sFileName = $this->generateFullFileName($oAccount, $sKey);
@ -156,23 +115,12 @@ class FileStorage implements \RainLoop\Providers\Files\IFiles
return $mResult;
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
*
* @return bool
*/
public function FileExists($oAccount, $sKey)
public function FileExists(\RainLoop\Model\Account $oAccount, string $sKey) : bool
{
return @\file_exists($this->generateFullFileName($oAccount, $sKey));
}
/**
* @param int $iTimeToClearInHours = 24
*
* @return bool
*/
public function GC($iTimeToClearInHours = 24)
public function GC(int $iTimeToClearInHours = 24) : bool
{
if (0 < $iTimeToClearInHours)
{
@ -183,10 +131,7 @@ class FileStorage implements \RainLoop\Providers\Files\IFiles
return false;
}
/**
* @return bool
*/
public function CloseAllOpenedFiles()
public function CloseAllOpenedFiles() : bool
{
if (\is_array($this->aResources) && 0 < \count($this->aResources))
{
@ -202,14 +147,7 @@ class FileStorage implements \RainLoop\Providers\Files\IFiles
return true;
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
* @param bool $bMkDir = false
*
* @return string
*/
private function generateFullFileName($oAccount, $sKey, $bMkDir = false)
private function generateFullFileName(\RainLoop\Model\Account $oAccount, string $sKey, bool $bMkDir = false) : string
{
$sEmail = $sSubEmail = '';
if ($oAccount instanceof \RainLoop\Model\Account)

View file

@ -4,77 +4,30 @@ namespace RainLoop\Providers\Files;
interface IFiles
{
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
*
* @return string
*/
public function GenerateLocalFullFileName($oAccount, $sKey);
public function GenerateLocalFullFileName(\RainLoop\Model\Account $oAccount, string $sKey) : string;
public function PutFile(\RainLoop\Model\Account $oAccount, string $sKey, resource $rSource) : bool;
public function MoveUploadedFile(\RainLoop\Model\Account $oAccount, string $sKey, string $sSource) : bool;
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
* @param resource $rSource
*
* @return bool
*/
public function PutFile($oAccount, $sKey, $rSource);
/**
* @param CAccount $oAccount
* @param string $sKey
* @param string $sSource
*
* @return bool
*/
public function MoveUploadedFile($oAccount, $sKey, $sSource);
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
* @param string $sOpenMode = 'rb'
*
* @return resource|bool
*/
public function GetFile($oAccount, $sKey, $sOpenMode = 'rb');
public function GetFile(\RainLoop\Model\Account $oAccount, string $sKey, string $sOpenMode = 'rb');
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
*
* @return string|bool
*/
public function GetFileName($oAccount, $sKey);
public function GetFileName(\RainLoop\Model\Account $oAccount, string $sKey);
public function Clear(\RainLoop\Model\Account $oAccount, string $sKey) : bool;
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
*
* @return bool
*/
public function Clear($oAccount, $sKey);
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
*
* @return int | bool
*/
public function FileSize($oAccount, $sKey);
public function FileSize(\RainLoop\Model\Account $oAccount, string $sKey);
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sKey
*
* @return bool
*/
public function FileExists($oAccount, $sKey);
public function FileExists(\RainLoop\Model\Account $oAccount, string $sKey) : bool;
/**
* @param int $iTimeToClearInHours = 24
* @return bool
*/
public function GC($iTimeToClearInHours = 24);
public function GC(int $iTimeToClearInHours = 24) : bool;
}

View file

@ -17,13 +17,7 @@ class Filters extends \RainLoop\Providers\AbstractProvider
$this->oDriver = $oDriver instanceof \RainLoop\Providers\Filters\FiltersInterface ? $oDriver : null;
}
/**
* @param \RainLoop\Account $oAccount
* @param bool $bAllowRaw = false
*
* @return array
*/
public function Load($oAccount, $bAllowRaw = false)
public function Load(\RainLoop\Model\Account $oAccount, bool $bAllowRaw = false) : array
{
try
{
@ -33,7 +27,7 @@ class Filters extends \RainLoop\Providers\AbstractProvider
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::ConnectionError, $oException);
}
catch (\Exception $oException)
catch (\Throwable $oException)
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CantGetFilters, $oException);
}
@ -41,15 +35,7 @@ class Filters extends \RainLoop\Providers\AbstractProvider
return false;
}
/**
* @param \RainLoop\Account $oAccount
* @param array $aFilters
* @param string $sRaw = ''
* @param bool $bRawIsActive = false
*
* @return bool
*/
public function Save($oAccount, $aFilters, $sRaw = '', $bRawIsActive = false)
public function Save(\RainLoop\Model\Account $oAccount, array $aFilters, string $sRaw = '', bool $bRawIsActive = false) : bool
{
try
{
@ -66,7 +52,7 @@ class Filters extends \RainLoop\Providers\AbstractProvider
\RainLoop\Notifications::ClientViewError, $oException,
\implode("\r\n", $oException->GetResponses()));
}
catch (\Exception $oException)
catch (\Throwable $oException)
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CantSaveFilters, $oException);
}
@ -74,11 +60,8 @@ class Filters extends \RainLoop\Providers\AbstractProvider
return false;
}
/**
* @return bool
*/
public function IsActive()
public function IsActive() : bool
{
return $this->oDriver instanceof \RainLoop\Providers\Filters\FiltersInterface;
}
}
}

View file

@ -101,122 +101,77 @@ class Filter
$this->bStop = true;
}
/**
* @return string
*/
public function ID()
public function ID() : string
{
return $this->sID;
}
/**
* @return bool
*/
public function Enabled()
public function Enabled() : bool
{
return $this->bEnabled;
}
/**
* @return string
*/
public function Name()
public function Name() : string
{
return $this->sName;
}
/**
* @return array
*/
public function Conditions()
public function Conditions() : array
{
return $this->aConditions;
}
/**
* @return string
*/
public function ConditionsType()
public function ConditionsType() : string
{
return $this->sConditionsType;
}
/**
* @return string
*/
public function ActionType()
public function ActionType() : string
{
return $this->sActionType;
}
/**
* @return string
*/
public function ActionValue()
public function ActionValue() : string
{
return $this->sActionValue;
}
/**
* @return string
*/
public function ActionValueSecond()
public function ActionValueSecond() : string
{
return $this->sActionValueSecond;
}
/**
* @return string
*/
public function ActionValueThird()
public function ActionValueThird() : string
{
return $this->sActionValueThird;
}
/**
* @return string
*/
public function ActionValueFourth()
public function ActionValueFourth() : string
{
return $this->sActionValueFourth;
}
/**
* @return bool
*/
public function MarkAsRead()
public function MarkAsRead() : bool
{
return $this->bMarkAsRead;
}
/**
* @return bool
*/
public function Stop()
public function Stop() : bool
{
return $this->bStop;
}
/**
* @return bool
*/
public function Keep()
public function Keep() : bool
{
return $this->bKeep;
}
/**
* @return string
*/
public function serializeToJson()
public function serializeToJson() : string
{
return \json_encode($this->ToSimpleJSON());
}
/**
* @param string $sFilterJson
*/
public function unserializeFromJson($sFilterJson)
public function unserializeFromJson(string $sFilterJson)
{
$aFilterJson = \json_decode(\trim($sFilterJson), true);
if (\is_array($aFilterJson))
@ -227,12 +182,7 @@ class Filter
return false;
}
/**
* @param array $aFilter
*
* @return array
*/
public function FromJSON($aFilter)
public function FromJSON(array $aFilter) : array
{
if (\is_array($aFilter))
{
@ -265,12 +215,7 @@ class Filter
return false;
}
/**
* @param bool $bAjax = false
*
* @return array
*/
public function ToSimpleJSON($bAjax = false)
public function ToSimpleJSON(bool $bAjax = false) : array
{
$aConditions = array();
foreach ($this->Conditions() as $oItem)

View file

@ -37,44 +37,27 @@ class FilterCondition
$this->sValueSecond = '';
}
/**
* @return string
*/
public function Field()
public function Field() : string
{
return $this->sField;
}
/**
* @return string
*/
public function Type()
public function Type() : string
{
return $this->sType;
}
/**
* @return string
*/
public function Value()
public function Value() : string
{
return $this->sValue;
}
/**
* @return string
*/
public function ValueSecond()
public function ValueSecond() : string
{
return $this->sValueSecond;
}
/**
* @param array $aData
*
* @return array
*/
public function FromJSON($aData)
public function FromJSON(array $aData) : array
{
if (\is_array($aData))
{
@ -93,12 +76,7 @@ class FilterCondition
return false;
}
/**
* @param bool $bAjax = false
*
* @return array
*/
public function ToSimpleJSON($bAjax = false)
public function ToSimpleJSON(bool $bAjax = false) : array
{
return array(
'Field' => $this->Field(),
@ -108,10 +86,7 @@ class FilterCondition
);
}
/**
* @return array
*/
public static function CollectionFromJSON($aCollection)
public static function CollectionFromJSON($aCollection) : array
{
$aResult = array();
if (\is_array($aCollection) && 0 < \count($aCollection))

View file

@ -4,19 +4,7 @@ namespace RainLoop\Providers\Filters;
interface FiltersInterface
{
/**
* @param \RainLoop\Account $oAccount
* @param bool $bAllowRaw = false
*
* @return array
*/
public function Load($oAccount, $bAllowRaw = false);
public function Load(\RainLoop\Model\Account $oAccount, bool $bAllowRaw = false) : array;
/**
* @param \RainLoop\Account $oAccount
* @param array $aFilters
*
* @return bool
*/
public function Save($oAccount, $aFilters);
public function Save(\RainLoop\Model\Account $oAccount, array $aFilters) : bool;
}

View file

@ -1,390 +1,66 @@
<?php
namespace RainLoop\Providers;
class Prem
{
/**
* @return void
*/
public function __construct($oConfig, $oLogger, $oCacher)
{
$this->oConfig = $oConfig;
$this->oLogger = $oLogger;
$this->oCacher = $oCacher;
}
/**
* @return bool
*/
public function Type()
{
static $bResult = null;
if (null === $bResult)
{
$bResult = $this->Parser($this->Fetcher(false, true));
}
return $bResult;
}
/**
* @return bool
*/
public function IsActive()
{
return true;
}
/**
* @param string $sInput
* @param int $iExpired = 0
*
* @return bool
*/
public function Parser($sInput, &$iExpired = 0)
{
$aMatch = array();
if (\preg_match('/^EXPIRED:([\d]+)$/', $sInput, $aMatch))
{
$iExpired = (int) $aMatch[1];
return \time() < $iExpired;
}
return false;
}
/**
* @param array $aAppData
*/
public function PopulateAppData(&$aAppData)
{
if (\is_array($aAppData))
{
$aAppData['Community'] = false;
$oConfig = $this->oConfig;
if ($oConfig && $this->Type())
{
$aAppData['PremType'] = true;
$aAppData['LoginLogo'] = $oConfig->Get('branding', 'login_logo', '');
$aAppData['LoginBackground'] = $oConfig->Get('branding', 'login_background', '');
$aAppData['LoginCss'] = $oConfig->Get('branding', 'login_css', '');
$aAppData['LoginDescription'] = $oConfig->Get('branding', 'login_desc', '');
$aAppData['UserLogo'] = $oConfig->Get('branding', 'user_logo', '');
$aAppData['UserLogoTitle'] = $oConfig->Get('branding', 'user_logo_title', '');
$aAppData['UserLogoMessage'] = $oConfig->Get('branding', 'user_logo_message', '');
$aAppData['UserIframeMessage'] = $oConfig->Get('branding', 'user_iframe_message', '');
$aAppData['UserCss'] = $oConfig->Get('branding', 'user_css', '');
$aAppData['WelcomePageUrl'] = $oConfig->Get('branding', 'welcome_page_url', '');
$aAppData['WelcomePageDisplay'] = \strtolower($oConfig->Get('branding', 'welcome_page_display', 'none'));
}
}
}
public function PremSection(&$oActions, &$oConfig)
{
if ($oActions && $oActions->HasOneOfActionParams(array(
'LoginLogo', 'LoginBackground', 'LoginDescription', 'LoginCss',
'UserLogo', 'UserLogoTitle', 'UserLogoMessage', 'UserIframeMessage', 'UserCss',
'WelcomePageUrl', 'WelcomePageDisplay'
)) && $this->Type())
{
$oActions->setConfigFromParams($oConfig, 'LoginLogo', 'branding', 'login_logo', 'string');
$oActions->setConfigFromParams($oConfig, 'LoginBackground', 'branding', 'login_background', 'string');
$oActions->setConfigFromParams($oConfig, 'LoginDescription', 'branding', 'login_desc', 'string');
$oActions->setConfigFromParams($oConfig, 'LoginCss', 'branding', 'login_css', 'string');
$oActions->setConfigFromParams($oConfig, 'UserLogo', 'branding', 'user_logo', 'string');
$oActions->setConfigFromParams($oConfig, 'UserLogoTitle', 'branding', 'user_logo_title', 'string');
$oActions->setConfigFromParams($oConfig, 'UserLogoMessage', 'branding', 'user_logo_message', 'string');
$oActions->setConfigFromParams($oConfig, 'UserIframeMessage', 'branding', 'user_iframe_message', 'string');
$oActions->setConfigFromParams($oConfig, 'UserCss', 'branding', 'user_css', 'string');
$oActions->setConfigFromParams($oConfig, 'WelcomePageUrl', 'branding', 'welcome_page_url', 'string');
$oActions->setConfigFromParams($oConfig, 'WelcomePageDisplay', 'branding', 'welcome_page_display', 'string');
}
}
/**
* @return string
*/
public function Activate($sDomain, $sKey, &$iCode)
{
$iCode = 0;
$sContentType = '';
$oHttp = \MailSo\Base\Http::SingletonInstance();
$sResult = $oHttp->GetUrlAsString(APP_API_PATH.'activate/'.\urlencode($sDomain).'/'.\urlencode($sKey),
'RainLoop/'.APP_VERSION, $sContentType, $iCode, $this->oLogger, 10,
$this->oConfig->Get('labs', 'curl_proxy', ''), $this->oConfig->Get('labs', 'curl_proxy_auth', ''),
array(), false
);
if (200 !== $iCode)
{
$sResult = '';
}
return $sResult;
}
/**
* @return string
*/
public function Fetcher($sForce = false, $bLongCache = false, $iFastCacheTimeInMin = 10, $iLongCacheTimeInDays = 3)
{
$sDomain = \trim(APP_SITE);
$oConfig = $this->oConfig;
$oLogger = $this->oLogger;
$oCacher = $this->oCacher;
$oHttp = \MailSo\Base\Http::SingletonInstance();
if (0 === \strlen($sDomain) || $oHttp->CheckLocalhost($sDomain) || !$oCacher || !$oConfig || !$oCacher->Verify(true))
{
return 'NO';
}
$sDomainKeyValue = \RainLoop\KeyPathHelper::LicensingDomainKeyValue($sDomain);
$sDomainLongKeyValue = \RainLoop\KeyPathHelper::LicensingDomainKeyOtherValue($sDomain);
$sValue = '';
if (!$sForce)
{
if ($bLongCache)
{
$bLock = $oCacher->GetLock($sDomainLongKeyValue);
$iTime = $bLock ? 0 : $oCacher->GetTimer($sDomainLongKeyValue);
if ($bLock || (0 < $iTime && \time() < $iTime + (60 * 60 * 24) * $iLongCacheTimeInDays))
{
$sValue = $oCacher->Get($sDomainLongKeyValue);
}
}
else
{
$iTime = $oCacher->GetTimer($sDomainKeyValue);
if (0 < $iTime && \time() < $iTime + 60 * $iFastCacheTimeInMin)
{
$sValue = $oCacher->Get($sDomainKeyValue);
}
}
}
if (0 === \strlen($sValue))
{
if ($bLongCache)
{
if (!$oCacher->SetTimer($sDomainLongKeyValue))
{
return 'NO';
}
$oCacher->SetLock($sDomainLongKeyValue);
}
$iCode = 0;
$sContentType = '';
$sValue = $oHttp->GetUrlAsString(APP_API_PATH.'status/'.\urlencode($sDomain),
'RainLoop/'.APP_VERSION, $sContentType, $iCode, $oLogger, 5,
$oConfig->Get('labs', 'curl_proxy', ''), $oConfig->Get('labs', 'curl_proxy_auth', ''),
array(), false
);
if ($oLogger)
{
$oLogger->Write($sValue);
}
if (404 === $iCode)
{
$sValue = 'NO';
}
else if (200 !== $iCode)
{
$sValue = '';
}
$oCacher->SetTimer($sDomainKeyValue);
$oCacher->Set($sDomainKeyValue, $sValue);
$oCacher->Set($sDomainLongKeyValue, $sValue);
if ($bLongCache)
{
$oCacher->RemoveLock($sDomainLongKeyValue);
}
}
return $sValue;
}
public function ClearOldVersion()
{
$sVPath = APP_INDEX_ROOT_PATH.'rainloop/v/';
if ($this->oLogger)
{
$this->oLogger->Write('Versions GC: Begin');
}
$aDirs = @\array_map('basename', @\array_filter(@\glob($sVPath.'*'), 'is_dir'));
if ($this->oLogger)
{
$this->oLogger->Write('Versions GC: Count:'.(\is_array($aDirs) ? \count($aDirs) : 0));
}
if (\is_array($aDirs) && 5 < \count($aDirs))
{
\uasort($aDirs, 'version_compare');
foreach ($aDirs as $sName)
{
if (APP_DEV_VERSION !== $sName && APP_VERSION !== $sName)
{
if ($this->oLogger)
{
$this->oLogger->Write('Versions GC: Begin to remove "'.$sVPath.$sName.'" version');
}
if (@\unlink($sVPath.$sName.'/index.php'))
{
@\MailSo\Base\Utils::RecRmDir($sVPath.$sName);
}
else
{
if ($this->oLogger)
{
$this->oLogger->Write('Versions GC (Error): index file cant be removed from"'.$sVPath.$sName.'"',
\MailSo\Log\Enumerations\Type::ERROR);
}
}
if ($this->oLogger)
{
$this->oLogger->Write('Versions GC: End to remove "'.$sVPath.$sName.'" version');
}
break;
}
}
}
if ($this->oLogger)
{
$this->oLogger->Write('Versions GC: End');
}
}
public function UpdateCore($oActions, $sFile)
{
$bResult = false;
$sNewVersion = '';
$sTmp = $oActions->downloadRemotePackageByUrl($sFile);
if (!empty($sTmp))
{
include_once APP_VERSION_ROOT_PATH.'app/libraries/pclzip/pclzip.lib.php';
$oArchive = new \PclZip($sTmp);
$sTmpFolder = APP_PRIVATE_DATA.\md5($sTmp);
\mkdir($sTmpFolder);
if (\is_dir($sTmpFolder))
{
$bResult = 0 !== $oArchive->extract(PCLZIP_OPT_PATH, $sTmpFolder);
if (!$bResult)
{
if ($this->oLogger)
{
$this->oLogger->Write('Cannot extract package files: '.$oArchive->errorInfo(), \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
}
}
if ($bResult && \file_exists($sTmpFolder.'/index.php') &&
\is_writable(APP_INDEX_ROOT_PATH.'rainloop/') &&
\is_writable(APP_INDEX_ROOT_PATH.'index.php') &&
\is_dir($sTmpFolder.'/rainloop/'))
{
$aMatch = array();
$sIndexFile = \file_get_contents($sTmpFolder.'/index.php');
if (\preg_match('/\'APP_VERSION\', \'([^\']+)\'/', $sIndexFile, $aMatch) && !empty($aMatch[1]))
{
$sNewVersion = \trim($aMatch[1]);
}
if (empty($sNewVersion))
{
if ($this->oLogger)
{
$this->oLogger->Write('Unknown version', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
}
}
else if (!\is_dir(APP_INDEX_ROOT_PATH.'rainloop/v/'.$sNewVersion))
{
\MailSo\Base\Utils::CopyDir($sTmpFolder.'/rainloop/', APP_INDEX_ROOT_PATH.'rainloop/');
if (\is_dir(APP_INDEX_ROOT_PATH.'rainloop/v/'.$sNewVersion) &&
\is_file(APP_INDEX_ROOT_PATH.'rainloop/v/'.$sNewVersion.'/index.php'))
{
$bResult = \copy($sTmpFolder.'/index.php', APP_INDEX_ROOT_PATH.'index.php');
if ($bResult)
{
if (\MailSo\Base\Utils::FunctionExistsAndEnabled('opcache_invalidate'))
{
@\opcache_invalidate(APP_INDEX_ROOT_PATH.'index.php', true);
}
if (\MailSo\Base\Utils::FunctionExistsAndEnabled('apc_delete_file'))
{
@\apc_delete_file(APP_INDEX_ROOT_PATH.'index.php');
}
}
}
else
{
if ($this->oLogger)
{
$this->oLogger->Write('Cannot copy new package files', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
$this->oLogger->Write($sTmpFolder.'/rainloop/ -> '.APP_INDEX_ROOT_PATH.'rainloop/', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
}
}
}
else if (!empty($sNewVersion))
{
if ($this->oLogger)
{
$this->oLogger->Write('"'.$sNewVersion.'" version already installed', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
}
}
}
else if ($bResult)
{
if ($this->oLogger)
{
$this->oLogger->Write('Cannot validate package files', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
}
}
\MailSo\Base\Utils::RecRmDir($sTmpFolder);
}
else
{
if ($this->oLogger)
{
$this->oLogger->Write('Cannot create tmp folder: '.$sTmpFolder, \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
}
}
@\unlink($sTmp);
}
return $bResult;
}
}
<?php
namespace RainLoop\Providers;
class Prem
{
/**
* @return void
*/
public function __construct($oConfig, $oLogger, $oCacher)
{
$this->oConfig = $oConfig;
$this->oLogger = $oLogger;
$this->oCacher = $oCacher;
}
public function PopulateAppData(array &$aAppData)
{
if (\is_array($aAppData))
{
$aAppData['Community'] = false;
$oConfig = $this->oConfig;
if ($oConfig)
{
$aAppData['PremType'] = true;
$aAppData['LoginLogo'] = $oConfig->Get('branding', 'login_logo', '');
$aAppData['LoginBackground'] = $oConfig->Get('branding', 'login_background', '');
$aAppData['LoginCss'] = $oConfig->Get('branding', 'login_css', '');
$aAppData['LoginDescription'] = $oConfig->Get('branding', 'login_desc', '');
$aAppData['UserLogo'] = $oConfig->Get('branding', 'user_logo', '');
$aAppData['UserLogoTitle'] = $oConfig->Get('branding', 'user_logo_title', '');
$aAppData['UserLogoMessage'] = $oConfig->Get('branding', 'user_logo_message', '');
$aAppData['UserIframeMessage'] = $oConfig->Get('branding', 'user_iframe_message', '');
$aAppData['UserCss'] = $oConfig->Get('branding', 'user_css', '');
$aAppData['WelcomePageUrl'] = $oConfig->Get('branding', 'welcome_page_url', '');
$aAppData['WelcomePageDisplay'] = \strtolower($oConfig->Get('branding', 'welcome_page_display', 'none'));
}
}
}
public function PremSection(&$oActions, &$oConfig)
{
if ($oActions && $oActions->HasOneOfActionParams(array(
'LoginLogo', 'LoginBackground', 'LoginDescription', 'LoginCss',
'UserLogo', 'UserLogoTitle', 'UserLogoMessage', 'UserIframeMessage', 'UserCss',
'WelcomePageUrl', 'WelcomePageDisplay'
)))
{
$oActions->setConfigFromParams($oConfig, 'LoginLogo', 'branding', 'login_logo', 'string');
$oActions->setConfigFromParams($oConfig, 'LoginBackground', 'branding', 'login_background', 'string');
$oActions->setConfigFromParams($oConfig, 'LoginDescription', 'branding', 'login_desc', 'string');
$oActions->setConfigFromParams($oConfig, 'LoginCss', 'branding', 'login_css', 'string');
$oActions->setConfigFromParams($oConfig, 'UserLogo', 'branding', 'user_logo', 'string');
$oActions->setConfigFromParams($oConfig, 'UserLogoTitle', 'branding', 'user_logo_title', 'string');
$oActions->setConfigFromParams($oConfig, 'UserLogoMessage', 'branding', 'user_logo_message', 'string');
$oActions->setConfigFromParams($oConfig, 'UserIframeMessage', 'branding', 'user_iframe_message', 'string');
$oActions->setConfigFromParams($oConfig, 'UserCss', 'branding', 'user_css', 'string');
$oActions->setConfigFromParams($oConfig, 'WelcomePageUrl', 'branding', 'welcome_page_url', 'string');
$oActions->setConfigFromParams($oConfig, 'WelcomePageDisplay', 'branding', 'welcome_page_display', 'string');
}
}
}

View file

@ -34,18 +34,13 @@ class Settings extends \RainLoop\Providers\AbstractProvider
/**
* @param \RainLoop\Model\Account $oAccount
* @param \RainLoop\Settings $oSettings
*
* @return bool
*/
public function Save(\RainLoop\Model\Account $oAccount, \RainLoop\Settings $oSettings)
public function Save(\RainLoop\Model\Account $oAccount, \RainLoop\Settings $oSettings) : bool
{
return $this->oDriver->Save($oAccount, $oSettings->DataAsArray());
}
/**
* @return bool
*/
public function IsActive()
public function IsActive() : bool
{
return $this->oDriver instanceof \RainLoop\Providers\Settings\ISettings;
}

View file

@ -12,20 +12,12 @@ class DefaultSettings implements \RainLoop\Providers\Settings\ISettings
*/
private $oStorageProvider;
/**
* @param \RainLoop\Providers\Storage $oStorageProvider
*/
public function __construct(\RainLoop\Providers\Storage $oStorageProvider)
{
$this->oStorageProvider = $oStorageProvider;
}
/**
* @param \RainLoop\Model\Account $oAccount
*
* @return array
*/
public function Load($oAccount)
public function Load(\RainLoop\Model\Account $oAccount) : array
{
$sValue = $this->oStorageProvider->Get($oAccount,
\RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG,
@ -47,13 +39,7 @@ class DefaultSettings implements \RainLoop\Providers\Settings\ISettings
return $aSettings;
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param array $aSettings
*
* @return bool
*/
public function Save($oAccount, array $aSettings)
public function Save(\RainLoop\Model\Account $oAccount, array $aSettings) : bool
{
return $this->oStorageProvider->Put($oAccount,
\RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG,
@ -63,12 +49,7 @@ class DefaultSettings implements \RainLoop\Providers\Settings\ISettings
\json_encode($aSettings));
}
/**
* @param \RainLoop\Model\Account $oAccount
*
* @return bool
*/
public function Delete($oAccount)
public function Delete(\RainLoop\Model\Account $oAccount) : bool
{
return $this->oStorageProvider->Clear($oAccount,
\RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG,
@ -76,4 +57,4 @@ class DefaultSettings implements \RainLoop\Providers\Settings\ISettings
\RainLoop\Providers\Settings\DefaultSettings::FILE_NAME_LOCAL :
\RainLoop\Providers\Settings\DefaultSettings::FILE_NAME);
}
}
}

View file

@ -4,25 +4,9 @@ namespace RainLoop\Providers\Settings;
interface ISettings
{
/**
* @param \RainLoop\Model\Account $oAccount
*
* @return array
*/
public function Load($oAccount);
public function Load(\RainLoop\Model\Account $oAccount) : array;
/**
* @param \RainLoop\Model\Account $oAccount
* @param array $aSettings
*
* @return bool
*/
public function Save($oAccount, array $aSettings);
public function Save(\RainLoop\Model\Account $oAccount, array $aSettings) : bool;
/**
* @param \RainLoop\Model\Account $oAccount
*
* @return bool
*/
public function Delete($oAccount);
}
public function Delete(\RainLoop\Model\Account $oAccount) : bool;
}

View file

@ -19,11 +19,8 @@ class Storage extends \RainLoop\Providers\AbstractProvider
/**
* @param \RainLoop\Model\Account|string|null $mAccount
* @param int $iStorageType
*
* @return bool
*/
private function verifyAccount($mAccount, $iStorageType)
private function verifyAccount($mAccount, int $iStorageType) : bool
{
if (\RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY !== $iStorageType &&
!($mAccount instanceof \RainLoop\Model\Account || \is_string($mAccount)))
@ -36,13 +33,9 @@ class Storage extends \RainLoop\Providers\AbstractProvider
/**
* @param \RainLoop\Model\Account|string|null $oAccount
* @param int $iStorageType
* @param string $sKey
* @param string $sValue
*
* @return bool
* @param mixed $sValue
*/
public function Put($oAccount, $iStorageType, $sKey, $sValue)
public function Put($oAccount, int $iStorageType, string $sKey, $sValue) : bool
{
if (!$this->verifyAccount($oAccount, $iStorageType))
{
@ -54,13 +47,11 @@ class Storage extends \RainLoop\Providers\AbstractProvider
/**
* @param \RainLoop\Model\Account|string|null $oAccount
* @param int $iStorageType
* @param string $sKey
* @param mixed $mDefault = false
*
* @return mixed
*/
public function Get($oAccount, $iStorageType, $sKey, $mDefault = false)
public function Get($oAccount, int $iStorageType, string $sKey, $mDefault = false)
{
if (!$this->verifyAccount($oAccount, $iStorageType))
{
@ -72,12 +63,8 @@ class Storage extends \RainLoop\Providers\AbstractProvider
/**
* @param \RainLoop\Model\Account|string|null $oAccount
* @param int $iStorageType
* @param string $sKey
*
* @return bool
*/
public function Clear($oAccount, $iStorageType, $sKey)
public function Clear($oAccount, int $iStorageType, string $sKey) : bool
{
if (!$this->verifyAccount($oAccount, $iStorageType))
{
@ -89,26 +76,18 @@ class Storage extends \RainLoop\Providers\AbstractProvider
/**
* @param \RainLoop\Model\Account|string $oAccount
*
* @return bool
*/
public function DeleteStorage($oAccount)
public function DeleteStorage($oAccount) : bool
{
return $this->oDriver->DeleteStorage($oAccount);
}
/**
* @return bool
*/
public function IsActive()
public function IsActive() : bool
{
return $this->oDriver instanceof \RainLoop\Providers\Storage\IStorage;
}
/**
* @return bool
*/
public function IsLocal()
public function IsLocal() : bool
{
return $this->oDriver instanceof \RainLoop\Providers\Storage\IStorage &&
$this->oDriver->IsLocal();

View file

@ -20,12 +20,9 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
protected $oLogger;
/**
* @param string $sStoragePath
* @param bool $bLocal = false
*
* @return void
*/
public function __construct($sStoragePath, $bLocal = false)
public function __construct(string $sStoragePath, bool $bLocal = false)
{
$this->sDataPath = \rtrim(\trim($sStoragePath), '\\/');
$this->bLocal = !!$bLocal;
@ -34,13 +31,9 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
/**
* @param \RainLoop\Model\Account|string|null $oAccount
* @param int $iStorageType
* @param string $sKey
* @param string $sValue
*
* @return bool
* @param mixed $sValue
*/
public function Put($oAccount, $iStorageType, $sKey, $sValue)
public function Put($oAccount, int $iStorageType, string $sKey, $sValue) : bool
{
return false !== @\file_put_contents(
$this->generateFileName($oAccount, $iStorageType, $sKey, true), $sValue);
@ -48,13 +41,11 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
/**
* @param \RainLoop\Model\Account|string|null $oAccount
* @param int $iStorageType
* @param string $sKey
* @param mixed $mDefault = false
*
* @return mixed
*/
public function Get($oAccount, $iStorageType, $sKey, $mDefault = false)
public function Get($oAccount, int $iStorageType, string $sKey, $mDefault = false)
{
$mValue = false;
$sFileName = $this->generateFileName($oAccount, $iStorageType, $sKey);
@ -68,12 +59,8 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
/**
* @param \RainLoop\Model\Account|string|null $oAccount
* @param int $iStorageType
* @param string $sKey
*
* @return bool
*/
public function Clear($oAccount, $iStorageType, $sKey)
public function Clear($oAccount, int $iStorageType, string $sKey) : bool
{
$mResult = true;
$sFileName = $this->generateFileName($oAccount, $iStorageType, $sKey);
@ -87,10 +74,8 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
/**
* @param \RainLoop\Model\Account|string $oAccount
*
* @return bool
*/
public function DeleteStorage($oAccount)
public function DeleteStorage($oAccount) : bool
{
$sPath = $this->generateFileName($oAccount,
\RainLoop\Providers\Storage\Enumerations\StorageType::USER, 'xxx', false, true);
@ -111,24 +96,15 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
return true;
}
/**
* @return bool
*/
public function IsLocal()
public function IsLocal() : bool
{
return $this->bLocal;
}
/**
* @param \RainLoop\Model\Account|string|null $mAccount
* @param int $iStorageType
* @param string $sKey
* @param bool $bMkDir = false
* @param bool $bForDeleteAction = false
*
* @return string
*/
public function generateFileName($mAccount, $iStorageType, $sKey, $bMkDir = false, $bForDeleteAction = false)
public function generateFileName($mAccount, int $iStorageType, string $sKey, bool $bMkDir = false, bool $bForDeleteAction = false) : string
{
if (null === $mAccount)
{
@ -196,8 +172,8 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
/**
* @param \MailSo\Log\Logger $oLogger
*/
public function SetLogger($oLogger)
public function SetLogger(?\MailSo\Log\Logger $oLogger)
{
$this->oLogger = $oLogger instanceof \MailSo\Log\Logger ? $oLogger : null;
$this->oLogger = $oLogger;
}
}

View file

@ -6,35 +6,22 @@ interface IStorage
{
/**
* @param \RainLoop\Model\Account|null $oAccount
* @param int $iStorageType
* @param string $sKey
* @param string $sValue
*
* @return bool
* @param mixed $sValue
*/
public function Put($oAccount, $iStorageType, $sKey, $sValue);
public function Put($oAccount, int $iStorageType, int $sKey, $sValue) : bool;
/**
* @param \RainLoop\Model\Account|null $oAccount
* @param int $iStorageType
* @param string $sKey
* @param mixed $mDefault = false
*
* @return mixed
*/
public function Get($oAccount, $iStorageType, $sKey, $mDefault = false);
public function Get($oAccount, int $iStorageType, string $sKey, $mDefault = false);
/**
* @param \RainLoop\Model\Account|null $oAccount
* @param int $iStorageType
* @param string $sKey
*
* @return bool
*/
public function Clear($oAccount, $iStorageType, $sKey);
public function Clear($oAccount, int $iStorageType, string $sKey) : bool;
/**
* @return bool
*/
public function IsLocal();
public function IsLocal() : bool;
}

View file

@ -6,26 +6,20 @@ class TemproryApcStorage extends \RainLoop\Providers\Storage\FileStorage
{
/**
* @param \RainLoop\Model\Account|string|null $oAccount
* @param int $iStorageType
* @param string $sKey
* @param string $sValue
*
* @return bool
* @param mixed $sValue
*/
public function Put($oAccount, $iStorageType, $sKey, $sValue)
public function Put($oAccount, int $iStorageType, string $sKey, $sValue) : bool
{
return !!@\apc_store($this->generateFileName($oAccount, $iStorageType, $sKey, true), $sValue);
}
/**
* @param \RainLoop\Model\Account|string|null $oAccount
* @param int $iStorageType
* @param string $sKey
* @param mixed $mDefault = false
*
* @return mixed
*/
public function Get($oAccount, $iStorageType, $sKey, $mDefault = false)
public function Get($oAccount, int $iStorageType, string $sKey, $mDefault = false)
{
$bValue = false;
$mValue = @\apc_fetch($this->generateFileName($oAccount, $iStorageType, $sKey), $bValue);
@ -39,12 +33,8 @@ class TemproryApcStorage extends \RainLoop\Providers\Storage\FileStorage
/**
* @param \RainLoop\Model\Account|string|null $oAccount
* @param int $iStorageType
* @param string $sKey
*
* @return bool
*/
public function Clear($oAccount, $iStorageType, $sKey)
public function Clear($oAccount, int $iStorageType, string $sKey) : bool
{
@\apc_delete($this->generateFileName($oAccount, $iStorageType, $sKey));
@ -53,24 +43,16 @@ class TemproryApcStorage extends \RainLoop\Providers\Storage\FileStorage
/**
* @param \RainLoop\Model\Account|string $oAccount
*
* @return bool
*/
public function DeleteStorage($oAccount)
public function DeleteStorage($oAccount) : bool
{
return !!$oAccount;
}
/**
* @param \RainLoop\Model\Account|string|null $mAccount
* @param int $iStorageType
* @param string $sKey
* @param bool $bMkDir = false
* @param bool $bForDeleteAction = false
*
* @return string
*/
public function generateFileName($mAccount, $iStorageType, $sKey, $bMkDir = false, $bForDeleteAction = false)
public function generateFileName($mAccount, int $iStorageType, string $sKey, bool $bMkDir = false, bool $bForDeleteAction = false) : string
{
$sFileName = parent::generateFileName($mAccount, $iStorageType, $sKey, false, false);
return $sFileName.'/'.\RainLoop\Utils::GetConnectionToken().'/';

View file

@ -14,7 +14,7 @@ class Suggestions extends \RainLoop\Providers\AbstractProvider
*
* @return void
*/
public function __construct($aDriver = null)
public function __construct(?array $aDriver = null)
{
if (\is_array($aDriver))
{
@ -26,14 +26,7 @@ class Suggestions extends \RainLoop\Providers\AbstractProvider
$this->aDrivers = \is_array($aDriver) && 0 < \count($aDriver) ? $aDriver : null;
}
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sQuery
* @param int $iLimit = 20
*
* @return array
*/
public function Process($oAccount, $sQuery, $iLimit = 20)
public function Process(\RainLoop\Model\Account $oAccount, string $sQuery, int $iLimit = 20) : array
{
$aSuggestions = array();
if ($oAccount instanceof \RainLoop\Model\Account &&
@ -63,11 +56,8 @@ class Suggestions extends \RainLoop\Providers\AbstractProvider
return $aResult;
}
/**
* @return bool
*/
public function IsActive()
public function IsActive() : bool
{
return \is_array($this->aDrivers) && 0 < \count($this->aDrivers);
}
}
}

View file

@ -5,11 +5,7 @@ namespace RainLoop\Providers\Suggestions;
interface ISuggestions
{
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sQuery
* @param int $iLimit = 20
*
* @return array [['email@1', 'name_1'], ['email@2', 'name_2']]
*/
public function Process($oAccount, $sQuery, $iLimit = 20);
}
public function Process(\RainLoop\Model\Account $oAccount, string $sQuery, int $iLimit = 20);
}

View file

@ -1,116 +0,0 @@
<?php
namespace RainLoop\Providers\Suggestions;
class OwnCloudSuggestions implements \RainLoop\Providers\Suggestions\ISuggestions
{
/**
* @var \MailSo\Log\Logger
*/
protected $oLogger;
/**
* @param \RainLoop\Model\Account $oAccount
* @param string $sQuery
* @param int $iLimit = 20
*
* @return array
*/
public function Process($oAccount, $sQuery, $iLimit = 20)
{
$iInputLimit = $iLimit;
$aResult = array();
$sQuery = \trim($sQuery);
try
{
if ('' === $sQuery || !$oAccount || !\RainLoop\Utils::IsOwnCloudLoggedIn())
{
return $aResult;
}
$aParams = array('FN', 'NICKNAME', 'TITLE', 'EMAIL');
if (\class_exists('OC') && isset(\OC::$server) && \method_exists(\OC::$server, 'getContactsManager'))
{
$cm = \OC::$server->getContactsManager();
if (!$cm && !$cm->isEnabled())
{
return $aResult;
}
$aSearchResult = $cm->search($sQuery, $aParams);
}
else if (\class_exists('OCP\Contacts') && \OCP\Contacts::isEnabled())
{
$aSearchResult = \OCP\Contacts::search($sQuery, $aParams);
}
else
{
return $aResult;
}
//$this->oLogger->WriteDump($aSearchResult);
$aHashes = array();
if (\is_array($aSearchResult) && 0 < \count($aSearchResult))
{
foreach ($aSearchResult as $aContact)
{
if (0 >= $iLimit)
{
break;
}
$sUid = empty($aContact['UID']) ? '' : $aContact['UID'];
if (!empty($sUid))
{
$mEmails = isset($aContact['EMAIL']) ? $aContact['EMAIL'] : '';
$sFullName = isset($aContact['FN']) ? \trim($aContact['FN']) : '';
if (empty($sFullName))
{
$sFullName = isset($aContact['NICKNAME']) ? \trim($aContact['NICKNAME']) : '';
}
if (!\is_array($mEmails))
{
$mEmails = array($mEmails);
}
foreach ($mEmails as $sEmail)
{
$sHash = '"'.$sFullName.'" <'.$sEmail.'>';
if (!isset($aHashes[$sHash]))
{
$aHashes[$sHash] = true;
$aResult[] = array($sEmail, $sFullName);
$iLimit--;
}
}
}
}
$aResult = \array_slice($aResult, 0, $iInputLimit);
}
unset($aSearchResult, $aHashes);
}
catch (\Exception $oException)
{
if ($this->oLogger)
{
$this->oLogger->WriteException($oException);
}
}
return $aResult;
}
/**
* @param \MailSo\Log\Logger $oLogger
*/
public function SetLogger($oLogger)
{
$this->oLogger = $oLogger instanceof \MailSo\Log\Logger ? $oLogger : null;
}
}

View file

@ -8,10 +8,8 @@ class TestSuggestions implements \RainLoop\Providers\Suggestions\ISuggestions
* @param \RainLoop\Model\Account $oAccount
* @param string $sQuery
* @param int $iLimit = 20
*
* @return array
*/
public function Process($oAccount, $sQuery, $iLimit = 20)
public function Process(\RainLoop\Model\Account $oAccount, string $sQuery, int $iLimit = 20) : array
{
return array(
array($oAccount->Email(), ''),

View file

@ -9,41 +9,23 @@ class TwoFactorAuth extends \RainLoop\Providers\AbstractProvider
*/
private $oDriver;
/**
* @param \RainLoop\Providers\TwoFactorAuth\TwoFactorAuthInterface|null $oDriver = null
*
* @return void
*/
public function __construct($oDriver = null)
public function __construct(?\RainLoop\Providers\TwoFactorAuth\TwoFactorAuthInterface $oDriver = null)
{
$this->oDriver = $oDriver;
}
/**
* @return bool
*/
public function IsActive()
public function IsActive() : bool
{
return $this->oDriver instanceof \RainLoop\Providers\TwoFactorAuth\TwoFactorAuthInterface;
}
/**
* @param string $sName
* @param string $sSecret
* @param string $sTitle = ''
*
* @return string
*/
public function GetQRCodeGoogleUrl($sName, $sSecret, $sTitle = '')
public function GetQRCodeGoogleUrl(string $sName, string $sSecret, string $sTitle = '') : string
{
$sUrl = sprintf('otpauth://%s/%s?secret=%s&issuer=%s', 'totp', urlencode($sName), $sSecret, urlencode($sTitle));
return 'https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl='.\urlencode($sUrl);
}
/**
* @return string
*/
public function CreateSecret()
public function CreateSecret() : string
{
$sResult = '';
if ($this->IsActive())
@ -53,14 +35,8 @@ class TwoFactorAuth extends \RainLoop\Providers\AbstractProvider
return $sResult;
}
/**
* @param string $sSecret
* @param string $sCode
*
* @return bool
*/
public function VerifyCode($sSecret, $sCode)
public function VerifyCode(string $sSecret, string $sCode) : bool
{
$bResult = false;
if ($this->IsActive())

View file

@ -4,20 +4,12 @@ namespace RainLoop\Providers\TwoFactorAuth;
abstract class AbstractTwoFactorAuth
{
/**
* @return string
*/
public function Label()
public function Label() : string
{
return 'Two Factor Authenticator Code';
}
/**
* @param string $sSecret
* @param string $sCode
* @return bool
*/
public function VerifyCode($sSecret, $sCode)
public function VerifyCode(string $sSecret, string $sCode) : bool
{
return false;
}

View file

@ -1,33 +0,0 @@
<?php
namespace RainLoop\Providers\TwoFactorAuth;
class GoogleTwoFactorAuth
extends \RainLoop\Providers\TwoFactorAuth\AbstractTwoFactorAuth
implements \RainLoop\Providers\TwoFactorAuth\TwoFactorAuthInterface
{
/**
* @param string $sSecret
* @param string $sCode
*
* @return bool
*/
public function VerifyCode($sSecret, $sCode)
{
include_once APP_VERSION_ROOT_PATH.'app/libraries/PHPGangsta/GoogleAuthenticator.php';
$oGoogleAuthenticator = new \PHPGangsta_GoogleAuthenticator();
return $oGoogleAuthenticator->verifyCode($sSecret, $sCode, 8);
}
/**
* @return string
*/
public function CreateSecret()
{
include_once APP_VERSION_ROOT_PATH.'app/libraries/PHPGangsta/GoogleAuthenticator.php';
$oGoogleAuthenticator = new \PHPGangsta_GoogleAuthenticator();
return $oGoogleAuthenticator->createSecret();
}
}

View file

@ -0,0 +1,101 @@
<?php
namespace RainLoop\Providers\TwoFactorAuth;
class TotpTwoFactorAuth
extends \RainLoop\Providers\TwoFactorAuth\AbstractTwoFactorAuth
implements \RainLoop\Providers\TwoFactorAuth\TwoFactorAuthInterface
{
public function VerifyCode(string $sSecret, string $sCode) : bool
{
$key = static::Base32Decode($sSecret);
$algo = 'SHA1'; // Google Authenticator doesn't support SHA256
$digits = 6; // Google Authenticator doesn't support 8
$modulo = \pow(10, $digits);
$timeSlice = \floor(\time() / 30);
$discrepancy = 1;
for ($i = -$discrepancy; $i <= $discrepancy; ++$i) {
// Pack time into binary string
$counter = \str_pad(\pack('N*', $timeSlice + $i), 8, "\x00", STR_PAD_LEFT);
// Hash it with users secret key
$hm = \hash_hmac($algo, $counter, $key, true);
// Unpak 4 bytes of the result, use last nipple of result as index/offset
$value = \unpack('N', \substr($hm, (\ord(\substr($hm, -1)) & 0x0F), 4));
// Only 32 bits
$value = $value[1] & 0x7FFFFFFF;
$value = \str_pad($value % $modulo, $digits, '0', STR_PAD_LEFT);
if (\hash_equals($value, $sCode)) {
return true;
}
}
return false;
}
public function CreateSecret() : string
{
$CHARS = \array_keys(static::$map);
$length = 16;
$secret = '';
while (0 < $length--) {
$secret .= $CHARS[\random_int(0,31)];
}
return $secret;
}
protected static $map = array(
'A' => 0, // ord 65
'B' => 1,
'C' => 2,
'D' => 3,
'E' => 4,
'F' => 5,
'G' => 6,
'H' => 7,
'I' => 8,
'J' => 9,
'K' => 10,
'L' => 11,
'M' => 12,
'N' => 13,
'O' => 14,
'P' => 15,
'Q' => 16,
'R' => 17,
'S' => 18,
'T' => 19,
'U' => 20,
'V' => 21,
'W' => 22,
'X' => 23,
'Y' => 24,
'Z' => 25, // ord 90
'2' => 26, // ord 50
'3' => 27,
'4' => 28,
'5' => 29,
'6' => 30,
'7' => 31 // ord 55
);
protected static function Base32Decode(string $data)
{
$data = \strtoupper(\rtrim($data, "=\x20\t\n\r\0\x0B"));
$dataSize = \strlen($data);
$buf = 0;
$bufSize = 0;
$res = '';
for ($i = 0; $i < $dataSize; ++$i) {
$c = $data[$i];
if (isset(static::$map[$c])) {
$buf = ($buf << 5) | static::$map[$c];
$bufSize += 5;
if ($bufSize > 7) {
$bufSize -= 8;
$res .= \chr(($buf & (0xff << $bufSize)) >> $bufSize);
}
}
}
return $res;
}
}

View file

@ -4,11 +4,5 @@ namespace RainLoop\Providers\TwoFactorAuth;
interface TwoFactorAuthInterface
{
/**
* @param string $sSecret
* @param string $sCode
*
* @return bool
*/
public function VerifyCode($sSecret, $sCode);
public function VerifyCode(string $sSecret, string $sCode) : bool;
}