mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-08 22:18:28 +03:00
Preparing to support wildcard domains.
This commit is contained in:
parent
c811fdf545
commit
126b55b2d5
4 changed files with 126 additions and 44 deletions
|
|
@ -14,11 +14,14 @@ class Helper
|
|||
/**
|
||||
* @param string $sString
|
||||
* @param string $sWildcardValues
|
||||
* @param string $sFoundedValue = ''
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
static public function ValidateWildcardValues($sString, $sWildcardValues)
|
||||
static public function ValidateWildcardValues($sString, $sWildcardValues, &$sFoundedValue = '')
|
||||
{
|
||||
$sFoundedValue = '';
|
||||
|
||||
$sString = \trim($sString);
|
||||
if ('' === $sString)
|
||||
{
|
||||
|
|
@ -26,11 +29,17 @@ class Helper
|
|||
}
|
||||
|
||||
$sWildcardValues = \trim($sWildcardValues);
|
||||
if ('' === $sWildcardValues || '*' === $sWildcardValues)
|
||||
if ('' === $sWildcardValues)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ('*' === $sWildcardValues)
|
||||
{
|
||||
$sFoundedValue = '*';
|
||||
return true;
|
||||
}
|
||||
|
||||
$sWildcardValues = \preg_replace('/[*]+/', '*', \preg_replace('/[\s,;]+/', ' ', $sWildcardValues));
|
||||
$aWildcardValues = \explode(' ', $sWildcardValues);
|
||||
|
||||
|
|
@ -40,6 +49,7 @@ class Helper
|
|||
{
|
||||
if ($sString === $sItem)
|
||||
{
|
||||
$sFoundedValue = $sItem;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -52,6 +62,7 @@ class Helper
|
|||
|
||||
if (\preg_match('/'.\implode('.*', $aItem).'/', $sString))
|
||||
{
|
||||
$sFoundedValue = $sItem;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,12 +37,11 @@ class Domain extends \RainLoop\Providers\AbstractProvider
|
|||
* @param string $sName
|
||||
* @param bool $bDefaultOnNull = false
|
||||
*
|
||||
* @return \RainLoop\Domain | null
|
||||
* @return \RainLoop\Domain|null
|
||||
*/
|
||||
public function Load($sName, $bDefaultOnNull = false)
|
||||
{
|
||||
$oDomain = $this->oDriver->Load($sName);
|
||||
return $oDomain ? $oDomain : ($bDefaultOnNull ? $this->oDriver->Load('default') : null);
|
||||
return $this->oDriver->Load($sName, $bDefaultOnNull);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,7 +16,28 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
|||
*/
|
||||
public function __construct($sDomainPath)
|
||||
{
|
||||
$this->sDomainPath = rtrim(trim($sDomainPath), '\\/');
|
||||
$this->sDomainPath = \rtrim(\trim($sDomainPath), '\\/');
|
||||
}
|
||||
|
||||
/**
|
||||
* @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';
|
||||
}
|
||||
|
||||
$sName = \strtolower($sName);
|
||||
return $bBack ? \str_replace('_wildcard_', '*', $sName) : \str_replace('*', '_wildcard_', $sName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -28,16 +49,16 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
|||
public function Disable($sName, $bDisable)
|
||||
{
|
||||
$sFile = '';
|
||||
if (file_exists($this->sDomainPath.'/disabled'))
|
||||
if (\file_exists($this->sDomainPath.'/disabled'))
|
||||
{
|
||||
$sFile = @file_get_contents($this->sDomainPath.'/disabled');
|
||||
$sFile = @\file_get_contents($this->sDomainPath.'/disabled');
|
||||
}
|
||||
|
||||
$aResult = array();
|
||||
$aNames = explode(',', $sFile);
|
||||
$aNames = \explode(',', $sFile);
|
||||
if ($bDisable)
|
||||
{
|
||||
array_push($aNames, $sName);
|
||||
\array_push($aNames, $sName);
|
||||
$aResult = $aNames;
|
||||
}
|
||||
else
|
||||
|
|
@ -51,36 +72,71 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
|||
}
|
||||
}
|
||||
|
||||
$aResult = array_unique($aResult);
|
||||
return false !== file_put_contents($this->sDomainPath.'/disabled', trim(implode(',', $aResult), ', '));
|
||||
$aResult = \array_unique($aResult);
|
||||
return false !== \file_put_contents($this->sDomainPath.'/disabled', \trim(\implode(',', $aResult), ', '));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param bool $bFindWithWildCard = false
|
||||
*
|
||||
* @return \RainLoop\Domain | null
|
||||
*/
|
||||
public function Load($sName)
|
||||
public function Load($sName, $bFindWithWildCard = false)
|
||||
{
|
||||
$mResult = null;
|
||||
$sName = strtolower($sName);
|
||||
if (file_exists($this->sDomainPath.'/'.$sName.'.ini'))
|
||||
$sName = \strtolower($sName);
|
||||
$sRealFileName = $this->codeFileName($sName);
|
||||
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini'))
|
||||
{
|
||||
$mResult = \RainLoop\Domain::NewInstanceFromDomainConfigArray(
|
||||
$sName, @parse_ini_file($this->sDomainPath.'/'.$sName.'.ini'));
|
||||
$sName, @\parse_ini_file($this->sDomainPath.'/'.$sRealFileName.'.ini'));
|
||||
|
||||
if ($mResult instanceof \RainLoop\Domain)
|
||||
{
|
||||
if (file_exists($this->sDomainPath.'/disabled'))
|
||||
if (\file_exists($this->sDomainPath.'/disabled'))
|
||||
{
|
||||
$sDisabled = @file_get_contents($this->sDomainPath.'/disabled');
|
||||
if (false !== $sDisabled && 0 < strlen($sDisabled))
|
||||
$sDisabled = @\file_get_contents($this->sDomainPath.'/disabled');
|
||||
if (false !== $sDisabled && 0 < \strlen($sDisabled))
|
||||
{
|
||||
$mResult->SetDisabled(false !== strpos(strtolower(','.$sDisabled.','), strtolower(','.$sName.',')));
|
||||
$mResult->SetDisabled(false !== \strpos(strtolower(','.$sDisabled.','), \strtolower(','.$sName.',')));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($bFindWithWildCard)
|
||||
{
|
||||
// TODO
|
||||
// $sNames = '';
|
||||
// $aNames = array();
|
||||
//
|
||||
// $aList = \glob($this->sDomainPath.'/*.ini');
|
||||
// foreach ($aList as $sFile)
|
||||
// {
|
||||
// $sName = \strtolower(\substr(\basename($sFile), 0, -4));
|
||||
// if ('default' === $sName || false !== strpos($sName, '_wildcard_'))
|
||||
// {
|
||||
// $aNames[] = $this->codeFileName($sName, true);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (0 < \count($aNames))
|
||||
// {
|
||||
// \rsort($sNames, SORT_STRING);
|
||||
// $sNames = \implode(' ', $aNames);
|
||||
// }
|
||||
//
|
||||
// if (0 < \strlen($sNames))
|
||||
// {
|
||||
// $sFoundedValue = '';
|
||||
// if (\RainLoop\Plugins\Helper::ValidateWildcardValues($sName, $sNames, $sFoundedValue) && 0 < \strlen($sFoundedValue))
|
||||
// {
|
||||
// $mResult = $this->Load($sFoundedValue, false);
|
||||
// }
|
||||
// }
|
||||
|
||||
$mResult = $this->Load('default', false);
|
||||
}
|
||||
|
||||
return $mResult;
|
||||
}
|
||||
|
|
@ -92,8 +148,11 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
|||
*/
|
||||
public function Save(\RainLoop\Domain $oDomain)
|
||||
{
|
||||
$mResult = file_put_contents($this->sDomainPath.'/'.strtolower($oDomain->Name()).'.ini', $oDomain->ToIniString());
|
||||
return is_int($mResult) && 0 < $mResult;
|
||||
$sName = \strtolower($oDomain->Name());
|
||||
$sRealFileName = $this->codeFileName($sName);
|
||||
|
||||
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.ini', $oDomain->ToIniString());
|
||||
return \is_int($mResult) && 0 < $mResult;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -104,10 +163,17 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
|||
public function Delete($sName)
|
||||
{
|
||||
$bResult = true;
|
||||
$sName = strtolower($sName);
|
||||
if (0 < strlen($sName) && file_exists($this->sDomainPath.'/'.$sName.'.ini'))
|
||||
$sName = \strtolower($sName);
|
||||
$sRealFileName = $this->codeFileName($sName);
|
||||
|
||||
if (0 < \strlen($sName) && \file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini'))
|
||||
{
|
||||
$bResult = unlink($this->sDomainPath.'/'.$sName.'.ini');
|
||||
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.ini');
|
||||
}
|
||||
|
||||
if ($bResult)
|
||||
{
|
||||
$this->Disable($sName, false);
|
||||
}
|
||||
|
||||
return $bResult;
|
||||
|
|
@ -116,45 +182,54 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
|||
/**
|
||||
* @param int $iOffset
|
||||
* @param int $iLimit = 20
|
||||
* @param string $sSearch = ''
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetList($iOffset, $iLimit = 20, $sSearch = '')
|
||||
public function GetList($iOffset, $iLimit = 20)
|
||||
{
|
||||
$aResult = array();
|
||||
$aList = glob($this->sDomainPath.'/*.ini');
|
||||
$aWildCards = array();
|
||||
$aList = \glob($this->sDomainPath.'/*.ini');
|
||||
|
||||
$sSearch = strtolower($sSearch);
|
||||
foreach ($aList as $sFile)
|
||||
{
|
||||
$sName = strtolower(substr(basename($sFile), 0, -4));
|
||||
if (0 === strlen($sSearch) || false !== strpos($sName, $sSearch))
|
||||
$sName = \strtolower(\substr(\basename($sFile), 0, -4));
|
||||
$sName = $this->codeFileName($sName, true);
|
||||
if (false === \strpos($sName, '*'))
|
||||
{
|
||||
$aResult[] = $sName;
|
||||
}
|
||||
else
|
||||
{
|
||||
$aWildCards[] = $sName;
|
||||
}
|
||||
}
|
||||
|
||||
\sort($aResult, SORT_STRING);
|
||||
\rsort($aWildCards, SORT_STRING);
|
||||
|
||||
$aResult = \array_merge($aResult, $aWildCards);
|
||||
|
||||
$iOffset = (0 > $iOffset) ? 0 : $iOffset;
|
||||
$iLimit = (0 > $iLimit) ? 0 : ((999 < $iLimit) ? 999 : $iLimit);
|
||||
|
||||
$aResult = array_slice($aResult, $iOffset, $iLimit);
|
||||
$aResult = \array_slice($aResult, $iOffset, $iLimit);
|
||||
|
||||
$aDisabledNames = array();
|
||||
if (0 < count($aResult) && file_exists($this->sDomainPath.'/disabled'))
|
||||
if (0 < \count($aResult) && \file_exists($this->sDomainPath.'/disabled'))
|
||||
{
|
||||
$sDisabled = @file_get_contents($this->sDomainPath.'/disabled');
|
||||
$sDisabled = @\file_get_contents($this->sDomainPath.'/disabled');
|
||||
if (false !== $sDisabled && 0 < strlen($sDisabled))
|
||||
{
|
||||
$aDisabledNames = explode(',', strtolower($sDisabled));
|
||||
$aDisabledNames = array_unique($aDisabledNames);
|
||||
$aDisabledNames = \explode(',', strtolower($sDisabled));
|
||||
$aDisabledNames = \array_unique($aDisabledNames);
|
||||
}
|
||||
}
|
||||
|
||||
$aReturn = array();
|
||||
foreach ($aResult as $sName)
|
||||
{
|
||||
$aReturn[$sName] = !in_array(strtolower($sName), $aDisabledNames);
|
||||
$aReturn[$sName] = !\in_array(\strtolower($sName), $aDisabledNames);
|
||||
}
|
||||
|
||||
return $aReturn;
|
||||
|
|
@ -165,8 +240,8 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
|||
*
|
||||
* @return int
|
||||
*/
|
||||
public function Count($sSearch = '')
|
||||
public function Count()
|
||||
{
|
||||
return count($this->GetList(0, 999, $sSearch));
|
||||
return \count($this->GetList(0, 999));
|
||||
}
|
||||
}
|
||||
|
|
@ -37,16 +37,13 @@ interface DomainAdminInterface extends DomainInterface
|
|||
/**
|
||||
* @param int $iOffset
|
||||
* @param int $iLimit = 20
|
||||
* @param string $sSearch = ''
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetList($iOffset, $iLimit = 20, $sSearch = '');
|
||||
public function GetList($iOffset, $iLimit = 20);
|
||||
|
||||
/**
|
||||
* @param string $sSearch = ''
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function Count($sSearch = '');
|
||||
public function Count();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue