1
0

StatusController.php 2.6 KB

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