mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-09-06 05:04:24 +08:00
Import Nextcloud RainLoop settings
https://github.com/pierre-alain-b/rainloop-nextcloud/issues/288
This commit is contained in:
parent
ce4c6d1925
commit
b39305c8d8
3 changed files with 63 additions and 62 deletions
|
@ -63,6 +63,10 @@ class Application extends App implements IBootstrap
|
|||
|
||||
public function boot(IBootContext $context): void
|
||||
{
|
||||
if (!\is_dir(\rtrim(\trim(\OC::$server->getSystemConfig()->getValue('datadirectory', '')), '\\/') . '/appdata_snappymail')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$container = $this->getContainer();
|
||||
$container->query('OCP\INavigationManager')->add(function () use ($container) {
|
||||
$urlGenerator = $container->query('OCP\IURLGenerator');
|
||||
|
|
|
@ -36,17 +36,8 @@ class AdminSettings implements ISettings
|
|||
$oConfig = \RainLoop\Api::Config();
|
||||
$passfile = APP_PRIVATE_DATA . 'admin_password.txt';
|
||||
$sPassword = $oConfig->Get('security', 'admin_password', '');
|
||||
if (!$sPassword) {
|
||||
$sPassword = \substr(\base64_encode(\random_bytes(16)), 0, 12);
|
||||
\RainLoop\Utils::saveFile($passfile, $sPassword . "\n");
|
||||
$oConfig->SetPassword($sPassword);
|
||||
$oConfig->Save();
|
||||
} else if (\is_file($passfile)) {
|
||||
if (\is_file($passfile)) {
|
||||
$sPassword = \file_get_contents($passfile);
|
||||
} else {
|
||||
$sPassword = '';
|
||||
}
|
||||
if ($sPassword) {
|
||||
$parameters['snappymail-admin-panel-link'] .= SnappyMailHelper::getAppUrl().'?admin#/security';
|
||||
}
|
||||
$parameters['snappymail-admin-password'] = $sPassword;
|
||||
|
|
|
@ -7,21 +7,48 @@ class SnappyMailHelper
|
|||
|
||||
public static function loadApp() : void
|
||||
{
|
||||
if (!\class_exists('RainLoop\\Api')) {
|
||||
// Nextcloud the default spl_autoload_register() not working
|
||||
\spl_autoload_register(function($sClassName){
|
||||
$file = RAINLOOP_APP_LIBRARIES_PATH . \strtolower(\strtr($sClassName, '\\', DIRECTORY_SEPARATOR)) . '.php';
|
||||
if (is_file($file)) {
|
||||
include_once $file;
|
||||
}
|
||||
});
|
||||
|
||||
$_ENV['SNAPPYMAIL_NEXTCLOUD'] = true;
|
||||
$_ENV['SNAPPYMAIL_INCLUDE_AS_API'] = true;
|
||||
|
||||
require_once \dirname(\dirname(__DIR__)) . '/app/index.php';
|
||||
if (\class_exists('RainLoop\\Api')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Nextcloud the default spl_autoload_register() not working
|
||||
\spl_autoload_register(function($sClassName){
|
||||
$file = RAINLOOP_APP_LIBRARIES_PATH . \strtolower(\strtr($sClassName, '\\', DIRECTORY_SEPARATOR)) . '.php';
|
||||
if (is_file($file)) {
|
||||
include_once $file;
|
||||
}
|
||||
});
|
||||
|
||||
$_ENV['SNAPPYMAIL_NEXTCLOUD'] = 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';
|
||||
|
||||
$oConfig = \RainLoop\Api::Config();
|
||||
$bSave = false;
|
||||
if (!$oConfig->Get('webmail', 'app_path')) {
|
||||
|
@ -37,6 +64,24 @@ class SnappyMailHelper
|
|||
$oConfig->Set('webmail', 'theme', 'Nextcloud@custom');
|
||||
$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();
|
||||
}
|
||||
|
||||
|
@ -119,43 +164,4 @@ class SnappyMailHelper
|
|||
static::loadApp();
|
||||
return \SnappyMail\Crypt::DecryptUrlSafe($sPassword, $sSalt);
|
||||
}
|
||||
|
||||
public static function importRainloop() : bool
|
||||
{
|
||||
$dir = \rtrim(\trim(\OC::$server->getSystemConfig()->getValue('datadirectory', '')), '\\/');
|
||||
|
||||
$dir_snappy = $dir . '/appdata_snappymail/';
|
||||
\is_dir($dir_snappy) || \mkdir($dir);
|
||||
|
||||
$dir_rainloop = $dir . '/rainloop-storage';
|
||||
if (\is_dir($dir_rainloop)) {
|
||||
$plugins = [];
|
||||
$iterator = new \RecursiveIteratorIterator(
|
||||
new \RecursiveDirectoryIterator($dir_rainloop, \RecursiveDirectoryIterator::SKIP_DOTS),
|
||||
\RecursiveIteratorIterator::SELF_FIRST
|
||||
);
|
||||
foreach ($iterator as $item) {
|
||||
$target = $dir_snappy . DIRECTORY_SEPARATOR . $iterator->getSubPathname();
|
||||
if (\preg_match('@/plugins/([^/])@', $target, $match)) {
|
||||
$plugins[$match[1]] = $match[1];
|
||||
} else if (!\strpos($target, '/cache/')) {
|
||||
if ($item->isDir()) {
|
||||
\mkdir($target);
|
||||
} else {
|
||||
\copy($item, $target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static::loadApp();
|
||||
foreach (\SnappyMail\Repository::getPackagesList()['List'] as $plugin) {
|
||||
if (\in_array($plugin['id'], $plugins)) {
|
||||
\SnappyMail\Repository::installPackage('plugin', $plugin['id']);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue