Ejemplo n.º 1
0
 function init()
 {
     if (!is_dir('store')) {
         os_mkdir('store', STORAGE_DEFAULT_PERMISSIONS, false);
     }
     $which = null;
     if (argc() > 1) {
         $which = argv(1);
     }
     $profile = 0;
     \App::$page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . z_root() . '/feed/' . $which . '" />' . "\r\n";
     if ($which) {
         profile_load($which, $profile);
     }
     $auth = new \Zotlabs\Storage\BasicAuth();
     $ob_hash = get_observer_hash();
     if ($ob_hash) {
         if (local_channel()) {
             $channel = \App::get_channel();
             $auth->setCurrentUser($channel['channel_address']);
             $auth->channel_id = $channel['channel_id'];
             $auth->channel_hash = $channel['channel_hash'];
             $auth->channel_account_id = $channel['channel_account_id'];
             if ($channel['channel_timezone']) {
                 $auth->setTimezone($channel['channel_timezone']);
             }
         }
         $auth->observer = $ob_hash;
     }
     if ($_GET['davguest']) {
         $_SESSION['davguest'] = true;
     }
     $_SERVER['QUERY_STRING'] = str_replace(array('?f=', '&f='), array('', ''), $_SERVER['QUERY_STRING']);
     $_SERVER['QUERY_STRING'] = strip_zids($_SERVER['QUERY_STRING']);
     $_SERVER['QUERY_STRING'] = preg_replace('/[\\?&]davguest=(.*?)([\\?&]|$)/ism', '', $_SERVER['QUERY_STRING']);
     $_SERVER['REQUEST_URI'] = str_replace(array('?f=', '&f='), array('', ''), $_SERVER['REQUEST_URI']);
     $_SERVER['REQUEST_URI'] = strip_zids($_SERVER['REQUEST_URI']);
     $_SERVER['REQUEST_URI'] = preg_replace('/[\\?&]davguest=(.*?)([\\?&]|$)/ism', '', $_SERVER['REQUEST_URI']);
     $rootDirectory = new \Zotlabs\Storage\Directory('/', $auth);
     // A SabreDAV server-object
     $server = new SDAV\Server($rootDirectory);
     // prevent overwriting changes each other with a lock backend
     $lockBackend = new SDAV\Locks\Backend\File('store/[data]/locks');
     $lockPlugin = new SDAV\Locks\Plugin($lockBackend);
     $server->addPlugin($lockPlugin);
     $is_readable = false;
     // provide a directory view for the cloud in Hubzilla
     $browser = new \Zotlabs\Storage\Browser($auth);
     $auth->setBrowserPlugin($browser);
     $server->addPlugin($browser);
     // Experimental QuotaPlugin
     //	require_once('\Zotlabs\Storage/QuotaPlugin.php');
     //	$server->addPlugin(new \Zotlabs\Storage\\QuotaPlugin($auth));
     ob_start();
     // All we need to do now, is to fire up the server
     $server->exec();
     ob_end_flush();
     killme();
 }
Ejemplo n.º 2
0
 function setUp()
 {
     $nodes = [new DAV\SimpleCollection('testdir')];
     $this->server = new DAV\Server($nodes);
     $this->plugin = new Plugin();
     $this->plugin->allowAccessToNodesWithoutACL = false;
     $this->server->addPlugin($this->plugin);
 }
Ejemplo n.º 3
0
 function setUp()
 {
     $nodes = array(new DAV\SimpleCollection('testdir'));
     $this->server = new DAV\Server($nodes);
     $aclPlugin = new Plugin();
     $aclPlugin->allowAccessToNodesWithoutACL = true;
     $this->server->addPlugin($aclPlugin);
 }
Ejemplo n.º 4
0
 function setUp()
 {
     $nodes = [new DAV\Mock\Collection('testdir', ['file1.txt' => 'contents'])];
     $this->server = new DAV\Server($nodes);
     $this->server->addPlugin(new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock()));
     // Login
     $this->server->getPlugin('auth')->beforeMethod(new \Sabre\HTTP\Request(), new \Sabre\HTTP\Response());
     $aclPlugin = new Plugin();
     $this->server->addPlugin($aclPlugin);
 }
