mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Seperate RainLoop importer for #584 and
https://github.com/pierre-alain-b/rainloop-nextcloud/issues/288
This commit is contained in:
parent
59c7baaab8
commit
2247be5026
4 changed files with 84 additions and 47 deletions
|
|
@ -59,6 +59,14 @@ class FetchController extends Controller {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($_POST['import-rainloop'])) {
|
||||||
|
$result = SnappyMailHelper::importRainLoop();
|
||||||
|
return new JSONResponse([
|
||||||
|
'status' => 'success',
|
||||||
|
'Message' => \implode("\n", $result)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
SnappyMailHelper::loadApp();
|
SnappyMailHelper::loadApp();
|
||||||
$debug = !empty($_POST['snappymail-debug']);
|
$debug = !empty($_POST['snappymail-debug']);
|
||||||
$oConfig = \RainLoop\Api::Config();
|
$oConfig = \RainLoop\Api::Config();
|
||||||
|
|
|
||||||
|
|
@ -38,10 +38,15 @@ class AdminSettings implements ISettings
|
||||||
$sPassword = '';
|
$sPassword = '';
|
||||||
if (\is_file($passfile)) {
|
if (\is_file($passfile)) {
|
||||||
$sPassword = \file_get_contents($passfile);
|
$sPassword = \file_get_contents($passfile);
|
||||||
$parameters['snappymail-admin-panel-link'] .= SnappyMailHelper::getAppUrl().'?admin#/security';
|
$parameters['snappymail-admin-panel-link'] .= '#/security';
|
||||||
}
|
}
|
||||||
$parameters['snappymail-admin-password'] = $sPassword;
|
$parameters['snappymail-admin-password'] = $sPassword;
|
||||||
|
|
||||||
|
$parameters['can-import-rainloop'] = \is_dir(
|
||||||
|
\rtrim(\trim(\OC::$server->getSystemConfig()->getValue('datadirectory', '')), '\\/')
|
||||||
|
. '/rainloop-storage'
|
||||||
|
);
|
||||||
|
|
||||||
$parameters['snappymail-debug'] = $oConfig->Get('debug', 'enable', false);
|
$parameters['snappymail-debug'] = $oConfig->Get('debug', 'enable', false);
|
||||||
|
|
||||||
// Check for nextcloud plugin update, if so then update
|
// Check for nextcloud plugin update, if so then update
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class SnappyMailHelper
|
||||||
// Nextcloud the default spl_autoload_register() not working
|
// Nextcloud the default spl_autoload_register() not working
|
||||||
\spl_autoload_register(function($sClassName){
|
\spl_autoload_register(function($sClassName){
|
||||||
$file = RAINLOOP_APP_LIBRARIES_PATH . \strtolower(\strtr($sClassName, '\\', DIRECTORY_SEPARATOR)) . '.php';
|
$file = RAINLOOP_APP_LIBRARIES_PATH . \strtolower(\strtr($sClassName, '\\', DIRECTORY_SEPARATOR)) . '.php';
|
||||||
if (is_file($file)) {
|
if (\is_file($file)) {
|
||||||
include_once $file;
|
include_once $file;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -22,31 +22,6 @@ class SnappyMailHelper
|
||||||
$_ENV['SNAPPYMAIL_NEXTCLOUD'] = true;
|
$_ENV['SNAPPYMAIL_NEXTCLOUD'] = true;
|
||||||
$_ENV['SNAPPYMAIL_INCLUDE_AS_API'] = true;
|
$_ENV['SNAPPYMAIL_INCLUDE_AS_API'] = true;
|
||||||
|
|
||||||
// Import data from RainLoop
|
|
||||||
$dir = \rtrim(\trim(\OC::$server->getSystemConfig()->getValue('datadirectory', '')), '\\/');
|
|
||||||
$dir_snappy = $dir . '/appdata_snappymail/';
|
|
||||||
$dir_rainloop = $dir . '/rainloop-storage';
|
|
||||||
$rainloop_plugins = [];
|
|
||||||
if (!\is_dir($dir_snappy) && \is_dir($dir_rainloop)) {
|
|
||||||
\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()) {
|
|
||||||
\mkdir($target, 0755, true);
|
|
||||||
} else {
|
|
||||||
\copy($item, $target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
require_once \dirname(\dirname(__DIR__)) . '/app/index.php';
|
require_once \dirname(\dirname(__DIR__)) . '/app/index.php';
|
||||||
|
|
||||||
$oConfig = \RainLoop\Api::Config();
|
$oConfig = \RainLoop\Api::Config();
|
||||||
|
|
@ -65,23 +40,6 @@ class SnappyMailHelper
|
||||||
$bSave = true;
|
$bSave = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sPassword = $oConfig->Get('security', 'admin_password');
|
|
||||||
if ('12345' == $sPassword || !$sPassword) {
|
|
||||||
$sPassword = \substr(\base64_encode(\random_bytes(16)), 0, 12);
|
|
||||||
\RainLoop\Utils::saveFile(APP_PRIVATE_DATA . 'admin_password.txt', $sPassword . "\n");
|
|
||||||
$oConfig->SetPassword($sPassword);
|
|
||||||
$bSave = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempt to install same plugins as RainLoop
|
|
||||||
if ($rainloop_plugins) {
|
|
||||||
foreach (\SnappyMail\Repository::getPackagesList()['List'] as $plugin) {
|
|
||||||
if (\in_array($plugin['id'], $rainloop_plugins)) {
|
|
||||||
\SnappyMail\Repository::installPackage('plugin', $plugin['id']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$bSave && $oConfig->Save();
|
$bSave && $oConfig->Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,4 +122,63 @@ class SnappyMailHelper
|
||||||
static::loadApp();
|
static::loadApp();
|
||||||
return \SnappyMail\Crypt::DecryptUrlSafe($sPassword, $sSalt);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,9 +48,16 @@
|
||||||
<label for="snappymail-debug">Debug</label>
|
<label for="snappymail-debug">Debug</label>
|
||||||
</p>
|
</p>
|
||||||
<br />
|
<br />
|
||||||
|
<?php if ($_['can-import-rainloop']) { ?>
|
||||||
|
<p>
|
||||||
|
<input id="import-rainloop" name="import-rainloop" type="checkbox" class="checkbox">
|
||||||
|
<label for="import-rainloop">Import RainLoop data</label>
|
||||||
|
</p>
|
||||||
|
<br />
|
||||||
|
<?php } ?>
|
||||||
<p>
|
<p>
|
||||||
<button id="snappymail-save-button" name="snappymail-save-button"><?php echo($l->t('Save')); ?></button>
|
<button id="snappymail-save-button" name="snappymail-save-button"><?php echo($l->t('Save')); ?></button>
|
||||||
<span class="snappymail-result-desc"></span>
|
<div class="snappymail-result-desc" style="white-space: pre"></div>
|
||||||
</p>
|
</p>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue