1
0

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