コード例 #1
0
 /**
  * @param string $baseUri
  * @param string $requestUri
  * @param BackendInterface $authBackend
  * @param callable $viewCallBack callback that should return the view for the dav endpoint
  * @return Server
  */
 public function createServer($baseUri, $requestUri, BackendInterface $authBackend, callable $viewCallBack)
 {
     // Fire up server
     $objectTree = new \OC\Connector\Sabre\ObjectTree();
     $server = new \OC\Connector\Sabre\Server($objectTree);
     // Set URL explicitly due to reverse-proxy situations
     $server->httpRequest->setUrl($requestUri);
     $server->setBaseUri($baseUri);
     // Load plugins
     $defaults = new \OC_Defaults();
     $server->addPlugin(new \OC\Connector\Sabre\MaintenancePlugin($this->config));
     $server->addPlugin(new \OC\Connector\Sabre\BlockLegacyClientPlugin($this->config));
     $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, $defaults->getName()));
     // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to /
     $server->addPlugin(new \OC\Connector\Sabre\DummyGetResponsePlugin());
     $server->addPlugin(new \OC\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger));
     $server->addPlugin(new \OC\Connector\Sabre\LockPlugin($objectTree));
     $server->addPlugin(new \OC\Connector\Sabre\ListenerPlugin($this->dispatcher));
     // wait with registering these until auth is handled and the filesystem is setup
     $server->on('beforeMethod', function () use($server, $objectTree, $viewCallBack) {
         /** @var \OC\Files\View $view */
         $view = $viewCallBack();
         $rootInfo = $view->getFileInfo('');
         // Create ownCloud Dir
         if ($rootInfo->getType() === 'dir') {
             $root = new \OC\Connector\Sabre\Directory($view, $rootInfo);
         } else {
             $root = new \OC\Connector\Sabre\File($view, $rootInfo);
         }
         $objectTree->init($root, $view, $this->mountManager);
         $server->addPlugin(new \OC\Connector\Sabre\FilesPlugin($objectTree, $view));
         $server->addPlugin(new \OC\Connector\Sabre\QuotaPlugin($view));
         if ($this->userSession->isLoggedIn()) {
             $server->addPlugin(new \OC\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager));
             // custom properties plugin must be the last one
             $server->addPlugin(new \Sabre\DAV\PropertyStorage\Plugin(new \OC\Connector\Sabre\CustomPropertiesBackend($objectTree, $this->databaseConnection, $this->userSession->getUser())));
         }
         $server->addPlugin(new \OC\Connector\Sabre\CopyEtagHeaderPlugin());
     }, 30);
     // priority 30: after auth (10) and acl(20), before lock(50) and handling the request
     return $server;
 }
コード例 #2
0
 * later.
 * See the COPYING-README file.
 */