Ejemplo n.º 5
0
 function setUp()
 {
     $nodes = [new DAV\SimpleCollection('testdir')];
     $this->server = new DAV\Server($nodes);
     $this->plugin = new Plugin();
     $this->plugin->setDefaultAcl([]);
     $this->server->addPlugin(new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock()));
     // Login
     $this->server->getPlugin('auth')->beforeMethod(new \Sabre\HTTP\Request(), new \Sabre\HTTP\Response());
     $this->server->addPlugin($this->plugin);
 }
Ejemplo n.º 6
0
 /**
  * @param Request $request
  *
  * @return StreamedResponse
  */
 public function indexAction(Request $request)
 {
     date_default_timezone_set('Europe/Paris');
     $baseUri = $this->generateUrl('caldav');
     $pmanager = $this->get('pmanager');
     // Backends:
     $authBackend = new Auth($pmanager);
     $calendarBackend = new Calendar($pmanager, $this->generateUrl('event_read', [], true), $this->get('cocur_slugify'));
     $principalBackend = new Principals($pmanager);
     $tree = [new Collection($principalBackend), new CalendarRoot($principalBackend, $calendarBackend)];
     $server = new Server($tree);
     $server->setBaseUri($baseUri);
     $server->addPlugin(new AuthPlugin($authBackend, 'SabreDAV'));
     $server->addPlugin(new ACLPlugin());
     $server->addPlugin(new ICSExportPlugin());
     $server->addPlugin(new CalDAVPlugin());
     $server->addPlugin(new SubscriptionsPlugin());
     $server->addPlugin(new SchedulePlugin());
     $server->addPlugin(new SyncPlugin());
     $server->addPlugin(new BrowserPlugin());
     $callback = function () use($server, $request) {
         /* These two lines fix a weird bug
            where SabreDAV wouldn't give the correct answer to a propfind */
         $url = $server->httpRequest->getUrl();
         $server->httpRequest = new SabreRequest($request->getMethod(), $url, $request->headers->all(), $request->getContent());
         $server->exec();
         /* These two lines log the request and the response */
         $responseBody = $server->httpResponse->getBodyAsString();
         $this->logIt($request, $server->httpResponse, $responseBody);
     };
     return new StreamedResponse($callback);
 }
Ejemplo n.º 7
0
 /**
  * Initializes the server object
  *
  * @return void
  */
 protected function initServer()
 {
     if ($this->authType === 'Basic') {
         $authBackend = new \Baikal\Core\PDOBasicAuth($this->pdo, $this->authRealm);
     } else {
         $authBackend = new \Sabre\DAV\Auth\Backend\PDO($this->pdo, $this->authRealm);
     }
     $principalBackend = new \Sabre\DAVACL\PrincipalBackend\PDO($this->pdo);
     $nodes = [new \Sabre\CalDAV\Principal\Collection($principalBackend)];
     if ($this->enableCalDAV) {
         $calendarBackend = new \Sabre\CalDAV\Backend\PDO($this->pdo);
         $nodes[] = new \Sabre\CalDAV\CalendarRoot($principalBackend, $calendarBackend);
     }
     if ($this->enableCardDAV) {
         $carddavBackend = new \Sabre\CardDAV\Backend\PDO($GLOBALS["DB"]->getPDO());
         $nodes[] = new \Sabre\CardDAV\AddressBookRoot($principalBackend, $carddavBackend);
     }
     $this->server = new \Sabre\DAV\Server($nodes);
     $this->server->setBaseUri($this->baseUri);
     $this->server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, $this->authRealm));
     $this->server->addPlugin(new \Sabre\DAVACL\Plugin());
     $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin());
     if ($this->enableCalDAV) {
         $this->server->addPlugin(new \Sabre\CalDAV\Plugin());
         $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
     }
     if ($this->enableCardDAV) {
         $this->server->addPlugin(new \Sabre\CardDAV\Plugin());
         $this->server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin());
     }
 }
