StatusController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Björn Schießle <bjoern@schiessle.org>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OCA\Encryption\Controller;
  28. use OCA\Encryption\Session;
  29. use OCP\AppFramework\Controller;
  30. use OCP\AppFramework\Http\DataResponse;
  31. use OCP\Encryption\IManager;
  32. use OCP\IL10N;
  33. use OCP\IRequest;
  34. class StatusController extends Controller {
  35. /** @var IL10N */
  36. private $l;
  37. /** @var Session */
  38. private $session;
  39. /** @var IManager */
  40. private $encryptionManager;
  41. /**
  42. * @param string $AppName
  43. * @param IRequest $request
  44. * @param IL10N $l10n
  45. * @param Session $session
  46. * @param IManager $encryptionManager
  47. */
  48. public function __construct($AppName,
  49. IRequest $request,
  50. IL10N $l10n,
  51. Session $session,
  52. IManager $encryptionManager
  53. ) {
  54. parent::__construct($AppName, $request);
  55. $this->l = $l10n;
  56. $this->session = $session;
  57. $this->encryptionManager = $encryptionManager;
  58. }
  59. /**
  60. * @NoAdminRequired
  61. * @return DataResponse
  62. */
  63. public function getStatus() {
  64. $status = 'error';
  65. $message = 'no valid init status';
  66. switch ($this->session->getStatus()) {
  67. case Session::INIT_EXECUTED:
  68. $status = 'interactionNeeded';
  69. $message = $this->l->t(
  70. 'Invalid private key for encryption app. Please update your private key password in your personal settings to recover access to your encrypted files.'
  71. );
  72. break;
  73. case Session::NOT_INITIALIZED:
  74. $status = 'interactionNeeded';
  75. if ($this->encryptionManager->isEnabled()) {
  76. $message = $this->l->t(
  77. 'Encryption App is enabled, but your keys are not initialized. Please log-out and log-in again.'
  78. );
  79. } else {
  80. $message = $this->l->t(
  81. 'Please enable server side encryption in the admin settings in order to use the encryption module.'
  82. );
  83. }
  84. break;
  85. case Session::INIT_SUCCESSFUL:
  86. $status = 'success';
  87. $message = $this->l->t('Encryption app is enabled and ready');
  88. }
  89. return new DataResponse(
  90. [
  91. 'status' => $status,
  92. 'data' => [
  93. 'message' => $message]
  94. ]
  95. );
  96. }
  97. }