if (OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled() === false) {
    return false;
}
// load needed apps
$RUNTIME_APPTYPES = array('filesystem', 'authentication', 'logging');
OC_App::loadApps($RUNTIME_APPTYPES);
OC_Util::obEnd();
// Backends
$authBackend = new OCA\Files_Sharing\Connector\PublicAuth(\OC::$server->getConfig());
$lockBackend = new OC_Connector_Sabre_Locks();
$requestBackend = new OC_Connector_Sabre_Request();
// Fire up server
$objectTree = new \OC\Connector\Sabre\ObjectTree();
$server = new OC_Connector_Sabre_Server($objectTree);
$server->httpRequest = $requestBackend;
$server->setBaseUri($baseuri);
// Load plugins
$defaults = new OC_Defaults();
$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, $defaults->getName()));
$server->addPlugin(new \Sabre\DAV\Locks\Plugin($lockBackend));
$server->addPlugin(new \Sabre\DAV\Browser\Plugin(false));
// Show something in the Browser, but no upload
$server->addPlugin(new OC_Connector_Sabre_FilesPlugin());
$server->addPlugin(new OC_Connector_Sabre_MaintenancePlugin());
$server->addPlugin(new OC_Connector_Sabre_ExceptionLoggerPlugin('webdav'));
// wait with registering these until auth is handled and the filesystem is setup
$server->subscribeEvent('beforeMethod', function () use($server, $objectTree, $authBackend) {
    $share = $authBackend->getShare();
コード例 #3
0
ファイル: objecttree.php プロジェクト: ninjasilicon/core
	public function testGetNodeForPathRoot() {
		$path = '/';


		$storage = new Temporary([]);

		$view = $this->getMock('\OC\Files\View', ['resolvePath']);
		$view->expects($this->any())
			->method('resolvePath')
			->will($this->returnCallback(function ($path) use ($storage) {
				return [$storage, ltrim($path, '/')];
			}));

		$rootNode = $this->getMockBuilder('\OC\Connector\Sabre\Directory')
			->disableOriginalConstructor()
			->getMock();
		$mountManager = $this->getMock('\OC\Files\Mount\Manager');

		$tree = new \OC\Connector\Sabre\ObjectTree();
		$tree->init($rootNode, $view, $mountManager);

		$this->assertInstanceOf('\Sabre\DAV\INode', $tree->getNodeForPath($path));
	}
コード例 #4
0
ファイル: webdav.php プロジェクト: olucao/owncloud-core
 /**
  * handle webdav request
  *
  * @param bool $body
  *
  * @note this init procedure is copied from /apps/files/appinfo/remote.php
  */
 function handleWebdavRequest($body = false)
 {
     // Backends
     $authBackend = new OC_Connector_Sabre_Auth();
     $lockBackend = new OC_Connector_Sabre_Locks();
     $requestBackend = new OC_Connector_Sabre_Request();
     // Create ownCloud Dir
     $root = '/' . $this->userId . '/files';
     $view = new \OC\Files\View($root);
     $publicDir = new OC_Connector_Sabre_Directory($view, $view->getFileInfo(''));
     $objectTree = new \OC\Connector\Sabre\ObjectTree();
     $mountManager = \OC\Files\Filesystem::getMountManager();
     $objectTree->init($publicDir, $view, $mountManager);
     // Fire up server
     $server = new \Sabre\DAV\Server($publicDir);
     $server->httpRequest = $requestBackend;
     $server->setBaseUri('/remote.php/webdav/');
     // Load plugins
     $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud'));
     $server->addPlugin(new \Sabre\DAV\Locks\Plugin($lockBackend));
     $server->addPlugin(new \Sabre\DAV\Browser\Plugin(false));
     // Show something in the Browser, but no upload
     $server->addPlugin(new OC_Connector_Sabre_QuotaPlugin($view));
     $server->addPlugin(new OC_Connector_Sabre_MaintenancePlugin());
     $server->debugExceptions = true;
     // And off we go!
     if ($body) {
         $server->httpRequest->setBody($body);
     }
     // turn on output buffering
     ob_start();
     // handle request
     $server->exec();
     // file content is written in the output buffer
     $content = ob_get_contents();
     // flush the output buffer and turn off output buffering
     ob_end_clean();
     // return captured content
     return $content;
 }
コード例 #5
0
 /**
  * @dataProvider nodeForPathProvider
  */
 public function testGetNodeForPath($inputFileName, $fileInfoQueryPath, $outputFileName, $type, $enableChunkingHeader)
 {
     if ($enableChunkingHeader) {
         $_SERVER['HTTP_OC_CHUNKED'] = true;
     }
     $rootNode = $this->getMockBuilder('\\OC\\Connector\\Sabre\\Directory')->disableOriginalConstructor()->getMock();
     $mountManager = $this->getMock('\\OC\\Files\\Mount\\Manager');
     $view = $this->getMock('\\OC\\Files\\View');
     $fileInfo = $this->getMock('\\OCP\\Files\\FileInfo');
     $fileInfo->expects($this->once())->method('getType')->will($this->returnValue($type));
     $fileInfo->expects($this->once())->method('getName')->will($this->returnValue($outputFileName));
     $view->expects($this->once())->method('getFileInfo')->with($fileInfoQueryPath)->will($this->returnValue($fileInfo));
     $tree = new \OC\Connector\Sabre\ObjectTree();
     $tree->init($rootNode, $view, $mountManager);
     $node = $tree->getNodeForPath($inputFileName);
     $this->assertNotNull($node);
     $this->assertEquals($outputFileName, $node->getName());
     if ($type === 'file') {
         $this->assertTrue($node instanceof \OC\Connector\Sabre\File);
     } else {
         $this->assertTrue($node instanceof \OC\Connector\Sabre\Directory);
     }
     unset($_SERVER['HTTP_OC_CHUNKED']);
 }