WebDAV.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * Original:
  6. * @author Frank Karlitschek
  7. * @copyright 2010 Frank Karlitschek karlitschek@kde.org
  8. *
  9. * Adapted:
  10. * @author Michiel de Jong, 2011
  11. *
  12. * This library is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  14. * License as published by the Free Software Foundation; either
  15. * version 3 of the License, or any later version.
  16. *
  17. * This library is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public
  23. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. // Do not load FS ...
  27. $RUNTIME_NOSETUPFS = true;
  28. require_once('../../lib/base.php');
  29. require_once('../../lib/user.php');
  30. require_once('../../lib/public/user.php');
  31. require_once('../../lib/app.php');
  32. require_once('../../lib/public/app.php');
  33. require_once('../../3rdparty/Sabre/DAV/Auth/IBackend.php');
  34. require_once('../../3rdparty/Sabre/DAV/Auth/Backend/AbstractBasic.php');
  35. require_once('../../lib/connector/sabre/auth.php');
  36. OCP\App::checkAppEnabled('remoteStorage');
  37. require_once('lib_remoteStorage.php');
  38. require_once('BearerAuth.php');
  39. require_once('oauth_ro_auth.php');
  40. ini_set('default_charset', 'UTF-8');
  41. #ini_set('error_reporting', '');
  42. @ob_clean();
  43. //allow use as remote storage for other websites
  44. if(isset($_SERVER['HTTP_ORIGIN'])) {
  45. header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
  46. header('Access-Control-Max-Age: 3600');
  47. header('Access-Control-Allow-Methods: OPTIONS, GET, PUT, DELETE, PROPFIND');
  48. header('Access-Control-Allow-Headers: Authorization, Content-Type');
  49. } else {
  50. header('Access-Control-Allow-Origin: *');
  51. }
  52. $path = substr($_SERVER["REQUEST_URI"], strlen($_SERVER["SCRIPT_NAME"]));
  53. $pathParts = explode('/', $path);
  54. // for webdav:
  55. // 0/ 1 / 2 / 3...
  56. // /$ownCloudUser/remoteStorage/$category/
  57. if(count($pathParts) >= 3 && $pathParts[0] == '') {
  58. list($dummy, $ownCloudUser, $dummy2, $category) = $pathParts;
  59. OC_Util::setupFS($ownCloudUser);
  60. // Create ownCloud Dir
  61. $publicDir = new OC_Connector_Sabre_Directory('');
  62. $server = new Sabre_DAV_Server($publicDir);
  63. // Path to our script
  64. $server->setBaseUri(OC::$WEBROOT."/apps/remoteStorage/WebDAV.php/$ownCloudUser");
  65. // Auth backend
  66. $authBackend = new OC_Connector_Sabre_Auth_ro_oauth(
  67. OC_remoteStorage::getValidTokens($ownCloudUser, $category),
  68. $category
  69. );
  70. $authPlugin = new Sabre_DAV_Auth_Plugin($authBackend,'ownCloud');//should use $validTokens here
  71. $server->addPlugin($authPlugin);
  72. // Also make sure there is a 'data' directory, writable by the server. This directory is used to store information about locks
  73. $lockBackend = new OC_Connector_Sabre_Locks();
  74. $lockPlugin = new Sabre_DAV_Locks_Plugin($lockBackend);
  75. $server->addPlugin($lockPlugin);
  76. // And off we go!
  77. $server->exec();
  78. } else {
  79. //die('not the right address format '.var_export($pathParts, true));
  80. die('not the right address format');
  81. }