adminrecovery.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Copyright (c) 2013, Sam Tuke <samtuke@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or later.
  5. * See the COPYING-README file.
  6. *
  7. * @brief Script to handle admin settings for encrypted key recovery
  8. */
  9. use OCA\Encryption;
  10. \OCP\JSON::checkAdminUser();
  11. \OCP\JSON::checkAppEnabled('files_encryption');
  12. \OCP\JSON::callCheck();
  13. $l = OC_L10N::get('files_encryption');
  14. $return = false;
  15. // Enable recoveryAdmin
  16. $recoveryKeyId = OC_Appconfig::getValue('files_encryption', 'recoveryKeyId');
  17. if (isset($_POST['adminEnableRecovery']) && $_POST['adminEnableRecovery'] === '1') {
  18. $return = \OCA\Encryption\Helper::adminEnableRecovery($recoveryKeyId, $_POST['recoveryPassword']);
  19. // Return success or failure
  20. if ($return) {
  21. \OCP\JSON::success(array('data' => array('message' => $l->t('Recovery key successfully enabled'))));
  22. } else {
  23. \OCP\JSON::error(array(
  24. 'data' => array(
  25. 'message' => $l->t(
  26. 'Could not enable recovery key. Please check your recovery key password!')
  27. )
  28. ));
  29. }
  30. // Disable recoveryAdmin
  31. } elseif (
  32. isset($_POST['adminEnableRecovery'])
  33. && '0' === $_POST['adminEnableRecovery']
  34. ) {
  35. $return = \OCA\Encryption\Helper::adminDisableRecovery($_POST['recoveryPassword']);
  36. // Return success or failure
  37. if ($return) {
  38. \OCP\JSON::success(array('data' => array('message' => $l->t('Recovery key successfully disabled'))));
  39. } else {
  40. \OCP\JSON::error(array(
  41. 'data' => array(
  42. 'message' => $l->t(
  43. 'Could not disable recovery key. Please check your recovery key password!')
  44. )
  45. ));
  46. }
  47. }