Application.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. * @author Björn Schießle <bjoern@schiessle.org>
  8. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  9. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  10. * @author Joas Schilling <coding@schilljs.com>
  11. * @author Lukas Reschke <lukas@statuscode.ch>
  12. * @author Morris Jobke <hey@morrisjobke.de>
  13. * @author Robin Appelman <robin@icewind.nl>
  14. * @author Roeland Jago Douma <roeland@famdouma.nl>
  15. * @author zulan <git@zulan.net>
  16. * @author Stephan Orbaugh <stephan.orbaugh@nextcloud.com>
  17. *
  18. * @license AGPL-3.0
  19. *
  20. * This code is free software: you can redistribute it and/or modify
  21. * it under the terms of the GNU Affero General Public License, version 3,
  22. * as published by the Free Software Foundation.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU Affero General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU Affero General Public License, version 3,
  30. * along with this program. If not, see <http://www.gnu.org/licenses/>
  31. *
  32. */
  33. namespace OCA\Settings\AppInfo;
  34. use OC\AppFramework\Utility\TimeFactory;
  35. use OC\Authentication\Events\AppPasswordCreatedEvent;
  36. use OC\Authentication\Token\IProvider;
  37. use OC\Server;
  38. use OCA\Settings\Hooks;
  39. use OCA\Settings\Listener\AppPasswordCreatedActivityListener;
  40. use OCA\Settings\Listener\GroupRemovedListener;
  41. use OCA\Settings\Listener\UserAddedToGroupActivityListener;
  42. use OCA\Settings\Listener\UserRemovedFromGroupActivityListener;
  43. use OCA\Settings\Mailer\NewUserMailHelper;
  44. use OCA\Settings\Middleware\SubadminMiddleware;
  45. use OCA\Settings\Search\AppSearch;
  46. use OCA\Settings\Search\SectionSearch;
  47. use OCA\Settings\Search\UserSearch;
  48. use OCA\Settings\SetupChecks\AppDirsWithDifferentOwner;
  49. use OCA\Settings\SetupChecks\BruteForceThrottler;
  50. use OCA\Settings\SetupChecks\CheckUserCertificates;
  51. use OCA\Settings\SetupChecks\CodeIntegrity;
  52. use OCA\Settings\SetupChecks\CronErrors;
  53. use OCA\Settings\SetupChecks\CronInfo;
  54. use OCA\Settings\SetupChecks\DatabaseHasMissingColumns;
  55. use OCA\Settings\SetupChecks\DatabaseHasMissingIndices;
  56. use OCA\Settings\SetupChecks\DatabaseHasMissingPrimaryKeys;
  57. use OCA\Settings\SetupChecks\DatabasePendingBigIntConversions;
  58. use OCA\Settings\SetupChecks\DebugMode;
  59. use OCA\Settings\SetupChecks\DefaultPhoneRegionSet;
  60. use OCA\Settings\SetupChecks\EmailTestSuccessful;
  61. use OCA\Settings\SetupChecks\FileLocking;
  62. use OCA\Settings\SetupChecks\ForwardedForHeaders;
  63. use OCA\Settings\SetupChecks\InternetConnectivity;
  64. use OCA\Settings\SetupChecks\JavaScriptModules;
  65. use OCA\Settings\SetupChecks\LegacySSEKeyFormat;
  66. use OCA\Settings\SetupChecks\MaintenanceWindowStart;
  67. use OCA\Settings\SetupChecks\MemcacheConfigured;
  68. use OCA\Settings\SetupChecks\MysqlUnicodeSupport;
  69. use OCA\Settings\SetupChecks\OverwriteCliUrl;
  70. use OCA\Settings\SetupChecks\PhpDefaultCharset;
  71. use OCA\Settings\SetupChecks\PhpDisabledFunctions;
  72. use OCA\Settings\SetupChecks\PhpFreetypeSupport;
  73. use OCA\Settings\SetupChecks\PhpGetEnv;
  74. use OCA\Settings\SetupChecks\PhpMemoryLimit;
  75. use OCA\Settings\SetupChecks\PhpModules;
  76. use OCA\Settings\SetupChecks\PhpOpcacheSetup;
  77. use OCA\Settings\SetupChecks\PhpOutdated;
  78. use OCA\Settings\SetupChecks\PhpOutputBuffering;
  79. use OCA\Settings\SetupChecks\PushService;
  80. use OCA\Settings\SetupChecks\RandomnessSecure;
  81. use OCA\Settings\SetupChecks\ReadOnlyConfig;
  82. use OCA\Settings\SetupChecks\SupportedDatabase;
  83. use OCA\Settings\SetupChecks\SystemIs64bit;
  84. use OCA\Settings\SetupChecks\TempSpaceAvailable;
  85. use OCA\Settings\SetupChecks\TransactionIsolation;
  86. use OCA\Settings\SetupChecks\Woff2Loading;
  87. use OCA\Settings\UserMigration\AccountMigrator;
  88. use OCA\Settings\WellKnown\ChangePasswordHandler;
  89. use OCA\Settings\WellKnown\SecurityTxtHandler;
  90. use OCP\AppFramework\App;
  91. use OCP\AppFramework\Bootstrap\IBootContext;
  92. use OCP\AppFramework\Bootstrap\IBootstrap;
  93. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  94. use OCP\AppFramework\IAppContainer;
  95. use OCP\Defaults;
  96. use OCP\Group\Events\GroupDeletedEvent;
  97. use OCP\Group\Events\UserAddedEvent;
  98. use OCP\Group\Events\UserRemovedEvent;
  99. use OCP\IServerContainer;
  100. use OCP\Settings\IManager;
  101. use OCP\Util;
  102. class Application extends App implements IBootstrap {
  103. public const APP_ID = 'settings';
  104. /**
  105. * @param array $urlParams
  106. */
  107. public function __construct(array $urlParams = []) {
  108. parent::__construct(self::APP_ID, $urlParams);
  109. }
  110. public function register(IRegistrationContext $context): void {
  111. // Register Middleware
  112. $context->registerServiceAlias('SubadminMiddleware', SubadminMiddleware::class);
  113. $context->registerMiddleware(SubadminMiddleware::class);
  114. $context->registerSearchProvider(SectionSearch::class);
  115. $context->registerSearchProvider(AppSearch::class);
  116. $context->registerSearchProvider(UserSearch::class);
  117. // Register listeners
  118. $context->registerEventListener(AppPasswordCreatedEvent::class, AppPasswordCreatedActivityListener::class);
  119. $context->registerEventListener(UserAddedEvent::class, UserAddedToGroupActivityListener::class);
  120. $context->registerEventListener(UserRemovedEvent::class, UserRemovedFromGroupActivityListener::class);
  121. $context->registerEventListener(GroupDeletedEvent::class, GroupRemovedListener::class);
  122. // Register well-known handlers
  123. $context->registerWellKnownHandler(SecurityTxtHandler::class);
  124. $context->registerWellKnownHandler(ChangePasswordHandler::class);
  125. /**
  126. * Core class wrappers
  127. */
  128. /** FIXME: Remove once OC_SubAdmin is non-static and mockable */
  129. $context->registerService('isSubAdmin', function () {
  130. $userObject = \OC::$server->getUserSession()->getUser();
  131. $isSubAdmin = false;
  132. if ($userObject !== null) {
  133. $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
  134. }
  135. return $isSubAdmin;
  136. });
  137. $context->registerService(IProvider::class, function (IAppContainer $appContainer) {
  138. /** @var IServerContainer $serverContainer */
  139. $serverContainer = $appContainer->query(IServerContainer::class);
  140. return $serverContainer->query(IProvider::class);
  141. });
  142. $context->registerService(IManager::class, function (IAppContainer $appContainer) {
  143. /** @var IServerContainer $serverContainer */
  144. $serverContainer = $appContainer->query(IServerContainer::class);
  145. return $serverContainer->getSettingsManager();
  146. });
  147. $context->registerService(NewUserMailHelper::class, function (IAppContainer $appContainer) {
  148. /** @var Server $server */
  149. $server = $appContainer->query(IServerContainer::class);
  150. /** @var Defaults $defaults */
  151. $defaults = $server->query(Defaults::class);
  152. return new NewUserMailHelper(
  153. $defaults,
  154. $server->getURLGenerator(),
  155. $server->getL10NFactory(),
  156. $server->getMailer(),
  157. $server->getSecureRandom(),
  158. new TimeFactory(),
  159. $server->getConfig(),
  160. $server->getCrypto(),
  161. Util::getDefaultEmailAddress('no-reply')
  162. );
  163. });
  164. $context->registerSetupCheck(AppDirsWithDifferentOwner::class);
  165. $context->registerSetupCheck(BruteForceThrottler::class);
  166. $context->registerSetupCheck(CheckUserCertificates::class);
  167. $context->registerSetupCheck(CodeIntegrity::class);
  168. $context->registerSetupCheck(CronErrors::class);
  169. $context->registerSetupCheck(CronInfo::class);
  170. $context->registerSetupCheck(DatabaseHasMissingColumns::class);
  171. $context->registerSetupCheck(DatabaseHasMissingIndices::class);
  172. $context->registerSetupCheck(DatabaseHasMissingPrimaryKeys::class);
  173. $context->registerSetupCheck(DatabasePendingBigIntConversions::class);
  174. $context->registerSetupCheck(DebugMode::class);
  175. $context->registerSetupCheck(DefaultPhoneRegionSet::class);
  176. $context->registerSetupCheck(EmailTestSuccessful::class);
  177. $context->registerSetupCheck(FileLocking::class);
  178. $context->registerSetupCheck(ForwardedForHeaders::class);
  179. $context->registerSetupCheck(InternetConnectivity::class);
  180. $context->registerSetupCheck(JavaScriptModules::class);
  181. $context->registerSetupCheck(LegacySSEKeyFormat::class);
  182. $context->registerSetupCheck(MaintenanceWindowStart::class);
  183. $context->registerSetupCheck(MemcacheConfigured::class);
  184. $context->registerSetupCheck(MysqlUnicodeSupport::class);
  185. $context->registerSetupCheck(OverwriteCliUrl::class);
  186. $context->registerSetupCheck(PhpDefaultCharset::class);
  187. $context->registerSetupCheck(PhpDisabledFunctions::class);
  188. $context->registerSetupCheck(PhpFreetypeSupport::class);
  189. $context->registerSetupCheck(PhpGetEnv::class);
  190. $context->registerSetupCheck(PhpMemoryLimit::class);
  191. $context->registerSetupCheck(PhpModules::class);
  192. $context->registerSetupCheck(PhpOpcacheSetup::class);
  193. $context->registerSetupCheck(PhpOutdated::class);
  194. $context->registerSetupCheck(PhpOutputBuffering::class);
  195. $context->registerSetupCheck(RandomnessSecure::class);
  196. $context->registerSetupCheck(ReadOnlyConfig::class);
  197. $context->registerSetupCheck(SupportedDatabase::class);
  198. $context->registerSetupCheck(SystemIs64bit::class);
  199. $context->registerSetupCheck(TempSpaceAvailable::class);
  200. $context->registerSetupCheck(TransactionIsolation::class);
  201. $context->registerSetupCheck(PushService::class);
  202. $context->registerSetupCheck(Woff2Loading::class);
  203. $context->registerUserMigrator(AccountMigrator::class);
  204. }
  205. public function boot(IBootContext $context): void {
  206. Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword');
  207. Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo');
  208. }
  209. /**
  210. * @param array $parameters
  211. * @throws \InvalidArgumentException
  212. * @throws \BadMethodCallException
  213. * @throws \Exception
  214. * @throws \OCP\AppFramework\QueryException
  215. */
  216. public function onChangePassword(array $parameters) {
  217. /** @var Hooks $hooks */
  218. $hooks = $this->getContainer()->query(Hooks::class);
  219. $hooks->onChangePassword($parameters['uid']);
  220. }
  221. /**
  222. * @param array $parameters
  223. * @throws \InvalidArgumentException
  224. * @throws \BadMethodCallException
  225. * @throws \Exception
  226. * @throws \OCP\AppFramework\QueryException
  227. */
  228. public function onChangeInfo(array $parameters) {
  229. if ($parameters['feature'] !== 'eMailAddress') {
  230. return;
  231. }
  232. /** @var Hooks $hooks */
  233. $hooks = $this->getContainer()->query(Hooks::class);
  234. $hooks->onChangeEmail($parameters['user'], $parameters['old_value']);
  235. }
  236. }