CodeIntegrity.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Settings\SetupChecks;
  8. use OC\IntegrityCheck\Checker;
  9. use OCP\IL10N;
  10. use OCP\IURLGenerator;
  11. use OCP\SetupCheck\ISetupCheck;
  12. use OCP\SetupCheck\SetupResult;
  13. class CodeIntegrity implements ISetupCheck {
  14. public function __construct(
  15. private IL10N $l10n,
  16. private IURLGenerator $urlGenerator,
  17. private Checker $checker,
  18. ) {
  19. }
  20. public function getName(): string {
  21. return $this->l10n->t('Code integrity');
  22. }
  23. public function getCategory(): string {
  24. return 'security';
  25. }
  26. public function run(): SetupResult {
  27. if (!$this->checker->isCodeCheckEnforced()) {
  28. return SetupResult::info($this->l10n->t('Integrity checker has been disabled. Integrity cannot be verified.'));
  29. }
  30. // If there are no results we need to run the verification
  31. if ($this->checker->getResults() === null) {
  32. $this->checker->runInstanceVerification();
  33. }
  34. if ($this->checker->hasPassedCheck()) {
  35. return SetupResult::success($this->l10n->t('No altered files'));
  36. } else {
  37. return SetupResult::error(
  38. $this->l10n->t('Some files have not passed the integrity check. {link1} {link2}'),
  39. $this->urlGenerator->linkToDocs('admin-code-integrity'),
  40. [
  41. 'link1' => [
  42. 'type' => 'highlight',
  43. 'id' => 'getFailedIntegrityCheckFiles',
  44. 'name' => 'List of invalid files…',
  45. 'link' => $this->urlGenerator->linkToRoute('settings.CheckSetup.getFailedIntegrityCheckFiles'),
  46. ],
  47. 'link2' => [
  48. 'type' => 'highlight',
  49. 'id' => 'rescanFailedIntegrityCheck',
  50. 'name' => 'Rescan…',
  51. 'link' => $this->urlGenerator->linkToRoute('settings.CheckSetup.rescanFailedIntegrityCheck'),
  52. ],
  53. ],
  54. );
  55. }
  56. }
  57. }