mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-10-30 17:13:36 +03:00
Resolve #898
This commit is contained in:
parent
8cf8823d56
commit
a7081660f0
4 changed files with 147 additions and 132 deletions
|
|
@ -123,16 +123,11 @@ class SnappyMailHelper
|
|||
if ($sPassword) {
|
||||
$sPassword = static::decodePassword($sPassword, \md5($sEmail));
|
||||
}
|
||||
} else if ($sCustomEmail = $config->getUserValue($sUID, 'rainloop', 'rainloop-email')) {
|
||||
$sEmail = $sCustomEmail;
|
||||
$this->config->setUserValue($sUser, 'snappymail', 'snappymail-email', $sEmail);
|
||||
|
||||
$sPassword = $config->getUserValue($sUID, 'rainloop', 'rainloop-password', '');
|
||||
if ($sPassword) {
|
||||
$sPassword = static::decodeRainLoopPassword($sPassword, md5($sEmail));
|
||||
}
|
||||
if ($sPassword) {
|
||||
$this->config->setUserValue($sUser, 'snappymail', 'snappymail-password', static::encodePassword($sPassword, \md5($sEmail)));
|
||||
} else if ($aRainLoop = RainLoop::getLoginCredentials($sUID, $config)) {
|
||||
$sEmail = $aRainLoop[0];
|
||||
$config->setUserValue($sUser, 'snappymail', 'snappymail-email', $sEmail);
|
||||
if ($aRainLoop[1]) {
|
||||
$config->setUserValue($sUser, 'snappymail', 'snappymail-password', static::encodePassword($aRainLoop[1], \md5($sEmail)));
|
||||
}
|
||||
}
|
||||
return [$sUID, $sEmail, $sPassword ?: ''];
|
||||
|
|
@ -164,103 +159,4 @@ class SnappyMailHelper
|
|||
static::loadApp();
|
||||
return \SnappyMail\Crypt::DecryptUrlSafe($sPassword, $sSalt);
|
||||
}
|
||||
|
||||
// Imports data from RainLoop
|
||||
public static function importRainLoop() : array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
$dir = \rtrim(\trim(\OC::$server->getSystemConfig()->getValue('datadirectory', '')), '\\/');
|
||||
$dir_snappy = $dir . '/appdata_snappymail/';
|
||||
$dir_rainloop = $dir . '/rainloop-storage';
|
||||
$rainloop_plugins = [];
|
||||
if (\is_dir($dir_rainloop)) {
|
||||
\is_dir($dir_snappy) || \mkdir($dir_snappy, 0755, true);
|
||||
$iterator = new \RecursiveIteratorIterator(
|
||||
new \RecursiveDirectoryIterator($dir_rainloop, \RecursiveDirectoryIterator::SKIP_DOTS),
|
||||
\RecursiveIteratorIterator::SELF_FIRST
|
||||
);
|
||||
foreach ($iterator as $item) {
|
||||
$target = $dir_snappy . $iterator->getSubPathname();
|
||||
if (\preg_match('@/plugins/([^/])@', $target, $match)) {
|
||||
$rainloop_plugins[$match[1]] = $match[1];
|
||||
} else if (!\strpos($target, '/cache/')) {
|
||||
if ($item->isDir()) {
|
||||
\is_dir($target) || \mkdir($target, 0755, true);
|
||||
} else if (\file_exists($target)) {
|
||||
$result[] = "skipped: {$target}";
|
||||
} else {
|
||||
\copy($item, $target);
|
||||
$result[] = "copied : {$target}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// $password = APP_PRIVATE_DATA . 'admin_password.txt';
|
||||
// \is_file($password) && \unlink($password);
|
||||
|
||||
static::loadApp();
|
||||
|
||||
// Attempt to install same plugins as RainLoop
|
||||
if ($rainloop_plugins) {
|
||||
foreach (\SnappyMail\Repository::getPackagesList()['List'] as $plugin) {
|
||||
if (\in_array($plugin['id'], $rainloop_plugins)) {
|
||||
$result[] = "install plugin : {$plugin['id']}";
|
||||
\SnappyMail\Repository::installPackage('plugin', $plugin['id']);
|
||||
unset($rainloop_plugins[$plugin['id']]);
|
||||
}
|
||||
}
|
||||
foreach ($rainloop_plugins as $plugin) {
|
||||
$result[] = "skipped plugin : {$plugin}";
|
||||
}
|
||||
}
|
||||
|
||||
$oConfig = \RainLoop\Api::Config();
|
||||
$oConfig->Set('webmail', 'theme', 'Nextcloud@custom');
|
||||
$oConfig->Save();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sPassword
|
||||
* @param string $sSalt
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function decodeRainLoopPassword($sPassword, $sSalt)
|
||||
{
|
||||
$method = 'AES-256-CBC';
|
||||
if (\function_exists('openssl_encrypt') &&
|
||||
\function_exists('openssl_decrypt') &&
|
||||
\function_exists('openssl_random_pseudo_bytes') &&
|
||||
\function_exists('openssl_cipher_iv_length') &&
|
||||
\function_exists('openssl_get_cipher_methods') &&
|
||||
\defined('OPENSSL_RAW_DATA') && \defined('OPENSSL_ZERO_PADDING') &&
|
||||
\in_array($method, openssl_get_cipher_methods())
|
||||
) {
|
||||
$sLine = base64_decode(trim($sPassword));
|
||||
$aParts = explode('|', $sLine, 2);
|
||||
if (is_array($aParts) && !empty($aParts[0]) && !empty($aParts[1])) {
|
||||
$sData = @base64_decode($aParts[0]);
|
||||
$iv = @base64_decode($aParts[1]);
|
||||
return @base64_decode(trim(
|
||||
@openssl_decrypt($sData, $method, md5($sSalt), OPENSSL_RAW_DATA, $iv)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if (\function_exists('mcrypt_encrypt') &&
|
||||
\function_exists('mcrypt_decrypt') &&
|
||||
\defined('MCRYPT_RIJNDAEL_256') &&
|
||||
\defined('MCRYPT_MODE_ECB')
|
||||
) {
|
||||
return @base64_decode(trim(
|
||||
@mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($sSalt), base64_decode(trim($sPassword)), MCRYPT_MODE_ECB)
|
||||
));
|
||||
}
|
||||
|
||||
return @base64_decode(trim($sPassword));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue