StatusController.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Encryption\Controller;
  8. use OCA\Encryption\Session;
  9. use OCP\AppFramework\Controller;
  10. use OCP\AppFramework\Http\Attribute\NoAdminRequired;
  11. use OCP\AppFramework\Http\DataResponse;
  12. use OCP\Encryption\IManager;
  13. use OCP\IL10N;
  14. use OCP\IRequest;
  15. class StatusController extends Controller {
  16. /** @var IL10N */
  17. private $l;
  18. /** @var Session */
  19. private $session;
  20. /** @var IManager */
  21. private $encryptionManager;
  22. /**
  23. * @param string $AppName
  24. * @param IRequest $request
  25. * @param IL10N $l10n
  26. * @param Session $session
  27. * @param IManager $encryptionManager
  28. */
  29. public function __construct($AppName,
  30. IRequest $request,
  31. IL10N $l10n,
  32. Session $session,
  33. IManager $encryptionManager,
  34. ) {
  35. parent::__construct($AppName, $request);
  36. $this->l = $l10n;
  37. $this->session = $session;
  38. $this->encryptionManager = $encryptionManager;
  39. }
  40. /**
  41. * @return DataResponse
  42. */
  43. #[NoAdminRequired]
  44. public function getStatus() {
  45. $status = 'error';
  46. $message = 'no valid init status';
  47. switch ($this->session->getStatus()) {
  48. case Session::INIT_EXECUTED:
  49. $status = 'interactionNeeded';
  50. $message = $this->l->t(
  51. 'Invalid private key for encryption app. Please update your private key password in your personal settings to recover access to your encrypted files.'
  52. );
  53. break;
  54. case Session::NOT_INITIALIZED:
  55. $status = 'interactionNeeded';
  56. if ($this->encryptionManager->isEnabled()) {
  57. $message = $this->l->t(
  58. 'Encryption App is enabled, but your keys are not initialized. Please log-out and log-in again.'
  59. );
  60. } else {
  61. $message = $this->l->t(
  62. 'Please enable server side encryption in the admin settings in order to use the encryption module.'
  63. );
  64. }
  65. break;
  66. case Session::INIT_SUCCESSFUL:
  67. $status = 'success';
  68. $message = $this->l->t('Encryption app is enabled and ready');
  69. }
  70. return new DataResponse(
  71. [
  72. 'status' => $status,
  73. 'data' => [
  74. 'message' => $message]
  75. ]
  76. );
  77. }
  78. }