Ejemplo n.º 8
0
 public function testPrepareResponses()
 {
     $requestedProps = ['{DAV:}getcontentlength', '{http://owncloud.org/ns}fileid', '{DAV:}resourcetype'];
     $node1 = $this->getMockBuilder('\\OCA\\DAV\\Connector\\Sabre\\Directory')->disableOriginalConstructor()->getMock();
     $node2 = $this->getMockBuilder('\\OCA\\DAV\\Connector\\Sabre\\File')->disableOriginalConstructor()->getMock();
     $node1->expects($this->once())->method('getInternalFileId')->will($this->returnValue('111'));
     $node2->expects($this->once())->method('getInternalFileId')->will($this->returnValue('222'));
     $node2->expects($this->once())->method('getSize')->will($this->returnValue(1024));
     $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesPlugin($this->tree, $this->view));
     $this->plugin->initialize($this->server);
     $responses = $this->plugin->prepareResponses($requestedProps, [$node1, $node2]);
     $this->assertCount(2, $responses);
     $this->assertEquals(200, $responses[0]->getHttpStatus());
     $this->assertEquals(200, $responses[1]->getHttpStatus());
     $props1 = $responses[0]->getResponseProperties();
     $this->assertEquals('111', $props1[200]['{http://owncloud.org/ns}fileid']);
     $this->assertNull($props1[404]['{DAV:}getcontentlength']);
     $this->assertInstanceOf('\\Sabre\\DAV\\Xml\\Property\\ResourceType', $props1[200]['{DAV:}resourcetype']);
     $resourceType1 = $props1[200]['{DAV:}resourcetype']->getValue();
     $this->assertEquals('{DAV:}collection', $resourceType1[0]);
     $props2 = $responses[1]->getResponseProperties();
     $this->assertEquals('1024', $props2[200]['{DAV:}getcontentlength']);
     $this->assertEquals('222', $props2[200]['{http://owncloud.org/ns}fileid']);
     $this->assertInstanceOf('\\Sabre\\DAV\\Xml\\Property\\ResourceType', $props2[200]['{DAV:}resourcetype']);
     $this->assertCount(0, $props2[200]['{DAV:}resourcetype']->getValue());
 }
Ejemplo n.º 9
0
 function testLockEtc()
 {
     mkdir(SABRE_TEMPDIR . '/mstest');
     $tree = new DAV\FS\Directory(SABRE_TEMPDIR . '/mstest');
     $server = new DAV\Server($tree);
     $server->debugExceptions = true;
     $locksBackend = new Backend\File(SABRE_TEMPDIR . '/locksdb');
     $locksPlugin = new Plugin($locksBackend);
     $server->addPlugin($locksPlugin);
     $response1 = new HTTP\ResponseMock();
     $server->httpRequest = $this->getLockRequest();
     $server->httpResponse = $response1;
     $server->sapi = new HTTP\SapiMock();
     $server->exec();
     $this->assertEquals(201, $server->httpResponse->getStatus(), 'Full response body:' . $response1->getBodyAsString());
     $this->assertTrue(!!$server->httpResponse->getHeaders('Lock-Token'));
     $lockToken = $server->httpResponse->getHeader('Lock-Token');
     //sleep(10);
     $response2 = new HTTP\ResponseMock();
     $server->httpRequest = $this->getLockRequest2();
     $server->httpResponse = $response2;
     $server->exec();
     $this->assertEquals(201, $server->httpResponse->status);
     $this->assertTrue(!!$server->httpResponse->getHeaders('Lock-Token'));
     //sleep(10);
     $response3 = new HTTP\ResponseMock();
     $server->httpRequest = $this->getPutRequest($lockToken);
     $server->httpResponse = $response3;
     $server->exec();
     $this->assertEquals(204, $server->httpResponse->status);
 }
