mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-31 21:19:21 +03:00
Improved private data directory handling
This commit is contained in:
parent
41a98d68c5
commit
2aceb89a8b
5 changed files with 58 additions and 50 deletions
|
|
@ -797,8 +797,8 @@ class Actions
|
||||||
$sPassword = $oConfig->Get('security', 'admin_password', '');
|
$sPassword = $oConfig->Get('security', 'admin_password', '');
|
||||||
if (!$sPassword) {
|
if (!$sPassword) {
|
||||||
$sPassword = \substr(\base64_encode(\random_bytes(16)), 0, 12);
|
$sPassword = \substr(\base64_encode(\random_bytes(16)), 0, 12);
|
||||||
\file_put_contents($passfile, $sPassword . "\n");
|
Utils::saveFile($passfile, $sPassword . "\n");
|
||||||
\chmod($passfile, 0600);
|
// \chmod($passfile, 0600);
|
||||||
$oConfig->SetPassword($sPassword);
|
$oConfig->SetPassword($sPassword);
|
||||||
$oConfig->Save();
|
$oConfig->Save();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -294,8 +294,11 @@ abstract class AbstractConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->clearCache();
|
$this->clearCache();
|
||||||
return false !== \file_put_contents($this->sFile,
|
|
||||||
|
\RainLoop\Utils::saveFile($this->sFile,
|
||||||
(\strlen($this->sFileHeader) ? $this->sFileHeader : '').
|
(\strlen($this->sFileHeader) ? $this->sFileHeader : '').
|
||||||
$sNewLine.\implode($sNewLine, $aResultLines));
|
$sNewLine.\implode($sNewLine, $aResultLines));
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -159,8 +159,9 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
||||||
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
|
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.ini', $oDomain->ToIniString());
|
\RainLoop\Utils::saveFile($this->sDomainPath.'/'.$sRealFileName.'.ini', $oDomain->ToIniString());
|
||||||
return \is_int($mResult) && 0 < $mResult;
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SaveAlias(string $sName, string $sAlias) : bool
|
public function SaveAlias(string $sName, string $sAlias) : bool
|
||||||
|
|
@ -172,8 +173,8 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
||||||
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
|
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.alias', $sAlias);
|
\RainLoop\Utils::saveFile($this->sDomainPath.'/'.$sRealFileName.'.alias', $sAlias);
|
||||||
return \is_int($mResult) && 0 < $mResult;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Disable(string $sName, bool $bDisable) : bool
|
public function Disable(string $sName, bool $bDisable) : bool
|
||||||
|
|
@ -204,8 +205,8 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$aResult = \array_unique($aResult);
|
\RainLoop\Utils::saveFile($this->sDomainPath.'/disabled', \trim(\implode(',', \array_unique($aResult)), ', '));
|
||||||
return false !== \file_put_contents($this->sDomainPath.'/disabled', \trim(\implode(',', $aResult), ', '));
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Delete(string $sName) : bool
|
public function Delete(string $sName) : bool
|
||||||
|
|
|
||||||
|
|
@ -220,4 +220,16 @@ class Utils
|
||||||
{
|
{
|
||||||
return \preg_replace('#[|\\\\?*<":>+\\[\\]/&\\s\\pC]#su', '-', $filename);
|
return \preg_replace('#[|\\\\?*<":>+\\[\\]/&\\s\\pC]#su', '-', $filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function saveFile(string $filename, string $data) : void
|
||||||
|
{
|
||||||
|
$dir = \dirname($filename);
|
||||||
|
if (!\is_dir($dir) && !\mkdir($dir, 0700, true)) {
|
||||||
|
throw new \RainLoop\Exceptions\Exception('Failed to create directory "'.$dir.'"');
|
||||||
|
}
|
||||||
|
if (false === \file_put_contents($filename, $data)) {
|
||||||
|
throw new \RainLoop\Exceptions\Exception('Failed to save file "'.$filename.'"');
|
||||||
|
}
|
||||||
|
\chmod($filename, 0600);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -182,65 +182,57 @@ if (defined('APP_VERSION'))
|
||||||
clearstatcache();
|
clearstatcache();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (array('logs', 'cache', 'configs', 'plugins', 'storage') as $sName)
|
foreach (array('logs', 'cache', 'configs', 'domains', 'plugins', 'storage') as $sName)
|
||||||
{
|
{
|
||||||
if (!is_dir(APP_PRIVATE_DATA.$sName))
|
if (!is_dir(APP_PRIVATE_DATA.$sName))
|
||||||
{
|
{
|
||||||
mkdir(APP_PRIVATE_DATA.$sName, 0755, true);
|
mkdir(APP_PRIVATE_DATA.$sName, 0700, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_exists(APP_PRIVATE_DATA.'domains/disabled'))
|
if (!file_exists(APP_PRIVATE_DATA.'domains/disabled') && is_dir(APP_PRIVATE_DATA.'domains'))
|
||||||
{
|
{
|
||||||
if (!is_dir(APP_PRIVATE_DATA.'domains'))
|
$sFile = $sNewFile = $sNewFileName = '';
|
||||||
{
|
$aFiles = glob(APP_VERSION_ROOT_PATH.'app/domains/*');
|
||||||
mkdir(APP_PRIVATE_DATA.'domains', 0755);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_dir(APP_PRIVATE_DATA.'domains'))
|
if (is_array($aFiles) && 0 < \count($aFiles))
|
||||||
{
|
{
|
||||||
$sFile = $sNewFile = $sNewFileName = '';
|
foreach ($aFiles as $sFile)
|
||||||
$aFiles = glob(APP_VERSION_ROOT_PATH.'app/domains/*');
|
|
||||||
|
|
||||||
if (is_array($aFiles) && 0 < \count($aFiles))
|
|
||||||
{
|
{
|
||||||
foreach ($aFiles as $sFile)
|
if (is_file($sFile))
|
||||||
{
|
{
|
||||||
if (is_file($sFile))
|
$sNewFileName = basename($sFile);
|
||||||
|
if ('default.ini.dist' !== $sNewFileName)
|
||||||
{
|
{
|
||||||
$sNewFileName = basename($sFile);
|
$sNewFile = APP_PRIVATE_DATA.'domains/'.$sNewFileName;
|
||||||
if ('default.ini.dist' !== $sNewFileName)
|
if (!file_exists($sNewFile))
|
||||||
{
|
{
|
||||||
$sNewFile = APP_PRIVATE_DATA.'domains/'.$sNewFileName;
|
copy($sFile, $sNewFile);
|
||||||
if (!file_exists($sNewFile))
|
|
||||||
{
|
|
||||||
copy($sFile, $sNewFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// $sClearedSiteName = preg_replace('/^(www|demo|snappymail|webmail|email|mail|imap|imap4|smtp)\./i', '', trim(APP_SITE));
|
|
||||||
// if (!empty($sClearedSiteName) && file_exists(APP_VERSION_ROOT_PATH.'app/domains/default.ini.dist') &&
|
|
||||||
// !file_exists(APP_PRIVATE_DATA.'domains/'.$sClearedSiteName.'.ini'))
|
|
||||||
// {
|
|
||||||
// $sConfigTemplate = file_get_contents(APP_VERSION_ROOT_PATH.'app/domains/default.ini.dist');
|
|
||||||
// if (!empty($sConfigTemplate))
|
|
||||||
// {
|
|
||||||
// file_put_contents(APP_PRIVATE_DATA.'domains/'.$sClearedSiteName.'.ini', strtr($sConfigTemplate, array(
|
|
||||||
// 'IMAP_HOST' => 'localhost' !== $sClearedSiteName? 'imap.'.$sClearedSiteName : $sClearedSiteName,
|
|
||||||
// 'IMAP_PORT' => '993',
|
|
||||||
// 'SMTP_HOST' => 'localhost' !== $sClearedSiteName? 'smtp.'.$sClearedSiteName : $sClearedSiteName,
|
|
||||||
// 'SMTP_PORT' => '465'
|
|
||||||
// )));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// unset($sConfigTemplate);
|
|
||||||
// }
|
|
||||||
|
|
||||||
unset($aFiles, $sFile, $sNewFileName, $sNewFile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// $sClearedSiteName = preg_replace('/^(www|demo|snappymail|webmail|email|mail|imap|imap4|smtp)\./i', '', trim(APP_SITE));
|
||||||
|
// if (!empty($sClearedSiteName) && file_exists(APP_VERSION_ROOT_PATH.'app/domains/default.ini.dist') &&
|
||||||
|
// !file_exists(APP_PRIVATE_DATA.'domains/'.$sClearedSiteName.'.ini'))
|
||||||
|
// {
|
||||||
|
// $sConfigTemplate = file_get_contents(APP_VERSION_ROOT_PATH.'app/domains/default.ini.dist');
|
||||||
|
// if (!empty($sConfigTemplate))
|
||||||
|
// {
|
||||||
|
// file_put_contents(APP_PRIVATE_DATA.'domains/'.$sClearedSiteName.'.ini', strtr($sConfigTemplate, array(
|
||||||
|
// 'IMAP_HOST' => 'localhost' !== $sClearedSiteName? 'imap.'.$sClearedSiteName : $sClearedSiteName,
|
||||||
|
// 'IMAP_PORT' => '993',
|
||||||
|
// 'SMTP_HOST' => 'localhost' !== $sClearedSiteName? 'smtp.'.$sClearedSiteName : $sClearedSiteName,
|
||||||
|
// 'SMTP_PORT' => '465'
|
||||||
|
// )));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// unset($sConfigTemplate);
|
||||||
|
// }
|
||||||
|
|
||||||
|
unset($aFiles, $sFile, $sNewFileName, $sNewFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue