2015-02-24 13:05:19 -05:00
|
|
|
<?php
|
2024-05-28 10:42:42 -04:00
|
|
|
|
2015-02-24 13:05:19 -05:00
|
|
|
/**
|
2024-05-28 10:42:42 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-02-24 13:05:19 -05:00
|
|
|
*/
|
|
|
|
|
namespace OCA\Encryption\AppInfo;
|
|
|
|
|
|
|
|
|
|
use OCA\Encryption\Crypto\Crypt;
|
2015-08-24 06:03:53 -04:00
|
|
|
use OCA\Encryption\Crypto\DecryptAll;
|
2015-08-24 09:56:04 -04:00
|
|
|
use OCA\Encryption\Crypto\EncryptAll;
|
2015-04-14 10:48:39 -04:00
|
|
|
use OCA\Encryption\Crypto\Encryption;
|
2015-02-24 13:05:19 -05:00
|
|
|
use OCA\Encryption\HookManager;
|
|
|
|
|
use OCA\Encryption\Hooks\UserHooks;
|
|
|
|
|
use OCA\Encryption\KeyManager;
|
|
|
|
|
use OCA\Encryption\Recovery;
|
2015-04-16 07:47:27 -04:00
|
|
|
use OCA\Encryption\Session;
|
2015-02-24 13:05:19 -05:00
|
|
|
use OCA\Encryption\Users\Setup;
|
2015-03-24 17:29:10 -04:00
|
|
|
use OCA\Encryption\Util;
|
2024-06-27 05:33:21 -04:00
|
|
|
use OCP\AppFramework\App;
|
|
|
|
|
use OCP\AppFramework\Bootstrap\IBootContext;
|
|
|
|
|
use OCP\AppFramework\Bootstrap\IBootstrap;
|
|
|
|
|
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
2015-02-24 13:05:19 -05:00
|
|
|
use OCP\Encryption\IManager;
|
|
|
|
|
use OCP\IConfig;
|
2023-06-29 09:41:40 -04:00
|
|
|
use Psr\Log\LoggerInterface;
|
2015-02-24 13:05:19 -05:00
|
|
|
|
2024-06-27 05:33:21 -04:00
|
|
|
class Application extends App implements IBootstrap {
|
|
|
|
|
public const APP_ID = 'encryption';
|
|
|
|
|
|
|
|
|
|
public function __construct(array $urlParams = []) {
|
|
|
|
|
parent::__construct(self::APP_ID, $urlParams);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function register(IRegistrationContext $context): void {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function boot(IBootContext $context): void {
|
|
|
|
|
\OCP\Util::addScript(self::APP_ID, 'encryption');
|
|
|
|
|
|
|
|
|
|
$context->injectFn(function (IManager $encryptionManager) use ($context) {
|
|
|
|
|
if (!($encryptionManager instanceof \OC\Encryption\Manager)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$encryptionManager->isReady()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$context->injectFn($this->registerEncryptionModule(...));
|
|
|
|
|
$context->injectFn($this->registerHooks(...));
|
|
|
|
|
$context->injectFn($this->setUp(...));
|
|
|
|
|
});
|
2017-05-30 06:54:58 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-22 16:09:09 -05:00
|
|
|
public function setUp(IManager $encryptionManager) {
|
|
|
|
|
if ($encryptionManager->isEnabled()) {
|
2016-03-02 07:58:06 -05:00
|
|
|
/** @var Setup $setup */
|
2020-11-11 14:46:22 -05:00
|
|
|
$setup = $this->getContainer()->query(Setup::class);
|
2016-03-02 07:58:06 -05:00
|
|
|
$setup->setupSystem();
|
|
|
|
|
}
|
2015-02-24 13:05:19 -05:00
|
|
|
}
|
|
|
|
|
|
2015-04-07 12:05:54 -04:00
|
|
|
/**
|
|
|
|
|
* register hooks
|
|
|
|
|
*/
|
2020-11-22 16:09:09 -05:00
|
|
|
public function registerHooks(IConfig $config) {
|
|
|
|
|
if (!$config->getSystemValueBool('maintenance')) {
|
2015-02-24 13:05:19 -05:00
|
|
|
$container = $this->getContainer();
|
|
|
|
|
$server = $container->getServer();
|
|
|
|
|
// Register our hooks and fire them.
|
|
|
|
|
$hookManager = new HookManager();
|
|
|
|
|
|
|
|
|
|
$hookManager->registerHook([
|
2020-11-11 14:46:22 -05:00
|
|
|
new UserHooks($container->query(KeyManager::class),
|
2015-09-11 15:18:13 -04:00
|
|
|
$server->getUserManager(),
|
2023-06-29 09:41:40 -04:00
|
|
|
$server->get(LoggerInterface::class),
|
2020-11-11 14:46:22 -05:00
|
|
|
$container->query(Setup::class),
|
2015-03-26 20:35:36 -04:00
|
|
|
$server->getUserSession(),
|
2020-11-11 14:46:22 -05:00
|
|
|
$container->query(Util::class),
|
|
|
|
|
$container->query(Session::class),
|
|
|
|
|
$container->query(Crypt::class),
|
|
|
|
|
$container->query(Recovery::class))
|
2015-02-24 13:05:19 -05:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$hookManager->fireHooks();
|
|
|
|
|
} else {
|
|
|
|
|
// Logout user if we are in maintenance to force re-login
|
|
|
|
|
$this->getContainer()->getServer()->getUserSession()->logout();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-22 16:09:09 -05:00
|
|
|
public function registerEncryptionModule(IManager $encryptionManager) {
|
2015-03-26 04:32:08 -04:00
|
|
|
$container = $this->getContainer();
|
2015-04-14 10:48:39 -04:00
|
|
|
|
2020-11-22 16:09:09 -05:00
|
|
|
$encryptionManager->registerEncryptionModule(
|
2015-04-14 10:48:39 -04:00
|
|
|
Encryption::ID,
|
|
|
|
|
Encryption::DISPLAY_NAME,
|
2020-04-09 07:53:40 -04:00
|
|
|
function () use ($container) {
|
2015-04-14 10:48:39 -04:00
|
|
|
return new Encryption(
|
2023-06-29 09:41:40 -04:00
|
|
|
$container->query(Crypt::class),
|
|
|
|
|
$container->query(KeyManager::class),
|
|
|
|
|
$container->query(Util::class),
|
|
|
|
|
$container->query(Session::class),
|
|
|
|
|
$container->query(EncryptAll::class),
|
|
|
|
|
$container->query(DecryptAll::class),
|
|
|
|
|
$container->getServer()->get(LoggerInterface::class),
|
|
|
|
|
$container->getServer()->getL10N($container->getAppName())
|
|
|
|
|
);
|
2015-03-26 04:32:08 -04:00
|
|
|
});
|
2015-02-24 13:05:19 -05:00
|
|
|
}
|
|
|
|
|
}
|