You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

adminrecovery.php 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * @author Björn Schießle <schiessle@owncloud.com>
  4. * @author Florin Peter <github@florin-peter.de>
  5. * @author Joas Schilling <nickvergessen@owncloud.com>
  6. * @author Lukas Reschke <lukas@owncloud.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Robin Appelman <icewind@owncloud.com>
  9. * @author Sam Tuke <mail@samtuke.com>
  10. *
  11. * @copyright Copyright (c) 2015, ownCloud, Inc.
  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. use OCA\Files_Encryption\Helper;
  28. \OCP\JSON::checkAdminUser();
  29. \OCP\JSON::checkAppEnabled('files_encryption');
  30. \OCP\JSON::callCheck();
  31. $l = \OC::$server->getL10N('files_encryption');
  32. $return = false;
  33. $errorMessage = $l->t("Unknown error");
  34. //check if both passwords are the same
  35. if (empty($_POST['recoveryPassword'])) {
  36. $errorMessage = $l->t('Missing recovery key password');
  37. \OCP\JSON::error(array('data' => array('message' => $errorMessage)));
  38. exit();
  39. }
  40. if (empty($_POST['confirmPassword'])) {
  41. $errorMessage = $l->t('Please repeat the recovery key password');
  42. \OCP\JSON::error(array('data' => array('message' => $errorMessage)));
  43. exit();
  44. }
  45. if ($_POST['recoveryPassword'] !== $_POST['confirmPassword']) {
  46. $errorMessage = $l->t('Repeated recovery key password does not match the provided recovery key password');
  47. \OCP\JSON::error(array('data' => array('message' => $errorMessage)));
  48. exit();
  49. }
  50. // Enable recoveryAdmin
  51. $recoveryKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryKeyId');
  52. if (isset($_POST['adminEnableRecovery']) && $_POST['adminEnableRecovery'] === '1') {
  53. $return = Helper::adminEnableRecovery($recoveryKeyId, (string)$_POST['recoveryPassword']);
  54. // Return success or failure
  55. if ($return) {
  56. $successMessage = $l->t('Recovery key successfully enabled');
  57. } else {
  58. $errorMessage = $l->t('Could not disable recovery key. Please check your recovery key password!');
  59. }
  60. // Disable recoveryAdmin
  61. } elseif (
  62. isset($_POST['adminEnableRecovery'])
  63. && '0' === $_POST['adminEnableRecovery']
  64. ) {
  65. $return = Helper::adminDisableRecovery((string)$_POST['recoveryPassword']);
  66. if ($return) {
  67. $successMessage = $l->t('Recovery key successfully disabled');
  68. } else {
  69. $errorMessage = $l->t('Could not disable recovery key. Please check your recovery key password!');
  70. }
  71. }
  72. // Return success or failure
  73. if ($return) {
  74. \OCP\JSON::success(array('data' => array('message' => $successMessage)));
  75. } else {
  76. \OCP\JSON::error(array('data' => array('message' => $errorMessage)));
  77. }