2011-09-02 16:56:40 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ownCloud
|
|
|
|
*
|
|
|
|
* Original:
|
|
|
|
* @author Frank Karlitschek
|
2012-05-26 21:14:24 +04:00
|
|
|
* @copyright 2012 Frank Karlitschek frank@owncloud.org
|
2011-09-02 16:56:40 +04:00
|
|
|
*
|
|
|
|
* Adapted:
|
|
|
|
* @author Michiel de Jong, 2011
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// Do not load FS ...
|
|
|
|
$RUNTIME_NOSETUPFS = true;
|
|
|
|
|
2012-04-17 21:31:29 +04:00
|
|
|
|
2012-05-09 17:22:05 +04:00
|
|
|
require_once('../../lib/base.php');
|
|
|
|
|
|
|
|
require_once('../../lib/user.php');
|
|
|
|
require_once('../../lib/public/user.php');
|
|
|
|
|
|
|
|
require_once('../../lib/app.php');
|
|
|
|
require_once('../../lib/public/app.php');
|
|
|
|
|
|
|
|
require_once('../../3rdparty/Sabre/DAV/Auth/IBackend.php');
|
|
|
|
require_once('../../3rdparty/Sabre/DAV/Auth/Backend/AbstractBasic.php');
|
|
|
|
require_once('../../lib/connector/sabre/auth.php');
|
|
|
|
|
2012-05-02 21:08:37 +04:00
|
|
|
OCP\App::checkAppEnabled('remoteStorage');
|
2011-10-04 12:07:46 +04:00
|
|
|
require_once('lib_remoteStorage.php');
|
2012-02-22 22:05:52 +04:00
|
|
|
require_once('BearerAuth.php');
|
2011-09-02 16:56:40 +04:00
|
|
|
require_once('oauth_ro_auth.php');
|
|
|
|
|
|
|
|
ini_set('default_charset', 'UTF-8');
|
|
|
|
#ini_set('error_reporting', '');
|
|
|
|
@ob_clean();
|
|
|
|
|
2011-10-04 12:07:46 +04:00
|
|
|
//allow use as remote storage for other websites
|
2011-09-02 16:56:40 +04:00
|
|
|
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');
|
2011-10-09 19:12:16 +04:00
|
|
|
header('Access-Control-Allow-Headers: Authorization, Content-Type');
|
2011-09-02 16:56:40 +04:00
|
|
|
} else {
|
|
|
|
header('Access-Control-Allow-Origin: *');
|
|
|
|
}
|
|
|
|
|
|
|
|
$path = substr($_SERVER["REQUEST_URI"], strlen($_SERVER["SCRIPT_NAME"]));
|
|
|
|
$pathParts = explode('/', $path);
|
|
|
|
// for webdav:
|
2011-12-07 18:51:47 +04:00
|
|
|
// 0/ 1 / 2 / 3...
|
|
|
|
// /$ownCloudUser/remoteStorage/$category/
|
2011-09-02 16:56:40 +04:00
|
|
|
|
2011-12-07 18:51:47 +04:00
|
|
|
if(count($pathParts) >= 3 && $pathParts[0] == '') {
|
|
|
|
list($dummy, $ownCloudUser, $dummy2, $category) = $pathParts;
|
2011-09-02 16:56:40 +04:00
|
|
|
|
|
|
|
OC_Util::setupFS($ownCloudUser);
|
|
|
|
|
|
|
|
// Create ownCloud Dir
|
|
|
|
$publicDir = new OC_Connector_Sabre_Directory('');
|
|
|
|
$server = new Sabre_DAV_Server($publicDir);
|
|
|
|
|
|
|
|
// Path to our script
|
2012-03-02 00:58:14 +04:00
|
|
|
$server->setBaseUri(OC::$WEBROOT."/apps/remoteStorage/WebDAV.php/$ownCloudUser");
|
2011-09-02 16:56:40 +04:00
|
|
|
|
|
|
|
// Auth backend
|
2012-02-26 01:59:58 +04:00
|
|
|
$authBackend = new OC_Connector_Sabre_Auth_ro_oauth(
|
|
|
|
OC_remoteStorage::getValidTokens($ownCloudUser, $category),
|
|
|
|
$category
|
|
|
|
);
|
2011-09-02 16:56:40 +04:00
|
|
|
|
|
|
|
$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 {
|
2012-02-26 01:59:58 +04:00
|
|
|
//die('not the right address format '.var_export($pathParts, true));
|
|
|
|
die('not the right address format');
|
2011-09-02 16:56:40 +04:00
|
|
|
}
|