mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-26 10:39: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', '');
|
||||
if (!$sPassword) {
|
||||
$sPassword = \substr(\base64_encode(\random_bytes(16)), 0, 12);
|
||||
\file_put_contents($passfile, $sPassword . "\n");
|
||||
\chmod($passfile, 0600);
|
||||
Utils::saveFile($passfile, $sPassword . "\n");
|
||||
// \chmod($passfile, 0600);
|
||||
$oConfig->SetPassword($sPassword);
|
||||
$oConfig->Save();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -294,8 +294,11 @@ abstract class AbstractConfig
|
|||
}
|
||||
|
||||
$this->clearCache();
|
||||
return false !== \file_put_contents($this->sFile,
|
||||
|
||||
\RainLoop\Utils::saveFile($this->sFile,
|
||||
(\strlen($this->sFileHeader) ? $this->sFileHeader : '').
|
||||
$sNewLine.\implode($sNewLine, $aResultLines));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,8 +159,9 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
|||
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
|
||||
}
|
||||
|
||||
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.ini', $oDomain->ToIniString());
|
||||
return \is_int($mResult) && 0 < $mResult;
|
||||
\RainLoop\Utils::saveFile($this->sDomainPath.'/'.$sRealFileName.'.ini', $oDomain->ToIniString());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function SaveAlias(string $sName, string $sAlias) : bool
|
||||
|
|
@ -172,8 +173,8 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
|||
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
|
||||
}
|
||||
|
||||
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.alias', $sAlias);
|
||||
return \is_int($mResult) && 0 < $mResult;
|
||||
\RainLoop\Utils::saveFile($this->sDomainPath.'/'.$sRealFileName.'.alias', $sAlias);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function Disable(string $sName, bool $bDisable) : bool
|
||||
|
|
@ -204,8 +205,8 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
|||
}
|
||||
}
|
||||
|
||||
$aResult = \array_unique($aResult);
|
||||
return false !== \file_put_contents($this->sDomainPath.'/disabled', \trim(\implode(',', $aResult), ', '));
|
||||
\RainLoop\Utils::saveFile($this->sDomainPath.'/disabled', \trim(\implode(',', \array_unique($aResult)), ', '));
|
||||
return true;
|
||||
}
|
||||
|
||||
public function Delete(string $sName) : bool
|
||||
|
|
|
|||
|
|
@ -220,4 +220,16 @@ class Utils
|
|||
{
|
||||
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();
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
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'))
|
||||
{
|
||||
mkdir(APP_PRIVATE_DATA.'domains', 0755);
|
||||
}
|
||||
$sFile = $sNewFile = $sNewFileName = '';
|
||||
$aFiles = glob(APP_VERSION_ROOT_PATH.'app/domains/*');
|
||||
|
||||
if (is_dir(APP_PRIVATE_DATA.'domains'))
|
||||
if (is_array($aFiles) && 0 < \count($aFiles))
|
||||
{
|
||||
$sFile = $sNewFile = $sNewFileName = '';
|
||||
$aFiles = glob(APP_VERSION_ROOT_PATH.'app/domains/*');
|
||||
|
||||
if (is_array($aFiles) && 0 < \count($aFiles))
|
||||
foreach ($aFiles as $sFile)
|
||||
{
|
||||
foreach ($aFiles as $sFile)
|
||||
if (is_file($sFile))
|
||||
{
|
||||
if (is_file($sFile))
|
||||
$sNewFileName = basename($sFile);
|
||||
if ('default.ini.dist' !== $sNewFileName)
|
||||
{
|
||||
$sNewFileName = basename($sFile);
|
||||
if ('default.ini.dist' !== $sNewFileName)
|
||||
$sNewFile = APP_PRIVATE_DATA.'domains/'.$sNewFileName;
|
||||
if (!file_exists($sNewFile))
|
||||
{
|
||||
$sNewFile = APP_PRIVATE_DATA.'domains/'.$sNewFileName;
|
||||
if (!file_exists($sNewFile))
|
||||
{
|
||||
copy($sFile, $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