Application.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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\MimeTypeMigrationAvailable;
  69. use OCA\Settings\SetupChecks\MysqlUnicodeSupport;
  70. use OCA\Settings\SetupChecks\OverwriteCliUrl;
  71. use OCA\Settings\SetupChecks\PhpDefaultCharset;
  72. use OCA\Settings\SetupChecks\PhpDisabledFunctions;
  73. use OCA\Settings\SetupChecks\PhpFreetypeSupport;
  74. use OCA\Settings\SetupChecks\PhpGetEnv;
  75. use OCA\Settings\SetupChecks\PhpMemoryLimit;
  76. use OCA\Settings\SetupChecks\PhpModules;
  77. use OCA\Settings\SetupChecks\PhpOpcacheSetup;
  78. use OCA\Settings\SetupChecks\PhpOutdated;
  79. use OCA\Settings\SetupChecks\PhpOutputBuffering;
  80. use OCA\Settings\SetupChecks\PushService;
  81. use OCA\Settings\SetupChecks\RandomnessSecure;
  82. use OCA\Settings\SetupChecks\ReadOnlyConfig;
  83. use OCA\Settings\SetupChecks\SchedulingTableSize;
  84. use OCA\Settings\SetupChecks\SupportedDatabase;
  85. use OCA\Settings\SetupChecks\SystemIs64bit;
  86. use OCA\Settings\SetupChecks\TempSpaceAvailable;
  87. use OCA\Settings\SetupChecks\TransactionIsolation;
  88. use OCA\Settings\UserMigration\AccountMigrator;
  89. use OCA\Settings\WellKnown\ChangePasswordHandler;
  90. use OCA\Settings\WellKnown\SecurityTxtHandler;
  91. use OCP\AppFramework\App;
  92. use OCP\AppFramework\Bootstrap\IBootContext;
  93. use OCP\AppFramework\Bootstrap\IBootstrap;
  94. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  95. use OCP\AppFramework\IAppContainer;
  96. use OCP\Defaults;
  97. use OCP\Group\Events\GroupDeletedEvent;
  98. use OCP\Group\Events\UserAddedEvent;
  99. use OCP\Group\Events\UserRemovedEvent;
  100. use OCP\IServerContainer;
  101. use OCP\Settings\IManager;
  102. use OCP\Util;
  103. class Application extends App implements IBootstrap {
  104. public const APP_ID = 'settings';
  105. /**
  106. * @param array $urlParams
  107. */
  108. public function __construct(array $urlParams = []) {
  109. parent::__construct(self::APP_ID, $urlParams);
  110. }
  111. public function register(IRegistrationContext $context): void {
  112. // Register Middleware
  113. $context->registerServiceAlias('SubadminMiddleware', SubadminMiddleware::class);
  114. $context->registerMiddleware(SubadminMiddleware::class);
  115. $context->registerSearchProvider(SectionSearch::class);
  116. $context->registerSearchProvider(AppSearch::class);
  117. $context->registerSearchProvider(UserSearch::class);
  118. // Register listeners
  119. $context->registerEventListener(AppPasswordCreatedEvent::class, AppPasswordCreatedActivityListener::class);
  120. $context->registerEventListener(UserAddedEvent::class, UserAddedToGroupActivityListener::class);
  121. $context->registerEventListener(UserRemovedEvent::class, UserRemovedFromGroupActivityListener::class);
  122. $context->registerEventListener(GroupDeletedEvent::class, GroupRemovedListener::class);
  123. // Register well-known handlers
  124. $context->registerWellKnownHandler(SecurityTxtHandler::class);
  125. $context->registerWellKnownHandler(ChangePasswordHandler::class);
  126. /**
  127. * Core class wrappers
  128. */
  129. /** FIXME: Remove once OC_SubAdmin is non-static and mockable */
  130. $context->registerService('isSubAdmin', function () {
  131. $userObject = \OC::$server->getUserSession()->getUser();
  132. $isSubAdmin = false;
  133. if ($userObject !== null) {
  134. $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
  135. }
  136. return $isSubAdmin;
  137. });
  138. $context->registerService(IProvider::class, function (IAppContainer $appContainer) {
  139. /** @var IServerContainer $serverContainer */
  140. $serverContainer = $appContainer->query(IServerContainer::class);
  141. return $serverContainer->query(IProvider::class);
  142. });
  143. $context->registerService(IManager::class, function (IAppContainer $appContainer) {
  144. /** @var IServerContainer $serverContainer */
  145. $serverContainer = $appContainer->query(IServerContainer::class);
  146. return $serverContainer->getSettingsManager();
  147. });
  148. $context->registerService(NewUserMailHelper::class, function (IAppContainer $appContainer) {
  149. /** @var Server $server */
  150. $server = $appContainer->query(IServerContainer::class);
  151. /** @var Defaults $defaults */
  152. $defaults = $server->query(Defaults::class);
  153. return new NewUserMailHelper(
  154. $defaults,
  155. $server->getURLGenerator(),
  156. $server->getL10NFactory(),
  157. $server->getMailer(),
  158. $server->getSecureRandom(),
  159. new TimeFactory(),
  160. $server->getConfig(),
  161. $server->getCrypto(),
  162. Util::getDefaultEmailAddress('no-reply')
  163. );
  164. });
  165. $context->registerSetupCheck(AppDirsWithDifferentOwner::class);
  166. $context->registerSetupCheck(BruteForceThrottler::class);
  167. $context->registerSetupCheck(CheckUserCertificates::class);
  168. $context->registerSetupCheck(CodeIntegrity::class);
  169. $context->registerSetupCheck(CronErrors::class);
  170. $context->registerSetupCheck(CronInfo::class);
  171. $context->registerSetupCheck(DatabaseHasMissingColumns::class);
  172. $context->registerSetupCheck(DatabaseHasMissingIndices::class);
  173. $context->registerSetupCheck(DatabaseHasMissingPrimaryKeys::class);
  174. $context->registerSetupCheck(DatabasePendingBigIntConversions::class);
  175. $context->registerSetupCheck(DebugMode::class);
  176. $context->registerSetupCheck(DefaultPhoneRegionSet::class);
  177. $context->registerSetupCheck(EmailTestSuccessful::class);
  178. $context->registerSetupCheck(FileLocking::class);
  179. $context->registerSetupCheck(ForwardedForHeaders::class);
  180. $context->registerSetupCheck(InternetConnectivity::class);
  181. $context->registerSetupCheck(JavaScriptModules::class);
  182. $context->registerSetupCheck(LegacySSEKeyFormat::class);
  183. $context->registerSetupCheck(MaintenanceWindowStart::class);
  184. $context->registerSetupCheck(MemcacheConfigured::class);
  185. $context->registerSetupCheck(MimeTypeMigrationAvailable::class);
  186. $context->registerSetupCheck(MysqlUnicodeSupport::class);
  187. $context->registerSetupCheck(OverwriteCliUrl::class);
  188. $context->registerSetupCheck(PhpDefaultCharset::class);
  189. $context->registerSetupCheck(PhpDisabledFunctions::class);
  190. $context->registerSetupCheck(PhpFreetypeSupport::class);
  191. $context->registerSetupCheck(PhpGetEnv::class);
  192. $context->registerSetupCheck(PhpMemoryLimit::class);
  193. $context->registerSetupCheck(PhpModules::class);
  194. $context->registerSetupCheck(PhpOpcacheSetup::class);
  195. $context->registerSetupCheck(PhpOutdated::class);
  196. $context->registerSetupCheck(PhpOutputBuffering::class);
  197. $context->registerSetupCheck(RandomnessSecure::class);
  198. $context->registerSetupCheck(ReadOnlyConfig::class);
  199. $context->registerSetupCheck(SchedulingTableSize::class);
  200. $context->registerSetupCheck(SupportedDatabase::class);
  201. $context->registerSetupCheck(SystemIs64bit::class);
  202. $context->registerSetupCheck(TempSpaceAvailable::class);
  203. $context->registerSetupCheck(TransactionIsolation::class);
  204. $context->registerSetupCheck(PushService::class);
  205. $context->registerUserMigrator(AccountMigrator::class);
  206. }
  207. public function boot(IBootContext $context): void {
  208. Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword');
  209. Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo');
  210. }
  211. /**
  212. * @param array $parameters
  213. * @throws \InvalidArgumentException
  214. * @throws \BadMethodCallException
  215. * @throws \Exception
  216. * @throws \OCP\AppFramework\QueryException
  217. */
  218. public function onChangePassword(array $parameters) {
  219. /** @var Hooks $hooks */
  220. $hooks = $this->getContainer()->query(Hooks::class);
  221. $hooks->onChangePassword($parameters['uid']);
  222. }
  223. /**
  224. * @param array $parameters
  225. * @throws \InvalidArgumentException
  226. * @throws \BadMethodCallException
  227. * @throws \Exception
  228. * @throws \OCP\AppFramework\QueryException
  229. */
  230. public function onChangeInfo(array $parameters) {
  231. if ($parameters['feature'] !== 'eMailAddress') {
  232. return;
  233. }
  234. /** @var Hooks $hooks */
  235. $hooks = $this->getContainer()->query(Hooks::class);
  236. $hooks->onChangeEmail($parameters['user'], $parameters['old_value']);
  237. }
  238. }