diff --git a/integrations/nextcloud/snappymail/appinfo/info.xml b/integrations/nextcloud/snappymail/appinfo/info.xml index e6f5c6fd6..3b98bac6f 100644 --- a/integrations/nextcloud/snappymail/appinfo/info.xml +++ b/integrations/nextcloud/snappymail/appinfo/info.xml @@ -77,4 +77,9 @@ There, click on the link to go to the SnappyMail admin panel. 4 + + + OCA\SnappyMail\Migration\InstallStep + + diff --git a/integrations/nextcloud/snappymail/lib/Migration/InstallStep.php b/integrations/nextcloud/snappymail/lib/Migration/InstallStep.php new file mode 100644 index 000000000..c035f63a0 --- /dev/null +++ b/integrations/nextcloud/snappymail/lib/Migration/InstallStep.php @@ -0,0 +1,100 @@ +getSystemConfig()->getValue('datadirectory', '')), '\\/').'/appdata_snappymail/'); + + $app_dir = \dirname(\dirname(__DIR__)) . '/app'; + + if (!\class_exists('RainLoop\\Api')) { + // Nextcloud the default spl_autoload_register() not working + \spl_autoload_register(function($sClassName){ + $file = SNAPPYMAIL_LIBRARIES_PATH . \strtolower(\strtr($sClassName, '\\', DIRECTORY_SEPARATOR)) . '.php'; + if (\is_file($file)) { + include_once $file; + } + }); + require_once $app_dir . '/index.php'; + } + + // https://github.com/the-djmaze/snappymail/issues/790#issuecomment-1366527884 + if (!file_exists($app_dir . '/.htaccess') && file_exists($app_dir . '/_htaccess')) { + rename($app_dir . '/_htaccess', $app_dir . '/.htaccess'); + if (!file_exists(APP_VERSION_ROOT_PATH . '/app/.htaccess') && file_exists(APP_VERSION_ROOT_PATH . '/app/_htaccess')) { + rename(APP_VERSION_ROOT_PATH . '/app/_htaccess', APP_VERSION_ROOT_PATH . '/app/.htaccess'); + } + if (!file_exists(APP_VERSION_ROOT_PATH . '/static/.htaccess') && file_exists(APP_VERSION_ROOT_PATH . '/static/_htaccess')) { + rename(APP_VERSION_ROOT_PATH . '/static/_htaccess', APP_VERSION_ROOT_PATH . '/static/.htaccess'); + } + } + + $oConfig = \RainLoop\Api::Config(); + $bSave = false; + + if (!$oConfig->Get('webmail', 'app_path')) { + $oConfig->Set('webmail', 'app_path', \OC::$server->getAppManager()->getAppWebPath('snappymail') . '/app/'); + $bSave = true; + } + + if (!\is_dir(APP_PLUGINS_PATH . 'nextcloud')) { + \SnappyMail\Repository::installPackage('plugin', 'nextcloud'); + $oConfig->Set('plugins', 'enable', true); + $aList = \SnappyMail\Repository::getEnabledPackagesNames(); + $aList[] = 'nextcloud'; + $oConfig->Set('plugins', 'enabled_list', \implode(',', \array_unique($aList))); + $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); + $oConfig->SetPassword($sPassword); + \RainLoop\Utils::saveFile(APP_PRIVATE_DATA . 'admin_password.txt', $sPassword . "\n"); + $bSave = true; + } + + // Pre-configure domain + $ocConfig = \OC::$server->getConfig(); + if ($ocConfig->getAppValue('snappymail', 'snappymail-autologin', false) + || $ocConfig->getAppValue('snappymail', 'snappymail-autologin-with-email', false) + ) { + $oProvider = \RainLoop\Api::Actions()->DomainProvider(); + $oDomain = $oProvider->Load('nextcloud'); + if (!$oDomain) { +// $oDomain = \RainLoop\Model\Domain::fromIniArray('nextcloud', []); + $oDomain = new \RainLoop\Model\Domain('nextcloud'); + $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::NONE; + $oDomain->SetConfig( + 'localhost', 143, $iSecurityType, true, + true, 'localhost', 4190, $iSecurityType, + 'localhost', 25, $iSecurityType, true, true, false, false, + ''); + $oProvider->Save($oDomain); + if (!$oConfig->Get('login', 'default_domain', '')) { + $oConfig->Set('login', 'default_domain', 'nextcloud'); + $bSave = true; + } + } + } + + $bSave && $oConfig->Save(); + } +} diff --git a/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php b/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php index c66b65610..a0ceadfc0 100644 --- a/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php +++ b/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php @@ -29,69 +29,6 @@ class SnappyMailHelper $app_dir = \dirname(\dirname(__DIR__)) . '/app'; require_once $app_dir . '/index.php'; - - // https://github.com/the-djmaze/snappymail/issues/790#issuecomment-1366527884 - if (!file_exists($app_dir . '/.htaccess') && file_exists($app_dir . '/_htaccess')) { - rename($app_dir . '/_htaccess', $app_dir . '/.htaccess'); - if (!file_exists(APP_VERSION_ROOT_PATH . '/app/.htaccess') && file_exists(APP_VERSION_ROOT_PATH . '/app/_htaccess')) { - rename(APP_VERSION_ROOT_PATH . '/app/_htaccess', APP_VERSION_ROOT_PATH . '/app/.htaccess'); - } - if (!file_exists(APP_VERSION_ROOT_PATH . '/static/.htaccess') && file_exists(APP_VERSION_ROOT_PATH . '/static/_htaccess')) { - rename(APP_VERSION_ROOT_PATH . '/static/_htaccess', APP_VERSION_ROOT_PATH . '/static/.htaccess'); - } - } - - $oConfig = \RainLoop\Api::Config(); - $bSave = false; - - if (!$oConfig->Get('webmail', 'app_path')) { - $oConfig->Set('webmail', 'app_path', \OC::$server->getAppManager()->getAppWebPath('snappymail') . '/app/'); - $bSave = true; - } - - if (!\is_dir(APP_PLUGINS_PATH . 'nextcloud')) { - \SnappyMail\Repository::installPackage('plugin', 'nextcloud'); - $oConfig->Set('plugins', 'enable', true); - $aList = \SnappyMail\Repository::getEnabledPackagesNames(); - $aList[] = 'nextcloud'; - $oConfig->Set('plugins', 'enabled_list', \implode(',', \array_unique($aList))); - $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); - $oConfig->SetPassword($sPassword); - \RainLoop\Utils::saveFile(APP_PRIVATE_DATA . 'admin_password.txt', $sPassword . "\n"); - $bSave = true; - } - - // Pre-configure domain - $ocConfig = \OC::$server->getConfig(); - if ($ocConfig->getAppValue('snappymail', 'snappymail-autologin', false) - || $ocConfig->getAppValue('snappymail', 'snappymail-autologin-with-email', false) - ) { - $oProvider = \RainLoop\Api::Actions()->DomainProvider(); - $oDomain = $oProvider->Load('nextcloud'); - if (!$oDomain) { -// $oDomain = \RainLoop\Model\Domain::fromIniArray('nextcloud', []); - $oDomain = new \RainLoop\Model\Domain('nextcloud'); - $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::NONE; - $oDomain->SetConfig( - 'localhost', 143, $iSecurityType, true, - true, 'localhost', 4190, $iSecurityType, - 'localhost', 25, $iSecurityType, true, true, false, false, - ''); - $oProvider->Save($oDomain); - if (!$oConfig->Get('login', 'default_domain', '')) { - $oConfig->Set('login', 'default_domain', 'nextcloud'); - $bSave = true; - } - } - } - - $bSave && $oConfig->Save(); } public static function startApp(bool $handle = false) : void