Ejemplo n.º 10
0
 function testLockEtc()
 {
     mkdir(SABRE_TEMPDIR . '/mstest');
     $tree = new DAV\FS\Directory(SABRE_TEMPDIR . '/mstest');
     $server = new DAV\Server($tree);
     $server->debugExceptions = true;
     $locksBackend = new Backend\File(SABRE_TEMPDIR . '/locksdb');
     $locksPlugin = new Plugin($locksBackend);
     $server->addPlugin($locksPlugin);
     $response1 = new HTTP\ResponseMock();
     $server->httpRequest = $this->getLockRequest();
     $server->httpResponse = $response1;
     $server->exec();
     $this->assertEquals('HTTP/1.1 201 Created', $server->httpResponse->status);
     $this->assertTrue(isset($server->httpResponse->headers['Lock-Token']));
     $lockToken = $server->httpResponse->headers['Lock-Token'];
     //sleep(10);
     $response2 = new HTTP\ResponseMock();
     $server->httpRequest = $this->getLockRequest2();
     $server->httpResponse = $response2;
     $server->exec();
     $this->assertEquals('HTTP/1.1 201 Created', $server->httpResponse->status);
     $this->assertTrue(isset($server->httpResponse->headers['Lock-Token']));
     //sleep(10);
     $response3 = new HTTP\ResponseMock();
     $server->httpRequest = $this->getPutRequest($lockToken);
     $server->httpResponse = $response3;
     $server->exec();
     $this->assertEquals('HTTP/1.1 204 No Content', $server->httpResponse->status);
 }
Ejemplo n.º 11
0
 /**
  * @depends testNoAdminAccess
  */
 function testAdminAccess()
 {
     $principalBackend = new PrincipalBackend\Mock();
     $tree = array(new MockACLNode('adminonly', array()), new PrincipalCollection($principalBackend));
     $fakeServer = new DAV\Server($tree);
     $plugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(), 'realm');
     $fakeServer->addPlugin($plugin);
     $plugin = new Plugin();
     $plugin->adminPrincipals = array('principals/admin');
     $fakeServer->addPlugin($plugin);
     $request = new HTTP\Request(array('REQUEST_METHOD' => 'OPTIONS', 'HTTP_DEPTH' => 1, 'REQUEST_URI' => '/adminonly'));
     $response = new HTTP\ResponseMock();
     $fakeServer->httpRequest = $request;
     $fakeServer->httpResponse = $response;
     $fakeServer->exec();
     $this->assertEquals('HTTP/1.1 200 OK', $response->status);
 }
Ejemplo n.º 12
0
 function schedule(Message $message)
 {
     $plugin = new IMip\MockPlugin('*****@*****.**');
     $server = new Server();
     $server->addPlugin($plugin);
     $server->emit('schedule', [$message]);
     return $plugin->getSentEmails();
 }
Ejemplo n.º 13
0
 /**
  * @depends testInit
  */
 function testGetCurrentUserPrincipal()
 {
     $fakeServer = new DAV\Server(new DAV\SimpleCollection('bla'));
     $plugin = new Plugin(new Backend\Mock(), 'realm');
     $fakeServer->addPlugin($plugin);
     $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]);
     $this->assertEquals('admin', $plugin->getCurrentUser());
 }
Ejemplo n.º 14
0
 function init()
 {
     // workaround for HTTP-auth in CGI mode
     if (x($_SERVER, 'REDIRECT_REMOTE_USER')) {
         $userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"], 6));
         if (strlen($userpass)) {
             list($name, $password) = explode(':', $userpass);
             $_SERVER['PHP_AUTH_USER'] = $name;
             $_SERVER['PHP_AUTH_PW'] = $password;
         }
     }
     if (x($_SERVER, 'HTTP_AUTHORIZATION')) {
         $userpass = base64_decode(substr($_SERVER["HTTP_AUTHORIZATION"], 6));
         if (strlen($userpass)) {
             list($name, $password) = explode(':', $userpass);
             $_SERVER['PHP_AUTH_USER'] = $name;
             $_SERVER['PHP_AUTH_PW'] = $password;
         }
     }
     if (!is_dir('store')) {
         os_mkdir('store', STORAGE_DEFAULT_PERMISSIONS, false);
     }
     if (argc() > 1) {
         profile_load(argv(1), 0);
     }
     $auth = new \Zotlabs\Storage\BasicAuth();
     $auth->setRealm(ucfirst(\Zotlabs\Lib\System::get_platform_name()) . ' ' . 'WebDAV');
     $rootDirectory = new \Zotlabs\Storage\Directory('/', $auth);
     // A SabreDAV server-object
     $server = new SDAV\Server($rootDirectory);
     $authPlugin = new \Sabre\DAV\Auth\Plugin($auth);
     $server->addPlugin($authPlugin);
     // prevent overwriting changes each other with a lock backend
     $lockBackend = new SDAV\Locks\Backend\File('store/[data]/locks');
     $lockPlugin = new SDAV\Locks\Plugin($lockBackend);
     $server->addPlugin($lockPlugin);
     // provide a directory view for the cloud in Hubzilla
     $browser = new \Zotlabs\Storage\Browser($auth);
     $auth->setBrowserPlugin($browser);
     // Experimental QuotaPlugin
     // require_once('Zotlabs/Storage/QuotaPlugin.php');
     // $server->addPlugin(new \Zotlabs\Storage\QuotaPlugin($auth));
     // All we need to do now, is to fire up the server
     $server->exec();
     killme();
 }
