PageRenderTime 52ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/apps/files/appinfo/filesync.php

https://github.com/sezuan/core
PHP | 64 lines | 38 code | 6 blank | 20 comment | 7 complexity | 85d7cbb498f4a974f2f9ede171afeed0 MD5 | raw file
Possible License(s): AGPL-3.0, AGPL-1.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. /**
  9. * filesync can be called with a PUT method.
  10. * PUT takes a stream starting with a 2 byte blocksize,
  11. * followed by binary md5 of the blocks. Everything in big-endian.
  12. * The return is a json encoded with:
  13. * - 'transferid'
  14. * - 'needed' chunks
  15. * - 'last' checked chunk
  16. * The URL is made of 3 parts, the service url (remote.php/filesync/), the sync
  17. * type and the path in ownCloud.
  18. * At the moment the only supported sync type is 'oc_chunked'.
  19. * The final URL will look like http://.../remote.php/filesync/oc_chunked/path/to/file
  20. */
  21. // load needed apps
  22. $RUNTIME_APPTYPES=array('filesystem', 'authentication', 'logging');
  23. OC_App::loadApps($RUNTIME_APPTYPES);
  24. if(!OC_User::isLoggedIn()) {
  25. if(!isset($_SERVER['PHP_AUTH_USER'])) {
  26. header('WWW-Authenticate: Basic realm="ownCloud Server"');
  27. header('HTTP/1.0 401 Unauthorized');
  28. echo 'Valid credentials must be supplied';
  29. exit();
  30. } else {
  31. if(!OC_User::login($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"])) {
  32. exit();
  33. }
  34. }
  35. }
  36. list($type, $file) = explode('/', substr($path_info, 1+strlen($service)+1), 2);
  37. if ($type != 'oc_chunked') {
  38. OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
  39. die;
  40. }
  41. if (!\OC\Files\Filesystem::is_file($file)) {
  42. OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
  43. die;
  44. }
  45. switch($_SERVER['REQUEST_METHOD']) {
  46. case 'PUT':
  47. $input = fopen("php://input", "r");
  48. $org_file = \OC\Files\Filesystem::fopen($file, 'rb');
  49. $info = array(
  50. 'name' => basename($file),
  51. );
  52. $sync = new OC_FileChunking($info);
  53. $result = $sync->signature_split($org_file, $input);
  54. echo json_encode($result);
  55. break;
  56. default:
  57. OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
  58. }