@@ -47,48 +47,48 @@ |
||
| 47 | 47 | use OCP\Util; |
| 48 | 48 | |
| 49 | 49 | class Application extends App implements IBootstrap { |
| 50 | - public const APP_ID = 'comments'; |
|
| 50 | + public const APP_ID = 'comments'; |
|
| 51 | 51 | |
| 52 | - public function __construct(array $urlParams = []) { |
|
| 53 | - parent::__construct(self::APP_ID, $urlParams); |
|
| 54 | - } |
|
| 52 | + public function __construct(array $urlParams = []) { |
|
| 53 | + parent::__construct(self::APP_ID, $urlParams); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function register(IRegistrationContext $context): void { |
|
| 57 | - $context->registerCapability(Capabilities::class); |
|
| 56 | + public function register(IRegistrationContext $context): void { |
|
| 57 | + $context->registerCapability(Capabilities::class); |
|
| 58 | 58 | |
| 59 | - $context->registerServiceAlias('NotificationsController', Notifications::class); |
|
| 59 | + $context->registerServiceAlias('NotificationsController', Notifications::class); |
|
| 60 | 60 | |
| 61 | - $context->registerEventListener( |
|
| 62 | - LoadAdditionalScriptsEvent::class, |
|
| 63 | - LoadAdditionalScripts::class |
|
| 64 | - ); |
|
| 65 | - $context->registerEventListener( |
|
| 66 | - LoadSidebar::class, |
|
| 67 | - LoadSidebarScripts::class |
|
| 68 | - ); |
|
| 69 | - $context->registerEventListener( |
|
| 70 | - CommentsEntityEvent::EVENT_ENTITY, |
|
| 71 | - CommentsEntityEventListener::class |
|
| 72 | - ); |
|
| 73 | - } |
|
| 61 | + $context->registerEventListener( |
|
| 62 | + LoadAdditionalScriptsEvent::class, |
|
| 63 | + LoadAdditionalScripts::class |
|
| 64 | + ); |
|
| 65 | + $context->registerEventListener( |
|
| 66 | + LoadSidebar::class, |
|
| 67 | + LoadSidebarScripts::class |
|
| 68 | + ); |
|
| 69 | + $context->registerEventListener( |
|
| 70 | + CommentsEntityEvent::EVENT_ENTITY, |
|
| 71 | + CommentsEntityEventListener::class |
|
| 72 | + ); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - public function boot(IBootContext $context): void { |
|
| 76 | - $this->registerNotifier($context->getServerContainer()); |
|
| 77 | - $this->registerCommentsEventHandler($context->getServerContainer()); |
|
| 75 | + public function boot(IBootContext $context): void { |
|
| 76 | + $this->registerNotifier($context->getServerContainer()); |
|
| 77 | + $this->registerCommentsEventHandler($context->getServerContainer()); |
|
| 78 | 78 | |
| 79 | - $jsSettingsHelper = new JSSettingsHelper($context->getServerContainer()); |
|
| 80 | - Util::connectHook('\OCP\Config', 'js', $jsSettingsHelper, 'extend'); |
|
| 79 | + $jsSettingsHelper = new JSSettingsHelper($context->getServerContainer()); |
|
| 80 | + Util::connectHook('\OCP\Config', 'js', $jsSettingsHelper, 'extend'); |
|
| 81 | 81 | |
| 82 | - $context->getServerContainer()->getSearch()->registerProvider(Provider::class, ['apps' => ['files']]); |
|
| 83 | - } |
|
| 82 | + $context->getServerContainer()->getSearch()->registerProvider(Provider::class, ['apps' => ['files']]); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - protected function registerNotifier(IServerContainer $container) { |
|
| 86 | - $container->getNotificationManager()->registerNotifierService(Notifier::class); |
|
| 87 | - } |
|
| 85 | + protected function registerNotifier(IServerContainer $container) { |
|
| 86 | + $container->getNotificationManager()->registerNotifierService(Notifier::class); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - protected function registerCommentsEventHandler(IServerContainer $container) { |
|
| 90 | - $container->getCommentsManager()->registerEventHandler(function () { |
|
| 91 | - return $this->getContainer()->query(EventHandler::class); |
|
| 92 | - }); |
|
| 93 | - } |
|
| 89 | + protected function registerCommentsEventHandler(IServerContainer $container) { |
|
| 90 | + $container->getCommentsManager()->registerEventHandler(function () { |
|
| 91 | + return $this->getContainer()->query(EventHandler::class); |
|
| 92 | + }); |
|
| 93 | + } |
|
| 94 | 94 | } |
@@ -30,15 +30,15 @@ |
||
| 30 | 30 | use OCP\EventDispatcher\IEventListener; |
| 31 | 31 | |
| 32 | 32 | class CommentsEntityEventListener implements IEventListener { |
| 33 | - public function handle(Event $event): void { |
|
| 34 | - if (!($event instanceof CommentsEntityEvent)) { |
|
| 35 | - // Unrelated |
|
| 36 | - return; |
|
| 37 | - } |
|
| 33 | + public function handle(Event $event): void { |
|
| 34 | + if (!($event instanceof CommentsEntityEvent)) { |
|
| 35 | + // Unrelated |
|
| 36 | + return; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - $event->addEntityCollection('files', function ($name) { |
|
| 40 | - $nodes = \OC::$server->getUserFolder()->getById((int)$name); |
|
| 41 | - return !empty($nodes); |
|
| 42 | - }); |
|
| 43 | - } |
|
| 39 | + $event->addEntityCollection('files', function ($name) { |
|
| 40 | + $nodes = \OC::$server->getUserFolder()->getById((int)$name); |
|
| 41 | + return !empty($nodes); |
|
| 42 | + }); |
|
| 43 | + } |
|
| 44 | 44 | } |
@@ -45,42 +45,42 @@ |
||
| 45 | 45 | use OCP\Util; |
| 46 | 46 | |
| 47 | 47 | class Application extends App implements IBootstrap { |
| 48 | - public const APP_ID = 'twofactor_backupcodes'; |
|
| 48 | + public const APP_ID = 'twofactor_backupcodes'; |
|
| 49 | 49 | |
| 50 | - public function __construct() { |
|
| 51 | - parent::__construct(self::APP_ID); |
|
| 52 | - } |
|
| 50 | + public function __construct() { |
|
| 51 | + parent::__construct(self::APP_ID); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - public function register(IRegistrationContext $context): void { |
|
| 55 | - $this->registerHooksAndEvents($context); |
|
| 56 | - } |
|
| 54 | + public function register(IRegistrationContext $context): void { |
|
| 55 | + $this->registerHooksAndEvents($context); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - public function boot(IBootContext $context): void { |
|
| 59 | - Util::connectHook('OC_User', 'post_deleteUser', $this, 'deleteUser'); |
|
| 58 | + public function boot(IBootContext $context): void { |
|
| 59 | + Util::connectHook('OC_User', 'post_deleteUser', $this, 'deleteUser'); |
|
| 60 | 60 | |
| 61 | - $this->registerNotification( |
|
| 62 | - $context->getAppContainer()->query(IManager::class) |
|
| 63 | - ); |
|
| 64 | - } |
|
| 61 | + $this->registerNotification( |
|
| 62 | + $context->getAppContainer()->query(IManager::class) |
|
| 63 | + ); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Register the hooks and events |
|
| 68 | - */ |
|
| 69 | - public function registerHooksAndEvents(IRegistrationContext $context) { |
|
| 70 | - $context->registerEventListener(CodesGenerated::class, ActivityPublisher::class); |
|
| 71 | - $context->registerEventListener(CodesGenerated::class, RegistryUpdater::class); |
|
| 72 | - $context->registerEventListener(CodesGenerated::class, ClearNotifications::class); |
|
| 73 | - $context->registerEventListener(IRegistry::EVENT_PROVIDER_ENABLED, ProviderEnabled::class); |
|
| 74 | - $context->registerEventListener(IRegistry::EVENT_PROVIDER_DISABLED, ProviderDisabled::class); |
|
| 75 | - } |
|
| 66 | + /** |
|
| 67 | + * Register the hooks and events |
|
| 68 | + */ |
|
| 69 | + public function registerHooksAndEvents(IRegistrationContext $context) { |
|
| 70 | + $context->registerEventListener(CodesGenerated::class, ActivityPublisher::class); |
|
| 71 | + $context->registerEventListener(CodesGenerated::class, RegistryUpdater::class); |
|
| 72 | + $context->registerEventListener(CodesGenerated::class, ClearNotifications::class); |
|
| 73 | + $context->registerEventListener(IRegistry::EVENT_PROVIDER_ENABLED, ProviderEnabled::class); |
|
| 74 | + $context->registerEventListener(IRegistry::EVENT_PROVIDER_DISABLED, ProviderDisabled::class); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - private function registerNotification(IManager $manager) { |
|
| 78 | - $manager->registerNotifierService(Notifier::class); |
|
| 79 | - } |
|
| 77 | + private function registerNotification(IManager $manager) { |
|
| 78 | + $manager->registerNotifierService(Notifier::class); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - public function deleteUser($params) { |
|
| 82 | - /** @var BackupCodeMapper $mapper */ |
|
| 83 | - $mapper = $this->getContainer()->query(BackupCodeMapper::class); |
|
| 84 | - $mapper->deleteCodesByUserId($params['uid']); |
|
| 85 | - } |
|
| 81 | + public function deleteUser($params) { |
|
| 82 | + /** @var BackupCodeMapper $mapper */ |
|
| 83 | + $mapper = $this->getContainer()->query(BackupCodeMapper::class); |
|
| 84 | + $mapper->deleteCodesByUserId($params['uid']); |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -36,55 +36,55 @@ |
||
| 36 | 36 | |
| 37 | 37 | class RepairUserConfig implements IRepairStep { |
| 38 | 38 | |
| 39 | - /** @var IUserManager */ |
|
| 40 | - protected $userManager; |
|
| 39 | + /** @var IUserManager */ |
|
| 40 | + protected $userManager; |
|
| 41 | 41 | |
| 42 | - /** @var IConfig */ |
|
| 43 | - protected $config; |
|
| 42 | + /** @var IConfig */ |
|
| 43 | + protected $config; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * MigrateUserConfig constructor. |
|
| 47 | - * |
|
| 48 | - * @param IConfig $config |
|
| 49 | - * @param IUserManager $userManager |
|
| 50 | - */ |
|
| 51 | - public function __construct(IConfig $config, |
|
| 52 | - IUserManager $userManager) { |
|
| 53 | - $this->config = $config; |
|
| 54 | - $this->userManager = $userManager; |
|
| 55 | - } |
|
| 45 | + /** |
|
| 46 | + * MigrateUserConfig constructor. |
|
| 47 | + * |
|
| 48 | + * @param IConfig $config |
|
| 49 | + * @param IUserManager $userManager |
|
| 50 | + */ |
|
| 51 | + public function __construct(IConfig $config, |
|
| 52 | + IUserManager $userManager) { |
|
| 53 | + $this->config = $config; |
|
| 54 | + $this->userManager = $userManager; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Returns the step's name |
|
| 59 | - * |
|
| 60 | - * @return string |
|
| 61 | - * @since 9.1.0 |
|
| 62 | - */ |
|
| 63 | - public function getName() { |
|
| 64 | - return 'Migrate old user config'; |
|
| 65 | - } |
|
| 57 | + /** |
|
| 58 | + * Returns the step's name |
|
| 59 | + * |
|
| 60 | + * @return string |
|
| 61 | + * @since 9.1.0 |
|
| 62 | + */ |
|
| 63 | + public function getName() { |
|
| 64 | + return 'Migrate old user config'; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Run repair step. |
|
| 69 | - * Must throw exception on error. |
|
| 70 | - * |
|
| 71 | - * @param IOutput $output |
|
| 72 | - * @throws \Exception in case of failure |
|
| 73 | - * @since 9.1.0 |
|
| 74 | - */ |
|
| 75 | - public function run(IOutput $output) { |
|
| 76 | - $output->startProgress(); |
|
| 77 | - $this->userManager->callForSeenUsers(function (IUser $user) use ($output) { |
|
| 78 | - $theme = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'theme', false); |
|
| 79 | - if ($theme === 'themedark') { |
|
| 80 | - $this->config->setUserValue($user->getUID(), Application::APP_ID, 'theme', 'dark'); |
|
| 81 | - } |
|
| 82 | - if ($theme === 'themehighcontrast') { |
|
| 83 | - $this->config->setUserValue($user->getUID(), Application::APP_ID, 'highcontrast', 'highcontrast'); |
|
| 84 | - $this->config->deleteUserValue($user->getUID(), Application::APP_ID, 'theme'); |
|
| 85 | - } |
|
| 86 | - $output->advance(); |
|
| 87 | - }); |
|
| 88 | - $output->finishProgress(); |
|
| 89 | - } |
|
| 67 | + /** |
|
| 68 | + * Run repair step. |
|
| 69 | + * Must throw exception on error. |
|
| 70 | + * |
|
| 71 | + * @param IOutput $output |
|
| 72 | + * @throws \Exception in case of failure |
|
| 73 | + * @since 9.1.0 |
|
| 74 | + */ |
|
| 75 | + public function run(IOutput $output) { |
|
| 76 | + $output->startProgress(); |
|
| 77 | + $this->userManager->callForSeenUsers(function (IUser $user) use ($output) { |
|
| 78 | + $theme = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'theme', false); |
|
| 79 | + if ($theme === 'themedark') { |
|
| 80 | + $this->config->setUserValue($user->getUID(), Application::APP_ID, 'theme', 'dark'); |
|
| 81 | + } |
|
| 82 | + if ($theme === 'themehighcontrast') { |
|
| 83 | + $this->config->setUserValue($user->getUID(), Application::APP_ID, 'highcontrast', 'highcontrast'); |
|
| 84 | + $this->config->deleteUserValue($user->getUID(), Application::APP_ID, 'theme'); |
|
| 85 | + } |
|
| 86 | + $output->advance(); |
|
| 87 | + }); |
|
| 88 | + $output->finishProgress(); |
|
| 89 | + } |
|
| 90 | 90 | } |
@@ -43,71 +43,71 @@ |
||
| 43 | 43 | |
| 44 | 44 | class Application extends App implements IBootstrap { |
| 45 | 45 | |
| 46 | - /** @var string */ |
|
| 47 | - public const APP_ID = 'accessibility'; |
|
| 46 | + /** @var string */ |
|
| 47 | + public const APP_ID = 'accessibility'; |
|
| 48 | 48 | |
| 49 | - /** @var IConfig */ |
|
| 50 | - private $config; |
|
| 49 | + /** @var IConfig */ |
|
| 50 | + private $config; |
|
| 51 | 51 | |
| 52 | - /** @var IUserSession */ |
|
| 53 | - private $userSession; |
|
| 52 | + /** @var IUserSession */ |
|
| 53 | + private $userSession; |
|
| 54 | 54 | |
| 55 | - /** @var IURLGenerator */ |
|
| 56 | - private $urlGenerator; |
|
| 55 | + /** @var IURLGenerator */ |
|
| 56 | + private $urlGenerator; |
|
| 57 | 57 | |
| 58 | - public function __construct() { |
|
| 59 | - parent::__construct(self::APP_ID); |
|
| 60 | - } |
|
| 58 | + public function __construct() { |
|
| 59 | + parent::__construct(self::APP_ID); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function register(IRegistrationContext $context): void { |
|
| 63 | - } |
|
| 62 | + public function register(IRegistrationContext $context): void { |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - public function boot(IBootContext $context): void { |
|
| 66 | - $this->injectCss( |
|
| 67 | - $context->getAppContainer()->query(IUserSession::class), |
|
| 68 | - $context->getAppContainer()->query(IConfig::class), |
|
| 69 | - $context->getAppContainer()->query(IURLGenerator::class) |
|
| 70 | - ); |
|
| 71 | - $this->injectJavascript( |
|
| 72 | - $context->getAppContainer()->query(IURLGenerator::class), |
|
| 73 | - $context->getAppContainer()->query(IConfig::class), |
|
| 74 | - $context->getServerContainer() |
|
| 75 | - ); |
|
| 76 | - } |
|
| 65 | + public function boot(IBootContext $context): void { |
|
| 66 | + $this->injectCss( |
|
| 67 | + $context->getAppContainer()->query(IUserSession::class), |
|
| 68 | + $context->getAppContainer()->query(IConfig::class), |
|
| 69 | + $context->getAppContainer()->query(IURLGenerator::class) |
|
| 70 | + ); |
|
| 71 | + $this->injectJavascript( |
|
| 72 | + $context->getAppContainer()->query(IURLGenerator::class), |
|
| 73 | + $context->getAppContainer()->query(IConfig::class), |
|
| 74 | + $context->getServerContainer() |
|
| 75 | + ); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - private function injectCss(IUserSession $userSession, |
|
| 79 | - IConfig $config, |
|
| 80 | - IURLGenerator $urlGenerator) { |
|
| 81 | - // Inject the fake css on all pages if enabled and user is logged |
|
| 82 | - $loggedUser = $userSession->getUser(); |
|
| 83 | - if ($loggedUser !== null) { |
|
| 84 | - $userValues = $config->getUserKeys($loggedUser->getUID(), self::APP_ID); |
|
| 85 | - // we want to check if any theme or font is enabled. |
|
| 86 | - if (count($userValues) > 0) { |
|
| 87 | - $hash = $config->getUserValue($loggedUser->getUID(), self::APP_ID, 'icons-css', md5(implode('-', $userValues))); |
|
| 88 | - $linkToCSS = $urlGenerator->linkToRoute(self::APP_ID . '.accessibility.getCss', ['md5' => $hash]); |
|
| 89 | - \OCP\Util::addHeader('link', ['rel' => 'stylesheet', 'href' => $linkToCSS]); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - } |
|
| 78 | + private function injectCss(IUserSession $userSession, |
|
| 79 | + IConfig $config, |
|
| 80 | + IURLGenerator $urlGenerator) { |
|
| 81 | + // Inject the fake css on all pages if enabled and user is logged |
|
| 82 | + $loggedUser = $userSession->getUser(); |
|
| 83 | + if ($loggedUser !== null) { |
|
| 84 | + $userValues = $config->getUserKeys($loggedUser->getUID(), self::APP_ID); |
|
| 85 | + // we want to check if any theme or font is enabled. |
|
| 86 | + if (count($userValues) > 0) { |
|
| 87 | + $hash = $config->getUserValue($loggedUser->getUID(), self::APP_ID, 'icons-css', md5(implode('-', $userValues))); |
|
| 88 | + $linkToCSS = $urlGenerator->linkToRoute(self::APP_ID . '.accessibility.getCss', ['md5' => $hash]); |
|
| 89 | + \OCP\Util::addHeader('link', ['rel' => 'stylesheet', 'href' => $linkToCSS]); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - private function injectJavascript(IURLGenerator $urlGenerator, |
|
| 95 | - IConfig $config, |
|
| 96 | - IServerContainer $serverContainer) { |
|
| 97 | - $linkToJs = $urlGenerator->linkToRoute( |
|
| 98 | - self::APP_ID . '.accessibility.getJavascript', |
|
| 99 | - [ |
|
| 100 | - 'v' => $config->getAppValue(self::APP_ID, 'cachebuster', '0'), |
|
| 101 | - ] |
|
| 102 | - ); |
|
| 94 | + private function injectJavascript(IURLGenerator $urlGenerator, |
|
| 95 | + IConfig $config, |
|
| 96 | + IServerContainer $serverContainer) { |
|
| 97 | + $linkToJs = $urlGenerator->linkToRoute( |
|
| 98 | + self::APP_ID . '.accessibility.getJavascript', |
|
| 99 | + [ |
|
| 100 | + 'v' => $config->getAppValue(self::APP_ID, 'cachebuster', '0'), |
|
| 101 | + ] |
|
| 102 | + ); |
|
| 103 | 103 | |
| 104 | - \OCP\Util::addHeader( |
|
| 105 | - 'script', |
|
| 106 | - [ |
|
| 107 | - 'src' => $linkToJs, |
|
| 108 | - 'nonce' => $serverContainer->getContentSecurityPolicyNonceManager()->getNonce() |
|
| 109 | - ], |
|
| 110 | - '' |
|
| 111 | - ); |
|
| 112 | - } |
|
| 104 | + \OCP\Util::addHeader( |
|
| 105 | + 'script', |
|
| 106 | + [ |
|
| 107 | + 'src' => $linkToJs, |
|
| 108 | + 'nonce' => $serverContainer->getContentSecurityPolicyNonceManager()->getNonce() |
|
| 109 | + ], |
|
| 110 | + '' |
|
| 111 | + ); |
|
| 112 | + } |
|
| 113 | 113 | } |
@@ -67,221 +67,221 @@ |
||
| 67 | 67 | |
| 68 | 68 | class Application extends App implements IBootstrap { |
| 69 | 69 | |
| 70 | - /** @var ILogger */ |
|
| 71 | - protected $logger; |
|
| 70 | + /** @var ILogger */ |
|
| 71 | + protected $logger; |
|
| 72 | 72 | |
| 73 | - public function __construct() { |
|
| 74 | - parent::__construct('admin_audit'); |
|
| 75 | - } |
|
| 73 | + public function __construct() { |
|
| 74 | + parent::__construct('admin_audit'); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - public function register(IRegistrationContext $context): void { |
|
| 78 | - } |
|
| 77 | + public function register(IRegistrationContext $context): void { |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - public function boot(IBootContext $context): void { |
|
| 81 | - $logger = $this->getLogger( |
|
| 82 | - $context->getAppContainer()->query(IConfig::class), |
|
| 83 | - $context->getAppContainer()->query(ILogger::class), |
|
| 84 | - $context->getAppContainer()->query(ILogFactory::class) |
|
| 85 | - ); |
|
| 80 | + public function boot(IBootContext $context): void { |
|
| 81 | + $logger = $this->getLogger( |
|
| 82 | + $context->getAppContainer()->query(IConfig::class), |
|
| 83 | + $context->getAppContainer()->query(ILogger::class), |
|
| 84 | + $context->getAppContainer()->query(ILogFactory::class) |
|
| 85 | + ); |
|
| 86 | 86 | |
| 87 | - /* |
|
| 87 | + /* |
|
| 88 | 88 | * TODO: once the hooks are migrated to lazy events, this should be done |
| 89 | 89 | * in \OCA\AdminAudit\AppInfo\Application::register |
| 90 | 90 | */ |
| 91 | - $this->registerHooks($logger, $context->getServerContainer()); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - private function getLogger(IConfig $config, |
|
| 95 | - ILogger $logger, |
|
| 96 | - ILogFactory $logFactory): ILogger { |
|
| 97 | - $default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log'; |
|
| 98 | - $logFile = $config->getAppValue('admin_audit', 'logfile', $default); |
|
| 99 | - |
|
| 100 | - if ($logFile === null) { |
|
| 101 | - return $logger; |
|
| 102 | - } |
|
| 103 | - return $logFactory->getCustomLogger($logFile); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Register hooks in order to log them |
|
| 108 | - */ |
|
| 109 | - private function registerHooks(ILogger $logger, |
|
| 110 | - IServerContainer $serverContainer) { |
|
| 111 | - $this->userManagementHooks($logger, $serverContainer); |
|
| 112 | - $this->groupHooks($logger, $serverContainer); |
|
| 113 | - $this->authHooks($logger); |
|
| 114 | - |
|
| 115 | - $this->consoleHooks($logger, $serverContainer); |
|
| 116 | - $this->appHooks($logger, $serverContainer); |
|
| 117 | - |
|
| 118 | - $this->sharingHooks($logger); |
|
| 119 | - |
|
| 120 | - $this->fileHooks($logger, $serverContainer); |
|
| 121 | - $this->trashbinHooks($logger); |
|
| 122 | - $this->versionsHooks($logger); |
|
| 123 | - |
|
| 124 | - $this->securityHooks($logger, $serverContainer); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - private function userManagementHooks(ILogger $logger, |
|
| 128 | - IServerContainer $serverContainer) { |
|
| 129 | - $userActions = new UserManagement($logger); |
|
| 130 | - |
|
| 131 | - Util::connectHook('OC_User', 'post_createUser', $userActions, 'create'); |
|
| 132 | - Util::connectHook('OC_User', 'post_deleteUser', $userActions, 'delete'); |
|
| 133 | - Util::connectHook('OC_User', 'changeUser', $userActions, 'change'); |
|
| 134 | - |
|
| 135 | - /** @var IUserSession|Session $userSession */ |
|
| 136 | - $userSession = $serverContainer->getUserSession(); |
|
| 137 | - $userSession->listen('\OC\User', 'postSetPassword', [$userActions, 'setPassword']); |
|
| 138 | - $userSession->listen('\OC\User', 'assignedUserId', [$userActions, 'assign']); |
|
| 139 | - $userSession->listen('\OC\User', 'postUnassignedUserId', [$userActions, 'unassign']); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - private function groupHooks(ILogger $logger, |
|
| 143 | - IServerContainer $serverContainer) { |
|
| 144 | - $groupActions = new GroupManagement($logger); |
|
| 145 | - |
|
| 146 | - /** @var IGroupManager|Manager $groupManager */ |
|
| 147 | - $groupManager = $serverContainer->getGroupManager(); |
|
| 148 | - $groupManager->listen('\OC\Group', 'postRemoveUser', [$groupActions, 'removeUser']); |
|
| 149 | - $groupManager->listen('\OC\Group', 'postAddUser', [$groupActions, 'addUser']); |
|
| 150 | - $groupManager->listen('\OC\Group', 'postDelete', [$groupActions, 'deleteGroup']); |
|
| 151 | - $groupManager->listen('\OC\Group', 'postCreate', [$groupActions, 'createGroup']); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - private function sharingHooks(ILogger $logger) { |
|
| 155 | - $shareActions = new Sharing($logger); |
|
| 156 | - |
|
| 157 | - Util::connectHook(Share::class, 'post_shared', $shareActions, 'shared'); |
|
| 158 | - Util::connectHook(Share::class, 'post_unshare', $shareActions, 'unshare'); |
|
| 159 | - Util::connectHook(Share::class, 'post_unshareFromSelf', $shareActions, 'unshare'); |
|
| 160 | - Util::connectHook(Share::class, 'post_update_permissions', $shareActions, 'updatePermissions'); |
|
| 161 | - Util::connectHook(Share::class, 'post_update_password', $shareActions, 'updatePassword'); |
|
| 162 | - Util::connectHook(Share::class, 'post_set_expiration_date', $shareActions, 'updateExpirationDate'); |
|
| 163 | - Util::connectHook(Share::class, 'share_link_access', $shareActions, 'shareAccessed'); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - private function authHooks(ILogger $logger) { |
|
| 167 | - $authActions = new Auth($logger); |
|
| 168 | - |
|
| 169 | - Util::connectHook('OC_User', 'pre_login', $authActions, 'loginAttempt'); |
|
| 170 | - Util::connectHook('OC_User', 'post_login', $authActions, 'loginSuccessful'); |
|
| 171 | - Util::connectHook('OC_User', 'logout', $authActions, 'logout'); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - private function appHooks(ILogger $logger, |
|
| 175 | - IServerContainer $serverContainer) { |
|
| 176 | - $eventDispatcher = $serverContainer->getEventDispatcher(); |
|
| 177 | - $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function (ManagerEvent $event) use ($logger) { |
|
| 178 | - $appActions = new AppManagement($logger); |
|
| 179 | - $appActions->enableApp($event->getAppID()); |
|
| 180 | - }); |
|
| 181 | - $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, function (ManagerEvent $event) use ($logger) { |
|
| 182 | - $appActions = new AppManagement($logger); |
|
| 183 | - $appActions->enableAppForGroups($event->getAppID(), $event->getGroups()); |
|
| 184 | - }); |
|
| 185 | - $eventDispatcher->addListener(ManagerEvent::EVENT_APP_DISABLE, function (ManagerEvent $event) use ($logger) { |
|
| 186 | - $appActions = new AppManagement($logger); |
|
| 187 | - $appActions->disableApp($event->getAppID()); |
|
| 188 | - }); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - private function consoleHooks(ILogger $logger, |
|
| 192 | - IServerContainer $serverContainer) { |
|
| 193 | - $eventDispatcher = $serverContainer->getEventDispatcher(); |
|
| 194 | - $eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function (ConsoleEvent $event) use ($logger) { |
|
| 195 | - $appActions = new Console($logger); |
|
| 196 | - $appActions->runCommand($event->getArguments()); |
|
| 197 | - }); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - private function fileHooks(ILogger $logger, |
|
| 201 | - IServerContainer $serverContainer) { |
|
| 202 | - $fileActions = new Files($logger); |
|
| 203 | - $eventDispatcher = $serverContainer->getEventDispatcher(); |
|
| 204 | - $eventDispatcher->addListener( |
|
| 205 | - IPreview::EVENT, |
|
| 206 | - function (GenericEvent $event) use ($fileActions) { |
|
| 207 | - /** @var File $file */ |
|
| 208 | - $file = $event->getSubject(); |
|
| 209 | - $fileActions->preview([ |
|
| 210 | - 'path' => mb_substr($file->getInternalPath(), 5), |
|
| 211 | - 'width' => $event->getArguments()['width'], |
|
| 212 | - 'height' => $event->getArguments()['height'], |
|
| 213 | - 'crop' => $event->getArguments()['crop'], |
|
| 214 | - 'mode' => $event->getArguments()['mode'] |
|
| 215 | - ]); |
|
| 216 | - } |
|
| 217 | - ); |
|
| 218 | - |
|
| 219 | - Util::connectHook( |
|
| 220 | - Filesystem::CLASSNAME, |
|
| 221 | - Filesystem::signal_post_rename, |
|
| 222 | - $fileActions, |
|
| 223 | - 'rename' |
|
| 224 | - ); |
|
| 225 | - Util::connectHook( |
|
| 226 | - Filesystem::CLASSNAME, |
|
| 227 | - Filesystem::signal_post_create, |
|
| 228 | - $fileActions, |
|
| 229 | - 'create' |
|
| 230 | - ); |
|
| 231 | - Util::connectHook( |
|
| 232 | - Filesystem::CLASSNAME, |
|
| 233 | - Filesystem::signal_post_copy, |
|
| 234 | - $fileActions, |
|
| 235 | - 'copy' |
|
| 236 | - ); |
|
| 237 | - Util::connectHook( |
|
| 238 | - Filesystem::CLASSNAME, |
|
| 239 | - Filesystem::signal_post_write, |
|
| 240 | - $fileActions, |
|
| 241 | - 'write' |
|
| 242 | - ); |
|
| 243 | - Util::connectHook( |
|
| 244 | - Filesystem::CLASSNAME, |
|
| 245 | - Filesystem::signal_post_update, |
|
| 246 | - $fileActions, |
|
| 247 | - 'update' |
|
| 248 | - ); |
|
| 249 | - Util::connectHook( |
|
| 250 | - Filesystem::CLASSNAME, |
|
| 251 | - Filesystem::signal_read, |
|
| 252 | - $fileActions, |
|
| 253 | - 'read' |
|
| 254 | - ); |
|
| 255 | - Util::connectHook( |
|
| 256 | - Filesystem::CLASSNAME, |
|
| 257 | - Filesystem::signal_delete, |
|
| 258 | - $fileActions, |
|
| 259 | - 'delete' |
|
| 260 | - ); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - private function versionsHooks(ILogger $logger) { |
|
| 264 | - $versionsActions = new Versions($logger); |
|
| 265 | - Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback'); |
|
| 266 | - Util::connectHook('\OCP\Versions', 'delete', $versionsActions, 'delete'); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - private function trashbinHooks(ILogger $logger) { |
|
| 270 | - $trashActions = new Trashbin($logger); |
|
| 271 | - Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete'); |
|
| 272 | - Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore'); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - private function securityHooks(ILogger $logger, |
|
| 276 | - IServerContainer $serverContainer) { |
|
| 277 | - $eventDispatcher = $serverContainer->getEventDispatcher(); |
|
| 278 | - $eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function (GenericEvent $event) use ($logger) { |
|
| 279 | - $security = new Security($logger); |
|
| 280 | - $security->twofactorSuccess($event->getSubject(), $event->getArguments()); |
|
| 281 | - }); |
|
| 282 | - $eventDispatcher->addListener(IProvider::EVENT_FAILED, function (GenericEvent $event) use ($logger) { |
|
| 283 | - $security = new Security($logger); |
|
| 284 | - $security->twofactorFailed($event->getSubject(), $event->getArguments()); |
|
| 285 | - }); |
|
| 286 | - } |
|
| 91 | + $this->registerHooks($logger, $context->getServerContainer()); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + private function getLogger(IConfig $config, |
|
| 95 | + ILogger $logger, |
|
| 96 | + ILogFactory $logFactory): ILogger { |
|
| 97 | + $default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log'; |
|
| 98 | + $logFile = $config->getAppValue('admin_audit', 'logfile', $default); |
|
| 99 | + |
|
| 100 | + if ($logFile === null) { |
|
| 101 | + return $logger; |
|
| 102 | + } |
|
| 103 | + return $logFactory->getCustomLogger($logFile); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Register hooks in order to log them |
|
| 108 | + */ |
|
| 109 | + private function registerHooks(ILogger $logger, |
|
| 110 | + IServerContainer $serverContainer) { |
|
| 111 | + $this->userManagementHooks($logger, $serverContainer); |
|
| 112 | + $this->groupHooks($logger, $serverContainer); |
|
| 113 | + $this->authHooks($logger); |
|
| 114 | + |
|
| 115 | + $this->consoleHooks($logger, $serverContainer); |
|
| 116 | + $this->appHooks($logger, $serverContainer); |
|
| 117 | + |
|
| 118 | + $this->sharingHooks($logger); |
|
| 119 | + |
|
| 120 | + $this->fileHooks($logger, $serverContainer); |
|
| 121 | + $this->trashbinHooks($logger); |
|
| 122 | + $this->versionsHooks($logger); |
|
| 123 | + |
|
| 124 | + $this->securityHooks($logger, $serverContainer); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + private function userManagementHooks(ILogger $logger, |
|
| 128 | + IServerContainer $serverContainer) { |
|
| 129 | + $userActions = new UserManagement($logger); |
|
| 130 | + |
|
| 131 | + Util::connectHook('OC_User', 'post_createUser', $userActions, 'create'); |
|
| 132 | + Util::connectHook('OC_User', 'post_deleteUser', $userActions, 'delete'); |
|
| 133 | + Util::connectHook('OC_User', 'changeUser', $userActions, 'change'); |
|
| 134 | + |
|
| 135 | + /** @var IUserSession|Session $userSession */ |
|
| 136 | + $userSession = $serverContainer->getUserSession(); |
|
| 137 | + $userSession->listen('\OC\User', 'postSetPassword', [$userActions, 'setPassword']); |
|
| 138 | + $userSession->listen('\OC\User', 'assignedUserId', [$userActions, 'assign']); |
|
| 139 | + $userSession->listen('\OC\User', 'postUnassignedUserId', [$userActions, 'unassign']); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + private function groupHooks(ILogger $logger, |
|
| 143 | + IServerContainer $serverContainer) { |
|
| 144 | + $groupActions = new GroupManagement($logger); |
|
| 145 | + |
|
| 146 | + /** @var IGroupManager|Manager $groupManager */ |
|
| 147 | + $groupManager = $serverContainer->getGroupManager(); |
|
| 148 | + $groupManager->listen('\OC\Group', 'postRemoveUser', [$groupActions, 'removeUser']); |
|
| 149 | + $groupManager->listen('\OC\Group', 'postAddUser', [$groupActions, 'addUser']); |
|
| 150 | + $groupManager->listen('\OC\Group', 'postDelete', [$groupActions, 'deleteGroup']); |
|
| 151 | + $groupManager->listen('\OC\Group', 'postCreate', [$groupActions, 'createGroup']); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + private function sharingHooks(ILogger $logger) { |
|
| 155 | + $shareActions = new Sharing($logger); |
|
| 156 | + |
|
| 157 | + Util::connectHook(Share::class, 'post_shared', $shareActions, 'shared'); |
|
| 158 | + Util::connectHook(Share::class, 'post_unshare', $shareActions, 'unshare'); |
|
| 159 | + Util::connectHook(Share::class, 'post_unshareFromSelf', $shareActions, 'unshare'); |
|
| 160 | + Util::connectHook(Share::class, 'post_update_permissions', $shareActions, 'updatePermissions'); |
|
| 161 | + Util::connectHook(Share::class, 'post_update_password', $shareActions, 'updatePassword'); |
|
| 162 | + Util::connectHook(Share::class, 'post_set_expiration_date', $shareActions, 'updateExpirationDate'); |
|
| 163 | + Util::connectHook(Share::class, 'share_link_access', $shareActions, 'shareAccessed'); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + private function authHooks(ILogger $logger) { |
|
| 167 | + $authActions = new Auth($logger); |
|
| 168 | + |
|
| 169 | + Util::connectHook('OC_User', 'pre_login', $authActions, 'loginAttempt'); |
|
| 170 | + Util::connectHook('OC_User', 'post_login', $authActions, 'loginSuccessful'); |
|
| 171 | + Util::connectHook('OC_User', 'logout', $authActions, 'logout'); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + private function appHooks(ILogger $logger, |
|
| 175 | + IServerContainer $serverContainer) { |
|
| 176 | + $eventDispatcher = $serverContainer->getEventDispatcher(); |
|
| 177 | + $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function (ManagerEvent $event) use ($logger) { |
|
| 178 | + $appActions = new AppManagement($logger); |
|
| 179 | + $appActions->enableApp($event->getAppID()); |
|
| 180 | + }); |
|
| 181 | + $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, function (ManagerEvent $event) use ($logger) { |
|
| 182 | + $appActions = new AppManagement($logger); |
|
| 183 | + $appActions->enableAppForGroups($event->getAppID(), $event->getGroups()); |
|
| 184 | + }); |
|
| 185 | + $eventDispatcher->addListener(ManagerEvent::EVENT_APP_DISABLE, function (ManagerEvent $event) use ($logger) { |
|
| 186 | + $appActions = new AppManagement($logger); |
|
| 187 | + $appActions->disableApp($event->getAppID()); |
|
| 188 | + }); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + private function consoleHooks(ILogger $logger, |
|
| 192 | + IServerContainer $serverContainer) { |
|
| 193 | + $eventDispatcher = $serverContainer->getEventDispatcher(); |
|
| 194 | + $eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function (ConsoleEvent $event) use ($logger) { |
|
| 195 | + $appActions = new Console($logger); |
|
| 196 | + $appActions->runCommand($event->getArguments()); |
|
| 197 | + }); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + private function fileHooks(ILogger $logger, |
|
| 201 | + IServerContainer $serverContainer) { |
|
| 202 | + $fileActions = new Files($logger); |
|
| 203 | + $eventDispatcher = $serverContainer->getEventDispatcher(); |
|
| 204 | + $eventDispatcher->addListener( |
|
| 205 | + IPreview::EVENT, |
|
| 206 | + function (GenericEvent $event) use ($fileActions) { |
|
| 207 | + /** @var File $file */ |
|
| 208 | + $file = $event->getSubject(); |
|
| 209 | + $fileActions->preview([ |
|
| 210 | + 'path' => mb_substr($file->getInternalPath(), 5), |
|
| 211 | + 'width' => $event->getArguments()['width'], |
|
| 212 | + 'height' => $event->getArguments()['height'], |
|
| 213 | + 'crop' => $event->getArguments()['crop'], |
|
| 214 | + 'mode' => $event->getArguments()['mode'] |
|
| 215 | + ]); |
|
| 216 | + } |
|
| 217 | + ); |
|
| 218 | + |
|
| 219 | + Util::connectHook( |
|
| 220 | + Filesystem::CLASSNAME, |
|
| 221 | + Filesystem::signal_post_rename, |
|
| 222 | + $fileActions, |
|
| 223 | + 'rename' |
|
| 224 | + ); |
|
| 225 | + Util::connectHook( |
|
| 226 | + Filesystem::CLASSNAME, |
|
| 227 | + Filesystem::signal_post_create, |
|
| 228 | + $fileActions, |
|
| 229 | + 'create' |
|
| 230 | + ); |
|
| 231 | + Util::connectHook( |
|
| 232 | + Filesystem::CLASSNAME, |
|
| 233 | + Filesystem::signal_post_copy, |
|
| 234 | + $fileActions, |
|
| 235 | + 'copy' |
|
| 236 | + ); |
|
| 237 | + Util::connectHook( |
|
| 238 | + Filesystem::CLASSNAME, |
|
| 239 | + Filesystem::signal_post_write, |
|
| 240 | + $fileActions, |
|
| 241 | + 'write' |
|
| 242 | + ); |
|
| 243 | + Util::connectHook( |
|
| 244 | + Filesystem::CLASSNAME, |
|
| 245 | + Filesystem::signal_post_update, |
|
| 246 | + $fileActions, |
|
| 247 | + 'update' |
|
| 248 | + ); |
|
| 249 | + Util::connectHook( |
|
| 250 | + Filesystem::CLASSNAME, |
|
| 251 | + Filesystem::signal_read, |
|
| 252 | + $fileActions, |
|
| 253 | + 'read' |
|
| 254 | + ); |
|
| 255 | + Util::connectHook( |
|
| 256 | + Filesystem::CLASSNAME, |
|
| 257 | + Filesystem::signal_delete, |
|
| 258 | + $fileActions, |
|
| 259 | + 'delete' |
|
| 260 | + ); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + private function versionsHooks(ILogger $logger) { |
|
| 264 | + $versionsActions = new Versions($logger); |
|
| 265 | + Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback'); |
|
| 266 | + Util::connectHook('\OCP\Versions', 'delete', $versionsActions, 'delete'); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + private function trashbinHooks(ILogger $logger) { |
|
| 270 | + $trashActions = new Trashbin($logger); |
|
| 271 | + Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete'); |
|
| 272 | + Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore'); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + private function securityHooks(ILogger $logger, |
|
| 276 | + IServerContainer $serverContainer) { |
|
| 277 | + $eventDispatcher = $serverContainer->getEventDispatcher(); |
|
| 278 | + $eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function (GenericEvent $event) use ($logger) { |
|
| 279 | + $security = new Security($logger); |
|
| 280 | + $security->twofactorSuccess($event->getSubject(), $event->getArguments()); |
|
| 281 | + }); |
|
| 282 | + $eventDispatcher->addListener(IProvider::EVENT_FAILED, function (GenericEvent $event) use ($logger) { |
|
| 283 | + $security = new Security($logger); |
|
| 284 | + $security->twofactorFailed($event->getSubject(), $event->getArguments()); |
|
| 285 | + }); |
|
| 286 | + } |
|
| 287 | 287 | } |
@@ -61,165 +61,165 @@ |
||
| 61 | 61 | use Symfony\Component\EventDispatcher\GenericEvent; |
| 62 | 62 | |
| 63 | 63 | class Application extends App implements IBootstrap { |
| 64 | - public const APP_ID = 'settings'; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @param array $urlParams |
|
| 68 | - */ |
|
| 69 | - public function __construct(array $urlParams=[]) { |
|
| 70 | - parent::__construct(self::APP_ID, $urlParams); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - public function register(IRegistrationContext $context): void { |
|
| 74 | - // Register Middleware |
|
| 75 | - $context->registerServiceAlias('SubadminMiddleware', SubadminMiddleware::class); |
|
| 76 | - $context->registerMiddleware(SubadminMiddleware::class); |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Core class wrappers |
|
| 80 | - */ |
|
| 81 | - /** FIXME: Remove once OC_User is non-static and mockable */ |
|
| 82 | - $context->registerService('isAdmin', function () { |
|
| 83 | - return \OC_User::isAdminUser(\OC_User::getUser()); |
|
| 84 | - }); |
|
| 85 | - /** FIXME: Remove once OC_SubAdmin is non-static and mockable */ |
|
| 86 | - $context->registerService('isSubAdmin', function (IContainer $c) { |
|
| 87 | - $userObject = \OC::$server->getUserSession()->getUser(); |
|
| 88 | - $isSubAdmin = false; |
|
| 89 | - if ($userObject !== null) { |
|
| 90 | - $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
| 91 | - } |
|
| 92 | - return $isSubAdmin; |
|
| 93 | - }); |
|
| 94 | - $context->registerService('userCertificateManager', function (IContainer $c) { |
|
| 95 | - return $c->query('ServerContainer')->getCertificateManager(); |
|
| 96 | - }, false); |
|
| 97 | - $context->registerService('systemCertificateManager', function (IContainer $c) { |
|
| 98 | - return $c->query('ServerContainer')->getCertificateManager(null); |
|
| 99 | - }, false); |
|
| 100 | - $context->registerService(IProvider::class, function (IContainer $c) { |
|
| 101 | - return $c->query('ServerContainer')->query(IProvider::class); |
|
| 102 | - }); |
|
| 103 | - $context->registerService(IManager::class, function (IContainer $c) { |
|
| 104 | - return $c->query('ServerContainer')->getSettingsManager(); |
|
| 105 | - }); |
|
| 106 | - |
|
| 107 | - $context->registerService(NewUserMailHelper::class, function (IContainer $c) { |
|
| 108 | - /** @var Server $server */ |
|
| 109 | - $server = $c->query('ServerContainer'); |
|
| 110 | - /** @var Defaults $defaults */ |
|
| 111 | - $defaults = $server->query(Defaults::class); |
|
| 112 | - |
|
| 113 | - return new NewUserMailHelper( |
|
| 114 | - $defaults, |
|
| 115 | - $server->getURLGenerator(), |
|
| 116 | - $server->getL10NFactory(), |
|
| 117 | - $server->getMailer(), |
|
| 118 | - $server->getSecureRandom(), |
|
| 119 | - new TimeFactory(), |
|
| 120 | - $server->getConfig(), |
|
| 121 | - $server->getCrypto(), |
|
| 122 | - Util::getDefaultEmailAddress('no-reply') |
|
| 123 | - ); |
|
| 124 | - }); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - public function boot(IBootContext $context): void { |
|
| 128 | - /** @var EventDispatcherInterface $eventDispatcher */ |
|
| 129 | - $eventDispatcher = $context->getServerContainer()->getEventDispatcher(); |
|
| 130 | - $container = $context->getAppContainer(); |
|
| 131 | - $eventDispatcher->addListener('app_password_created', function (GenericEvent $event) use ($container) { |
|
| 132 | - if (($token = $event->getSubject()) instanceof IToken) { |
|
| 133 | - /** @var IActivityManager $activityManager */ |
|
| 134 | - $activityManager = $container->query(IActivityManager::class); |
|
| 135 | - /** @var ILogger $logger */ |
|
| 136 | - $logger = $container->query(ILogger::class); |
|
| 137 | - |
|
| 138 | - $activity = $activityManager->generateEvent(); |
|
| 139 | - $activity->setApp('settings') |
|
| 140 | - ->setType('security') |
|
| 141 | - ->setAffectedUser($token->getUID()) |
|
| 142 | - ->setAuthor($token->getUID()) |
|
| 143 | - ->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $token->getName()]) |
|
| 144 | - ->setObject('app_token', $token->getId()); |
|
| 145 | - |
|
| 146 | - try { |
|
| 147 | - $activityManager->publish($activity); |
|
| 148 | - } catch (BadMethodCallException $e) { |
|
| 149 | - $logger->logException($e, ['message' => 'could not publish activity', 'level' => ILogger::WARN]); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - }); |
|
| 153 | - |
|
| 154 | - Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword'); |
|
| 155 | - Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo'); |
|
| 156 | - |
|
| 157 | - $groupManager = $context->getServerContainer()->getGroupManager(); |
|
| 158 | - $groupManager->listen('\OC\Group', 'postRemoveUser', [$this, 'removeUserFromGroup']); |
|
| 159 | - $groupManager->listen('\OC\Group', 'postAddUser', [$this, 'addUserToGroup']); |
|
| 160 | - |
|
| 161 | - Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig'); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - public function addUserToGroup(IGroup $group, IUser $user): void { |
|
| 165 | - /** @var Hooks $hooks */ |
|
| 166 | - $hooks = $this->getContainer()->query(Hooks::class); |
|
| 167 | - $hooks->addUserToGroup($group, $user); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - public function removeUserFromGroup(IGroup $group, IUser $user): void { |
|
| 171 | - /** @var Hooks $hooks */ |
|
| 172 | - $hooks = $this->getContainer()->query(Hooks::class); |
|
| 173 | - $hooks->removeUserFromGroup($group, $user); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @param array $parameters |
|
| 179 | - * @throws \InvalidArgumentException |
|
| 180 | - * @throws \BadMethodCallException |
|
| 181 | - * @throws \Exception |
|
| 182 | - * @throws \OCP\AppFramework\QueryException |
|
| 183 | - */ |
|
| 184 | - public function onChangePassword(array $parameters) { |
|
| 185 | - /** @var Hooks $hooks */ |
|
| 186 | - $hooks = $this->getContainer()->query(Hooks::class); |
|
| 187 | - $hooks->onChangePassword($parameters['uid']); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * @param array $parameters |
|
| 192 | - * @throws \InvalidArgumentException |
|
| 193 | - * @throws \BadMethodCallException |
|
| 194 | - * @throws \Exception |
|
| 195 | - * @throws \OCP\AppFramework\QueryException |
|
| 196 | - */ |
|
| 197 | - public function onChangeInfo(array $parameters) { |
|
| 198 | - if ($parameters['feature'] !== 'eMailAddress') { |
|
| 199 | - return; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** @var Hooks $hooks */ |
|
| 203 | - $hooks = $this->getContainer()->query(Hooks::class); |
|
| 204 | - $hooks->onChangeEmail($parameters['user'], $parameters['old_value']); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * @param array $settings |
|
| 209 | - */ |
|
| 210 | - public function extendJsConfig(array $settings) { |
|
| 211 | - $appConfig = json_decode($settings['array']['oc_appconfig'], true); |
|
| 212 | - |
|
| 213 | - $publicWebFinger = \OC::$server->getConfig()->getAppValue('core', 'public_webfinger', ''); |
|
| 214 | - if (!empty($publicWebFinger)) { |
|
| 215 | - $appConfig['core']['public_webfinger'] = $publicWebFinger; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $publicNodeInfo = \OC::$server->getConfig()->getAppValue('core', 'public_nodeinfo', ''); |
|
| 219 | - if (!empty($publicNodeInfo)) { |
|
| 220 | - $appConfig['core']['public_nodeinfo'] = $publicNodeInfo; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - $settings['array']['oc_appconfig'] = json_encode($appConfig); |
|
| 224 | - } |
|
| 64 | + public const APP_ID = 'settings'; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @param array $urlParams |
|
| 68 | + */ |
|
| 69 | + public function __construct(array $urlParams=[]) { |
|
| 70 | + parent::__construct(self::APP_ID, $urlParams); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + public function register(IRegistrationContext $context): void { |
|
| 74 | + // Register Middleware |
|
| 75 | + $context->registerServiceAlias('SubadminMiddleware', SubadminMiddleware::class); |
|
| 76 | + $context->registerMiddleware(SubadminMiddleware::class); |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Core class wrappers |
|
| 80 | + */ |
|
| 81 | + /** FIXME: Remove once OC_User is non-static and mockable */ |
|
| 82 | + $context->registerService('isAdmin', function () { |
|
| 83 | + return \OC_User::isAdminUser(\OC_User::getUser()); |
|
| 84 | + }); |
|
| 85 | + /** FIXME: Remove once OC_SubAdmin is non-static and mockable */ |
|
| 86 | + $context->registerService('isSubAdmin', function (IContainer $c) { |
|
| 87 | + $userObject = \OC::$server->getUserSession()->getUser(); |
|
| 88 | + $isSubAdmin = false; |
|
| 89 | + if ($userObject !== null) { |
|
| 90 | + $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
| 91 | + } |
|
| 92 | + return $isSubAdmin; |
|
| 93 | + }); |
|
| 94 | + $context->registerService('userCertificateManager', function (IContainer $c) { |
|
| 95 | + return $c->query('ServerContainer')->getCertificateManager(); |
|
| 96 | + }, false); |
|
| 97 | + $context->registerService('systemCertificateManager', function (IContainer $c) { |
|
| 98 | + return $c->query('ServerContainer')->getCertificateManager(null); |
|
| 99 | + }, false); |
|
| 100 | + $context->registerService(IProvider::class, function (IContainer $c) { |
|
| 101 | + return $c->query('ServerContainer')->query(IProvider::class); |
|
| 102 | + }); |
|
| 103 | + $context->registerService(IManager::class, function (IContainer $c) { |
|
| 104 | + return $c->query('ServerContainer')->getSettingsManager(); |
|
| 105 | + }); |
|
| 106 | + |
|
| 107 | + $context->registerService(NewUserMailHelper::class, function (IContainer $c) { |
|
| 108 | + /** @var Server $server */ |
|
| 109 | + $server = $c->query('ServerContainer'); |
|
| 110 | + /** @var Defaults $defaults */ |
|
| 111 | + $defaults = $server->query(Defaults::class); |
|
| 112 | + |
|
| 113 | + return new NewUserMailHelper( |
|
| 114 | + $defaults, |
|
| 115 | + $server->getURLGenerator(), |
|
| 116 | + $server->getL10NFactory(), |
|
| 117 | + $server->getMailer(), |
|
| 118 | + $server->getSecureRandom(), |
|
| 119 | + new TimeFactory(), |
|
| 120 | + $server->getConfig(), |
|
| 121 | + $server->getCrypto(), |
|
| 122 | + Util::getDefaultEmailAddress('no-reply') |
|
| 123 | + ); |
|
| 124 | + }); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + public function boot(IBootContext $context): void { |
|
| 128 | + /** @var EventDispatcherInterface $eventDispatcher */ |
|
| 129 | + $eventDispatcher = $context->getServerContainer()->getEventDispatcher(); |
|
| 130 | + $container = $context->getAppContainer(); |
|
| 131 | + $eventDispatcher->addListener('app_password_created', function (GenericEvent $event) use ($container) { |
|
| 132 | + if (($token = $event->getSubject()) instanceof IToken) { |
|
| 133 | + /** @var IActivityManager $activityManager */ |
|
| 134 | + $activityManager = $container->query(IActivityManager::class); |
|
| 135 | + /** @var ILogger $logger */ |
|
| 136 | + $logger = $container->query(ILogger::class); |
|
| 137 | + |
|
| 138 | + $activity = $activityManager->generateEvent(); |
|
| 139 | + $activity->setApp('settings') |
|
| 140 | + ->setType('security') |
|
| 141 | + ->setAffectedUser($token->getUID()) |
|
| 142 | + ->setAuthor($token->getUID()) |
|
| 143 | + ->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $token->getName()]) |
|
| 144 | + ->setObject('app_token', $token->getId()); |
|
| 145 | + |
|
| 146 | + try { |
|
| 147 | + $activityManager->publish($activity); |
|
| 148 | + } catch (BadMethodCallException $e) { |
|
| 149 | + $logger->logException($e, ['message' => 'could not publish activity', 'level' => ILogger::WARN]); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + }); |
|
| 153 | + |
|
| 154 | + Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword'); |
|
| 155 | + Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo'); |
|
| 156 | + |
|
| 157 | + $groupManager = $context->getServerContainer()->getGroupManager(); |
|
| 158 | + $groupManager->listen('\OC\Group', 'postRemoveUser', [$this, 'removeUserFromGroup']); |
|
| 159 | + $groupManager->listen('\OC\Group', 'postAddUser', [$this, 'addUserToGroup']); |
|
| 160 | + |
|
| 161 | + Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig'); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + public function addUserToGroup(IGroup $group, IUser $user): void { |
|
| 165 | + /** @var Hooks $hooks */ |
|
| 166 | + $hooks = $this->getContainer()->query(Hooks::class); |
|
| 167 | + $hooks->addUserToGroup($group, $user); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + public function removeUserFromGroup(IGroup $group, IUser $user): void { |
|
| 171 | + /** @var Hooks $hooks */ |
|
| 172 | + $hooks = $this->getContainer()->query(Hooks::class); |
|
| 173 | + $hooks->removeUserFromGroup($group, $user); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @param array $parameters |
|
| 179 | + * @throws \InvalidArgumentException |
|
| 180 | + * @throws \BadMethodCallException |
|
| 181 | + * @throws \Exception |
|
| 182 | + * @throws \OCP\AppFramework\QueryException |
|
| 183 | + */ |
|
| 184 | + public function onChangePassword(array $parameters) { |
|
| 185 | + /** @var Hooks $hooks */ |
|
| 186 | + $hooks = $this->getContainer()->query(Hooks::class); |
|
| 187 | + $hooks->onChangePassword($parameters['uid']); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * @param array $parameters |
|
| 192 | + * @throws \InvalidArgumentException |
|
| 193 | + * @throws \BadMethodCallException |
|
| 194 | + * @throws \Exception |
|
| 195 | + * @throws \OCP\AppFramework\QueryException |
|
| 196 | + */ |
|
| 197 | + public function onChangeInfo(array $parameters) { |
|
| 198 | + if ($parameters['feature'] !== 'eMailAddress') { |
|
| 199 | + return; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** @var Hooks $hooks */ |
|
| 203 | + $hooks = $this->getContainer()->query(Hooks::class); |
|
| 204 | + $hooks->onChangeEmail($parameters['user'], $parameters['old_value']); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * @param array $settings |
|
| 209 | + */ |
|
| 210 | + public function extendJsConfig(array $settings) { |
|
| 211 | + $appConfig = json_decode($settings['array']['oc_appconfig'], true); |
|
| 212 | + |
|
| 213 | + $publicWebFinger = \OC::$server->getConfig()->getAppValue('core', 'public_webfinger', ''); |
|
| 214 | + if (!empty($publicWebFinger)) { |
|
| 215 | + $appConfig['core']['public_webfinger'] = $publicWebFinger; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $publicNodeInfo = \OC::$server->getConfig()->getAppValue('core', 'public_nodeinfo', ''); |
|
| 219 | + if (!empty($publicNodeInfo)) { |
|
| 220 | + $appConfig['core']['public_nodeinfo'] = $publicNodeInfo; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + $settings['array']['oc_appconfig'] = json_encode($appConfig); |
|
| 224 | + } |
|
| 225 | 225 | } |
@@ -75,1019 +75,1019 @@ |
||
| 75 | 75 | * OC_autoload! |
| 76 | 76 | */ |
| 77 | 77 | class OC { |
| 78 | - /** |
|
| 79 | - * Associative array for autoloading. classname => filename |
|
| 80 | - */ |
|
| 81 | - public static $CLASSPATH = []; |
|
| 82 | - /** |
|
| 83 | - * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
| 84 | - */ |
|
| 85 | - public static $SERVERROOT = ''; |
|
| 86 | - /** |
|
| 87 | - * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
| 88 | - */ |
|
| 89 | - private static $SUBURI = ''; |
|
| 90 | - /** |
|
| 91 | - * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
| 92 | - */ |
|
| 93 | - public static $WEBROOT = ''; |
|
| 94 | - /** |
|
| 95 | - * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
| 96 | - * web path in 'url' |
|
| 97 | - */ |
|
| 98 | - public static $APPSROOTS = []; |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @var string |
|
| 102 | - */ |
|
| 103 | - public static $configDir; |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * requested app |
|
| 107 | - */ |
|
| 108 | - public static $REQUESTEDAPP = ''; |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * check if Nextcloud runs in cli mode |
|
| 112 | - */ |
|
| 113 | - public static $CLI = false; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @var \OC\Autoloader $loader |
|
| 117 | - */ |
|
| 118 | - public static $loader = null; |
|
| 119 | - |
|
| 120 | - /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
| 121 | - public static $composerAutoloader = null; |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @var \OC\Server |
|
| 125 | - */ |
|
| 126 | - public static $server = null; |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @var \OC\Config |
|
| 130 | - */ |
|
| 131 | - private static $config = null; |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @throws \RuntimeException when the 3rdparty directory is missing or |
|
| 135 | - * the app path list is empty or contains an invalid path |
|
| 136 | - */ |
|
| 137 | - public static function initPaths() { |
|
| 138 | - if (defined('PHPUNIT_CONFIG_DIR')) { |
|
| 139 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
| 140 | - } elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
| 141 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
| 142 | - } elseif ($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
| 143 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
| 144 | - } else { |
|
| 145 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
| 146 | - } |
|
| 147 | - self::$config = new \OC\Config(self::$configDir); |
|
| 148 | - |
|
| 149 | - OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
| 150 | - /** |
|
| 151 | - * FIXME: The following lines are required because we can't yet instantiate |
|
| 152 | - * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
| 153 | - */ |
|
| 154 | - $params = [ |
|
| 155 | - 'server' => [ |
|
| 156 | - 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
| 157 | - 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
| 158 | - ], |
|
| 159 | - ]; |
|
| 160 | - $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
| 161 | - $scriptName = $fakeRequest->getScriptName(); |
|
| 162 | - if (substr($scriptName, -1) == '/') { |
|
| 163 | - $scriptName .= 'index.php'; |
|
| 164 | - //make sure suburi follows the same rules as scriptName |
|
| 165 | - if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
| 166 | - if (substr(OC::$SUBURI, -1) != '/') { |
|
| 167 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
| 168 | - } |
|
| 169 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - if (OC::$CLI) { |
|
| 175 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 176 | - } else { |
|
| 177 | - if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
| 178 | - OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
| 179 | - |
|
| 180 | - if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
| 181 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
| 182 | - } |
|
| 183 | - } else { |
|
| 184 | - // The scriptName is not ending with OC::$SUBURI |
|
| 185 | - // This most likely means that we are calling from CLI. |
|
| 186 | - // However some cron jobs still need to generate |
|
| 187 | - // a web URL, so we use overwritewebroot as a fallback. |
|
| 188 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
| 192 | - // slash which is required by URL generation. |
|
| 193 | - if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
| 194 | - substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
| 195 | - header('Location: '.\OC::$WEBROOT.'/'); |
|
| 196 | - exit(); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // search the apps folder |
|
| 201 | - $config_paths = self::$config->getValue('apps_paths', []); |
|
| 202 | - if (!empty($config_paths)) { |
|
| 203 | - foreach ($config_paths as $paths) { |
|
| 204 | - if (isset($paths['url']) && isset($paths['path'])) { |
|
| 205 | - $paths['url'] = rtrim($paths['url'], '/'); |
|
| 206 | - $paths['path'] = rtrim($paths['path'], '/'); |
|
| 207 | - OC::$APPSROOTS[] = $paths; |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
| 211 | - OC::$APPSROOTS[] = ['path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true]; |
|
| 212 | - } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
| 213 | - OC::$APPSROOTS[] = [ |
|
| 214 | - 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
| 215 | - 'url' => '/apps', |
|
| 216 | - 'writable' => true |
|
| 217 | - ]; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - if (empty(OC::$APPSROOTS)) { |
|
| 221 | - throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
| 222 | - . ' or the folder above. You can also configure the location in the config.php file.'); |
|
| 223 | - } |
|
| 224 | - $paths = []; |
|
| 225 | - foreach (OC::$APPSROOTS as $path) { |
|
| 226 | - $paths[] = $path['path']; |
|
| 227 | - if (!is_dir($path['path'])) { |
|
| 228 | - throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
| 229 | - . ' Nextcloud folder or the folder above. You can also configure the location in the' |
|
| 230 | - . ' config.php file.', $path['path'])); |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - // set the right include path |
|
| 235 | - set_include_path( |
|
| 236 | - implode(PATH_SEPARATOR, $paths) |
|
| 237 | - ); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - public static function checkConfig() { |
|
| 241 | - $l = \OC::$server->getL10N('lib'); |
|
| 242 | - |
|
| 243 | - // Create config if it does not already exist |
|
| 244 | - $configFilePath = self::$configDir .'/config.php'; |
|
| 245 | - if (!file_exists($configFilePath)) { |
|
| 246 | - @touch($configFilePath); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - // Check if config is writable |
|
| 250 | - $configFileWritable = is_writable($configFilePath); |
|
| 251 | - if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
| 252 | - || !$configFileWritable && \OCP\Util::needUpgrade()) { |
|
| 253 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 254 | - |
|
| 255 | - if (self::$CLI) { |
|
| 256 | - echo $l->t('Cannot write into "config" directory!')."\n"; |
|
| 257 | - echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
| 258 | - echo "\n"; |
|
| 259 | - echo $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.')."\n"; |
|
| 260 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ])."\n"; |
|
| 261 | - exit; |
|
| 262 | - } else { |
|
| 263 | - OC_Template::printErrorPage( |
|
| 264 | - $l->t('Cannot write into "config" directory!'), |
|
| 265 | - $l->t('This can usually be fixed by giving the webserver write access to the config directory.') . '. ' |
|
| 266 | - . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
|
| 267 | - [ $urlGenerator->linkToDocs('admin-config') ]), |
|
| 268 | - 503 |
|
| 269 | - ); |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - public static function checkInstalled() { |
|
| 275 | - if (defined('OC_CONSOLE')) { |
|
| 276 | - return; |
|
| 277 | - } |
|
| 278 | - // Redirect to installer if not installed |
|
| 279 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
| 280 | - if (OC::$CLI) { |
|
| 281 | - throw new Exception('Not installed'); |
|
| 282 | - } else { |
|
| 283 | - $url = OC::$WEBROOT . '/index.php'; |
|
| 284 | - header('Location: ' . $url); |
|
| 285 | - } |
|
| 286 | - exit(); |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - public static function checkMaintenanceMode() { |
|
| 291 | - // Allow ajax update script to execute without being stopped |
|
| 292 | - if (((bool) \OC::$server->getSystemConfig()->getValue('maintenance', false)) && OC::$SUBURI != '/core/ajax/update.php') { |
|
| 293 | - // send http status 503 |
|
| 294 | - http_response_code(503); |
|
| 295 | - header('Retry-After: 120'); |
|
| 296 | - |
|
| 297 | - // render error page |
|
| 298 | - $template = new OC_Template('', 'update.user', 'guest'); |
|
| 299 | - OC_Util::addScript('dist/maintenance'); |
|
| 300 | - OC_Util::addStyle('core', 'guest'); |
|
| 301 | - $template->printPage(); |
|
| 302 | - die(); |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Prints the upgrade page |
|
| 308 | - * |
|
| 309 | - * @param \OC\SystemConfig $systemConfig |
|
| 310 | - */ |
|
| 311 | - private static function printUpgradePage(\OC\SystemConfig $systemConfig) { |
|
| 312 | - $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
| 313 | - $tooBig = false; |
|
| 314 | - if (!$disableWebUpdater) { |
|
| 315 | - $apps = \OC::$server->getAppManager(); |
|
| 316 | - if ($apps->isInstalled('user_ldap')) { |
|
| 317 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 318 | - |
|
| 319 | - $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
| 320 | - ->from('ldap_user_mapping') |
|
| 321 | - ->execute(); |
|
| 322 | - $row = $result->fetch(); |
|
| 323 | - $result->closeCursor(); |
|
| 324 | - |
|
| 325 | - $tooBig = ($row['user_count'] > 50); |
|
| 326 | - } |
|
| 327 | - if (!$tooBig && $apps->isInstalled('user_saml')) { |
|
| 328 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 329 | - |
|
| 330 | - $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
| 331 | - ->from('user_saml_users') |
|
| 332 | - ->execute(); |
|
| 333 | - $row = $result->fetch(); |
|
| 334 | - $result->closeCursor(); |
|
| 335 | - |
|
| 336 | - $tooBig = ($row['user_count'] > 50); |
|
| 337 | - } |
|
| 338 | - if (!$tooBig) { |
|
| 339 | - // count users |
|
| 340 | - $stats = \OC::$server->getUserManager()->countUsers(); |
|
| 341 | - $totalUsers = array_sum($stats); |
|
| 342 | - $tooBig = ($totalUsers > 50); |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) && |
|
| 346 | - $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
| 347 | - |
|
| 348 | - if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
| 349 | - // send http status 503 |
|
| 350 | - http_response_code(503); |
|
| 351 | - header('Retry-After: 120'); |
|
| 352 | - |
|
| 353 | - // render error page |
|
| 354 | - $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
| 355 | - $template->assign('productName', 'nextcloud'); // for now |
|
| 356 | - $template->assign('version', OC_Util::getVersionString()); |
|
| 357 | - $template->assign('tooBig', $tooBig); |
|
| 358 | - |
|
| 359 | - $template->printPage(); |
|
| 360 | - die(); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - // check whether this is a core update or apps update |
|
| 364 | - $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
| 365 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 366 | - |
|
| 367 | - // if not a core upgrade, then it's apps upgrade |
|
| 368 | - $isAppsOnlyUpgrade = version_compare($currentVersion, $installedVersion, '='); |
|
| 369 | - |
|
| 370 | - $oldTheme = $systemConfig->getValue('theme'); |
|
| 371 | - $systemConfig->setValue('theme', ''); |
|
| 372 | - OC_Util::addScript('config'); // needed for web root |
|
| 373 | - OC_Util::addScript('update'); |
|
| 374 | - |
|
| 375 | - /** @var \OC\App\AppManager $appManager */ |
|
| 376 | - $appManager = \OC::$server->getAppManager(); |
|
| 377 | - |
|
| 378 | - $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
| 379 | - $tmpl->assign('version', OC_Util::getVersionString()); |
|
| 380 | - $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
| 381 | - |
|
| 382 | - // get third party apps |
|
| 383 | - $ocVersion = \OCP\Util::getVersion(); |
|
| 384 | - $ocVersion = implode('.', $ocVersion); |
|
| 385 | - $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
| 386 | - $incompatibleShippedApps = []; |
|
| 387 | - foreach ($incompatibleApps as $appInfo) { |
|
| 388 | - if ($appManager->isShipped($appInfo['id'])) { |
|
| 389 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - if (!empty($incompatibleShippedApps)) { |
|
| 394 | - $l = \OC::$server->getL10N('core'); |
|
| 395 | - $hint = $l->t('The files of the app %1$s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
| 396 | - throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
| 400 | - $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
| 401 | - $tmpl->assign('productName', 'Nextcloud'); // for now |
|
| 402 | - $tmpl->assign('oldTheme', $oldTheme); |
|
| 403 | - $tmpl->printPage(); |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - public static function initSession() { |
|
| 407 | - if (self::$server->getRequest()->getServerProtocol() === 'https') { |
|
| 408 | - ini_set('session.cookie_secure', true); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - // prevents javascript from accessing php session cookies |
|
| 412 | - ini_set('session.cookie_httponly', 'true'); |
|
| 413 | - |
|
| 414 | - // set the cookie path to the Nextcloud directory |
|
| 415 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
| 416 | - ini_set('session.cookie_path', $cookie_path); |
|
| 417 | - |
|
| 418 | - // Let the session name be changed in the initSession Hook |
|
| 419 | - $sessionName = OC_Util::getInstanceId(); |
|
| 420 | - |
|
| 421 | - try { |
|
| 422 | - // Allow session apps to create a custom session object |
|
| 423 | - $useCustomSession = false; |
|
| 424 | - $session = self::$server->getSession(); |
|
| 425 | - OC_Hook::emit('OC', 'initSession', ['session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession]); |
|
| 426 | - if (!$useCustomSession) { |
|
| 427 | - // set the session name to the instance id - which is unique |
|
| 428 | - $session = new \OC\Session\Internal($sessionName); |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
| 432 | - $session = $cryptoWrapper->wrapSession($session); |
|
| 433 | - self::$server->setSession($session); |
|
| 434 | - |
|
| 435 | - // if session can't be started break with http 500 error |
|
| 436 | - } catch (Exception $e) { |
|
| 437 | - \OC::$server->getLogger()->logException($e, ['app' => 'base']); |
|
| 438 | - //show the user a detailed error page |
|
| 439 | - OC_Template::printExceptionErrorPage($e, 500); |
|
| 440 | - die(); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
| 444 | - |
|
| 445 | - // session timeout |
|
| 446 | - if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
| 447 | - if (isset($_COOKIE[session_name()])) { |
|
| 448 | - setcookie(session_name(), '', -1, self::$WEBROOT ? : '/'); |
|
| 449 | - } |
|
| 450 | - \OC::$server->getUserSession()->logout(); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - $session->set('LAST_ACTIVITY', time()); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - /** |
|
| 457 | - * @return string |
|
| 458 | - */ |
|
| 459 | - private static function getSessionLifeTime() { |
|
| 460 | - return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Try to set some values to the required Nextcloud default |
|
| 465 | - */ |
|
| 466 | - public static function setRequiredIniValues() { |
|
| 467 | - @ini_set('default_charset', 'UTF-8'); |
|
| 468 | - @ini_set('gd.jpeg_ignore_warning', '1'); |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * Send the same site cookies |
|
| 473 | - */ |
|
| 474 | - private static function sendSameSiteCookies() { |
|
| 475 | - $cookieParams = session_get_cookie_params(); |
|
| 476 | - $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
| 477 | - $policies = [ |
|
| 478 | - 'lax', |
|
| 479 | - 'strict', |
|
| 480 | - ]; |
|
| 481 | - |
|
| 482 | - // Append __Host to the cookie if it meets the requirements |
|
| 483 | - $cookiePrefix = ''; |
|
| 484 | - if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 485 | - $cookiePrefix = '__Host-'; |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - foreach ($policies as $policy) { |
|
| 489 | - header( |
|
| 490 | - sprintf( |
|
| 491 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 492 | - $cookiePrefix, |
|
| 493 | - $policy, |
|
| 494 | - $cookieParams['path'], |
|
| 495 | - $policy |
|
| 496 | - ), |
|
| 497 | - false |
|
| 498 | - ); |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
| 504 | - * be set in every request if cookies are sent to add a second level of |
|
| 505 | - * defense against CSRF. |
|
| 506 | - * |
|
| 507 | - * If the cookie is not sent this will set the cookie and reload the page. |
|
| 508 | - * We use an additional cookie since we want to protect logout CSRF and |
|
| 509 | - * also we can't directly interfere with PHP's session mechanism. |
|
| 510 | - */ |
|
| 511 | - private static function performSameSiteCookieProtection() { |
|
| 512 | - $request = \OC::$server->getRequest(); |
|
| 513 | - |
|
| 514 | - // Some user agents are notorious and don't really properly follow HTTP |
|
| 515 | - // specifications. For those, have an automated opt-out. Since the protection |
|
| 516 | - // for remote.php is applied in base.php as starting point we need to opt out |
|
| 517 | - // here. |
|
| 518 | - $incompatibleUserAgents = \OC::$server->getConfig()->getSystemValue('csrf.optout'); |
|
| 519 | - |
|
| 520 | - // Fallback, if csrf.optout is unset |
|
| 521 | - if (!is_array($incompatibleUserAgents)) { |
|
| 522 | - $incompatibleUserAgents = [ |
|
| 523 | - // OS X Finder |
|
| 524 | - '/^WebDAVFS/', |
|
| 525 | - // Windows webdav drive |
|
| 526 | - '/^Microsoft-WebDAV-MiniRedir/', |
|
| 527 | - ]; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - if ($request->isUserAgent($incompatibleUserAgents)) { |
|
| 531 | - return; |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - if (count($_COOKIE) > 0) { |
|
| 535 | - $requestUri = $request->getScriptName(); |
|
| 536 | - $processingScript = explode('/', $requestUri); |
|
| 537 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
| 538 | - |
|
| 539 | - // index.php routes are handled in the middleware |
|
| 540 | - if ($processingScript === 'index.php') { |
|
| 541 | - return; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - // All other endpoints require the lax and the strict cookie |
|
| 545 | - if (!$request->passesStrictCookieCheck()) { |
|
| 546 | - self::sendSameSiteCookies(); |
|
| 547 | - // Debug mode gets access to the resources without strict cookie |
|
| 548 | - // due to the fact that the SabreDAV browser also lives there. |
|
| 549 | - if (!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 550 | - http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 551 | - exit(); |
|
| 552 | - } |
|
| 553 | - } |
|
| 554 | - } elseif (!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
| 555 | - self::sendSameSiteCookies(); |
|
| 556 | - } |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - public static function init() { |
|
| 560 | - // calculate the root directories |
|
| 561 | - OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
| 562 | - |
|
| 563 | - // register autoloader |
|
| 564 | - $loaderStart = microtime(true); |
|
| 565 | - require_once __DIR__ . '/autoloader.php'; |
|
| 566 | - self::$loader = new \OC\Autoloader([ |
|
| 567 | - OC::$SERVERROOT . '/lib/private/legacy', |
|
| 568 | - ]); |
|
| 569 | - if (defined('PHPUNIT_RUN')) { |
|
| 570 | - self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
| 571 | - } |
|
| 572 | - spl_autoload_register([self::$loader, 'load']); |
|
| 573 | - $loaderEnd = microtime(true); |
|
| 574 | - |
|
| 575 | - self::$CLI = (php_sapi_name() == 'cli'); |
|
| 576 | - |
|
| 577 | - // Add default composer PSR-4 autoloader |
|
| 578 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
| 579 | - |
|
| 580 | - try { |
|
| 581 | - self::initPaths(); |
|
| 582 | - // setup 3rdparty autoloader |
|
| 583 | - $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
| 584 | - if (!file_exists($vendorAutoLoad)) { |
|
| 585 | - throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
| 586 | - } |
|
| 587 | - require_once $vendorAutoLoad; |
|
| 588 | - } catch (\RuntimeException $e) { |
|
| 589 | - if (!self::$CLI) { |
|
| 590 | - http_response_code(503); |
|
| 591 | - } |
|
| 592 | - // we can't use the template error page here, because this needs the |
|
| 593 | - // DI container which isn't available yet |
|
| 594 | - print($e->getMessage()); |
|
| 595 | - exit(); |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - // setup the basic server |
|
| 599 | - self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
| 600 | - self::$server->boot(); |
|
| 601 | - \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
| 602 | - \OC::$server->getEventLogger()->start('boot', 'Initialize'); |
|
| 603 | - |
|
| 604 | - // Override php.ini and log everything if we're troubleshooting |
|
| 605 | - if (self::$config->getValue('loglevel') === ILogger::DEBUG) { |
|
| 606 | - error_reporting(E_ALL); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - // Don't display errors and log them |
|
| 610 | - @ini_set('display_errors', '0'); |
|
| 611 | - @ini_set('log_errors', '1'); |
|
| 612 | - |
|
| 613 | - if (!date_default_timezone_set('UTC')) { |
|
| 614 | - throw new \RuntimeException('Could not set timezone to UTC'); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - //try to configure php to enable big file uploads. |
|
| 618 | - //this doesn´t work always depending on the webserver and php configuration. |
|
| 619 | - //Let´s try to overwrite some defaults anyway |
|
| 620 | - |
|
| 621 | - //try to set the maximum execution time to 60min |
|
| 622 | - if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 623 | - @set_time_limit(3600); |
|
| 624 | - } |
|
| 625 | - @ini_set('max_execution_time', '3600'); |
|
| 626 | - @ini_set('max_input_time', '3600'); |
|
| 627 | - |
|
| 628 | - //try to set the maximum filesize to 10G |
|
| 629 | - @ini_set('upload_max_filesize', '10G'); |
|
| 630 | - @ini_set('post_max_size', '10G'); |
|
| 631 | - @ini_set('file_uploads', '50'); |
|
| 632 | - |
|
| 633 | - self::setRequiredIniValues(); |
|
| 634 | - self::handleAuthHeaders(); |
|
| 635 | - self::registerAutoloaderCache(); |
|
| 636 | - |
|
| 637 | - // initialize intl fallback is necessary |
|
| 638 | - \Patchwork\Utf8\Bootup::initIntl(); |
|
| 639 | - OC_Util::isSetLocaleWorking(); |
|
| 640 | - |
|
| 641 | - if (!defined('PHPUNIT_RUN')) { |
|
| 642 | - OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
| 643 | - $debug = \OC::$server->getConfig()->getSystemValue('debug', false); |
|
| 644 | - OC\Log\ErrorHandler::register($debug); |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - /** @var \OC\AppFramework\Bootstrap\Coordinator $bootstrapCoordinator */ |
|
| 648 | - $bootstrapCoordinator = \OC::$server->query(\OC\AppFramework\Bootstrap\Coordinator::class); |
|
| 649 | - $bootstrapCoordinator->runRegistration(); |
|
| 650 | - |
|
| 651 | - \OC::$server->getEventLogger()->start('init_session', 'Initialize session'); |
|
| 652 | - OC_App::loadApps(['session']); |
|
| 653 | - if (!self::$CLI) { |
|
| 654 | - self::initSession(); |
|
| 655 | - } |
|
| 656 | - \OC::$server->getEventLogger()->end('init_session'); |
|
| 657 | - self::checkConfig(); |
|
| 658 | - self::checkInstalled(); |
|
| 659 | - |
|
| 660 | - OC_Response::addSecurityHeaders(); |
|
| 661 | - |
|
| 662 | - self::performSameSiteCookieProtection(); |
|
| 663 | - |
|
| 664 | - if (!defined('OC_CONSOLE')) { |
|
| 665 | - $errors = OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
| 666 | - if (count($errors) > 0) { |
|
| 667 | - if (!self::$CLI) { |
|
| 668 | - http_response_code(503); |
|
| 669 | - OC_Util::addStyle('guest'); |
|
| 670 | - try { |
|
| 671 | - OC_Template::printGuestPage('', 'error', ['errors' => $errors]); |
|
| 672 | - exit; |
|
| 673 | - } catch (\Exception $e) { |
|
| 674 | - // In case any error happens when showing the error page, we simply fall back to posting the text. |
|
| 675 | - // This might be the case when e.g. the data directory is broken and we can not load/write SCSS to/from it. |
|
| 676 | - } |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - // Convert l10n string into regular string for usage in database |
|
| 680 | - $staticErrors = []; |
|
| 681 | - foreach ($errors as $error) { |
|
| 682 | - echo $error['error'] . "\n"; |
|
| 683 | - echo $error['hint'] . "\n\n"; |
|
| 684 | - $staticErrors[] = [ |
|
| 685 | - 'error' => (string)$error['error'], |
|
| 686 | - 'hint' => (string)$error['hint'], |
|
| 687 | - ]; |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - try { |
|
| 691 | - \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
| 692 | - } catch (\Exception $e) { |
|
| 693 | - echo('Writing to database failed'); |
|
| 694 | - } |
|
| 695 | - exit(1); |
|
| 696 | - } elseif (self::$CLI && \OC::$server->getConfig()->getSystemValue('installed', false)) { |
|
| 697 | - \OC::$server->getConfig()->deleteAppValue('core', 'cronErrors'); |
|
| 698 | - } |
|
| 699 | - } |
|
| 700 | - //try to set the session lifetime |
|
| 701 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
| 702 | - @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
| 703 | - |
|
| 704 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
| 705 | - |
|
| 706 | - // User and Groups |
|
| 707 | - if (!$systemConfig->getValue("installed", false)) { |
|
| 708 | - self::$server->getSession()->set('user_id', ''); |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - OC_User::useBackend(new \OC\User\Database()); |
|
| 712 | - \OC::$server->getGroupManager()->addBackend(new \OC\Group\Database()); |
|
| 713 | - |
|
| 714 | - // Subscribe to the hook |
|
| 715 | - \OCP\Util::connectHook( |
|
| 716 | - '\OCA\Files_Sharing\API\Server2Server', |
|
| 717 | - 'preLoginNameUsedAsUserName', |
|
| 718 | - '\OC\User\Database', |
|
| 719 | - 'preLoginNameUsedAsUserName' |
|
| 720 | - ); |
|
| 721 | - |
|
| 722 | - //setup extra user backends |
|
| 723 | - if (!\OCP\Util::needUpgrade()) { |
|
| 724 | - OC_User::setupBackends(); |
|
| 725 | - } else { |
|
| 726 | - // Run upgrades in incognito mode |
|
| 727 | - OC_User::setIncognitoMode(true); |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - self::registerCleanupHooks(); |
|
| 731 | - self::registerFilesystemHooks(); |
|
| 732 | - self::registerShareHooks(); |
|
| 733 | - self::registerEncryptionWrapper(); |
|
| 734 | - self::registerEncryptionHooks(); |
|
| 735 | - self::registerAccountHooks(); |
|
| 736 | - self::registerResourceCollectionHooks(); |
|
| 737 | - self::registerAppRestrictionsHooks(); |
|
| 738 | - |
|
| 739 | - // Make sure that the application class is not loaded before the database is setup |
|
| 740 | - if ($systemConfig->getValue("installed", false)) { |
|
| 741 | - OC_App::loadApp('settings'); |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - //make sure temporary files are cleaned up |
|
| 745 | - $tmpManager = \OC::$server->getTempManager(); |
|
| 746 | - register_shutdown_function([$tmpManager, 'clean']); |
|
| 747 | - $lockProvider = \OC::$server->getLockingProvider(); |
|
| 748 | - register_shutdown_function([$lockProvider, 'releaseAll']); |
|
| 749 | - |
|
| 750 | - // Check whether the sample configuration has been copied |
|
| 751 | - if ($systemConfig->getValue('copied_sample_config', false)) { |
|
| 752 | - $l = \OC::$server->getL10N('lib'); |
|
| 753 | - OC_Template::printErrorPage( |
|
| 754 | - $l->t('Sample configuration detected'), |
|
| 755 | - $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php'), |
|
| 756 | - 503 |
|
| 757 | - ); |
|
| 758 | - return; |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - $request = \OC::$server->getRequest(); |
|
| 762 | - $host = $request->getInsecureServerHost(); |
|
| 763 | - /** |
|
| 764 | - * if the host passed in headers isn't trusted |
|
| 765 | - * FIXME: Should not be in here at all :see_no_evil: |
|
| 766 | - */ |
|
| 767 | - if (!OC::$CLI |
|
| 768 | - && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
| 769 | - && self::$server->getConfig()->getSystemValue('installed', false) |
|
| 770 | - ) { |
|
| 771 | - // Allow access to CSS resources |
|
| 772 | - $isScssRequest = false; |
|
| 773 | - if (strpos($request->getPathInfo(), '/css/') === 0) { |
|
| 774 | - $isScssRequest = true; |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - if (substr($request->getRequestUri(), -11) === '/status.php') { |
|
| 778 | - http_response_code(400); |
|
| 779 | - header('Content-Type: application/json'); |
|
| 780 | - echo '{"error": "Trusted domain error.", "code": 15}'; |
|
| 781 | - exit(); |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - if (!$isScssRequest) { |
|
| 785 | - http_response_code(400); |
|
| 786 | - |
|
| 787 | - \OC::$server->getLogger()->info( |
|
| 788 | - 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
| 789 | - [ |
|
| 790 | - 'app' => 'core', |
|
| 791 | - 'remoteAddress' => $request->getRemoteAddress(), |
|
| 792 | - 'host' => $host, |
|
| 793 | - ] |
|
| 794 | - ); |
|
| 795 | - |
|
| 796 | - $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
| 797 | - $tmpl->assign('docUrl', \OC::$server->getURLGenerator()->linkToDocs('admin-trusted-domains')); |
|
| 798 | - $tmpl->printPage(); |
|
| 799 | - |
|
| 800 | - exit(); |
|
| 801 | - } |
|
| 802 | - } |
|
| 803 | - \OC::$server->getEventLogger()->end('boot'); |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - /** |
|
| 807 | - * register hooks for the cleanup of cache and bruteforce protection |
|
| 808 | - */ |
|
| 809 | - public static function registerCleanupHooks() { |
|
| 810 | - //don't try to do this before we are properly setup |
|
| 811 | - if (\OC::$server->getSystemConfig()->getValue('installed', false) && !\OCP\Util::needUpgrade()) { |
|
| 812 | - |
|
| 813 | - // NOTE: This will be replaced to use OCP |
|
| 814 | - $userSession = self::$server->getUserSession(); |
|
| 815 | - $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
| 816 | - if (!defined('PHPUNIT_RUN') && $userSession->isLoggedIn()) { |
|
| 817 | - // reset brute force delay for this IP address and username |
|
| 818 | - $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
|
| 819 | - $request = \OC::$server->getRequest(); |
|
| 820 | - $throttler = \OC::$server->getBruteForceThrottler(); |
|
| 821 | - $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - try { |
|
| 825 | - $cache = new \OC\Cache\File(); |
|
| 826 | - $cache->gc(); |
|
| 827 | - } catch (\OC\ServerNotAvailableException $e) { |
|
| 828 | - // not a GC exception, pass it on |
|
| 829 | - throw $e; |
|
| 830 | - } catch (\OC\ForbiddenException $e) { |
|
| 831 | - // filesystem blocked for this request, ignore |
|
| 832 | - } catch (\Exception $e) { |
|
| 833 | - // a GC exception should not prevent users from using OC, |
|
| 834 | - // so log the exception |
|
| 835 | - \OC::$server->getLogger()->logException($e, [ |
|
| 836 | - 'message' => 'Exception when running cache gc.', |
|
| 837 | - 'level' => ILogger::WARN, |
|
| 838 | - 'app' => 'core', |
|
| 839 | - ]); |
|
| 840 | - } |
|
| 841 | - }); |
|
| 842 | - } |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - private static function registerEncryptionWrapper() { |
|
| 846 | - $manager = self::$server->getEncryptionManager(); |
|
| 847 | - \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - private static function registerEncryptionHooks() { |
|
| 851 | - $enabled = self::$server->getEncryptionManager()->isEnabled(); |
|
| 852 | - if ($enabled) { |
|
| 853 | - \OCP\Util::connectHook(Share::class, 'post_shared', HookManager::class, 'postShared'); |
|
| 854 | - \OCP\Util::connectHook(Share::class, 'post_unshare', HookManager::class, 'postUnshared'); |
|
| 855 | - \OCP\Util::connectHook('OC_Filesystem', 'post_rename', HookManager::class, 'postRename'); |
|
| 856 | - \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', HookManager::class, 'postRestore'); |
|
| 857 | - } |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - private static function registerAccountHooks() { |
|
| 861 | - $hookHandler = new \OC\Accounts\Hooks(\OC::$server->getLogger()); |
|
| 862 | - \OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook'); |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - private static function registerAppRestrictionsHooks() { |
|
| 866 | - $groupManager = self::$server->query(\OCP\IGroupManager::class); |
|
| 867 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OCP\IGroup $group) { |
|
| 868 | - $appManager = self::$server->getAppManager(); |
|
| 869 | - $apps = $appManager->getEnabledAppsForGroup($group); |
|
| 870 | - foreach ($apps as $appId) { |
|
| 871 | - $restrictions = $appManager->getAppRestriction($appId); |
|
| 872 | - if (empty($restrictions)) { |
|
| 873 | - continue; |
|
| 874 | - } |
|
| 875 | - $key = array_search($group->getGID(), $restrictions); |
|
| 876 | - unset($restrictions[$key]); |
|
| 877 | - $restrictions = array_values($restrictions); |
|
| 878 | - if (empty($restrictions)) { |
|
| 879 | - $appManager->disableApp($appId); |
|
| 880 | - } else { |
|
| 881 | - $appManager->enableAppForGroups($appId, $restrictions); |
|
| 882 | - } |
|
| 883 | - } |
|
| 884 | - }); |
|
| 885 | - } |
|
| 886 | - |
|
| 887 | - private static function registerResourceCollectionHooks() { |
|
| 888 | - \OC\Collaboration\Resources\Listener::register(\OC::$server->getEventDispatcher()); |
|
| 889 | - } |
|
| 890 | - |
|
| 891 | - /** |
|
| 892 | - * register hooks for the filesystem |
|
| 893 | - */ |
|
| 894 | - public static function registerFilesystemHooks() { |
|
| 895 | - // Check for blacklisted files |
|
| 896 | - OC_Hook::connect('OC_Filesystem', 'write', Filesystem::class, 'isBlacklisted'); |
|
| 897 | - OC_Hook::connect('OC_Filesystem', 'rename', Filesystem::class, 'isBlacklisted'); |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - /** |
|
| 901 | - * register hooks for sharing |
|
| 902 | - */ |
|
| 903 | - public static function registerShareHooks() { |
|
| 904 | - if (\OC::$server->getSystemConfig()->getValue('installed')) { |
|
| 905 | - OC_Hook::connect('OC_User', 'post_deleteUser', Hooks::class, 'post_deleteUser'); |
|
| 906 | - OC_Hook::connect('OC_User', 'post_removeFromGroup', Hooks::class, 'post_removeFromGroup'); |
|
| 907 | - OC_Hook::connect('OC_User', 'post_deleteGroup', Hooks::class, 'post_deleteGroup'); |
|
| 908 | - } |
|
| 909 | - } |
|
| 910 | - |
|
| 911 | - protected static function registerAutoloaderCache() { |
|
| 912 | - // The class loader takes an optional low-latency cache, which MUST be |
|
| 913 | - // namespaced. The instanceid is used for namespacing, but might be |
|
| 914 | - // unavailable at this point. Furthermore, it might not be possible to |
|
| 915 | - // generate an instanceid via \OC_Util::getInstanceId() because the |
|
| 916 | - // config file may not be writable. As such, we only register a class |
|
| 917 | - // loader cache if instanceid is available without trying to create one. |
|
| 918 | - $instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 919 | - if ($instanceId) { |
|
| 920 | - try { |
|
| 921 | - $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
| 922 | - self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
| 923 | - } catch (\Exception $ex) { |
|
| 924 | - } |
|
| 925 | - } |
|
| 926 | - } |
|
| 927 | - |
|
| 928 | - /** |
|
| 929 | - * Handle the request |
|
| 930 | - */ |
|
| 931 | - public static function handleRequest() { |
|
| 932 | - \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
| 933 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
| 934 | - |
|
| 935 | - // Check if Nextcloud is installed or in maintenance (update) mode |
|
| 936 | - if (!$systemConfig->getValue('installed', false)) { |
|
| 937 | - \OC::$server->getSession()->clear(); |
|
| 938 | - $setupHelper = new OC\Setup( |
|
| 939 | - $systemConfig, |
|
| 940 | - \OC::$server->getIniWrapper(), |
|
| 941 | - \OC::$server->getL10N('lib'), |
|
| 942 | - \OC::$server->query(\OCP\Defaults::class), |
|
| 943 | - \OC::$server->getLogger(), |
|
| 944 | - \OC::$server->getSecureRandom(), |
|
| 945 | - \OC::$server->query(\OC\Installer::class) |
|
| 946 | - ); |
|
| 947 | - $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
| 948 | - $controller->run($_POST); |
|
| 949 | - exit(); |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - $request = \OC::$server->getRequest(); |
|
| 953 | - $requestPath = $request->getRawPathInfo(); |
|
| 954 | - if ($requestPath === '/heartbeat') { |
|
| 955 | - return; |
|
| 956 | - } |
|
| 957 | - if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
| 958 | - self::checkMaintenanceMode(); |
|
| 959 | - |
|
| 960 | - if (\OCP\Util::needUpgrade()) { |
|
| 961 | - if (function_exists('opcache_reset')) { |
|
| 962 | - opcache_reset(); |
|
| 963 | - } |
|
| 964 | - if (!((bool) $systemConfig->getValue('maintenance', false))) { |
|
| 965 | - self::printUpgradePage($systemConfig); |
|
| 966 | - exit(); |
|
| 967 | - } |
|
| 968 | - } |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - // emergency app disabling |
|
| 972 | - if ($requestPath === '/disableapp' |
|
| 973 | - && $request->getMethod() === 'POST' |
|
| 974 | - && ((array)$request->getParam('appid')) !== '' |
|
| 975 | - ) { |
|
| 976 | - \OC_JSON::callCheck(); |
|
| 977 | - \OC_JSON::checkAdminUser(); |
|
| 978 | - $appIds = (array)$request->getParam('appid'); |
|
| 979 | - foreach ($appIds as $appId) { |
|
| 980 | - $appId = \OC_App::cleanAppId($appId); |
|
| 981 | - \OC::$server->getAppManager()->disableApp($appId); |
|
| 982 | - } |
|
| 983 | - \OC_JSON::success(); |
|
| 984 | - exit(); |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - // Always load authentication apps |
|
| 988 | - OC_App::loadApps(['authentication']); |
|
| 989 | - |
|
| 990 | - // Load minimum set of apps |
|
| 991 | - if (!\OCP\Util::needUpgrade() |
|
| 992 | - && !((bool) $systemConfig->getValue('maintenance', false))) { |
|
| 993 | - // For logged-in users: Load everything |
|
| 994 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 995 | - OC_App::loadApps(); |
|
| 996 | - } else { |
|
| 997 | - // For guests: Load only filesystem and logging |
|
| 998 | - OC_App::loadApps(['filesystem', 'logging']); |
|
| 999 | - self::handleLogin($request); |
|
| 1000 | - } |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - if (!self::$CLI) { |
|
| 1004 | - try { |
|
| 1005 | - if (!((bool) $systemConfig->getValue('maintenance', false)) && !\OCP\Util::needUpgrade()) { |
|
| 1006 | - OC_App::loadApps(['filesystem', 'logging']); |
|
| 1007 | - OC_App::loadApps(); |
|
| 1008 | - } |
|
| 1009 | - OC_Util::setupFS(); |
|
| 1010 | - OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo()); |
|
| 1011 | - return; |
|
| 1012 | - } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
| 1013 | - //header('HTTP/1.0 404 Not Found'); |
|
| 1014 | - } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
| 1015 | - http_response_code(405); |
|
| 1016 | - return; |
|
| 1017 | - } |
|
| 1018 | - } |
|
| 1019 | - |
|
| 1020 | - // Handle WebDAV |
|
| 1021 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
| 1022 | - // not allowed any more to prevent people |
|
| 1023 | - // mounting this root directly. |
|
| 1024 | - // Users need to mount remote.php/webdav instead. |
|
| 1025 | - http_response_code(405); |
|
| 1026 | - return; |
|
| 1027 | - } |
|
| 1028 | - |
|
| 1029 | - // Someone is logged in |
|
| 1030 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1031 | - OC_App::loadApps(); |
|
| 1032 | - OC_User::setupBackends(); |
|
| 1033 | - OC_Util::setupFS(); |
|
| 1034 | - // FIXME |
|
| 1035 | - // Redirect to default application |
|
| 1036 | - OC_Util::redirectToDefaultPage(); |
|
| 1037 | - } else { |
|
| 1038 | - // Not handled and not logged in |
|
| 1039 | - header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
| 1040 | - } |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - /** |
|
| 1044 | - * Check login: apache auth, auth token, basic auth |
|
| 1045 | - * |
|
| 1046 | - * @param OCP\IRequest $request |
|
| 1047 | - * @return boolean |
|
| 1048 | - */ |
|
| 1049 | - public static function handleLogin(OCP\IRequest $request) { |
|
| 1050 | - $userSession = self::$server->getUserSession(); |
|
| 1051 | - if (OC_User::handleApacheAuth()) { |
|
| 1052 | - return true; |
|
| 1053 | - } |
|
| 1054 | - if ($userSession->tryTokenLogin($request)) { |
|
| 1055 | - return true; |
|
| 1056 | - } |
|
| 1057 | - if (isset($_COOKIE['nc_username']) |
|
| 1058 | - && isset($_COOKIE['nc_token']) |
|
| 1059 | - && isset($_COOKIE['nc_session_id']) |
|
| 1060 | - && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
| 1061 | - return true; |
|
| 1062 | - } |
|
| 1063 | - if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
| 1064 | - return true; |
|
| 1065 | - } |
|
| 1066 | - return false; |
|
| 1067 | - } |
|
| 1068 | - |
|
| 1069 | - protected static function handleAuthHeaders() { |
|
| 1070 | - //copy http auth headers for apache+php-fcgid work around |
|
| 1071 | - if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
| 1072 | - $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
| 1076 | - $vars = [ |
|
| 1077 | - 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
| 1078 | - 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
| 1079 | - ]; |
|
| 1080 | - foreach ($vars as $var) { |
|
| 1081 | - if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
| 1082 | - $credentials = explode(':', base64_decode($matches[1]), 2); |
|
| 1083 | - if (count($credentials) === 2) { |
|
| 1084 | - $_SERVER['PHP_AUTH_USER'] = $credentials[0]; |
|
| 1085 | - $_SERVER['PHP_AUTH_PW'] = $credentials[1]; |
|
| 1086 | - break; |
|
| 1087 | - } |
|
| 1088 | - } |
|
| 1089 | - } |
|
| 1090 | - } |
|
| 78 | + /** |
|
| 79 | + * Associative array for autoloading. classname => filename |
|
| 80 | + */ |
|
| 81 | + public static $CLASSPATH = []; |
|
| 82 | + /** |
|
| 83 | + * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
| 84 | + */ |
|
| 85 | + public static $SERVERROOT = ''; |
|
| 86 | + /** |
|
| 87 | + * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
| 88 | + */ |
|
| 89 | + private static $SUBURI = ''; |
|
| 90 | + /** |
|
| 91 | + * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
| 92 | + */ |
|
| 93 | + public static $WEBROOT = ''; |
|
| 94 | + /** |
|
| 95 | + * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
| 96 | + * web path in 'url' |
|
| 97 | + */ |
|
| 98 | + public static $APPSROOTS = []; |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @var string |
|
| 102 | + */ |
|
| 103 | + public static $configDir; |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * requested app |
|
| 107 | + */ |
|
| 108 | + public static $REQUESTEDAPP = ''; |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * check if Nextcloud runs in cli mode |
|
| 112 | + */ |
|
| 113 | + public static $CLI = false; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @var \OC\Autoloader $loader |
|
| 117 | + */ |
|
| 118 | + public static $loader = null; |
|
| 119 | + |
|
| 120 | + /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
| 121 | + public static $composerAutoloader = null; |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @var \OC\Server |
|
| 125 | + */ |
|
| 126 | + public static $server = null; |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @var \OC\Config |
|
| 130 | + */ |
|
| 131 | + private static $config = null; |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @throws \RuntimeException when the 3rdparty directory is missing or |
|
| 135 | + * the app path list is empty or contains an invalid path |
|
| 136 | + */ |
|
| 137 | + public static function initPaths() { |
|
| 138 | + if (defined('PHPUNIT_CONFIG_DIR')) { |
|
| 139 | + self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
| 140 | + } elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
| 141 | + self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
| 142 | + } elseif ($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
| 143 | + self::$configDir = rtrim($dir, '/') . '/'; |
|
| 144 | + } else { |
|
| 145 | + self::$configDir = OC::$SERVERROOT . '/config/'; |
|
| 146 | + } |
|
| 147 | + self::$config = new \OC\Config(self::$configDir); |
|
| 148 | + |
|
| 149 | + OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
| 150 | + /** |
|
| 151 | + * FIXME: The following lines are required because we can't yet instantiate |
|
| 152 | + * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
| 153 | + */ |
|
| 154 | + $params = [ |
|
| 155 | + 'server' => [ |
|
| 156 | + 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
| 157 | + 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
| 158 | + ], |
|
| 159 | + ]; |
|
| 160 | + $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
| 161 | + $scriptName = $fakeRequest->getScriptName(); |
|
| 162 | + if (substr($scriptName, -1) == '/') { |
|
| 163 | + $scriptName .= 'index.php'; |
|
| 164 | + //make sure suburi follows the same rules as scriptName |
|
| 165 | + if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
| 166 | + if (substr(OC::$SUBURI, -1) != '/') { |
|
| 167 | + OC::$SUBURI = OC::$SUBURI . '/'; |
|
| 168 | + } |
|
| 169 | + OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + if (OC::$CLI) { |
|
| 175 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 176 | + } else { |
|
| 177 | + if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
| 178 | + OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
| 179 | + |
|
| 180 | + if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
| 181 | + OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
| 182 | + } |
|
| 183 | + } else { |
|
| 184 | + // The scriptName is not ending with OC::$SUBURI |
|
| 185 | + // This most likely means that we are calling from CLI. |
|
| 186 | + // However some cron jobs still need to generate |
|
| 187 | + // a web URL, so we use overwritewebroot as a fallback. |
|
| 188 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
| 192 | + // slash which is required by URL generation. |
|
| 193 | + if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
| 194 | + substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
| 195 | + header('Location: '.\OC::$WEBROOT.'/'); |
|
| 196 | + exit(); |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // search the apps folder |
|
| 201 | + $config_paths = self::$config->getValue('apps_paths', []); |
|
| 202 | + if (!empty($config_paths)) { |
|
| 203 | + foreach ($config_paths as $paths) { |
|
| 204 | + if (isset($paths['url']) && isset($paths['path'])) { |
|
| 205 | + $paths['url'] = rtrim($paths['url'], '/'); |
|
| 206 | + $paths['path'] = rtrim($paths['path'], '/'); |
|
| 207 | + OC::$APPSROOTS[] = $paths; |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
| 211 | + OC::$APPSROOTS[] = ['path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true]; |
|
| 212 | + } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
| 213 | + OC::$APPSROOTS[] = [ |
|
| 214 | + 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
| 215 | + 'url' => '/apps', |
|
| 216 | + 'writable' => true |
|
| 217 | + ]; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + if (empty(OC::$APPSROOTS)) { |
|
| 221 | + throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
| 222 | + . ' or the folder above. You can also configure the location in the config.php file.'); |
|
| 223 | + } |
|
| 224 | + $paths = []; |
|
| 225 | + foreach (OC::$APPSROOTS as $path) { |
|
| 226 | + $paths[] = $path['path']; |
|
| 227 | + if (!is_dir($path['path'])) { |
|
| 228 | + throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
| 229 | + . ' Nextcloud folder or the folder above. You can also configure the location in the' |
|
| 230 | + . ' config.php file.', $path['path'])); |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + // set the right include path |
|
| 235 | + set_include_path( |
|
| 236 | + implode(PATH_SEPARATOR, $paths) |
|
| 237 | + ); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + public static function checkConfig() { |
|
| 241 | + $l = \OC::$server->getL10N('lib'); |
|
| 242 | + |
|
| 243 | + // Create config if it does not already exist |
|
| 244 | + $configFilePath = self::$configDir .'/config.php'; |
|
| 245 | + if (!file_exists($configFilePath)) { |
|
| 246 | + @touch($configFilePath); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + // Check if config is writable |
|
| 250 | + $configFileWritable = is_writable($configFilePath); |
|
| 251 | + if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
| 252 | + || !$configFileWritable && \OCP\Util::needUpgrade()) { |
|
| 253 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 254 | + |
|
| 255 | + if (self::$CLI) { |
|
| 256 | + echo $l->t('Cannot write into "config" directory!')."\n"; |
|
| 257 | + echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
| 258 | + echo "\n"; |
|
| 259 | + echo $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.')."\n"; |
|
| 260 | + echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ])."\n"; |
|
| 261 | + exit; |
|
| 262 | + } else { |
|
| 263 | + OC_Template::printErrorPage( |
|
| 264 | + $l->t('Cannot write into "config" directory!'), |
|
| 265 | + $l->t('This can usually be fixed by giving the webserver write access to the config directory.') . '. ' |
|
| 266 | + . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
|
| 267 | + [ $urlGenerator->linkToDocs('admin-config') ]), |
|
| 268 | + 503 |
|
| 269 | + ); |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + public static function checkInstalled() { |
|
| 275 | + if (defined('OC_CONSOLE')) { |
|
| 276 | + return; |
|
| 277 | + } |
|
| 278 | + // Redirect to installer if not installed |
|
| 279 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
| 280 | + if (OC::$CLI) { |
|
| 281 | + throw new Exception('Not installed'); |
|
| 282 | + } else { |
|
| 283 | + $url = OC::$WEBROOT . '/index.php'; |
|
| 284 | + header('Location: ' . $url); |
|
| 285 | + } |
|
| 286 | + exit(); |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + public static function checkMaintenanceMode() { |
|
| 291 | + // Allow ajax update script to execute without being stopped |
|
| 292 | + if (((bool) \OC::$server->getSystemConfig()->getValue('maintenance', false)) && OC::$SUBURI != '/core/ajax/update.php') { |
|
| 293 | + // send http status 503 |
|
| 294 | + http_response_code(503); |
|
| 295 | + header('Retry-After: 120'); |
|
| 296 | + |
|
| 297 | + // render error page |
|
| 298 | + $template = new OC_Template('', 'update.user', 'guest'); |
|
| 299 | + OC_Util::addScript('dist/maintenance'); |
|
| 300 | + OC_Util::addStyle('core', 'guest'); |
|
| 301 | + $template->printPage(); |
|
| 302 | + die(); |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Prints the upgrade page |
|
| 308 | + * |
|
| 309 | + * @param \OC\SystemConfig $systemConfig |
|
| 310 | + */ |
|
| 311 | + private static function printUpgradePage(\OC\SystemConfig $systemConfig) { |
|
| 312 | + $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
| 313 | + $tooBig = false; |
|
| 314 | + if (!$disableWebUpdater) { |
|
| 315 | + $apps = \OC::$server->getAppManager(); |
|
| 316 | + if ($apps->isInstalled('user_ldap')) { |
|
| 317 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 318 | + |
|
| 319 | + $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
| 320 | + ->from('ldap_user_mapping') |
|
| 321 | + ->execute(); |
|
| 322 | + $row = $result->fetch(); |
|
| 323 | + $result->closeCursor(); |
|
| 324 | + |
|
| 325 | + $tooBig = ($row['user_count'] > 50); |
|
| 326 | + } |
|
| 327 | + if (!$tooBig && $apps->isInstalled('user_saml')) { |
|
| 328 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 329 | + |
|
| 330 | + $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
| 331 | + ->from('user_saml_users') |
|
| 332 | + ->execute(); |
|
| 333 | + $row = $result->fetch(); |
|
| 334 | + $result->closeCursor(); |
|
| 335 | + |
|
| 336 | + $tooBig = ($row['user_count'] > 50); |
|
| 337 | + } |
|
| 338 | + if (!$tooBig) { |
|
| 339 | + // count users |
|
| 340 | + $stats = \OC::$server->getUserManager()->countUsers(); |
|
| 341 | + $totalUsers = array_sum($stats); |
|
| 342 | + $tooBig = ($totalUsers > 50); |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) && |
|
| 346 | + $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
| 347 | + |
|
| 348 | + if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
| 349 | + // send http status 503 |
|
| 350 | + http_response_code(503); |
|
| 351 | + header('Retry-After: 120'); |
|
| 352 | + |
|
| 353 | + // render error page |
|
| 354 | + $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
| 355 | + $template->assign('productName', 'nextcloud'); // for now |
|
| 356 | + $template->assign('version', OC_Util::getVersionString()); |
|
| 357 | + $template->assign('tooBig', $tooBig); |
|
| 358 | + |
|
| 359 | + $template->printPage(); |
|
| 360 | + die(); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + // check whether this is a core update or apps update |
|
| 364 | + $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
| 365 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 366 | + |
|
| 367 | + // if not a core upgrade, then it's apps upgrade |
|
| 368 | + $isAppsOnlyUpgrade = version_compare($currentVersion, $installedVersion, '='); |
|
| 369 | + |
|
| 370 | + $oldTheme = $systemConfig->getValue('theme'); |
|
| 371 | + $systemConfig->setValue('theme', ''); |
|
| 372 | + OC_Util::addScript('config'); // needed for web root |
|
| 373 | + OC_Util::addScript('update'); |
|
| 374 | + |
|
| 375 | + /** @var \OC\App\AppManager $appManager */ |
|
| 376 | + $appManager = \OC::$server->getAppManager(); |
|
| 377 | + |
|
| 378 | + $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
| 379 | + $tmpl->assign('version', OC_Util::getVersionString()); |
|
| 380 | + $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
| 381 | + |
|
| 382 | + // get third party apps |
|
| 383 | + $ocVersion = \OCP\Util::getVersion(); |
|
| 384 | + $ocVersion = implode('.', $ocVersion); |
|
| 385 | + $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
| 386 | + $incompatibleShippedApps = []; |
|
| 387 | + foreach ($incompatibleApps as $appInfo) { |
|
| 388 | + if ($appManager->isShipped($appInfo['id'])) { |
|
| 389 | + $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + if (!empty($incompatibleShippedApps)) { |
|
| 394 | + $l = \OC::$server->getL10N('core'); |
|
| 395 | + $hint = $l->t('The files of the app %1$s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
| 396 | + throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
| 400 | + $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
| 401 | + $tmpl->assign('productName', 'Nextcloud'); // for now |
|
| 402 | + $tmpl->assign('oldTheme', $oldTheme); |
|
| 403 | + $tmpl->printPage(); |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + public static function initSession() { |
|
| 407 | + if (self::$server->getRequest()->getServerProtocol() === 'https') { |
|
| 408 | + ini_set('session.cookie_secure', true); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + // prevents javascript from accessing php session cookies |
|
| 412 | + ini_set('session.cookie_httponly', 'true'); |
|
| 413 | + |
|
| 414 | + // set the cookie path to the Nextcloud directory |
|
| 415 | + $cookie_path = OC::$WEBROOT ? : '/'; |
|
| 416 | + ini_set('session.cookie_path', $cookie_path); |
|
| 417 | + |
|
| 418 | + // Let the session name be changed in the initSession Hook |
|
| 419 | + $sessionName = OC_Util::getInstanceId(); |
|
| 420 | + |
|
| 421 | + try { |
|
| 422 | + // Allow session apps to create a custom session object |
|
| 423 | + $useCustomSession = false; |
|
| 424 | + $session = self::$server->getSession(); |
|
| 425 | + OC_Hook::emit('OC', 'initSession', ['session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession]); |
|
| 426 | + if (!$useCustomSession) { |
|
| 427 | + // set the session name to the instance id - which is unique |
|
| 428 | + $session = new \OC\Session\Internal($sessionName); |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
| 432 | + $session = $cryptoWrapper->wrapSession($session); |
|
| 433 | + self::$server->setSession($session); |
|
| 434 | + |
|
| 435 | + // if session can't be started break with http 500 error |
|
| 436 | + } catch (Exception $e) { |
|
| 437 | + \OC::$server->getLogger()->logException($e, ['app' => 'base']); |
|
| 438 | + //show the user a detailed error page |
|
| 439 | + OC_Template::printExceptionErrorPage($e, 500); |
|
| 440 | + die(); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
| 444 | + |
|
| 445 | + // session timeout |
|
| 446 | + if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
| 447 | + if (isset($_COOKIE[session_name()])) { |
|
| 448 | + setcookie(session_name(), '', -1, self::$WEBROOT ? : '/'); |
|
| 449 | + } |
|
| 450 | + \OC::$server->getUserSession()->logout(); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + $session->set('LAST_ACTIVITY', time()); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + /** |
|
| 457 | + * @return string |
|
| 458 | + */ |
|
| 459 | + private static function getSessionLifeTime() { |
|
| 460 | + return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Try to set some values to the required Nextcloud default |
|
| 465 | + */ |
|
| 466 | + public static function setRequiredIniValues() { |
|
| 467 | + @ini_set('default_charset', 'UTF-8'); |
|
| 468 | + @ini_set('gd.jpeg_ignore_warning', '1'); |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * Send the same site cookies |
|
| 473 | + */ |
|
| 474 | + private static function sendSameSiteCookies() { |
|
| 475 | + $cookieParams = session_get_cookie_params(); |
|
| 476 | + $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
| 477 | + $policies = [ |
|
| 478 | + 'lax', |
|
| 479 | + 'strict', |
|
| 480 | + ]; |
|
| 481 | + |
|
| 482 | + // Append __Host to the cookie if it meets the requirements |
|
| 483 | + $cookiePrefix = ''; |
|
| 484 | + if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 485 | + $cookiePrefix = '__Host-'; |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + foreach ($policies as $policy) { |
|
| 489 | + header( |
|
| 490 | + sprintf( |
|
| 491 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 492 | + $cookiePrefix, |
|
| 493 | + $policy, |
|
| 494 | + $cookieParams['path'], |
|
| 495 | + $policy |
|
| 496 | + ), |
|
| 497 | + false |
|
| 498 | + ); |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
| 504 | + * be set in every request if cookies are sent to add a second level of |
|
| 505 | + * defense against CSRF. |
|
| 506 | + * |
|
| 507 | + * If the cookie is not sent this will set the cookie and reload the page. |
|
| 508 | + * We use an additional cookie since we want to protect logout CSRF and |
|
| 509 | + * also we can't directly interfere with PHP's session mechanism. |
|
| 510 | + */ |
|
| 511 | + private static function performSameSiteCookieProtection() { |
|
| 512 | + $request = \OC::$server->getRequest(); |
|
| 513 | + |
|
| 514 | + // Some user agents are notorious and don't really properly follow HTTP |
|
| 515 | + // specifications. For those, have an automated opt-out. Since the protection |
|
| 516 | + // for remote.php is applied in base.php as starting point we need to opt out |
|
| 517 | + // here. |
|
| 518 | + $incompatibleUserAgents = \OC::$server->getConfig()->getSystemValue('csrf.optout'); |
|
| 519 | + |
|
| 520 | + // Fallback, if csrf.optout is unset |
|
| 521 | + if (!is_array($incompatibleUserAgents)) { |
|
| 522 | + $incompatibleUserAgents = [ |
|
| 523 | + // OS X Finder |
|
| 524 | + '/^WebDAVFS/', |
|
| 525 | + // Windows webdav drive |
|
| 526 | + '/^Microsoft-WebDAV-MiniRedir/', |
|
| 527 | + ]; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + if ($request->isUserAgent($incompatibleUserAgents)) { |
|
| 531 | + return; |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + if (count($_COOKIE) > 0) { |
|
| 535 | + $requestUri = $request->getScriptName(); |
|
| 536 | + $processingScript = explode('/', $requestUri); |
|
| 537 | + $processingScript = $processingScript[count($processingScript)-1]; |
|
| 538 | + |
|
| 539 | + // index.php routes are handled in the middleware |
|
| 540 | + if ($processingScript === 'index.php') { |
|
| 541 | + return; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + // All other endpoints require the lax and the strict cookie |
|
| 545 | + if (!$request->passesStrictCookieCheck()) { |
|
| 546 | + self::sendSameSiteCookies(); |
|
| 547 | + // Debug mode gets access to the resources without strict cookie |
|
| 548 | + // due to the fact that the SabreDAV browser also lives there. |
|
| 549 | + if (!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 550 | + http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 551 | + exit(); |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | + } elseif (!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
| 555 | + self::sendSameSiteCookies(); |
|
| 556 | + } |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + public static function init() { |
|
| 560 | + // calculate the root directories |
|
| 561 | + OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
| 562 | + |
|
| 563 | + // register autoloader |
|
| 564 | + $loaderStart = microtime(true); |
|
| 565 | + require_once __DIR__ . '/autoloader.php'; |
|
| 566 | + self::$loader = new \OC\Autoloader([ |
|
| 567 | + OC::$SERVERROOT . '/lib/private/legacy', |
|
| 568 | + ]); |
|
| 569 | + if (defined('PHPUNIT_RUN')) { |
|
| 570 | + self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
| 571 | + } |
|
| 572 | + spl_autoload_register([self::$loader, 'load']); |
|
| 573 | + $loaderEnd = microtime(true); |
|
| 574 | + |
|
| 575 | + self::$CLI = (php_sapi_name() == 'cli'); |
|
| 576 | + |
|
| 577 | + // Add default composer PSR-4 autoloader |
|
| 578 | + self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
| 579 | + |
|
| 580 | + try { |
|
| 581 | + self::initPaths(); |
|
| 582 | + // setup 3rdparty autoloader |
|
| 583 | + $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
| 584 | + if (!file_exists($vendorAutoLoad)) { |
|
| 585 | + throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
| 586 | + } |
|
| 587 | + require_once $vendorAutoLoad; |
|
| 588 | + } catch (\RuntimeException $e) { |
|
| 589 | + if (!self::$CLI) { |
|
| 590 | + http_response_code(503); |
|
| 591 | + } |
|
| 592 | + // we can't use the template error page here, because this needs the |
|
| 593 | + // DI container which isn't available yet |
|
| 594 | + print($e->getMessage()); |
|
| 595 | + exit(); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + // setup the basic server |
|
| 599 | + self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
| 600 | + self::$server->boot(); |
|
| 601 | + \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
| 602 | + \OC::$server->getEventLogger()->start('boot', 'Initialize'); |
|
| 603 | + |
|
| 604 | + // Override php.ini and log everything if we're troubleshooting |
|
| 605 | + if (self::$config->getValue('loglevel') === ILogger::DEBUG) { |
|
| 606 | + error_reporting(E_ALL); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + // Don't display errors and log them |
|
| 610 | + @ini_set('display_errors', '0'); |
|
| 611 | + @ini_set('log_errors', '1'); |
|
| 612 | + |
|
| 613 | + if (!date_default_timezone_set('UTC')) { |
|
| 614 | + throw new \RuntimeException('Could not set timezone to UTC'); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + //try to configure php to enable big file uploads. |
|
| 618 | + //this doesn´t work always depending on the webserver and php configuration. |
|
| 619 | + //Let´s try to overwrite some defaults anyway |
|
| 620 | + |
|
| 621 | + //try to set the maximum execution time to 60min |
|
| 622 | + if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 623 | + @set_time_limit(3600); |
|
| 624 | + } |
|
| 625 | + @ini_set('max_execution_time', '3600'); |
|
| 626 | + @ini_set('max_input_time', '3600'); |
|
| 627 | + |
|
| 628 | + //try to set the maximum filesize to 10G |
|
| 629 | + @ini_set('upload_max_filesize', '10G'); |
|
| 630 | + @ini_set('post_max_size', '10G'); |
|
| 631 | + @ini_set('file_uploads', '50'); |
|
| 632 | + |
|
| 633 | + self::setRequiredIniValues(); |
|
| 634 | + self::handleAuthHeaders(); |
|
| 635 | + self::registerAutoloaderCache(); |
|
| 636 | + |
|
| 637 | + // initialize intl fallback is necessary |
|
| 638 | + \Patchwork\Utf8\Bootup::initIntl(); |
|
| 639 | + OC_Util::isSetLocaleWorking(); |
|
| 640 | + |
|
| 641 | + if (!defined('PHPUNIT_RUN')) { |
|
| 642 | + OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
| 643 | + $debug = \OC::$server->getConfig()->getSystemValue('debug', false); |
|
| 644 | + OC\Log\ErrorHandler::register($debug); |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + /** @var \OC\AppFramework\Bootstrap\Coordinator $bootstrapCoordinator */ |
|
| 648 | + $bootstrapCoordinator = \OC::$server->query(\OC\AppFramework\Bootstrap\Coordinator::class); |
|
| 649 | + $bootstrapCoordinator->runRegistration(); |
|
| 650 | + |
|
| 651 | + \OC::$server->getEventLogger()->start('init_session', 'Initialize session'); |
|
| 652 | + OC_App::loadApps(['session']); |
|
| 653 | + if (!self::$CLI) { |
|
| 654 | + self::initSession(); |
|
| 655 | + } |
|
| 656 | + \OC::$server->getEventLogger()->end('init_session'); |
|
| 657 | + self::checkConfig(); |
|
| 658 | + self::checkInstalled(); |
|
| 659 | + |
|
| 660 | + OC_Response::addSecurityHeaders(); |
|
| 661 | + |
|
| 662 | + self::performSameSiteCookieProtection(); |
|
| 663 | + |
|
| 664 | + if (!defined('OC_CONSOLE')) { |
|
| 665 | + $errors = OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
| 666 | + if (count($errors) > 0) { |
|
| 667 | + if (!self::$CLI) { |
|
| 668 | + http_response_code(503); |
|
| 669 | + OC_Util::addStyle('guest'); |
|
| 670 | + try { |
|
| 671 | + OC_Template::printGuestPage('', 'error', ['errors' => $errors]); |
|
| 672 | + exit; |
|
| 673 | + } catch (\Exception $e) { |
|
| 674 | + // In case any error happens when showing the error page, we simply fall back to posting the text. |
|
| 675 | + // This might be the case when e.g. the data directory is broken and we can not load/write SCSS to/from it. |
|
| 676 | + } |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + // Convert l10n string into regular string for usage in database |
|
| 680 | + $staticErrors = []; |
|
| 681 | + foreach ($errors as $error) { |
|
| 682 | + echo $error['error'] . "\n"; |
|
| 683 | + echo $error['hint'] . "\n\n"; |
|
| 684 | + $staticErrors[] = [ |
|
| 685 | + 'error' => (string)$error['error'], |
|
| 686 | + 'hint' => (string)$error['hint'], |
|
| 687 | + ]; |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + try { |
|
| 691 | + \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
| 692 | + } catch (\Exception $e) { |
|
| 693 | + echo('Writing to database failed'); |
|
| 694 | + } |
|
| 695 | + exit(1); |
|
| 696 | + } elseif (self::$CLI && \OC::$server->getConfig()->getSystemValue('installed', false)) { |
|
| 697 | + \OC::$server->getConfig()->deleteAppValue('core', 'cronErrors'); |
|
| 698 | + } |
|
| 699 | + } |
|
| 700 | + //try to set the session lifetime |
|
| 701 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
| 702 | + @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
| 703 | + |
|
| 704 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
| 705 | + |
|
| 706 | + // User and Groups |
|
| 707 | + if (!$systemConfig->getValue("installed", false)) { |
|
| 708 | + self::$server->getSession()->set('user_id', ''); |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + OC_User::useBackend(new \OC\User\Database()); |
|
| 712 | + \OC::$server->getGroupManager()->addBackend(new \OC\Group\Database()); |
|
| 713 | + |
|
| 714 | + // Subscribe to the hook |
|
| 715 | + \OCP\Util::connectHook( |
|
| 716 | + '\OCA\Files_Sharing\API\Server2Server', |
|
| 717 | + 'preLoginNameUsedAsUserName', |
|
| 718 | + '\OC\User\Database', |
|
| 719 | + 'preLoginNameUsedAsUserName' |
|
| 720 | + ); |
|
| 721 | + |
|
| 722 | + //setup extra user backends |
|
| 723 | + if (!\OCP\Util::needUpgrade()) { |
|
| 724 | + OC_User::setupBackends(); |
|
| 725 | + } else { |
|
| 726 | + // Run upgrades in incognito mode |
|
| 727 | + OC_User::setIncognitoMode(true); |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + self::registerCleanupHooks(); |
|
| 731 | + self::registerFilesystemHooks(); |
|
| 732 | + self::registerShareHooks(); |
|
| 733 | + self::registerEncryptionWrapper(); |
|
| 734 | + self::registerEncryptionHooks(); |
|
| 735 | + self::registerAccountHooks(); |
|
| 736 | + self::registerResourceCollectionHooks(); |
|
| 737 | + self::registerAppRestrictionsHooks(); |
|
| 738 | + |
|
| 739 | + // Make sure that the application class is not loaded before the database is setup |
|
| 740 | + if ($systemConfig->getValue("installed", false)) { |
|
| 741 | + OC_App::loadApp('settings'); |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + //make sure temporary files are cleaned up |
|
| 745 | + $tmpManager = \OC::$server->getTempManager(); |
|
| 746 | + register_shutdown_function([$tmpManager, 'clean']); |
|
| 747 | + $lockProvider = \OC::$server->getLockingProvider(); |
|
| 748 | + register_shutdown_function([$lockProvider, 'releaseAll']); |
|
| 749 | + |
|
| 750 | + // Check whether the sample configuration has been copied |
|
| 751 | + if ($systemConfig->getValue('copied_sample_config', false)) { |
|
| 752 | + $l = \OC::$server->getL10N('lib'); |
|
| 753 | + OC_Template::printErrorPage( |
|
| 754 | + $l->t('Sample configuration detected'), |
|
| 755 | + $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php'), |
|
| 756 | + 503 |
|
| 757 | + ); |
|
| 758 | + return; |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + $request = \OC::$server->getRequest(); |
|
| 762 | + $host = $request->getInsecureServerHost(); |
|
| 763 | + /** |
|
| 764 | + * if the host passed in headers isn't trusted |
|
| 765 | + * FIXME: Should not be in here at all :see_no_evil: |
|
| 766 | + */ |
|
| 767 | + if (!OC::$CLI |
|
| 768 | + && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
| 769 | + && self::$server->getConfig()->getSystemValue('installed', false) |
|
| 770 | + ) { |
|
| 771 | + // Allow access to CSS resources |
|
| 772 | + $isScssRequest = false; |
|
| 773 | + if (strpos($request->getPathInfo(), '/css/') === 0) { |
|
| 774 | + $isScssRequest = true; |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + if (substr($request->getRequestUri(), -11) === '/status.php') { |
|
| 778 | + http_response_code(400); |
|
| 779 | + header('Content-Type: application/json'); |
|
| 780 | + echo '{"error": "Trusted domain error.", "code": 15}'; |
|
| 781 | + exit(); |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + if (!$isScssRequest) { |
|
| 785 | + http_response_code(400); |
|
| 786 | + |
|
| 787 | + \OC::$server->getLogger()->info( |
|
| 788 | + 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
| 789 | + [ |
|
| 790 | + 'app' => 'core', |
|
| 791 | + 'remoteAddress' => $request->getRemoteAddress(), |
|
| 792 | + 'host' => $host, |
|
| 793 | + ] |
|
| 794 | + ); |
|
| 795 | + |
|
| 796 | + $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
| 797 | + $tmpl->assign('docUrl', \OC::$server->getURLGenerator()->linkToDocs('admin-trusted-domains')); |
|
| 798 | + $tmpl->printPage(); |
|
| 799 | + |
|
| 800 | + exit(); |
|
| 801 | + } |
|
| 802 | + } |
|
| 803 | + \OC::$server->getEventLogger()->end('boot'); |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + /** |
|
| 807 | + * register hooks for the cleanup of cache and bruteforce protection |
|
| 808 | + */ |
|
| 809 | + public static function registerCleanupHooks() { |
|
| 810 | + //don't try to do this before we are properly setup |
|
| 811 | + if (\OC::$server->getSystemConfig()->getValue('installed', false) && !\OCP\Util::needUpgrade()) { |
|
| 812 | + |
|
| 813 | + // NOTE: This will be replaced to use OCP |
|
| 814 | + $userSession = self::$server->getUserSession(); |
|
| 815 | + $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
| 816 | + if (!defined('PHPUNIT_RUN') && $userSession->isLoggedIn()) { |
|
| 817 | + // reset brute force delay for this IP address and username |
|
| 818 | + $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
|
| 819 | + $request = \OC::$server->getRequest(); |
|
| 820 | + $throttler = \OC::$server->getBruteForceThrottler(); |
|
| 821 | + $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + try { |
|
| 825 | + $cache = new \OC\Cache\File(); |
|
| 826 | + $cache->gc(); |
|
| 827 | + } catch (\OC\ServerNotAvailableException $e) { |
|
| 828 | + // not a GC exception, pass it on |
|
| 829 | + throw $e; |
|
| 830 | + } catch (\OC\ForbiddenException $e) { |
|
| 831 | + // filesystem blocked for this request, ignore |
|
| 832 | + } catch (\Exception $e) { |
|
| 833 | + // a GC exception should not prevent users from using OC, |
|
| 834 | + // so log the exception |
|
| 835 | + \OC::$server->getLogger()->logException($e, [ |
|
| 836 | + 'message' => 'Exception when running cache gc.', |
|
| 837 | + 'level' => ILogger::WARN, |
|
| 838 | + 'app' => 'core', |
|
| 839 | + ]); |
|
| 840 | + } |
|
| 841 | + }); |
|
| 842 | + } |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + private static function registerEncryptionWrapper() { |
|
| 846 | + $manager = self::$server->getEncryptionManager(); |
|
| 847 | + \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
| 848 | + } |
|
| 849 | + |
|
| 850 | + private static function registerEncryptionHooks() { |
|
| 851 | + $enabled = self::$server->getEncryptionManager()->isEnabled(); |
|
| 852 | + if ($enabled) { |
|
| 853 | + \OCP\Util::connectHook(Share::class, 'post_shared', HookManager::class, 'postShared'); |
|
| 854 | + \OCP\Util::connectHook(Share::class, 'post_unshare', HookManager::class, 'postUnshared'); |
|
| 855 | + \OCP\Util::connectHook('OC_Filesystem', 'post_rename', HookManager::class, 'postRename'); |
|
| 856 | + \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', HookManager::class, 'postRestore'); |
|
| 857 | + } |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + private static function registerAccountHooks() { |
|
| 861 | + $hookHandler = new \OC\Accounts\Hooks(\OC::$server->getLogger()); |
|
| 862 | + \OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook'); |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + private static function registerAppRestrictionsHooks() { |
|
| 866 | + $groupManager = self::$server->query(\OCP\IGroupManager::class); |
|
| 867 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OCP\IGroup $group) { |
|
| 868 | + $appManager = self::$server->getAppManager(); |
|
| 869 | + $apps = $appManager->getEnabledAppsForGroup($group); |
|
| 870 | + foreach ($apps as $appId) { |
|
| 871 | + $restrictions = $appManager->getAppRestriction($appId); |
|
| 872 | + if (empty($restrictions)) { |
|
| 873 | + continue; |
|
| 874 | + } |
|
| 875 | + $key = array_search($group->getGID(), $restrictions); |
|
| 876 | + unset($restrictions[$key]); |
|
| 877 | + $restrictions = array_values($restrictions); |
|
| 878 | + if (empty($restrictions)) { |
|
| 879 | + $appManager->disableApp($appId); |
|
| 880 | + } else { |
|
| 881 | + $appManager->enableAppForGroups($appId, $restrictions); |
|
| 882 | + } |
|
| 883 | + } |
|
| 884 | + }); |
|
| 885 | + } |
|
| 886 | + |
|
| 887 | + private static function registerResourceCollectionHooks() { |
|
| 888 | + \OC\Collaboration\Resources\Listener::register(\OC::$server->getEventDispatcher()); |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + /** |
|
| 892 | + * register hooks for the filesystem |
|
| 893 | + */ |
|
| 894 | + public static function registerFilesystemHooks() { |
|
| 895 | + // Check for blacklisted files |
|
| 896 | + OC_Hook::connect('OC_Filesystem', 'write', Filesystem::class, 'isBlacklisted'); |
|
| 897 | + OC_Hook::connect('OC_Filesystem', 'rename', Filesystem::class, 'isBlacklisted'); |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + /** |
|
| 901 | + * register hooks for sharing |
|
| 902 | + */ |
|
| 903 | + public static function registerShareHooks() { |
|
| 904 | + if (\OC::$server->getSystemConfig()->getValue('installed')) { |
|
| 905 | + OC_Hook::connect('OC_User', 'post_deleteUser', Hooks::class, 'post_deleteUser'); |
|
| 906 | + OC_Hook::connect('OC_User', 'post_removeFromGroup', Hooks::class, 'post_removeFromGroup'); |
|
| 907 | + OC_Hook::connect('OC_User', 'post_deleteGroup', Hooks::class, 'post_deleteGroup'); |
|
| 908 | + } |
|
| 909 | + } |
|
| 910 | + |
|
| 911 | + protected static function registerAutoloaderCache() { |
|
| 912 | + // The class loader takes an optional low-latency cache, which MUST be |
|
| 913 | + // namespaced. The instanceid is used for namespacing, but might be |
|
| 914 | + // unavailable at this point. Furthermore, it might not be possible to |
|
| 915 | + // generate an instanceid via \OC_Util::getInstanceId() because the |
|
| 916 | + // config file may not be writable. As such, we only register a class |
|
| 917 | + // loader cache if instanceid is available without trying to create one. |
|
| 918 | + $instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 919 | + if ($instanceId) { |
|
| 920 | + try { |
|
| 921 | + $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
| 922 | + self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
| 923 | + } catch (\Exception $ex) { |
|
| 924 | + } |
|
| 925 | + } |
|
| 926 | + } |
|
| 927 | + |
|
| 928 | + /** |
|
| 929 | + * Handle the request |
|
| 930 | + */ |
|
| 931 | + public static function handleRequest() { |
|
| 932 | + \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
| 933 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
| 934 | + |
|
| 935 | + // Check if Nextcloud is installed or in maintenance (update) mode |
|
| 936 | + if (!$systemConfig->getValue('installed', false)) { |
|
| 937 | + \OC::$server->getSession()->clear(); |
|
| 938 | + $setupHelper = new OC\Setup( |
|
| 939 | + $systemConfig, |
|
| 940 | + \OC::$server->getIniWrapper(), |
|
| 941 | + \OC::$server->getL10N('lib'), |
|
| 942 | + \OC::$server->query(\OCP\Defaults::class), |
|
| 943 | + \OC::$server->getLogger(), |
|
| 944 | + \OC::$server->getSecureRandom(), |
|
| 945 | + \OC::$server->query(\OC\Installer::class) |
|
| 946 | + ); |
|
| 947 | + $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
| 948 | + $controller->run($_POST); |
|
| 949 | + exit(); |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + $request = \OC::$server->getRequest(); |
|
| 953 | + $requestPath = $request->getRawPathInfo(); |
|
| 954 | + if ($requestPath === '/heartbeat') { |
|
| 955 | + return; |
|
| 956 | + } |
|
| 957 | + if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
| 958 | + self::checkMaintenanceMode(); |
|
| 959 | + |
|
| 960 | + if (\OCP\Util::needUpgrade()) { |
|
| 961 | + if (function_exists('opcache_reset')) { |
|
| 962 | + opcache_reset(); |
|
| 963 | + } |
|
| 964 | + if (!((bool) $systemConfig->getValue('maintenance', false))) { |
|
| 965 | + self::printUpgradePage($systemConfig); |
|
| 966 | + exit(); |
|
| 967 | + } |
|
| 968 | + } |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + // emergency app disabling |
|
| 972 | + if ($requestPath === '/disableapp' |
|
| 973 | + && $request->getMethod() === 'POST' |
|
| 974 | + && ((array)$request->getParam('appid')) !== '' |
|
| 975 | + ) { |
|
| 976 | + \OC_JSON::callCheck(); |
|
| 977 | + \OC_JSON::checkAdminUser(); |
|
| 978 | + $appIds = (array)$request->getParam('appid'); |
|
| 979 | + foreach ($appIds as $appId) { |
|
| 980 | + $appId = \OC_App::cleanAppId($appId); |
|
| 981 | + \OC::$server->getAppManager()->disableApp($appId); |
|
| 982 | + } |
|
| 983 | + \OC_JSON::success(); |
|
| 984 | + exit(); |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + // Always load authentication apps |
|
| 988 | + OC_App::loadApps(['authentication']); |
|
| 989 | + |
|
| 990 | + // Load minimum set of apps |
|
| 991 | + if (!\OCP\Util::needUpgrade() |
|
| 992 | + && !((bool) $systemConfig->getValue('maintenance', false))) { |
|
| 993 | + // For logged-in users: Load everything |
|
| 994 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 995 | + OC_App::loadApps(); |
|
| 996 | + } else { |
|
| 997 | + // For guests: Load only filesystem and logging |
|
| 998 | + OC_App::loadApps(['filesystem', 'logging']); |
|
| 999 | + self::handleLogin($request); |
|
| 1000 | + } |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + if (!self::$CLI) { |
|
| 1004 | + try { |
|
| 1005 | + if (!((bool) $systemConfig->getValue('maintenance', false)) && !\OCP\Util::needUpgrade()) { |
|
| 1006 | + OC_App::loadApps(['filesystem', 'logging']); |
|
| 1007 | + OC_App::loadApps(); |
|
| 1008 | + } |
|
| 1009 | + OC_Util::setupFS(); |
|
| 1010 | + OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo()); |
|
| 1011 | + return; |
|
| 1012 | + } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
| 1013 | + //header('HTTP/1.0 404 Not Found'); |
|
| 1014 | + } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
| 1015 | + http_response_code(405); |
|
| 1016 | + return; |
|
| 1017 | + } |
|
| 1018 | + } |
|
| 1019 | + |
|
| 1020 | + // Handle WebDAV |
|
| 1021 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
| 1022 | + // not allowed any more to prevent people |
|
| 1023 | + // mounting this root directly. |
|
| 1024 | + // Users need to mount remote.php/webdav instead. |
|
| 1025 | + http_response_code(405); |
|
| 1026 | + return; |
|
| 1027 | + } |
|
| 1028 | + |
|
| 1029 | + // Someone is logged in |
|
| 1030 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1031 | + OC_App::loadApps(); |
|
| 1032 | + OC_User::setupBackends(); |
|
| 1033 | + OC_Util::setupFS(); |
|
| 1034 | + // FIXME |
|
| 1035 | + // Redirect to default application |
|
| 1036 | + OC_Util::redirectToDefaultPage(); |
|
| 1037 | + } else { |
|
| 1038 | + // Not handled and not logged in |
|
| 1039 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
| 1040 | + } |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + /** |
|
| 1044 | + * Check login: apache auth, auth token, basic auth |
|
| 1045 | + * |
|
| 1046 | + * @param OCP\IRequest $request |
|
| 1047 | + * @return boolean |
|
| 1048 | + */ |
|
| 1049 | + public static function handleLogin(OCP\IRequest $request) { |
|
| 1050 | + $userSession = self::$server->getUserSession(); |
|
| 1051 | + if (OC_User::handleApacheAuth()) { |
|
| 1052 | + return true; |
|
| 1053 | + } |
|
| 1054 | + if ($userSession->tryTokenLogin($request)) { |
|
| 1055 | + return true; |
|
| 1056 | + } |
|
| 1057 | + if (isset($_COOKIE['nc_username']) |
|
| 1058 | + && isset($_COOKIE['nc_token']) |
|
| 1059 | + && isset($_COOKIE['nc_session_id']) |
|
| 1060 | + && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
| 1061 | + return true; |
|
| 1062 | + } |
|
| 1063 | + if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
| 1064 | + return true; |
|
| 1065 | + } |
|
| 1066 | + return false; |
|
| 1067 | + } |
|
| 1068 | + |
|
| 1069 | + protected static function handleAuthHeaders() { |
|
| 1070 | + //copy http auth headers for apache+php-fcgid work around |
|
| 1071 | + if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
| 1072 | + $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
| 1076 | + $vars = [ |
|
| 1077 | + 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
| 1078 | + 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
| 1079 | + ]; |
|
| 1080 | + foreach ($vars as $var) { |
|
| 1081 | + if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
| 1082 | + $credentials = explode(':', base64_decode($matches[1]), 2); |
|
| 1083 | + if (count($credentials) === 2) { |
|
| 1084 | + $_SERVER['PHP_AUTH_USER'] = $credentials[0]; |
|
| 1085 | + $_SERVER['PHP_AUTH_PW'] = $credentials[1]; |
|
| 1086 | + break; |
|
| 1087 | + } |
|
| 1088 | + } |
|
| 1089 | + } |
|
| 1090 | + } |
|
| 1091 | 1091 | } |
| 1092 | 1092 | |
| 1093 | 1093 | OC::init(); |
@@ -37,72 +37,72 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | interface IRegistrationContext { |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @param string $capability |
|
| 42 | - * @see IAppContainer::registerCapability |
|
| 43 | - * |
|
| 44 | - * @since 20.0.0 |
|
| 45 | - */ |
|
| 46 | - public function registerCapability(string $capability): void; |
|
| 40 | + /** |
|
| 41 | + * @param string $capability |
|
| 42 | + * @see IAppContainer::registerCapability |
|
| 43 | + * |
|
| 44 | + * @since 20.0.0 |
|
| 45 | + */ |
|
| 46 | + public function registerCapability(string $capability): void; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Register a service |
|
| 50 | - * |
|
| 51 | - * @param string $name |
|
| 52 | - * @param callable $factory |
|
| 53 | - * @param bool $shared |
|
| 54 | - * |
|
| 55 | - * @return void |
|
| 56 | - * @see IContainer::registerService() |
|
| 57 | - * |
|
| 58 | - * @since 20.0.0 |
|
| 59 | - */ |
|
| 60 | - public function registerService(string $name, callable $factory, bool $shared = true): void; |
|
| 48 | + /** |
|
| 49 | + * Register a service |
|
| 50 | + * |
|
| 51 | + * @param string $name |
|
| 52 | + * @param callable $factory |
|
| 53 | + * @param bool $shared |
|
| 54 | + * |
|
| 55 | + * @return void |
|
| 56 | + * @see IContainer::registerService() |
|
| 57 | + * |
|
| 58 | + * @since 20.0.0 |
|
| 59 | + */ |
|
| 60 | + public function registerService(string $name, callable $factory, bool $shared = true): void; |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @param string $alias |
|
| 64 | - * @param string $target |
|
| 65 | - * |
|
| 66 | - * @return void |
|
| 67 | - * @see IContainer::registerAlias() |
|
| 68 | - * |
|
| 69 | - * @since 20.0.0 |
|
| 70 | - */ |
|
| 71 | - public function registerServiceAlias(string $alias, string $target): void; |
|
| 62 | + /** |
|
| 63 | + * @param string $alias |
|
| 64 | + * @param string $target |
|
| 65 | + * |
|
| 66 | + * @return void |
|
| 67 | + * @see IContainer::registerAlias() |
|
| 68 | + * |
|
| 69 | + * @since 20.0.0 |
|
| 70 | + */ |
|
| 71 | + public function registerServiceAlias(string $alias, string $target): void; |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @param string $name |
|
| 75 | - * @param mixed $value |
|
| 76 | - * |
|
| 77 | - * @return void |
|
| 78 | - * @see IContainer::registerParameter() |
|
| 79 | - * |
|
| 80 | - * @since 20.0.0 |
|
| 81 | - */ |
|
| 82 | - public function registerParameter(string $name, $value): void; |
|
| 73 | + /** |
|
| 74 | + * @param string $name |
|
| 75 | + * @param mixed $value |
|
| 76 | + * |
|
| 77 | + * @return void |
|
| 78 | + * @see IContainer::registerParameter() |
|
| 79 | + * |
|
| 80 | + * @since 20.0.0 |
|
| 81 | + */ |
|
| 82 | + public function registerParameter(string $name, $value): void; |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Register a service listener |
|
| 86 | - * |
|
| 87 | - * This is equivalent to calling IEventDispatcher::addServiceListener |
|
| 88 | - * |
|
| 89 | - * @param string $event preferably the fully-qualified class name of the Event sub class to listen for |
|
| 90 | - * @param string $listener fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container |
|
| 91 | - * @param int $priority |
|
| 92 | - * |
|
| 93 | - * @see IEventDispatcher::addServiceListener() |
|
| 94 | - * |
|
| 95 | - * @since 20.0.0 |
|
| 96 | - */ |
|
| 97 | - public function registerEventListener(string $event, string $listener, int $priority = 0): void; |
|
| 84 | + /** |
|
| 85 | + * Register a service listener |
|
| 86 | + * |
|
| 87 | + * This is equivalent to calling IEventDispatcher::addServiceListener |
|
| 88 | + * |
|
| 89 | + * @param string $event preferably the fully-qualified class name of the Event sub class to listen for |
|
| 90 | + * @param string $listener fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container |
|
| 91 | + * @param int $priority |
|
| 92 | + * |
|
| 93 | + * @see IEventDispatcher::addServiceListener() |
|
| 94 | + * |
|
| 95 | + * @since 20.0.0 |
|
| 96 | + */ |
|
| 97 | + public function registerEventListener(string $event, string $listener, int $priority = 0): void; |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * @param string $class |
|
| 101 | - * |
|
| 102 | - * @return void |
|
| 103 | - * @see IAppContainer::registerMiddleWare() |
|
| 104 | - * |
|
| 105 | - * @since 20.0.0 |
|
| 106 | - */ |
|
| 107 | - public function registerMiddleware(string $class): void; |
|
| 99 | + /** |
|
| 100 | + * @param string $class |
|
| 101 | + * |
|
| 102 | + * @return void |
|
| 103 | + * @see IAppContainer::registerMiddleWare() |
|
| 104 | + * |
|
| 105 | + * @since 20.0.0 |
|
| 106 | + */ |
|
| 107 | + public function registerMiddleware(string $class): void; |
|
| 108 | 108 | } |