Ejemplo n.º 15
0
 /**
  * @depends testInit
  */
 function testGetCurrentUserPrincipal()
 {
     $fakeServer = new DAV\Server(new DAV\SimpleCollection('bla'));
     $plugin = new Plugin(new Backend\Mock(), 'realm');
     $fakeServer->addPlugin($plugin);
     $fakeServer->broadCastEvent('beforeMethod', array('GET', '/'));
     $this->assertEquals('admin', $plugin->getCurrentUser());
 }
Ejemplo n.º 16
0
 public function setUp()
 {
     $tree = array(new File(SABRE_TEMPDIR . '/foobar.txt'));
     $server = new Server($tree);
     $server->debugExceptions = true;
     $server->addPlugin(new Plugin());
     $tree[0]->put('1234567890');
     $this->server = $server;
 }
 public function testSetBadNode()
 {
     $tree = array(new DAV\SimpleCollection('foo'));
     $server = new DAV\Server($tree);
     $server->addPlugin(new Plugin());
     $result = $server->updateProperties('foo', array('{DAV:}group-member-set' => new DAV\Property\HrefList(array('/bar', '/baz'), false)));
     $expected = array('{DAV:}group-member-set' => 403);
     $this->assertEquals($expected, $result);
 }
Ejemplo n.º 18
0
 function testResourceType()
 {
     $tree = array(new DirectoryMock('directory'));
     $server = new DAV\Server($tree);
     $plugin = new Plugin();
     $server->addPlugin($plugin);
     $props = $server->getProperties('directory', array('{DAV:}resourcetype'));
     $this->assertTrue($props['{DAV:}resourcetype']->is('{' . Plugin::NS_CARDDAV . '}directory'));
 }
Ejemplo n.º 19
0
 function testSetBadNode()
 {
     $tree = [new DAV\SimpleCollection('foo')];
     $server = new DAV\Server($tree);
     $server->addPlugin(new Plugin());
     $result = $server->updateProperties('foo', ['{DAV:}group-member-set' => new DAV\Xml\Property\Href(['/bar', '/baz'], false)]);
     $expected = ['{DAV:}group-member-set' => 403];
     $this->assertEquals($expected, $result);
 }
Ejemplo n.º 20
0
 /**
  * Run the server
  */
 public function runServer()
 {
     $pdo = $this->getPdoConnection();
     $principalBackend = new PrincipalBackendTypo3($pdo);
     $tree = [new Collection($principalBackend), new CalendarRoot($principalBackend, new BackendTypo3($pdo))];
     $server = new Server($tree);
     $server->setBaseUri('/CalDav/');
     /* Server Plugins */
     $authPlugin = new AuthPlugin(new AuthBackendTypo3($pdo));
     $server->addPlugin($authPlugin);
     #$aclPlugin = new \Sabre\DAVACL\Plugin();
     #$server->addPlugin($aclPlugin);
     $caldavPlugin = new Plugin();
     $server->addPlugin($caldavPlugin);
     if (GeneralUtility::getApplicationContext()->isDevelopment()) {
         $server->addPlugin(new BrowserPlugin());
     }
     $server->exec();
 }
