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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 Sam Tuke <mail@samtuke.com>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  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. \OCP\JSON::checkLoggedIn();
  28. \OCP\JSON::checkAppEnabled('files_encryption');
  29. \OCP\JSON::callCheck();
  30. $l = \OC::$server->getL10N('files_encryption');
  31. if (
  32. isset($_POST['userEnableRecovery'])
  33. && (0 == $_POST['userEnableRecovery'] || '1' === $_POST['userEnableRecovery'])
  34. ) {
  35. $userId = \OCP\USER::getUser();
  36. $view = new \OC\Files\View('/');
  37. $util = new \OCA\Files_Encryption\Util($view, $userId);
  38. // Save recovery preference to DB
  39. $return = $util->setRecoveryForUser((string)$_POST['userEnableRecovery']);
  40. if ($_POST['userEnableRecovery'] === '1') {
  41. $util->addRecoveryKeys();
  42. } else {
  43. $util->removeRecoveryKeys();
  44. }
  45. } else {
  46. $return = false;
  47. }
  48. // Return success or failure
  49. if ($return) {
  50. \OCP\JSON::success(array('data' => array('message' => $l->t('File recovery settings updated'))));
  51. } else {
  52. \OCP\JSON::error(array('data' => array('message' => $l->t('Could not update file recovery'))));
  53. }