mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-09 06:28:28 +03:00
Improved domains .ini files handling
This commit is contained in:
parent
eb0cd796b0
commit
b5920cbc32
2 changed files with 64 additions and 77 deletions
|
|
@ -20,7 +20,7 @@ class DefaultDomain implements DomainInterface
|
|||
$this->oCacher = $oCacher;
|
||||
}
|
||||
|
||||
public function codeFileName(string $sName, bool $bBack = false) : string
|
||||
private static function codeFileName(string $sName, bool $bBack = false) : string
|
||||
{
|
||||
if ($bBack && 'default' === $sName) {
|
||||
return '*';
|
||||
|
|
@ -35,7 +35,7 @@ class DefaultDomain implements DomainInterface
|
|||
: \str_replace('*', '_wildcard_', \MailSo\Base\Utils::IdnToAscii($sName, true));
|
||||
}
|
||||
|
||||
private function wildcardDomainsCacheKey() : string
|
||||
private static function wildcardDomainsCacheKey() : string
|
||||
{
|
||||
return '/WildCard/DomainCache/'.\md5(APP_VERSION.APP_PRIVATE_DATA_NAME).'/';
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ class DefaultDomain implements DomainInterface
|
|||
{
|
||||
if ($this->oCacher)
|
||||
{
|
||||
$sResult = $this->oCacher->Get($this->wildcardDomainsCacheKey());
|
||||
$sResult = $this->oCacher->Get(static::wildcardDomainsCacheKey());
|
||||
if (\strlen($sResult))
|
||||
{
|
||||
return $sResult;
|
||||
|
|
@ -60,7 +60,7 @@ class DefaultDomain implements DomainInterface
|
|||
$sName = \substr(\basename($sFile), 0, -4);
|
||||
if ('default' === $sName || false !== \strpos($sName, '_wildcard_'))
|
||||
{
|
||||
$aNames[] = $this->codeFileName($sName, true);
|
||||
$aNames[] = static::codeFileName($sName, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ class DefaultDomain implements DomainInterface
|
|||
|
||||
if ($this->oCacher)
|
||||
{
|
||||
$this->oCacher->Set($this->wildcardDomainsCacheKey(), $sResult);
|
||||
$this->oCacher->Set(static::wildcardDomainsCacheKey(), $sResult);
|
||||
}
|
||||
|
||||
return $sResult;
|
||||
|
|
@ -85,7 +85,7 @@ class DefaultDomain implements DomainInterface
|
|||
$aDisabled = [];
|
||||
$sFoundValue = '';
|
||||
|
||||
$sRealFileName = $this->codeFileName($sName);
|
||||
$sRealFileName = static::codeFileName($sName);
|
||||
|
||||
if (\file_exists($this->sDomainPath.'/disabled')) {
|
||||
$aDisabled = \explode(',', \file_get_contents($this->sDomainPath.'/disabled'));
|
||||
|
|
@ -140,11 +140,11 @@ class DefaultDomain implements DomainInterface
|
|||
|
||||
public function Save(\RainLoop\Model\Domain $oDomain) : bool
|
||||
{
|
||||
$sRealFileName = $this->codeFileName($oDomain->Name());
|
||||
$sRealFileName = static::codeFileName($oDomain->Name());
|
||||
|
||||
if ($this->oCacher)
|
||||
{
|
||||
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
|
||||
$this->oCacher->Delete(static::wildcardDomainsCacheKey());
|
||||
}
|
||||
|
||||
\RainLoop\Utils::saveFile($this->sDomainPath.'/'.$sRealFileName.'.ini', $oDomain->ToIniString());
|
||||
|
|
@ -154,11 +154,11 @@ class DefaultDomain implements DomainInterface
|
|||
|
||||
public function SaveAlias(string $sName, string $sAlias) : bool
|
||||
{
|
||||
$sRealFileName = $this->codeFileName($sName);
|
||||
$sRealFileName = static::codeFileName($sName);
|
||||
|
||||
if ($this->oCacher)
|
||||
{
|
||||
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
|
||||
$this->oCacher->Delete(static::wildcardDomainsCacheKey());
|
||||
}
|
||||
|
||||
\RainLoop\Utils::saveFile($this->sDomainPath.'/'.$sRealFileName.'.alias', $sAlias);
|
||||
|
|
@ -200,7 +200,7 @@ class DefaultDomain implements DomainInterface
|
|||
public function Delete(string $sName) : bool
|
||||
{
|
||||
$bResult = true;
|
||||
$sRealFileName = $this->codeFileName($sName);
|
||||
$sRealFileName = static::codeFileName($sName);
|
||||
|
||||
if (\strlen($sName))
|
||||
{
|
||||
|
|
@ -221,7 +221,7 @@ class DefaultDomain implements DomainInterface
|
|||
|
||||
if ($this->oCacher)
|
||||
{
|
||||
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
|
||||
$this->oCacher->Delete(static::wildcardDomainsCacheKey());
|
||||
}
|
||||
|
||||
return $bResult;
|
||||
|
|
@ -229,71 +229,55 @@ class DefaultDomain implements DomainInterface
|
|||
|
||||
public function GetList(bool $bIncludeAliases = true) : array
|
||||
{
|
||||
$aDisabledNames = array();
|
||||
if (\file_exists($this->sDomainPath.'/disabled')) {
|
||||
$sDisabled = \file_get_contents($this->sDomainPath.'/disabled');
|
||||
if (\strlen($sDisabled)) {
|
||||
$aDisabledNames = \explode(',', $sDisabled);
|
||||
foreach ($aDisabledNames as &$sValue) {
|
||||
$sValue = \MailSo\Base\Utils::IdnToUtf8($sValue, true);
|
||||
}
|
||||
$aDisabledNames = \array_unique($aDisabledNames);
|
||||
}
|
||||
}
|
||||
|
||||
$aResult = array();
|
||||
$aWildCards = array();
|
||||
$aAliases = array();
|
||||
|
||||
// $aList = \glob($this->sDomainPath.'/*.{ini,alias}', GLOB_BRACE);
|
||||
$aList = \array_diff(\scandir($this->sDomainPath), array('.', '..'));
|
||||
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;
|
||||
foreach ($aList as $sFile) {
|
||||
$bAlias = '.alias' === \substr($sFile, -6);
|
||||
if ($bAlias || '.ini' === \substr($sFile, -4)) {
|
||||
$sName = static::codeFileName(\preg_replace('/\.(ini|alias)$/', '', $sFile), true);
|
||||
if ($bAlias) {
|
||||
if ($bIncludeAliases) {
|
||||
$aAliases[$sName] = array(
|
||||
'name' => $sName,
|
||||
'disabled' => \in_array($sName, $aDisabledNames),
|
||||
'alias' => true
|
||||
);
|
||||
}
|
||||
}
|
||||
else if (false !== \strpos($sName, '*'))
|
||||
{
|
||||
$aWildCards[] = $sName;
|
||||
}
|
||||
else
|
||||
{
|
||||
$aResult[] = $sName;
|
||||
} else if (false !== \strpos($sName, '*')) {
|
||||
$aWildCards[$sName] = array(
|
||||
'name' => $sName,
|
||||
'disabled' => \in_array($sName, $aDisabledNames),
|
||||
'alias' => false
|
||||
);
|
||||
} else {
|
||||
$aResult[$sName] = array(
|
||||
'name' => $sName,
|
||||
'disabled' => \in_array($sName, $aDisabledNames),
|
||||
'alias' => false
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\sort($aResult, SORT_STRING);
|
||||
\sort($aAliases, SORT_STRING);
|
||||
\rsort($aWildCards, SORT_STRING);
|
||||
|
||||
$aResult = \array_merge($aResult, $aAliases, $aWildCards);
|
||||
|
||||
$aDisabledNames = array();
|
||||
if (\count($aResult) && \file_exists($this->sDomainPath.'/disabled'))
|
||||
{
|
||||
$sDisabled = \file_get_contents($this->sDomainPath.'/disabled');
|
||||
if (false !== $sDisabled && \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[] = array(
|
||||
'name' => $sName,
|
||||
'disabled' => \in_array($sName, $aDisabledNames),
|
||||
'alias' => \in_array($sName, $aAliases)
|
||||
);
|
||||
}
|
||||
|
||||
return $aReturn;
|
||||
\ksort($aResult, SORT_STRING);
|
||||
\ksort($aAliases, SORT_STRING);
|
||||
\krsort($aWildCards, SORT_STRING);
|
||||
return \array_values(\array_merge($aResult, $aAliases, $aWildCards));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,22 +142,25 @@ if (defined('APP_VERSION'))
|
|||
|
||||
if (!file_exists(APP_PRIVATE_DATA.'domains/disabled') && is_dir(APP_PRIVATE_DATA.'domains'))
|
||||
{
|
||||
$sFile = $sNewFile = '';
|
||||
$aFiles = glob(APP_VERSION_ROOT_PATH.'app/domains/*');
|
||||
if ($aFiles)
|
||||
{
|
||||
foreach ($aFiles as $sFile)
|
||||
{
|
||||
if (is_file($sFile))
|
||||
{
|
||||
if ($aFiles) {
|
||||
foreach ($aFiles as $sFile) {
|
||||
if (is_file($sFile)) {
|
||||
$sNewFile = APP_PRIVATE_DATA.'domains/'.basename($sFile);
|
||||
if (!file_exists($sNewFile))
|
||||
{
|
||||
if (!file_exists($sNewFile)) {
|
||||
copy($sFile, $sNewFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($aFiles, $sFile, $sNewFile);
|
||||
/*
|
||||
$sNewFile = APP_PRIVATE_DATA.'domains/'.gethostname().'.ini';
|
||||
if (!file_exists($sNewFile)) {
|
||||
\file_put_contents(
|
||||
$sNewFile,
|
||||
\str_replace('short_login = Off', 'short_login = On', \file_get_contents(APP_VERSION_ROOT_PATH.'app/domains/default.ini'))
|
||||
);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue