StatusController.php 2.1 KB

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