mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 10:09:20 +03:00
Merge pull request #1 from nextgen-networks/php_8.5_ready-16593493786561827381
PHP 8.4/8.5 Compatibility: Fix implicit nullable types in Predis
This commit is contained in:
commit
553bf4e2e0
12 changed files with 365 additions and 304 deletions
|
|
@ -64,7 +64,7 @@ There, click on the link to go to the SnappyMail admin panel.
|
||||||
<lib>xxtea</lib>
|
<lib>xxtea</lib>
|
||||||
<lib>zip</lib>
|
<lib>zip</lib>
|
||||||
-->
|
-->
|
||||||
<nextcloud min-version="20" max-version="32" />
|
<nextcloud min-version="25" max-version="33" />
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<settings>
|
<settings>
|
||||||
<admin>OCA\SnappyMail\Settings\AdminSettings</admin>
|
<admin>OCA\SnappyMail\Settings\AdminSettings</admin>
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ namespace OCA\SnappyMail\AppInfo;
|
||||||
use OCA\SnappyMail\Util\SnappyMailHelper;
|
use OCA\SnappyMail\Util\SnappyMailHelper;
|
||||||
use OCA\SnappyMail\Controller\FetchController;
|
use OCA\SnappyMail\Controller\FetchController;
|
||||||
use OCA\SnappyMail\Controller\PageController;
|
use OCA\SnappyMail\Controller\PageController;
|
||||||
use OCA\SnappyMail\Dashboard\UnreadMailWidget;
|
|
||||||
use OCA\SnappyMail\Search\Provider;
|
use OCA\SnappyMail\Search\Provider;
|
||||||
use OCA\SnappyMail\Listeners\AccessTokenUpdatedListener;
|
use OCA\SnappyMail\Listeners\AccessTokenUpdatedListener;
|
||||||
|
|
||||||
|
|
@ -18,6 +17,10 @@ use OCP\IUser;
|
||||||
use OCP\User\Events\PostLoginEvent;
|
use OCP\User\Events\PostLoginEvent;
|
||||||
use OCP\User\Events\BeforeUserLoggedOutEvent;
|
use OCP\User\Events\BeforeUserLoggedOutEvent;
|
||||||
use OCA\OIDCLogin\Events\AccessTokenUpdatedEvent;
|
use OCA\OIDCLogin\Events\AccessTokenUpdatedEvent;
|
||||||
|
use OCP\IConfig;
|
||||||
|
use OCP\ISession;
|
||||||
|
use OCP\IUserSession;
|
||||||
|
use OCP\INavigationManager;
|
||||||
|
|
||||||
class Application extends App implements IBootstrap
|
class Application extends App implements IBootstrap
|
||||||
{
|
{
|
||||||
|
|
@ -37,7 +40,9 @@ class Application extends App implements IBootstrap
|
||||||
'PageController', function($c) {
|
'PageController', function($c) {
|
||||||
return new PageController(
|
return new PageController(
|
||||||
$c->query('AppName'),
|
$c->query('AppName'),
|
||||||
$c->query('Request')
|
$c->query('Request'),
|
||||||
|
$c->query(IConfig::class),
|
||||||
|
$c->query(INavigationManager::class)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
@ -47,9 +52,10 @@ class Application extends App implements IBootstrap
|
||||||
return new FetchController(
|
return new FetchController(
|
||||||
$c->query('AppName'),
|
$c->query('AppName'),
|
||||||
$c->query('Request'),
|
$c->query('Request'),
|
||||||
$c->getServer()->getAppManager(),
|
$c->query('ServerContainer')->getAppManager(),
|
||||||
$c->query('ServerContainer')->getConfig(),
|
$c->query('ServerContainer')->getConfig(),
|
||||||
$c->query(IL10N::class)
|
$c->query(IL10N::class),
|
||||||
|
$c->query(IUserSession::class)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
@ -72,22 +78,24 @@ class Application extends App implements IBootstrap
|
||||||
|
|
||||||
public function boot(IBootContext $context): void
|
public function boot(IBootContext $context): void
|
||||||
{
|
{
|
||||||
if (!\is_dir(\rtrim(\trim(\OC::$server->getSystemConfig()->getValue('datadirectory', '')), '\\/') . '/appdata_snappymail')) {
|
$config = $context->getServerContainer()->getConfig();
|
||||||
|
if (!\is_dir(\rtrim(\trim($config->getSystemValue('datadirectory', '')), '\\/') . '/appdata_snappymail')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$dispatcher = $context->getAppContainer()->query('OCP\EventDispatcher\IEventDispatcher');
|
$dispatcher = $context->getAppContainer()->query('OCP\EventDispatcher\IEventDispatcher');
|
||||||
$dispatcher->addListener(PostLoginEvent::class, function (PostLoginEvent $Event) {
|
$dispatcher->addListener(PostLoginEvent::class, function (PostLoginEvent $Event) use ($context) {
|
||||||
/*
|
/*
|
||||||
$config = \OC::$server->getConfig();
|
$config = $context->getServerContainer()->getConfig();
|
||||||
// Only store the user's password in the current session if they have
|
// Only store the user's password in the current session if they have
|
||||||
// enabled auto-login using Nextcloud username or email address.
|
// enabled auto-login using Nextcloud username or email address.
|
||||||
if ($config->getAppValue('snappymail', 'snappymail-autologin', false)
|
if ($config->getAppValue('snappymail', 'snappymail-autologin', false)
|
||||||
|| $config->getAppValue('snappymail', 'snappymail-autologin-with-email', false)) {
|
|| $config->getAppValue('snappymail', 'snappymail-autologin-with-email', false)) {
|
||||||
*/
|
*/
|
||||||
$sUID = $Event->getUser()->getUID();
|
$sUID = $Event->getUser()->getUID();
|
||||||
\OC::$server->getSession()['snappymail-nc-uid'] = $sUID;
|
$session = $context->getServerContainer()->getSession();
|
||||||
\OC::$server->getSession()['snappymail-passphrase'] = SnappyMailHelper::encodePassword($Event->getPassword(), $sUID);
|
$session['snappymail-nc-uid'] = $sUID;
|
||||||
|
$session['snappymail-passphrase'] = SnappyMailHelper::encodePassword($Event->getPassword(), $sUID);
|
||||||
/*
|
/*
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
@ -105,13 +113,13 @@ class Application extends App implements IBootstrap
|
||||||
// https://github.com/nextcloud/impersonate/pull/180
|
// https://github.com/nextcloud/impersonate/pull/180
|
||||||
$class = 'OCA\Impersonate\Events\BeginImpersonateEvent';
|
$class = 'OCA\Impersonate\Events\BeginImpersonateEvent';
|
||||||
if (\class_exists($class)) {
|
if (\class_exists($class)) {
|
||||||
$dispatcher->addListener($class, function ($Event) {
|
$dispatcher->addListener($class, function ($Event) use ($context) {
|
||||||
\OC::$server->getSession()['snappymail-passphrase'] = '';
|
$context->getServerContainer()->getSession()['snappymail-passphrase'] = '';
|
||||||
SnappyMailHelper::loadApp();
|
SnappyMailHelper::loadApp();
|
||||||
\RainLoop\Api::Actions()->Logout(true);
|
\RainLoop\Api::Actions()->Logout(true);
|
||||||
});
|
});
|
||||||
$dispatcher->addListener('OCA\Impersonate\Events\EndImpersonateEvent', function ($Event) {
|
$dispatcher->addListener('OCA\Impersonate\Events\EndImpersonateEvent', function ($Event) use ($context) {
|
||||||
\OC::$server->getSession()['snappymail-passphrase'] = '';
|
$context->getServerContainer()->getSession()['snappymail-passphrase'] = '';
|
||||||
SnappyMailHelper::loadApp();
|
SnappyMailHelper::loadApp();
|
||||||
\RainLoop\Api::Actions()->Logout(true);
|
\RainLoop\Api::Actions()->Logout(true);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,14 @@
|
||||||
namespace OCA\SnappyMail\Command;
|
namespace OCA\SnappyMail\Command;
|
||||||
|
|
||||||
use OCA\SnappyMail\Util\SnappyMailHelper;
|
use OCA\SnappyMail\Util\SnappyMailHelper;
|
||||||
use OC\Core\Command\Base;
|
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
class Settings extends Base
|
class Settings extends Command
|
||||||
{
|
{
|
||||||
protected IUserManager $userManager;
|
protected IUserManager $userManager;
|
||||||
protected IConfig $config;
|
protected IConfig $config;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
namespace OCA\SnappyMail;
|
namespace OCA\SnappyMail;
|
||||||
|
|
||||||
|
use OCP\Server;
|
||||||
|
use OCP\Security\IContentSecurityPolicyNonceManager;
|
||||||
|
|
||||||
class ContentSecurityPolicy extends \OCP\AppFramework\Http\ContentSecurityPolicy {
|
class ContentSecurityPolicy extends \OCP\AppFramework\Http\ContentSecurityPolicy {
|
||||||
|
|
||||||
/** @var bool Whether inline JS snippets are allowed */
|
/** @var bool Whether inline JS snippets are allowed */
|
||||||
|
|
@ -37,7 +40,7 @@ class ContentSecurityPolicy extends \OCP\AppFramework\Http\ContentSecurityPolicy
|
||||||
public function getSnappyMailNonce() {
|
public function getSnappyMailNonce() {
|
||||||
static $sNonce;
|
static $sNonce;
|
||||||
if (!$sNonce) {
|
if (!$sNonce) {
|
||||||
$cspManager = \OC::$server->getContentSecurityPolicyNonceManager();
|
$cspManager = Server::get(IContentSecurityPolicyNonceManager::class);
|
||||||
$sNonce = $cspManager->getNonce() ?: \SnappyMail\UUID::generate();
|
$sNonce = $cspManager->getNonce() ?: \SnappyMail\UUID::generate();
|
||||||
if (\method_exists($cspManager, 'browserSupportsCspV3') && !$cspManager->browserSupportsCspV3()) {
|
if (\method_exists($cspManager, 'browserSupportsCspV3') && !$cspManager->browserSupportsCspV3()) {
|
||||||
$this->addAllowedScriptDomain("'nonce-{$sNonce}'");
|
$this->addAllowedScriptDomain("'nonce-{$sNonce}'");
|
||||||
|
|
|
||||||
|
|
@ -10,17 +10,21 @@ use OCP\AppFramework\Http\JSONResponse;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
|
use OCP\IUserSession;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
class FetchController extends Controller {
|
class FetchController extends Controller {
|
||||||
private IConfig $config;
|
private IConfig $config;
|
||||||
private IAppManager $appManager;
|
private IAppManager $appManager;
|
||||||
private IL10N $l;
|
private IL10N $l;
|
||||||
|
private IUserSession $userSession;
|
||||||
|
|
||||||
public function __construct(string $appName, IRequest $request, IAppManager $appManager, IConfig $config, IL10N $l) {
|
public function __construct(string $appName, IRequest $request, IAppManager $appManager, IConfig $config, IL10N $l, IUserSession $userSession) {
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->appManager = $appManager;
|
$this->appManager = $appManager;
|
||||||
$this->l = $l;
|
$this->l = $l;
|
||||||
|
$this->userSession = $userSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function upgrade(): JSONResponse {
|
public function upgrade(): JSONResponse {
|
||||||
|
|
@ -104,15 +108,18 @@ class FetchController extends Controller {
|
||||||
try {
|
try {
|
||||||
$sEmail = '';
|
$sEmail = '';
|
||||||
if (isset($_POST['appname'], $_POST['snappymail-password'], $_POST['snappymail-email']) && 'snappymail' === $_POST['appname']) {
|
if (isset($_POST['appname'], $_POST['snappymail-password'], $_POST['snappymail-email']) && 'snappymail' === $_POST['appname']) {
|
||||||
$sUser = \OC::$server->getUserSession()->getUser()->getUID();
|
$user = $this->userSession->getUser();
|
||||||
|
$sUser = $user ? $user->getUID() : '';
|
||||||
|
|
||||||
$sEmail = $_POST['snappymail-email'];
|
if ($sUser) {
|
||||||
$this->config->setUserValue($sUser, 'snappymail', 'snappymail-email', $sEmail);
|
$sEmail = $_POST['snappymail-email'];
|
||||||
|
$this->config->setUserValue($sUser, 'snappymail', 'snappymail-email', $sEmail);
|
||||||
|
|
||||||
$sPass = $_POST['snappymail-password'];
|
$sPass = $_POST['snappymail-password'];
|
||||||
if ('******' !== $sPass) {
|
if ('******' !== $sPass) {
|
||||||
$this->config->setUserValue($sUser, 'snappymail', 'passphrase',
|
$this->config->setUserValue($sUser, 'snappymail', 'passphrase',
|
||||||
$sPass ? SnappyMailHelper::encodePassword($sPass, \md5($sEmail)) : '');
|
$sPass ? SnappyMailHelper::encodePassword($sPass, \md5($sEmail)) : '');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new JSONResponse([
|
return new JSONResponse([
|
||||||
|
|
@ -144,4 +151,3 @@ class FetchController extends Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,23 +7,27 @@ use OCA\SnappyMail\ContentSecurityPolicy;
|
||||||
|
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
|
use OCP\INavigationManager;
|
||||||
// SnappyMail Nextcoud 32 compatibility workaound - START
|
use OCP\IConfig;
|
||||||
// src: https://github.com/the-djmaze/snappymail/issues/1994#issuecomment-3366086651
|
use OCP\IRequest;
|
||||||
|
|
||||||
use OCP\INavigationManager; // <<<<<<<<<<<< add this
|
|
||||||
use OCP\Server; // <<<<<<<<<<<< add this
|
|
||||||
|
|
||||||
class PageController extends Controller
|
class PageController extends Controller
|
||||||
{
|
{
|
||||||
|
private IConfig $config;
|
||||||
|
private INavigationManager $navigationManager;
|
||||||
|
|
||||||
|
public function __construct($appName, IRequest $request, IConfig $config, INavigationManager $navigationManager) {
|
||||||
|
parent::__construct($appName, $request);
|
||||||
|
$this->config = $config;
|
||||||
|
$this->navigationManager = $navigationManager;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$config = \OC::$server->getConfig();
|
|
||||||
$nav = Server::get(INavigationManager::class); // <<<<<<<<<<<< add this
|
|
||||||
$bAdmin = false;
|
$bAdmin = false;
|
||||||
if (!empty($_SERVER['QUERY_STRING'])) {
|
if (!empty($_SERVER['QUERY_STRING'])) {
|
||||||
SnappyMailHelper::loadApp();
|
SnappyMailHelper::loadApp();
|
||||||
|
|
@ -33,11 +37,8 @@ class PageController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$bAdmin && $config->getAppValue('snappymail', 'snappymail-no-embed')) {
|
if (!$bAdmin && $this->config->getAppValue('snappymail', 'snappymail-no-embed')) {
|
||||||
// \OC::$server->getNavigationManager()->setActiveEntry('snappymail'); // <<<<<<<<<<<< Comment this
|
$this->navigationManager->setActiveEntry('snappymail');
|
||||||
$nav->setActiveEntry('snappymail'); // <<<<<<<<<<<< add this
|
|
||||||
\OCP\Util::addScript('snappymail', 'snappymail');
|
|
||||||
\OCP\Util::addStyle('snappymail', 'style');
|
|
||||||
SnappyMailHelper::startApp();
|
SnappyMailHelper::startApp();
|
||||||
$response = new TemplateResponse('snappymail', 'index', [
|
$response = new TemplateResponse('snappymail', 'index', [
|
||||||
'snappymail-iframe-url' => SnappyMailHelper::normalizeUrl(SnappyMailHelper::getAppUrl())
|
'snappymail-iframe-url' => SnappyMailHelper::normalizeUrl(SnappyMailHelper::getAppUrl())
|
||||||
|
|
@ -50,12 +51,7 @@ class PageController extends Controller
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
// \OC::$server->getNavigationManager()->setActiveEntry('snappymail'); // <<<<<<<<<<<< Comment this
|
$this->navigationManager->setActiveEntry('snappymail');
|
||||||
$nav->setActiveEntry('snappymail'); // <<<<<<<<<<<< add this
|
|
||||||
|
|
||||||
// SnappyMail Nextcoud 32 compatibility workaound - END
|
|
||||||
|
|
||||||
\OCP\Util::addStyle('snappymail', 'embed');
|
|
||||||
|
|
||||||
SnappyMailHelper::startApp();
|
SnappyMailHelper::startApp();
|
||||||
$oConfig = \RainLoop\Api::Config();
|
$oConfig = \RainLoop\Api::Config();
|
||||||
|
|
@ -69,6 +65,8 @@ class PageController extends Controller
|
||||||
$csp = new ContentSecurityPolicy();
|
$csp = new ContentSecurityPolicy();
|
||||||
$sNonce = $csp->getSnappyMailNonce();
|
$sNonce = $csp->getSnappyMailNonce();
|
||||||
|
|
||||||
|
$cssLink = \RainLoop\Utils::WebStaticPath('css/'.($bAdmin?'admin':'app').$sAppCssMin.'.css');
|
||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
'Admin' => $bAdmin ? 1 : 0,
|
'Admin' => $bAdmin ? 1 : 0,
|
||||||
'LoadingDescriptionEsc' => \htmlspecialchars($oConfig->Get('webmail', 'loading_description', 'SnappyMail'), ENT_QUOTES|ENT_IGNORE, 'UTF-8'),
|
'LoadingDescriptionEsc' => \htmlspecialchars($oConfig->Get('webmail', 'loading_description', 'SnappyMail'), ENT_QUOTES|ENT_IGNORE, 'UTF-8'),
|
||||||
|
|
@ -81,16 +79,10 @@ class PageController extends Controller
|
||||||
'/\\s*([:;{},]+)\\s*/s',
|
'/\\s*([:;{},]+)\\s*/s',
|
||||||
'$1',
|
'$1',
|
||||||
$oActions->compileCss($oActions->GetTheme($bAdmin), $bAdmin)
|
$oActions->compileCss($oActions->GetTheme($bAdmin), $bAdmin)
|
||||||
)
|
),
|
||||||
|
'CssLink' => $cssLink
|
||||||
];
|
];
|
||||||
|
|
||||||
// \OCP\Util::addScript('snappymail', '../app/snappymail/v/'.APP_VERSION.'/static/js'.($sAppJsMin ? '/min' : '').'/boot'.$sAppJsMin);
|
|
||||||
|
|
||||||
// Nextcloud html encodes, so addHeader('style') is not possible
|
|
||||||
// \OCP\Util::addHeader('style', ['id'=>'app-boot-css'], \file_get_contents(APP_VERSION_ROOT_PATH.'static/css/boot'.$sAppCssMin.'.css'));
|
|
||||||
\OCP\Util::addHeader('link', ['type'=>'text/css','rel'=>'stylesheet','href'=>\RainLoop\Utils::WebStaticPath('css/'.($bAdmin?'admin':'app').$sAppCssMin.'.css')], '');
|
|
||||||
// \OCP\Util::addHeader('style', ['id'=>'app-theme-style','data-href'=>$params['BaseAppThemeCssLink']], $params['BaseAppThemeCss']);
|
|
||||||
|
|
||||||
$response = new TemplateResponse('snappymail', 'index_embed', $params);
|
$response = new TemplateResponse('snappymail', 'index_embed', $params);
|
||||||
|
|
||||||
$response->setContentSecurityPolicy($csp);
|
$response->setContentSecurityPolicy($csp);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@ use OCA\SnappyMail\AppInfo\Application;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\Migration\IOutput;
|
use OCP\Migration\IOutput;
|
||||||
use OCP\Migration\IRepairStep;
|
use OCP\Migration\IRepairStep;
|
||||||
use OCP\ILogger;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use OCP\App\IAppManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note: this is not run at install, but when:
|
* Note: this is not run at install, but when:
|
||||||
|
|
@ -15,6 +16,16 @@ use OCP\ILogger;
|
||||||
*/
|
*/
|
||||||
class InstallStep implements IRepairStep
|
class InstallStep implements IRepairStep
|
||||||
{
|
{
|
||||||
|
private IAppManager $appManager;
|
||||||
|
private IConfig $config;
|
||||||
|
private LoggerInterface $logger;
|
||||||
|
|
||||||
|
public function __construct(IAppManager $appManager, IConfig $config, LoggerInterface $logger) {
|
||||||
|
$this->appManager = $appManager;
|
||||||
|
$this->config = $config;
|
||||||
|
$this->logger = $logger;
|
||||||
|
}
|
||||||
|
|
||||||
public function getName() {
|
public function getName() {
|
||||||
return 'Setup SnappyMail';
|
return 'Setup SnappyMail';
|
||||||
}
|
}
|
||||||
|
|
@ -53,7 +64,7 @@ class InstallStep implements IRepairStep
|
||||||
|
|
||||||
if (!$oConfig->Get('webmail', 'app_path')) {
|
if (!$oConfig->Get('webmail', 'app_path')) {
|
||||||
$output->info('Set config [webmail]app_path');
|
$output->info('Set config [webmail]app_path');
|
||||||
$oConfig->Set('webmail', 'app_path', \OC::$server->getAppManager()->getAppWebPath('snappymail') . '/app/');
|
$oConfig->Set('webmail', 'app_path', $this->appManager->getAppWebPath('snappymail') . '/app/');
|
||||||
$oConfig->Set('webmail', 'allow_languages_on_settings', false);
|
$oConfig->Set('webmail', 'allow_languages_on_settings', false);
|
||||||
$oConfig->Set('login', 'allow_languages_on_login', false);
|
$oConfig->Set('login', 'allow_languages_on_login', false);
|
||||||
$bSave = true;
|
$bSave = true;
|
||||||
|
|
@ -116,9 +127,7 @@ class InstallStep implements IRepairStep
|
||||||
// ex: php occ config:app:set snappymail custom_config_file --value="/path/to/config.php"
|
// ex: php occ config:app:set snappymail custom_config_file --value="/path/to/config.php"
|
||||||
// https://github.com/the-djmaze/snappymail/pull/1197
|
// https://github.com/the-djmaze/snappymail/pull/1197
|
||||||
try {
|
try {
|
||||||
/** @var IConfig $ncConfig */
|
$customConfigFile = $this->config->getAppValue(Application::APP_ID, 'custom_config_file');
|
||||||
$ncConfig = \OC::$server->get(IConfig::class);
|
|
||||||
$customConfigFile = $ncConfig->getAppValue(Application::APP_ID, 'custom_config_file');
|
|
||||||
if ($customConfigFile) {
|
if ($customConfigFile) {
|
||||||
$output->info("Load custom config: {$customConfigFile}");
|
$output->info("Load custom config: {$customConfigFile}");
|
||||||
if (!\str_contains($customConfigFile, ':') && \is_readable($customConfigFile)) {
|
if (!\str_contains($customConfigFile, ':') && \is_readable($customConfigFile)) {
|
||||||
|
|
@ -129,9 +138,7 @@ class InstallStep implements IRepairStep
|
||||||
}
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
$output->warning("custom config error: " . $e->getMessage());
|
$output->warning("custom config error: " . $e->getMessage());
|
||||||
/** @var \Psr\Log\LoggerInterface $logger */
|
$this->logger->error("custom config error: " . $e->getMessage());
|
||||||
$logger = \OC::$server->get(\Psr\Log\LoggerInterface::class);
|
|
||||||
$logger->error("custom config error: " . $e->getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,32 @@ use OCA\SnappyMail\Util\SnappyMailHelper;
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\Settings\ISettings;
|
use OCP\Settings\ISettings;
|
||||||
|
use OCP\IUserSession;
|
||||||
|
use OCP\IGroupManager;
|
||||||
|
use OCP\IURLGenerator;
|
||||||
|
use OCP\App\IAppManager;
|
||||||
|
use OCP\Util;
|
||||||
|
|
||||||
class AdminSettings implements ISettings
|
class AdminSettings implements ISettings
|
||||||
{
|
{
|
||||||
private $config;
|
private IConfig $config;
|
||||||
|
private IUserSession $userSession;
|
||||||
|
private IGroupManager $groupManager;
|
||||||
|
private IURLGenerator $urlGenerator;
|
||||||
|
private IAppManager $appManager;
|
||||||
|
|
||||||
public function __construct(IConfig $config)
|
public function __construct(
|
||||||
{
|
IConfig $config,
|
||||||
|
IUserSession $userSession,
|
||||||
|
IGroupManager $groupManager,
|
||||||
|
IURLGenerator $urlGenerator,
|
||||||
|
IAppManager $appManager
|
||||||
|
) {
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
$this->userSession = $userSession;
|
||||||
|
$this->groupManager = $groupManager;
|
||||||
|
$this->urlGenerator = $urlGenerator;
|
||||||
|
$this->appManager = $appManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getForm()
|
public function getForm()
|
||||||
|
|
@ -30,12 +48,15 @@ class AdminSettings implements ISettings
|
||||||
$v = $this->config->getAppValue('snappymail', $k);
|
$v = $this->config->getAppValue('snappymail', $k);
|
||||||
$parameters[$k] = $v;
|
$parameters[$k] = $v;
|
||||||
}
|
}
|
||||||
$uid = \OC::$server->getUserSession()->getUser()->getUID();
|
|
||||||
if (\OC_User::isAdminUser($uid)) {
|
$user = $this->userSession->getUser();
|
||||||
|
$uid = $user ? $user->getUID() : null;
|
||||||
|
|
||||||
|
if ($uid && $this->groupManager->isAdmin($uid)) {
|
||||||
// $parameters['snappymail-admin-panel-link'] = SnappyMailHelper::getAppUrl().'?admin';
|
// $parameters['snappymail-admin-panel-link'] = SnappyMailHelper::getAppUrl().'?admin';
|
||||||
SnappyMailHelper::loadApp();
|
SnappyMailHelper::loadApp();
|
||||||
$parameters['snappymail-admin-panel-link'] =
|
$parameters['snappymail-admin-panel-link'] =
|
||||||
\OC::$server->getURLGenerator()->linkToRoute('snappymail.page.index')
|
$this->urlGenerator->linkToRoute('snappymail.page.index')
|
||||||
. '?' . \RainLoop\Api::Config()->Get('security', 'admin_panel_key', 'admin');
|
. '?' . \RainLoop\Api::Config()->Get('security', 'admin_panel_key', 'admin');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,7 +70,7 @@ class AdminSettings implements ISettings
|
||||||
$parameters['snappymail-admin-password'] = $sPassword;
|
$parameters['snappymail-admin-password'] = $sPassword;
|
||||||
|
|
||||||
$parameters['can-import-rainloop'] = $sPassword && \is_dir(
|
$parameters['can-import-rainloop'] = $sPassword && \is_dir(
|
||||||
\rtrim(\trim(\OC::$server->getSystemConfig()->getValue('datadirectory', '')), '\\/')
|
\rtrim(\trim($this->config->getSystemValue('datadirectory', '')), '\\/')
|
||||||
. '/rainloop-storage'
|
. '/rainloop-storage'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -65,7 +86,7 @@ class AdminSettings implements ISettings
|
||||||
// Prevent "Failed loading /nextcloud/snappymail/v/2.N.N/static/js/min/libs.min.js"
|
// Prevent "Failed loading /nextcloud/snappymail/v/2.N.N/static/js/min/libs.min.js"
|
||||||
$app_path = $oConfig->Get('webmail', 'app_path');
|
$app_path = $oConfig->Get('webmail', 'app_path');
|
||||||
if (!$app_path) {
|
if (!$app_path) {
|
||||||
$app_path = \OC::$server->getAppManager()->getAppWebPath('snappymail') . '/app/';
|
$app_path = $this->appManager->getAppWebPath('snappymail') . '/app/';
|
||||||
$oConfig->Set('webmail', 'app_path', $app_path);
|
$oConfig->Set('webmail', 'app_path', $app_path);
|
||||||
$oConfig->Set('webmail', 'theme', 'NextcloudV25+');
|
$oConfig->Set('webmail', 'theme', 'NextcloudV25+');
|
||||||
$oConfig->Save();
|
$oConfig->Save();
|
||||||
|
|
@ -73,7 +94,6 @@ class AdminSettings implements ISettings
|
||||||
$parameters['snappymail-app_path'] = $oConfig->Get('webmail', 'app_path', false);
|
$parameters['snappymail-app_path'] = $oConfig->Get('webmail', 'app_path', false);
|
||||||
$parameters['snappymail-nc-lang'] = !$oConfig->Get('webmail', 'allow_languages_on_settings', true);
|
$parameters['snappymail-nc-lang'] = !$oConfig->Get('webmail', 'allow_languages_on_settings', true);
|
||||||
|
|
||||||
\OCP\Util::addScript('snappymail', 'snappymail');
|
|
||||||
return new TemplateResponse('snappymail', 'admin-local', $parameters);
|
return new TemplateResponse('snappymail', 'admin-local', $parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,14 @@
|
||||||
|
|
||||||
namespace OCA\SnappyMail\Util;
|
namespace OCA\SnappyMail\Util;
|
||||||
|
|
||||||
|
use OCP\Server;
|
||||||
|
use OCP\IUserSession;
|
||||||
|
use OCP\IConfig;
|
||||||
|
use OCP\IURLGenerator;
|
||||||
|
use OCP\App\IAppManager;
|
||||||
|
use OCP\ISession;
|
||||||
|
use OCP\IGroupManager;
|
||||||
|
|
||||||
class SnappyMailResponse extends \OCP\AppFramework\Http\Response
|
class SnappyMailResponse extends \OCP\AppFramework\Http\Response
|
||||||
{
|
{
|
||||||
public function render(): string
|
public function render(): string
|
||||||
|
|
@ -56,8 +64,10 @@ class SnappyMailHelper
|
||||||
try {
|
try {
|
||||||
$oActions = \RainLoop\Api::Actions();
|
$oActions = \RainLoop\Api::Actions();
|
||||||
if (isset($_GET[$oConfig->Get('security', 'admin_panel_key', 'admin')])) {
|
if (isset($_GET[$oConfig->Get('security', 'admin_panel_key', 'admin')])) {
|
||||||
|
$user = Server::get(IUserSession::class)->getUser();
|
||||||
if ($oConfig->Get('security', 'allow_admin_panel', true)
|
if ($oConfig->Get('security', 'allow_admin_panel', true)
|
||||||
&& \OC_User::isAdminUser(\OC::$server->getUserSession()->getUser()->getUID())
|
&& $user
|
||||||
|
&& Server::get(IGroupManager::class)->isAdmin($user->getUID())
|
||||||
&& !$oActions->IsAdminLoggined(false)
|
&& !$oActions->IsAdminLoggined(false)
|
||||||
) {
|
) {
|
||||||
$sRand = \MailSo\Base\Utils::Sha1Rand();
|
$sRand = \MailSo\Base\Utils::Sha1Rand();
|
||||||
|
|
@ -79,7 +89,7 @@ class SnappyMailHelper
|
||||||
// file_get_contents(\OC::$SERVERROOT . 'config/config.php');
|
// file_get_contents(\OC::$SERVERROOT . 'config/config.php');
|
||||||
// $CONFIG['version']
|
// $CONFIG['version']
|
||||||
if (24 < $OC_Version[0]) {
|
if (24 < $OC_Version[0]) {
|
||||||
$ocSession = \OC::$server->getSession();
|
$ocSession = Server::get(ISession::class);
|
||||||
$ocSession->reopen();
|
$ocSession->reopen();
|
||||||
if (!$doLogin && $ocSession['snappymail-uid'] && $ocSession['snappymail-uid'] != $aCredentials[0]) {
|
if (!$doLogin && $ocSession['snappymail-uid'] && $ocSession['snappymail-uid'] != $aCredentials[0]) {
|
||||||
// UID changed, Impersonate plugin probably active
|
// UID changed, Impersonate plugin probably active
|
||||||
|
|
@ -92,7 +102,7 @@ class SnappyMailHelper
|
||||||
if ($doLogin && $aCredentials[1] && $aCredentials[2]) {
|
if ($doLogin && $aCredentials[1] && $aCredentials[2]) {
|
||||||
$isOIDC = \str_starts_with($aCredentials[2], 'oidc_login|');
|
$isOIDC = \str_starts_with($aCredentials[2], 'oidc_login|');
|
||||||
try {
|
try {
|
||||||
$ocSession = \OC::$server->getSession();
|
$ocSession = Server::get(ISession::class);
|
||||||
$oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2]);
|
$oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2]);
|
||||||
if (!$isOIDC && $oAccount
|
if (!$isOIDC && $oAccount
|
||||||
&& $oConfig->Get('login', 'sign_me_auto', \RainLoop\Enumerations\SignMeType::DefaultOff) === \RainLoop\Enumerations\SignMeType::DefaultOn
|
&& $oConfig->Get('login', 'sign_me_auto', \RainLoop\Enumerations\SignMeType::DefaultOff) === \RainLoop\Enumerations\SignMeType::DefaultOn
|
||||||
|
|
@ -102,10 +112,14 @@ class SnappyMailHelper
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
// Login failure, reset password to prevent more attempts
|
// Login failure, reset password to prevent more attempts
|
||||||
if (!$isOIDC) {
|
if (!$isOIDC) {
|
||||||
$sUID = \OC::$server->getUserSession()->getUser()->getUID();
|
$user = Server::get(IUserSession::class)->getUser();
|
||||||
\OC::$server->getSession()['snappymail-passphrase'] = '';
|
$sUID = $user ? $user->getUID() : null;
|
||||||
\OC::$server->getConfig()->setUserValue($sUID, 'snappymail', 'passphrase', '');
|
if ($sUID) {
|
||||||
\SnappyMail\Log::error('Nextcloud', $e->getMessage());
|
$session = Server::get(ISession::class);
|
||||||
|
$session['snappymail-passphrase'] = '';
|
||||||
|
Server::get(IConfig::class)->setUserValue($sUID, 'snappymail', 'passphrase', '');
|
||||||
|
\SnappyMail\Log::error('Nextcloud', $e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -127,12 +141,12 @@ class SnappyMailHelper
|
||||||
// https://apps.nextcloud.com/apps/oidc_login
|
// https://apps.nextcloud.com/apps/oidc_login
|
||||||
public static function isOIDCLogin() : bool
|
public static function isOIDCLogin() : bool
|
||||||
{
|
{
|
||||||
$config = \OC::$server->getConfig();
|
$config = Server::get(IConfig::class);
|
||||||
if ($config->getAppValue('snappymail', 'snappymail-autologin-oidc', false)) {
|
if ($config->getAppValue('snappymail', 'snappymail-autologin-oidc', false)) {
|
||||||
// Check if the OIDC Login app is enabled
|
// Check if the OIDC Login app is enabled
|
||||||
if (\OC::$server->getAppManager()->isEnabledForUser('oidc_login')) {
|
if (Server::get(IAppManager::class)->isEnabledForUser('oidc_login')) {
|
||||||
// Check if session is an OIDC Login
|
// Check if session is an OIDC Login
|
||||||
$ocSession = \OC::$server->getSession();
|
$ocSession = Server::get(ISession::class);
|
||||||
if ($ocSession->get('is_oidc')) {
|
if ($ocSession->get('is_oidc')) {
|
||||||
// IToken->getPassword() ???
|
// IToken->getPassword() ???
|
||||||
if ($ocSession->get('oidc_access_token')) {
|
if ($ocSession->get('oidc_access_token')) {
|
||||||
|
|
@ -151,9 +165,14 @@ class SnappyMailHelper
|
||||||
|
|
||||||
private static function getLoginCredentials() : array
|
private static function getLoginCredentials() : array
|
||||||
{
|
{
|
||||||
$sUID = \OC::$server->getUserSession()->getUser()->getUID();
|
$user = Server::get(IUserSession::class)->getUser();
|
||||||
$config = \OC::$server->getConfig();
|
$sUID = $user ? $user->getUID() : '';
|
||||||
$ocSession = \OC::$server->getSession();
|
$config = Server::get(IConfig::class);
|
||||||
|
$ocSession = Server::get(ISession::class);
|
||||||
|
|
||||||
|
if (!$sUID) {
|
||||||
|
return ['', '', ''];
|
||||||
|
}
|
||||||
|
|
||||||
// If the user has set credentials for SnappyMail in their personal settings,
|
// If the user has set credentials for SnappyMail in their personal settings,
|
||||||
// this has the first priority.
|
// this has the first priority.
|
||||||
|
|
@ -171,6 +190,7 @@ class SnappyMailHelper
|
||||||
|
|
||||||
// If the current user ID is identical to login ID (not valid when using account switching),
|
// If the current user ID is identical to login ID (not valid when using account switching),
|
||||||
// this has the second priority.
|
// this has the second priority.
|
||||||
|
// Note: $ocSession array access is supported but deprecated? ISession implements ArrayAccess.
|
||||||
if ($ocSession['snappymail-nc-uid'] == $sUID) {
|
if ($ocSession['snappymail-nc-uid'] == $sUID) {
|
||||||
|
|
||||||
// If OpenID Connect (OIDC) is enabled and used for login, use this.
|
// If OpenID Connect (OIDC) is enabled and used for login, use this.
|
||||||
|
|
@ -204,7 +224,7 @@ class SnappyMailHelper
|
||||||
|
|
||||||
public static function getAppUrl() : string
|
public static function getAppUrl() : string
|
||||||
{
|
{
|
||||||
return \OC::$server->getURLGenerator()->linkToRoute('snappymail.page.appGet');
|
return Server::get(IURLGenerator::class)->linkToRoute('snappymail.page.appGet');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function normalizeUrl(string $sUrl) : string
|
public static function normalizeUrl(string $sUrl) : string
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
<?php script('snappymail', 'snappymail'); ?>
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<form class="snappymail" action="admin.php" method="post">
|
<form class="snappymail" action="admin.php" method="post">
|
||||||
<input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>" id="requesttoken">
|
<input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>" id="requesttoken">
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
<iframe id="rliframe" style="border: none; width: 100%; min-height: 100%; position: relative;" tabindex="-1" frameborder="0" src="<?php echo $_['snappymail-iframe-url']; ?>"></iframe>
|
|
||||||
<?php
|
<?php
|
||||||
// OCP\Util::addScript('snappymail', 'resize');
|
script('snappymail', 'snappymail');
|
||||||
|
style('snappymail', 'style');
|
||||||
|
?>
|
||||||
|
<iframe id="rliframe" style="border: none; width: 100%; min-height: 100%; position: relative;" tabindex="-1" frameborder="0" src="<?php echo $_['snappymail-iframe-url']; ?>"></iframe>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
<?php style('snappymail', 'embed'); ?>
|
||||||
|
<link type="text/css" rel="stylesheet" href="<?php echo $_['CssLink']; ?>" />
|
||||||
<style id="app-boot-css"><?php echo $_['BaseAppBootCss']; ?></style>
|
<style id="app-boot-css"><?php echo $_['BaseAppBootCss']; ?></style>
|
||||||
<style id="app-theme-style"><?php echo $_['BaseAppThemeCss']; ?></style>
|
<style id="app-theme-style"><?php echo $_['BaseAppThemeCss']; ?></style>
|
||||||
<div id="rl-app" data-admin="<?php echo $_['Admin']; ?>" spellcheck="false">
|
<div id="rl-app" data-admin="<?php echo $_['Admin']; ?>" spellcheck="false">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue