This commit is contained in:
the-djmaze 2023-01-31 09:03:01 +01:00
parent 3396a3d791
commit a86c143160
6 changed files with 15 additions and 22 deletions

View file

@ -31,7 +31,7 @@ class DemoStorage extends \RainLoop\Providers\Storage\FileStorage
}
}
$sDataPath .= '/' . \RainLoop\Utils::fixName(\RainLoop\Utils::GetConnectionToken());
$sDataPath .= '/' . \MailSo\Base\Utils::SecureFileName(\RainLoop\Utils::GetConnectionToken());
if (!\is_dir($sDataPath) && \mkdir($sDataPath, 0700, true)) {
\file_put_contents("{$sDataPath}/settings",'{"RemoveColors":true,"ListInlineAttachments":true}');
if (\mkdir($sDataPath.'/.gnupg/private-keys-v1.d', 0700, true)) {

View file

@ -490,11 +490,13 @@ abstract class Utils
return false;
}
# Replace ampersand, spaces and reserved characters (based on Win95 VFAT)
# en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
/**
* Replace control characters, ampersand and reserved characters (based on Win95 VFAT)
* en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
*/
public static function SecureFileName(string $sFileName) : string
{
return \preg_replace('#[|\\\\?*<":>+\\[\\]/&\\s\\pC]#su', '-', $sFileName);
return \preg_replace('#[|\\\\?*<":>+\\[\\]/&\\pC]#su', '-', $sFileName);
}
public static function Trim(string $sValue) : string

View file

@ -144,9 +144,9 @@ class FileStorage implements \RainLoop\Providers\Files\IFiles
$aEmail = \explode('@', $sEmail ?: 'nobody@unknown.tld');
$sDomain = \trim(1 < \count($aEmail) ? \array_pop($aEmail) : '');
$sFilePath = $this->sDataPath
.'/'.\RainLoop\Utils::fixName($sDomain ?: 'unknown.tld')
.'/'.\RainLoop\Utils::fixName(\implode('@', $aEmail) ?: '.unknown')
.($sSubEmail ? '/'.\RainLoop\Utils::fixName($sSubEmail) : '')
.'/'.\MailSo\Base\Utils::SecureFileName($sDomain ?: 'unknown.tld')
.'/'.\MailSo\Base\Utils::SecureFileName(\implode('@', $aEmail) ?: '.unknown')
.($sSubEmail ? '/'.\MailSo\Base\Utils::SecureFileName($sSubEmail) : '')
.'/.files/'.\sha1($sKey);
if ($bMkDir && !\is_dir(\dirname($sFilePath)) && !\mkdir(\dirname($sFilePath), 0700, true)) {

View file

@ -137,9 +137,9 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
$aEmail = \explode('@', $sEmail ?: 'nobody@unknown.tld');
$sDomain = \trim(1 < \count($aEmail) ? \array_pop($aEmail) : '');
$sFilePath = $this->sDataPath
.'/'.\RainLoop\Utils::fixName($sDomain ?: 'unknown.tld')
.'/'.\RainLoop\Utils::fixName(\implode('@', $aEmail) ?: '.unknown')
.'/'.($sSubFolder ? \RainLoop\Utils::fixName($sSubFolder).'/' : '');
.'/'.\MailSo\Base\Utils::SecureFileName($sDomain ?: 'unknown.tld')
.'/'.\MailSo\Base\Utils::SecureFileName(\implode('@', $aEmail) ?: '.unknown')
.'/'.($sSubFolder ? \MailSo\Base\Utils::SecureFileName($sSubFolder).'/' : '');
break;
default:
throw new \Exception("Invalid storage type {$iStorageType}");
@ -163,7 +163,7 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
if (StorageType::NOBODY === $iStorageType) {
$sFilePath .= \sha1($sKey ?: \time());
} else {
$sFilePath .= ($sKey ? \RainLoop\Utils::fixName($sKey) : '');
$sFilePath .= ($sKey ? \MailSo\Base\Utils::SecureFileName($sKey) : '');
}
}
return $sFilePath;

View file

@ -275,15 +275,6 @@ class Utils
return true;
}
/**
* Replace control characters, ampersand, spaces and reserved characters (based on Win95 VFAT)
* en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
*/
public static function fixName(string $filename) : string
{
return \preg_replace('#[|\\\\?*<":>+\\[\\]/&\\s\\pC]#su', '-', $filename);
}
public static function saveFile(string $filename, string $data) : void
{
$dir = \dirname($filename);

View file

@ -15,8 +15,8 @@ abstract class Upgrade
$aEmail = \explode('@', \basename($sDomainDir));
$sDomain = \trim(1 < \count($aEmail) ? \array_pop($aEmail) : '');
$sNewDir = $sDataPath
.'/'.\RainLoop\Utils::fixName($sDomain ?: 'unknown.tld')
.'/'.\RainLoop\Utils::fixName(\implode('@', $aEmail) ?: '.unknown');
.'/'.\MailSo\Base\Utils::SecureFileName($sDomain ?: 'unknown.tld')
.'/'.\MailSo\Base\Utils::SecureFileName(\implode('@', $aEmail) ?: '.unknown');
if (\is_dir($sNewDir) || \mkdir($sNewDir, 0700, true)) {
foreach (\glob("{$sDomainDir}/*") as $sItem) {
$sName = \basename($sItem);