Ejemplo n.º 21
0
 function testSupportedReportSetUserCalendars()
 {
     $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
     $props = $this->server->getPropertiesForPath('/calendars/user1', ['{DAV:}supported-report-set']);
     $this->assertArrayHasKey(0, $props);
     $this->assertArrayHasKey(200, $props[0]);
     $this->assertArrayHasKey('{DAV:}supported-report-set', $props[0][200]);
     $prop = $props[0][200]['{DAV:}supported-report-set'];
     $this->assertInstanceOf('\\Sabre\\DAV\\Xml\\Property\\SupportedReportSet', $prop);
     $value = ['{DAV:}sync-collection', '{DAV:}expand-property', '{DAV:}principal-property-search', '{DAV:}principal-search-property-set'];
     $this->assertEquals($value, $prop->getValue());
 }
Ejemplo n.º 22
0
 function getServer()
 {
     $tree = array(new MockPropertyNode('node1', array('{http://sabredav.org/ns}simple' => 'foo', '{http://sabredav.org/ns}href' => new DAV\Property\Href('node2'), '{DAV:}displayname' => 'Node 1')), new MockPropertyNode('node2', array('{http://sabredav.org/ns}simple' => 'simple', '{http://sabredav.org/ns}hreflist' => new DAV\Property\HrefList(array('node1', 'node3')), '{DAV:}displayname' => 'Node 2')), new MockPropertyNode('node3', array('{http://sabredav.org/ns}simple' => 'simple', '{DAV:}displayname' => 'Node 3')));
     $fakeServer = new DAV\Server($tree);
     $fakeServer->debugExceptions = true;
     $fakeServer->httpResponse = new HTTP\ResponseMock();
     $plugin = new Plugin();
     $plugin->allowAccessToNodesWithoutACL = true;
     $this->assertTrue($plugin instanceof Plugin);
     $fakeServer->addPlugin($plugin);
     $this->assertEquals($plugin, $fakeServer->getPlugin('acl'));
     return $fakeServer;
 }
Ejemplo n.º 23
0
 function getServer()
 {
     $tree = [new DAV\Mock\PropertiesCollection('node1', [], ['{http://sabredav.org/ns}simple' => 'foo', '{http://sabredav.org/ns}href' => new DAV\Xml\Property\Href('node2'), '{DAV:}displayname' => 'Node 1']), new DAV\Mock\PropertiesCollection('node2', [], ['{http://sabredav.org/ns}simple' => 'simple', '{http://sabredav.org/ns}hreflist' => new DAV\Xml\Property\Href(['node1', 'node3']), '{DAV:}displayname' => 'Node 2']), new DAV\Mock\PropertiesCollection('node3', [], ['{http://sabredav.org/ns}simple' => 'simple', '{DAV:}displayname' => 'Node 3'])];
     $fakeServer = new DAV\Server($tree);
     $fakeServer->sapi = new HTTP\SapiMock();
     $fakeServer->debugExceptions = true;
     $fakeServer->httpResponse = new HTTP\ResponseMock();
     $plugin = new Plugin();
     $plugin->allowAccessToNodesWithoutACL = true;
     $this->assertTrue($plugin instanceof Plugin);
     $fakeServer->addPlugin($plugin);
     $this->assertEquals($plugin, $fakeServer->getPlugin('acl'));
     return $fakeServer;
 }
 function getServer()
 {
     $backend = new PrincipalBackend\Mock();
     $dir = new DAV\SimpleCollection('root');
     $principals = new PrincipalCollection($backend);
     $dir->addChild($principals);
     $fakeServer = new DAV\Server(new DAV\ObjectTree($dir));
     $fakeServer->httpResponse = new HTTP\ResponseMock();
     $plugin = new Plugin($backend, 'realm');
     $this->assertTrue($plugin instanceof Plugin);
     $fakeServer->addPlugin($plugin);
     $this->assertEquals($plugin, $fakeServer->getPlugin('acl'));
     return $fakeServer;
 }
 function getServer()
 {
     $backend = new PrincipalBackend\Mock();
     $dir = new DAV\SimpleCollection('root');
     $principals = new PrincipalCollection($backend);
     $dir->addChild($principals);
     $fakeServer = new DAV\Server($dir);
     $fakeServer->sapi = new HTTP\SapiMock();
     $fakeServer->httpResponse = new HTTP\ResponseMock();
     $plugin = new Plugin();
     $plugin->allowUnauthenticatedAccess = false;
     $this->assertTrue($plugin instanceof Plugin);
     $fakeServer->addPlugin($plugin);
     $this->assertEquals($plugin, $fakeServer->getPlugin('acl'));
     return $fakeServer;
 }
