mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-08 00:47:04 +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,22 +182,15 @@ 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 (!is_dir(APP_PRIVATE_DATA.'domains'))
|
||||
{
|
||||
mkdir(APP_PRIVATE_DATA.'domains', 0755);
|
||||
}
|
||||
|
||||
if (is_dir(APP_PRIVATE_DATA.'domains'))
|
||||
if (!file_exists(APP_PRIVATE_DATA.'domains/disabled') && is_dir(APP_PRIVATE_DATA.'domains'))
|
||||
{
|
||||
$sFile = $sNewFile = $sNewFileName = '';
|
||||
$aFiles = glob(APP_VERSION_ROOT_PATH.'app/domains/*');
|
||||
|
|
@ -242,7 +235,6 @@ if (defined('APP_VERSION'))
|
|||
unset($aFiles, $sFile, $sNewFileName, $sNewFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($sSalt, $sData, $sInstalled, $sPrivateDataFolderInternalName);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue