export.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * ownCloud - user_migrate
  4. *
  5. * @author Tom Needham
  6. * @copyright 2012 Tom Needham tom@owncloud.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. // Init owncloud
  23. // Check if we are a user
  24. OCP\JSON::checkLoggedIn();
  25. OCP\App::checkAppEnabled('user_migrate');
  26. // Which operation
  27. if( $_GET['operation']=='create' ){
  28. $uid = !empty( $_POST['uid'] ) ? $_POST['uid'] : OCP\USER::getUser();
  29. if( $uid != OCP\USER::getUser() ){
  30. // Needs to be admin to export someone elses account
  31. OCP\JSON::error();
  32. die();
  33. }
  34. // Create the export zip
  35. $response = json_decode( OC_Migrate::export( $uid ) );
  36. if( !$response->success ){
  37. // Error
  38. OCP\JSON::error();
  39. die();
  40. } else {
  41. // Save path in session
  42. $_SESSION['ocuserexportpath'] = $response->data;
  43. }
  44. OCP\JSON::success();
  45. die();
  46. } else if( $_GET['operation']=='download' ){
  47. // Download the export
  48. $path = isset( $_SESSION['ocuserexportpath'] ) ? $_SESSION['ocuserexportpath'] : false;
  49. if( !$path ){
  50. OCP\JSON::error();
  51. }
  52. header("Content-Type: application/zip");
  53. header("Content-Disposition: attachment; filename=" . basename($path));
  54. header("Content-Length: " . filesize($path));
  55. @ob_end_clean();
  56. readfile($path);
  57. unlink( $path );
  58. $_SESSION['ocuserexportpath'] = '';
  59. }