From 7ab35af6dd9f0338f0a239aab20c045cfcbd34b5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 16 Jul 2012 19:55:36 +0200 Subject: use the remote.php infrastructure for remoteStorage --- apps/remoteStorage/webdav.php | 87 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 apps/remoteStorage/webdav.php (limited to 'apps/remoteStorage/webdav.php') diff --git a/apps/remoteStorage/webdav.php b/apps/remoteStorage/webdav.php new file mode 100644 index 00000000000..8d8ec6a45a1 --- /dev/null +++ b/apps/remoteStorage/webdav.php @@ -0,0 +1,87 @@ +. +* +*/ + +OC_App::loadApps(array('filesystem','authentication')); + +OCP\App::checkAppEnabled('remoteStorage'); +require_once('lib_remoteStorage.php'); +require_once('BearerAuth.php'); +require_once('oauth_ro_auth.php'); + +ini_set('default_charset', 'UTF-8'); +#ini_set('error_reporting', ''); +@ob_clean(); + +//allow use as remote storage for other websites +if(isset($_SERVER['HTTP_ORIGIN'])) { + header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']); + header('Access-Control-Max-Age: 3600'); + header('Access-Control-Allow-Methods: OPTIONS, GET, PUT, DELETE, PROPFIND'); + header('Access-Control-Allow-Headers: Authorization, Content-Type'); +} else { + header('Access-Control-Allow-Origin: *'); +} + +$path = substr($_SERVER["REQUEST_URI"], strlen($baseuri)); + +$pathParts = explode('/', $path); +// for webdav: +// 0 / 1 / 2... +// $ownCloudUser/remoteStorage/$category/ + +if(count($pathParts) >= 2) { + list($ownCloudUser, $dummy2, $category) = $pathParts; + + OC_Util::setupFS($ownCloudUser); + + // Create ownCloud Dir + $publicDir = new OC_Connector_Sabre_Directory(''); + $server = new Sabre_DAV_Server($publicDir); + + // Path to our script + $server->setBaseUri($baseuri.$ownCloudUser); + + // Auth backend + $authBackend = new OC_Connector_Sabre_Auth_ro_oauth( + OC_remoteStorage::getValidTokens($ownCloudUser, $category), + $category + ); + + $authPlugin = new Sabre_DAV_Auth_Plugin($authBackend,'ownCloud');//should use $validTokens here + $server->addPlugin($authPlugin); + + // Also make sure there is a 'data' directory, writable by the server. This directory is used to store information about locks + $lockBackend = new OC_Connector_Sabre_Locks(); + $lockPlugin = new Sabre_DAV_Locks_Plugin($lockBackend); + $server->addPlugin($lockPlugin); + + // And off we go! + $server->exec(); +} else { + //die('not the right address format '.var_export($pathParts, true)); + die('not the right address format'); +} -- cgit v1.2.3