CheckSetupController.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Cthulhux <git@tuxproject.de>
  8. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  9. * @author Derek <derek.kelly27@gmail.com>
  10. * @author Georg Ehrke <oc.list@georgehrke.com>
  11. * @author J0WI <J0WI@users.noreply.github.com>
  12. * @author Joas Schilling <coding@schilljs.com>
  13. * @author Julius Härtl <jus@bitgrid.net>
  14. * @author Ko- <k.stoffelen@cs.ru.nl>
  15. * @author Lauris Binde <laurisb@users.noreply.github.com>
  16. * @author Lukas Reschke <lukas@statuscode.ch>
  17. * @author Michael Weimann <mail@michael-weimann.eu>
  18. * @author Morris Jobke <hey@morrisjobke.de>
  19. * @author nhirokinet <nhirokinet@nhiroki.net>
  20. * @author Robin Appelman <robin@icewind.nl>
  21. * @author Robin McCorkell <robin@mccorkell.me.uk>
  22. * @author Roeland Jago Douma <roeland@famdouma.nl>
  23. * @author Sven Strickroth <email@cs-ware.de>
  24. * @author Sylvia van Os <sylvia@hackerchick.me>
  25. * @author timm2k <timm2k@gmx.de>
  26. * @author Timo Förster <tfoerster@webfoersterei.de>
  27. * @author Valdnet <47037905+Valdnet@users.noreply.github.com>
  28. * @author MichaIng <micha@dietpi.com>
  29. * @author Kate Döen <kate.doeen@nextcloud.com>
  30. *
  31. * @license AGPL-3.0
  32. *
  33. * This code is free software: you can redistribute it and/or modify
  34. * it under the terms of the GNU Affero General Public License, version 3,
  35. * as published by the Free Software Foundation.
  36. *
  37. * This program is distributed in the hope that it will be useful,
  38. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  39. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  40. * GNU Affero General Public License for more details.
  41. *
  42. * You should have received a copy of the GNU Affero General Public License, version 3,
  43. * along with this program. If not, see <http://www.gnu.org/licenses/>
  44. *
  45. */
  46. namespace OCA\Settings\Controller;
  47. use OC\AppFramework\Http;
  48. use OC\IntegrityCheck\Checker;
  49. use OCP\AppFramework\Controller;
  50. use OCP\AppFramework\Http\Attribute\OpenAPI;
  51. use OCP\AppFramework\Http\DataDisplayResponse;
  52. use OCP\AppFramework\Http\DataResponse;
  53. use OCP\AppFramework\Http\RedirectResponse;
  54. use OCP\IConfig;
  55. use OCP\IL10N;
  56. use OCP\IRequest;
  57. use OCP\IURLGenerator;
  58. use OCP\SetupCheck\ISetupCheckManager;
  59. use Psr\Log\LoggerInterface;
  60. #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
  61. class CheckSetupController extends Controller {
  62. /** @var IConfig */
  63. private $config;
  64. /** @var IURLGenerator */
  65. private $urlGenerator;
  66. /** @var IL10N */
  67. private $l10n;
  68. /** @var Checker */
  69. private $checker;
  70. /** @var LoggerInterface */
  71. private $logger;
  72. private ISetupCheckManager $setupCheckManager;
  73. public function __construct($AppName,
  74. IRequest $request,
  75. IConfig $config,
  76. IURLGenerator $urlGenerator,
  77. IL10N $l10n,
  78. Checker $checker,
  79. LoggerInterface $logger,
  80. ISetupCheckManager $setupCheckManager,
  81. ) {
  82. parent::__construct($AppName, $request);
  83. $this->config = $config;
  84. $this->urlGenerator = $urlGenerator;
  85. $this->l10n = $l10n;
  86. $this->checker = $checker;
  87. $this->logger = $logger;
  88. $this->setupCheckManager = $setupCheckManager;
  89. }
  90. /**
  91. * @NoAdminRequired
  92. * @NoCSRFRequired
  93. * @return DataResponse
  94. */
  95. public function setupCheckManager(): DataResponse {
  96. return new DataResponse($this->setupCheckManager->runAll());
  97. }
  98. /**
  99. * @NoCSRFRequired
  100. * @return RedirectResponse
  101. * @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\Overview)
  102. */
  103. public function rescanFailedIntegrityCheck(): RedirectResponse {
  104. $this->checker->runInstanceVerification();
  105. return new RedirectResponse(
  106. $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'overview'])
  107. );
  108. }
  109. /**
  110. * @NoCSRFRequired
  111. * @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\Overview)
  112. */
  113. public function getFailedIntegrityCheckFiles(): DataDisplayResponse {
  114. if (!$this->checker->isCodeCheckEnforced()) {
  115. return new DataDisplayResponse('Integrity checker has been disabled. Integrity cannot be verified.');
  116. }
  117. $completeResults = $this->checker->getResults();
  118. if ($completeResults === null) {
  119. return new DataDisplayResponse('Integrity checker has not been run. Integrity information not available.');
  120. }
  121. if (!empty($completeResults)) {
  122. $formattedTextResponse = 'Technical information
  123. =====================
  124. The following list covers which files have failed the integrity check. Please read
  125. the previous linked documentation to learn more about the errors and how to fix
  126. them.
  127. Results
  128. =======
  129. ';
  130. foreach ($completeResults as $context => $contextResult) {
  131. $formattedTextResponse .= "- $context\n";
  132. foreach ($contextResult as $category => $result) {
  133. $formattedTextResponse .= "\t- $category\n";
  134. if ($category !== 'EXCEPTION') {
  135. foreach ($result as $key => $results) {
  136. $formattedTextResponse .= "\t\t- $key\n";
  137. }
  138. } else {
  139. foreach ($result as $key => $results) {
  140. $formattedTextResponse .= "\t\t- $results\n";
  141. }
  142. }
  143. }
  144. }
  145. $formattedTextResponse .= '
  146. Raw output
  147. ==========
  148. ';
  149. $formattedTextResponse .= print_r($completeResults, true);
  150. } else {
  151. $formattedTextResponse = 'No errors have been found.';
  152. }
  153. return new DataDisplayResponse(
  154. $formattedTextResponse,
  155. Http::STATUS_OK,
  156. [
  157. 'Content-Type' => 'text/plain',
  158. ]
  159. );
  160. }
  161. /**
  162. * @return DataResponse
  163. * @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\Overview)
  164. */
  165. public function check() {
  166. return new DataResponse(
  167. [
  168. 'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'),
  169. 'reverseProxyGeneratedURL' => $this->urlGenerator->getAbsoluteURL('index.php'),
  170. 'generic' => $this->setupCheckManager->runAll(),
  171. ]
  172. );
  173. }
  174. }