StatusController.php 1.9 KB

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