Ejemplo n.º 26
0
 function getServer()
 {
     $tree = [new DAV\Mock\PropertiesCollection('node1', [], ['{http://sabredav.org/ns}simple' => 'foo', '{http://sabredav.org/ns}href' => new DAV\Xml\Property\Href('node2'), '{DAV:}displayname' => 'Node 1']), new DAV\Mock\PropertiesCollection('node2', [], ['{http://sabredav.org/ns}simple' => 'simple', '{http://sabredav.org/ns}hreflist' => new DAV\Xml\Property\Href(['node1', 'node3']), '{DAV:}displayname' => 'Node 2']), new DAV\Mock\PropertiesCollection('node3', [], ['{http://sabredav.org/ns}simple' => 'simple', '{DAV:}displayname' => 'Node 3'])];
     $fakeServer = new DAV\Server($tree);
     $fakeServer->sapi = new HTTP\SapiMock();
     $fakeServer->debugExceptions = true;
     $fakeServer->httpResponse = new HTTP\ResponseMock();
     $plugin = new Plugin();
     $plugin->allowUnauthenticatedAccess = false;
     // Anyone can do anything
     $plugin->setDefaultACL([['principal' => '{DAV:}all', 'privilege' => '{DAV:}all']]);
     $this->assertTrue($plugin instanceof Plugin);
     $fakeServer->addPlugin($plugin);
     $this->assertEquals($plugin, $fakeServer->getPlugin('acl'));
     return $fakeServer;
 }
 function getServer()
 {
     $backend = new PrincipalBackend\Mock();
     $dir = new DAV\SimpleCollection('root');
     $principals = new PrincipalCollection($backend);
     $dir->addChild($principals);
     $fakeServer = new DAV\Server($dir);
     $fakeServer->sapi = new HTTP\SapiMock();
     $fakeServer->httpResponse = new HTTP\ResponseMock();
     $fakeServer->debugExceptions = true;
     $plugin = new MockPlugin($backend, 'realm');
     $plugin->allowAccessToNodesWithoutACL = true;
     $this->assertTrue($plugin instanceof Plugin);
     $fakeServer->addPlugin($plugin);
     $this->assertEquals($plugin, $fakeServer->getPlugin('acl'));
     return $fakeServer;
 }
Ejemplo n.º 28
0
/**
 * @param Exception $e
 */
