예제 #1
0
} else {
    header('Access-Control-Allow-Origin: *');
}
$path = substr($_SERVER["REQUEST_URI"], strlen($_SERVER["SCRIPT_NAME"]));
$pathParts = explode('/', $path);
// for webdav:
// 0/     1       /   2    /   3...
//  /$ownCloudUser/remoteStorage/$category/
if (count($pathParts) >= 3 && $pathParts[0] == '') {
    list($dummy, $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(OC::$WEBROOT . "/apps/remoteStorage/WebDAV.php/{$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');
}
// for webdav:
// 0/     1       /   2    /   3  /   4     /    5     /   6     / 7
//  /$ownCloudUser/remoteStorage/webdav/$userHost/$userName/$dataScope/$key
// for oauth:
// 0/      1      /  2     /  3  / 4
//  /$ownCloudUser/remoteStorage/oauth/auth
if (count($pathParts) >= 8 && $pathParts[0] == '' && $pathParts[2] == 'remoteStorage' && $pathParts[3] == 'webdav') {
    list($dummy0, $ownCloudUser, $dummy2, $dummy3, $userHost, $userName, $dataScope) = $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(OC::$WEBROOT . "/apps/remoteStorage/compat.php/{$ownCloudUser}");
    // Auth backend
    $authBackend = new OC_Connector_Sabre_Auth_ro_oauth(OC_remoteStorage::getValidTokens($ownCloudUser, $userName . '@' . $userHost, $dataScope));
    $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 {
    if (count($pathParts) >= 4 && $pathParts[0] == '' && $pathParts[2] == 'remoteStorage' && $pathParts[3] == 'oauth2' && ($pathParts[4] = 'auth')) {
        if (isset($_POST['allow'])) {
            //TODO: input checking. these explodes may fail to produces the desired arrays:
            $ownCloudUser = $pathParts[1];
            foreach ($_GET as $k => $v) {