function handleException(Exception $e)
{
    $request = \OC::$server->getRequest();
    // in case the request content type is text/xml - we assume it's a WebDAV request
    $isXmlContentType = strpos($request->getHeader('Content-Type'), 'text/xml');
    if ($isXmlContentType === 0) {
        // fire up a simple server to properly process the exception
        $server = new Server();
        if (!$e instanceof RemoteException) {
            // we shall not log on RemoteException
            $server->addPlugin(new ExceptionLoggerPlugin('webdav', \OC::$server->getLogger()));
        }
        $server->on('beforeMethod', function () use($e) {
            if ($e instanceof RemoteException) {
                switch ($e->getCode()) {
                    case OC_Response::STATUS_SERVICE_UNAVAILABLE:
                        throw new ServiceUnavailable($e->getMessage());
                    case OC_Response::STATUS_NOT_FOUND:
                        throw new \Sabre\DAV\Exception\NotFound($e->getMessage());
                }
            }
            $class = get_class($e);
            $msg = $e->getMessage();
            throw new ServiceUnavailable("{$class}: {$msg}");
        });
        $server->exec();
    } else {
        $statusCode = OC_Response::STATUS_INTERNAL_SERVER_ERROR;
        if ($e instanceof \OC\ServiceUnavailableException) {
            $statusCode = OC_Response::STATUS_SERVICE_UNAVAILABLE;
        }
        if ($e instanceof RemoteException) {
            // we shall not log on RemoteException
            OC_Response::setStatus($e->getCode());
            OC_Template::printErrorPage($e->getMessage());
        } else {
            \OCP\Util::writeLog('remote', $e->getMessage(), \OCP\Util::FATAL);
            OC_Response::setStatus($statusCode);
            OC_Template::printExceptionErrorPage($e);
        }
    }
}
Ejemplo n.º 29
0
 /**
  * init the dav server
  */
 protected function initServer()
 {
     // create server
     $root = new \Sabre\DAV\FS\Directory($this->rootDirectory);
     $this->davServer = new \Sabre\DAV\Server($root);
     if (isset($this->baseUri)) {
         $this->davServer->setBaseUri($this->baseUri);
     }
     // Authentication backend
     $authBackend = new \Sabre\DAV\Auth\Backend\BasicCallBack(array($this, 'authCallback'));
     $auth = new \Sabre\DAV\Auth\Plugin($authBackend, 'Development Area');
     $this->davServer->addPlugin($auth);
     // Support for LOCK and UNLOCK
     $lockBackend = new \Sabre\DAV\Locks\Backend\File($this->lockFilePath);
     $lockPlugin = new \Sabre\DAV\Locks\Plugin($lockBackend);
     $this->davServer->addPlugin($lockPlugin);
     // Support for html frontend
     $browser = new \Sabre\DAV\Browser\Plugin();
     $this->davServer->addPlugin($browser);
     // Automatically guess (some) contenttypes, based on extension
     $this->davServer->addPlugin(new \Sabre\DAV\Browser\GuessContentType());
     // Support for mounting
     $this->davServer->addPlugin(new \Sabre\DAV\Mount\Plugin());
 }
Ejemplo n.º 30
0
 public function create(Horde_Injector $injector)
 {
     global $conf, $registry;
     $principalBackend = new Horde_Dav_Principals(new Horde_Core_Auth_UsernameHook(array('base' => $injector->getInstance('Horde_Core_Factory_Auth')->create())), $injector->getInstance('Horde_Core_Factory_Identity_DavUsernameHook'));
     $principals = new DAVACL\PrincipalCollection($principalBackend);
     $principals->disableListing = $conf['auth']['list_users'] == 'input';
     $calendarBackend = new Horde_Dav_Calendar_Backend($registry, $injector->getInstance('Horde_Dav_Storage'));
     $caldav = new CalDAV\CalendarRootNode($principalBackend, $calendarBackend);
     $contactsBackend = new Horde_Dav_Contacts_Backend($registry);
     $carddav = new CardDAV\AddressBookRoot($principalBackend, $contactsBackend);
     $server = new DAV\Server(new Horde_Dav_RootCollection($registry, array($principals, $caldav, $carddav), isset($conf['mime']['magic_db']) ? $conf['mime']['magic_db'] : null));
     $server->debugExceptions = false;
     $server->setBaseUri($registry->get('webroot', 'horde') . ($GLOBALS['conf']['urls']['pretty'] == 'rewrite' ? '/rpc/' : '/rpc.php/'));
     $server->addPlugin(new DAV\Auth\Plugin(new Horde_Core_Dav_Auth($injector->getInstance('Horde_Core_Factory_Auth')->create()), 'Horde DAV Server'));
     $server->addPlugin(new CalDAV\Plugin());
     $server->addPlugin(new CardDAV\Plugin());
     $server->addPlugin(new DAV\Locks\Plugin(new Horde_Dav_Locks($registry, $injector->getInstance('Horde_Lock'))));
     $server->addPlugin(new DAVACL\Plugin());
     $server->addPlugin(new DAV\Browser\Plugin());
     return $server;
 }