/** * serialize * * @param DOMElement $prop * @return void */ public function serialize(Sabre_DAV_Server $server, DOMElement $prop) { $doc = $prop->ownerDocument; foreach ($this->locks as $lock) { $activeLock = $doc->createElementNS('DAV:', 'd:activelock'); $prop->appendChild($activeLock); $lockScope = $doc->createElementNS('DAV:', 'd:lockscope'); $activeLock->appendChild($lockScope); $lockScope->appendChild($doc->createElementNS('DAV:', 'd:' . ($lock->scope == Sabre_DAV_Locks_LockInfo::EXCLUSIVE ? 'exclusive' : 'shared'))); $lockType = $doc->createElementNS('DAV:', 'd:locktype'); $activeLock->appendChild($lockType); $lockType->appendChild($doc->createElementNS('DAV:', 'd:write')); /* {DAV:}lockroot */ if (!self::$hideLockRoot) { $lockRoot = $doc->createElementNS('DAV:', 'd:lockroot'); $activeLock->appendChild($lockRoot); $href = $doc->createElementNS('DAV:', 'd:href'); $href->appendChild($doc->createTextNode($server->getBaseUri() . $lock->uri)); $lockRoot->appendChild($href); } $activeLock->appendChild($doc->createElementNS('DAV:', 'd:depth', $lock->depth == Sabre_DAV_Server::DEPTH_INFINITY ? 'infinity' : $lock->depth)); $activeLock->appendChild($doc->createElementNS('DAV:', 'd:timeout', 'Second-' . $lock->timeout)); if ($this->revealLockToken) { $lockToken = $doc->createElementNS('DAV:', 'd:locktoken'); $activeLock->appendChild($lockToken); $lockToken->appendChild($doc->createElementNS('DAV:', 'd:href', 'opaquelocktoken:' . $lock->token)); } $activeLock->appendChild($doc->createElementNS('DAV:', 'd:owner', $lock->owner)); } }
function testBrief() { $httpRequest = new Sabre_HTTP_Request(array('HTTP_BRIEF' => 't')); $server = new Sabre_DAV_Server(); $server->httpRequest = $httpRequest; $this->assertEquals(array('strict' => false, 'lenient' => false, 'wait' => null, 'return-asynch' => false, 'return-minimal' => true, 'return-representation' => false), $server->getHTTPPrefer()); }
/** * serialize * * @param Sabre_DAV_Server $server * @param DOMElement $dom * @return void */ public function serialize(Sabre_DAV_Server $server, DOMElement $dom) { $document = $dom->ownerDocument; $properties = $this->responseProperties; $xresponse = $document->createElement('d:response'); $dom->appendChild($xresponse); $uri = Sabre_DAV_URLUtil::encodePath($this->href); // Adding the baseurl to the beginning of the url $uri = $server->getBaseUri() . $uri; $xresponse->appendChild($document->createElement('d:href', $uri)); // The properties variable is an array containing properties, grouped by // HTTP status foreach ($properties as $httpStatus => $propertyGroup) { // The 'href' is also in this array, and it's special cased. // We will ignore it if ($httpStatus == 'href') { continue; } // If there are no properties in this group, we can also just carry on if (!count($propertyGroup)) { continue; } $xpropstat = $document->createElement('d:propstat'); $xresponse->appendChild($xpropstat); $xprop = $document->createElement('d:prop'); $xpropstat->appendChild($xprop); $nsList = $server->xmlNamespaces; foreach ($propertyGroup as $propertyName => $propertyValue) { $propName = null; preg_match('/^{([^}]*)}(.*)$/', $propertyName, $propName); // special case for empty namespaces if ($propName[1] == '') { $currentProperty = $document->createElement($propName[2]); $xprop->appendChild($currentProperty); $currentProperty->setAttribute('xmlns', ''); } else { if (!isset($nsList[$propName[1]])) { $nsList[$propName[1]] = 'x' . count($nsList); } // If the namespace was defined in the top-level xml namespaces, it means // there was already a namespace declaration, and we don't have to worry about it. if (isset($server->xmlNamespaces[$propName[1]])) { $currentProperty = $document->createElement($nsList[$propName[1]] . ':' . $propName[2]); } else { $currentProperty = $document->createElementNS($propName[1], $nsList[$propName[1]] . ':' . $propName[2]); } $xprop->appendChild($currentProperty); } if (is_scalar($propertyValue)) { $text = $document->createTextNode($propertyValue); $currentProperty->appendChild($text); } elseif ($propertyValue instanceof Sabre_DAV_PropertyInterface) { $propertyValue->serialize($server, $currentProperty); } elseif (!is_null($propertyValue)) { throw new Sabre_DAV_Exception('Unknown property value type: ' . gettype($propertyValue) . ' for property: ' . $propertyName); } } $xpropstat->appendChild($document->createElement('d:status', $server->httpResponse->getStatusMessage($httpStatus))); } }
/** * Serializes this property. * * It will additionally prepend the href property with the server's base uri. * * @param Sabre_DAV_Server $server * @param DOMElement $dom * @return void */ public function serialize(Sabre_DAV_Server $server, DOMElement $dom) { $prefix = $server->xmlNamespaces['DAV:']; $elem = $dom->ownerDocument->createElement($prefix . ':href'); $elem->nodeValue = ($this->autoPrefix ? $server->getBaseUri() : '') . $this->href; $dom->appendChild($elem); }
function testLockEtc() { mkdir(SABRE_TEMPDIR . '/mstest'); $tree = new Sabre_DAV_FS_Directory(SABRE_TEMPDIR . '/mstest'); $server = new Sabre_DAV_Server($tree); $server->debugExceptions = true; $locksBackend = new Sabre_DAV_Locks_Backend_File(SABRE_TEMPDIR . '/locksdb'); $locksPlugin = new Sabre_DAV_Locks_Plugin($locksBackend); $server->addPlugin($locksPlugin); $response1 = new Sabre_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 Sabre_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 Sabre_HTTP_ResponseMock(); $server->httpRequest = $this->getPutRequest($lockToken); $server->httpResponse = $response3; $server->exec(); $this->assertEquals('HTTP/1.1 204 No Content', $server->httpResponse->status); }
/** * 'beforeMethod' event handles. This event handles intercepts GET requests ending * with ?export * * @param string $method * @param string $uri * @return bool */ public function beforeMethod($method, $uri) { if ($method != 'GET') { return; } if ($this->server->httpRequest->getQueryString() != 'export') { return; } // splitting uri list($uri) = explode('?', $uri, 2); $node = $this->server->tree->getNodeForPath($uri); if (!$node instanceof Sabre_CalDAV_Calendar) { return; } // Checking ACL, if available. if ($aclPlugin = $this->server->getPlugin('acl')) { $aclPlugin->checkPrivileges($uri, '{DAV:}read'); } $this->server->httpResponse->setHeader('Content-Type', 'text/calendar'); $this->server->httpResponse->sendStatus(200); $nodes = $this->server->getPropertiesForPath($uri, array('{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}calendar-data'), 1); $this->server->httpResponse->sendBody($this->generateICS($nodes)); // Returning false to break the event chain return false; }
function testBeforeMethodNoExport() { $p = new Sabre_CalDAV_ICSExportPlugin(); $s = new Sabre_DAV_Server(); $s->addPlugin($p); $this->assertNull($p->beforeMethod('GET', 'UUID-123467')); }
public function indexAction() { // Set the root directory $webdavPath = Phprojekt::getInstance()->getConfig()->webdavPath; if (Phprojekt_Auth::isLoggedIn()) { $project = new Project_Models_Project(); $project = $project->find(1); $rootDirectory = new WebDAV_Models_ProjectDirectory($project); } else { // Some clients seem to send some queries without http auth. We need the dummy to serve those. $rootDirectory = new WebDAV_Models_EmptyDir(); } // The server object is responsible for making sense out of the WebDAV protocol $server = new Sabre_DAV_Server($rootDirectory); $server->setBaseUri($this->view->baseUrl('index.php/WebDAV/index/index/')); // The lock manager is reponsible for making sure users don't overwrite each others changes. // Change 'data' to a different directory, if you're storing your data somewhere else. $lockBackend = new Sabre_DAV_Locks_Backend_File($webdavPath . 'data/locks'); $lockPlugin = new Sabre_DAV_Locks_Plugin($lockBackend); $server->addPlugin($lockPlugin); // Authentication $authBackend = new WebDAV_Helper_Auth(); $authPlugin = new Sabre_DAV_Auth_Plugin($authBackend, 'WebDAV'); $server->addPlugin($authPlugin); // All we need to do now, is to fire up the server $server->exec(); }
/** * @depends testInit */ function testGetCurrentUserPrincipal() { $fakeServer = new Sabre_DAV_Server(new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleDirectory('bla'))); $plugin = new Sabre_DAV_Auth_Plugin(new Sabre_DAV_Auth_MockBackend(), 'realm'); $fakeServer->addPlugin($plugin); $fakeServer->broadCastEvent('beforeMethod', array('GET', '/')); $this->assertEquals('admin', $plugin->getCurrentUser()); }
function testAfterGetProperties() { $properties = array('href' => 'foo', '200' => array('{DAV:}displayname' => 'foo', '{DAV:}getcontentlength' => 500), '404' => array('{DAV:}bar' => null), '403' => array('{DAV:}owner' => null)); $expected = array('href' => 'foo', '200' => array('{DAV:}displayname' => 'foo', '{DAV:}getcontentlength' => 500), '404' => array('{DAV:}bar' => null), '403' => array('{DAV:}owner' => null)); $r = $this->server->broadcastEvent('afterGetProperties', array('testdir', &$properties)); $this->assertTrue($r); $this->assertEquals($expected, $properties); }
/** * Initializes the plugin * * @param Sabre_DAV_Server $server * @return void */ public function initialize(Sabre_DAV_Server $server) { $this->server = $server; $server->subscribeEvent('beforeGetProperties', array($this, 'beforeGetProperties')); $server->xmlNamespaces[Sabre_CalDAV_Plugin::NS_CALDAV] = 'cal'; $server->resourceTypeMapping['Sabre_CalDAV_ICalendar'] = '{urn:ietf:params:xml:ns:caldav}calendar'; array_push($server->protectedProperties, '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}schedule-calendar-transp', '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}schedule-default-calendar-URL', '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}schedule-tag'); }
/** * This initializes the plugin. * * This function is called by Sabre_DAV_Server, after * addPlugin is called. * * This method should set up the required event subscriptions. * * @param Sabre_DAV_Server $server * @return void */ public function initialize(Sabre_DAV_Server $server) { $server->xmlNamespaces[self::NS_OWNCLOUD] = 'oc'; $server->protectedProperties[] = '{' . self::NS_OWNCLOUD . '}id'; $this->server = $server; $this->server->subscribeEvent('beforeGetProperties', array($this, 'beforeGetProperties')); $this->server->subscribeEvent('afterCreateFile', array($this, 'sendFileIdHeader')); $this->server->subscribeEvent('afterWriteContent', array($this, 'sendFileIdHeader')); }
function testResourceType() { $tree = array(new Sabre_CardDAV_DirectoryMock('directory')); $server = new Sabre_DAV_Server($tree); $plugin = new Sabre_CardDAV_Plugin(); $server->addPlugin($plugin); $props = $server->getProperties('directory', array('{DAV:}resourcetype')); $this->assertTrue($props['{DAV:}resourcetype']->is('{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}directory')); }
public function testSetBadNode() { $tree = array(new Sabre_DAV_SimpleCollection('foo')); $server = new Sabre_DAV_Server($tree); $server->addPlugin(new Sabre_DAVACL_Plugin()); $result = $server->updateProperties('foo', array('{DAV:}group-member-set' => new Sabre_DAV_Property_HrefList(array('bar', 'baz')), '{DAV:}bar' => 'baz')); $expected = array('href' => 'foo', '403' => array('{DAV:}group-member-set' => null), '424' => array('{DAV:}bar' => null)); $this->assertEquals($expected, $result); }
function testUpdatePropertiesEventSuccess() { $tree = array(new Sabre_DAV_SimpleDirectory('foo')); $server = new Sabre_DAV_Server($tree); $server->subscribeEvent('updateProperties', array($this, 'updatepropsuccess')); $result = $server->updateProperties('foo', array('{DAV:}foo' => 'bar', '{DAV:}foo2' => 'bla')); $expected = array('href' => 'foo', '200' => array('{DAV:}foo' => null), '201' => array('{DAV:}foo2' => null)); $this->assertEquals($expected, $result); }
/** * Makes a request, and returns a response object. * * You can either pass an isntance of Sabre_HTTP_Request, or an array, * which will then be used as the _SERVER array. * * @param array|Sabre_HTTP_Request $request * @return Sabre_HTTP_Response */ function request($request) { if (is_array($request)) { $request = new Sabre_HTTP_Request($request); } $this->server->httpRequest = $request; $this->server->httpResponse = new Sabre_HTTP_ResponseMock(); $this->server->exec(); return $this->server->httpResponse; }
public function handle() { try { Tinebase_Core::initFramework(); } catch (Zend_Session_Exception $exception) { if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' invalid session. Delete session cookie.'); } Zend_Session::expireSessionCookie(); header('WWW-Authenticate: Basic realm="WebDAV for Tine 2.0"'); header('HTTP/1.1 401 Unauthorized'); return; } if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' is CalDav, CardDAV or WebDAV request.'); } if (empty($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['REMOTE_USER']) && empty($_SERVER['REDIRECT_REMOTE_USER'])) { header('WWW-Authenticate: Basic realm="WebDav for Tine 2.0"'); header('HTTP/1.1 401 Unauthorized'); return; } // when used with (f)cgi no PHP_AUTH variables are available without defining a special rewrite rule if (!isset($_SERVER['PHP_AUTH_USER'])) { // $_SERVER["REMOTE_USER"] == "Basic didhfiefdhfu4fjfjdsa34drsdfterrde..." $basicAuthData = base64_decode(substr(isset($_SERVER["REMOTE_USER"]) ? $_SERVER["REMOTE_USER"] : $_SERVER['REDIRECT_REMOTE_USER'], 6)); list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(":", $basicAuthData); } if (Tinebase_Controller::getInstance()->login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_SERVER['REMOTE_ADDR'], 'TineWebDav') !== true) { header('WWW-Authenticate: Basic realm="CardDav for Tine 2.0"'); header('HTTP/1.1 401 Unauthorized'); return; } self::$_server = new Sabre_DAV_Server(new Tinebase_WebDav_Root()); // compute base uri $request = new Zend_Controller_Request_Http(); self::$_server->setBaseUri($request->getBaseUrl() . '/'); $tempDir = Tinebase_Core::getTempDir(); if (!empty($tempDir)) { $lockBackend = new Sabre_DAV_Locks_Backend_File($tempDir . '/webdav.lock'); $lockPlugin = new Sabre_DAV_Locks_Plugin($lockBackend); self::$_server->addPlugin($lockPlugin); } $authPlugin = new Sabre_DAV_Auth_Plugin(new Tinebase_WebDav_Auth(), null); self::$_server->addPlugin($authPlugin); $aclPlugin = new Sabre_DAVACL_Plugin(); $aclPlugin->defaultUsernamePath = 'principals/users'; $aclPlugin->principalCollectionSet = array($aclPlugin->defaultUsernamePath); self::$_server->addPlugin($aclPlugin); self::$_server->addPlugin(new Sabre_CardDAV_Plugin()); self::$_server->addPlugin(new Sabre_CalDAV_Plugin()); self::$_server->addPlugin(new Sabre_CalDAV_Schedule_Plugin()); self::$_server->addPlugin(new Sabre_DAV_Browser_Plugin()); self::$_server->exec(); }
function setUp() { $this->backend = new Sabre_CardDAV_Backend_Mock(); $principalBackend = new Sabre_DAVACL_MockPrincipalBackend(); $tree = array(new Sabre_CardDAV_AddressBookRoot($principalBackend, $this->backend), new Sabre_DAVACL_PrincipalCollection($principalBackend)); $this->plugin = new Sabre_CardDAV_Plugin(); $this->plugin->directories = array('directory'); $this->server = new Sabre_DAV_Server($tree); $this->server->addPlugin($this->plugin); $this->server->debugExceptions = true; }
function testReportPassThrough() { $fakeServer = new Sabre_DAV_Server(new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleDirectory('bla'))); $plugin = new Sabre_DAV_Auth_Plugin(new Sabre_DAV_Auth_MockBackend(), 'realm'); $fakeServer->addPlugin($plugin); $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/')); $request->setBody('<?xml version="1.0"?><s:somereport xmlns:s="http://www.rooftopsolutions.nl/NS/example" />'); $fakeServer->httpRequest = $request; $fakeServer->httpResponse = new Sabre_HTTP_ResponseMock(); $fakeServer->exec(); $this->assertEquals('HTTP/1.1 501 Not Implemented', $fakeServer->httpResponse->status); }
/** * This method intercepts GET requests to non-files, and changes it into an HTTP PROPFIND request * * @param string $method * @return bool */ public function httpGetInterceptor($method) { if ($method != 'GET') { return true; } $node = $this->server->tree->getNodeForPath($this->server->getRequestUri()); if ($node instanceof Sabre_DAV_IFile) { return true; } $this->server->httpPropFind(); return false; }
/** * This method intercepts GET requests to non-files, and changes it into an HTTP PROPFIND request * * @param string $method * @param string $uri * @return bool */ public function httpGetInterceptor($method, $uri) { if ($method != 'GET') { return true; } $node = $this->server->tree->getNodeForPath($uri); if ($node instanceof Sabre_DAV_IFile) { return; } $this->server->invokeMethod('PROPFIND', $uri); return false; }
public function frameResponse(\FrameResponseObject $frameResponseObject) { $root = array(new \SteamDavDirectory($GLOBALS["STEAM"]->get_current_steam_user()->get_workroom()), new \Sabre_DAV_SimpleDirectory("Lesezeichen"), new \Sabre_DAV_SimpleDirectory("Gruppen"), new \Sabre_DAV_SimpleDirectory("Kurse")); $server = new \Sabre_DAV_Server($root); $server->setBaseUri("/webdav/index/"); // Support for html frontend $browser = new \Sabre_DAV_Browser_Plugin(); $server->addPlugin($browser); // And off we go! $server->exec(); exit; }
function testCheckPrivileges() { $acl = array(array('principal' => 'principals/admin', 'privilege' => '{DAV:}read'), array('principal' => 'principals/user1', 'privilege' => '{DAV:}read'), array('principal' => 'principals/admin', 'privilege' => '{DAV:}write')); $tree = array(new Sabre_DAVACL_MockACLNode('foo', $acl), new Sabre_DAV_SimpleCollection('principals', array(new Sabre_DAVACL_MockPrincipal('admin', 'principals/admin')))); $server = new Sabre_DAV_Server($tree); $aclPlugin = new Sabre_DAVACL_Plugin(); $server->addPlugin($aclPlugin); $auth = new Sabre_DAV_Auth_Plugin(new Sabre_DAV_Auth_MockBackend(), 'SabreDAV'); $server->addPlugin($auth); //forcing login //$auth->beforeMethod('GET','/'); $this->assertFalse($aclPlugin->checkPrivileges('foo', array('{DAV:}read'), Sabre_DAVACL_Plugin::R_PARENT, false)); }
function getServer() { $tree = array(new Sabre_DAVACL_MockPropertyNode('node1', array('{http://sabredav.org/ns}simple' => 'foo', '{http://sabredav.org/ns}href' => new Sabre_DAV_Property_Href('node2'), '{DAV:}displayname' => 'Node 1')), new Sabre_DAVACL_MockPropertyNode('node2', array('{http://sabredav.org/ns}simple' => 'simple', '{http://sabredav.org/ns}hreflist' => new Sabre_DAV_Property_HrefList(array('node1', 'node3')), '{DAV:}displayname' => 'Node 2')), new Sabre_DAVACL_MockPropertyNode('node3', array('{http://sabredav.org/ns}simple' => 'simple', '{DAV:}displayname' => 'Node 3'))); $fakeServer = new Sabre_DAV_Server($tree); $fakeServer->debugExceptions = true; $fakeServer->httpResponse = new Sabre_HTTP_ResponseMock(); $plugin = new Sabre_DAVACL_Plugin(); $plugin->allowAccessToNodesWithoutACL = true; $this->assertTrue($plugin instanceof Sabre_DAVACL_Plugin); $fakeServer->addPlugin($plugin); $this->assertEquals($plugin, $fakeServer->getPlugin('acl')); return $fakeServer; }
function getServer() { $backend = new Sabre_DAV_Auth_MockBackend(); $dir = new Sabre_DAV_SimpleDirectory('root'); $principals = new Sabre_DAV_Auth_PrincipalCollection($backend); $dir->addChild($principals); $fakeServer = new Sabre_DAV_Server(new Sabre_DAV_ObjectTree($dir)); $fakeServer->httpResponse = new Sabre_HTTP_ResponseMock(); $plugin = new Sabre_DAV_Auth_Plugin($backend, 'realm'); $this->assertTrue($plugin instanceof Sabre_DAV_Auth_Plugin); $fakeServer->addPlugin($plugin); $this->assertEquals($plugin, $fakeServer->getPlugin('Sabre_DAV_Auth_Plugin')); return $fakeServer; }
function testGetCurrentUserPrivilegeSet() { $acl = array(array('principal' => 'principals/admin', 'privilege' => '{DAV:}read'), array('principal' => 'principals/user1', 'privilege' => '{DAV:}read'), array('principal' => 'principals/admin', 'privilege' => '{DAV:}write')); $tree = array(new Sabre_DAVACL_MockACLNode('foo', $acl), new Sabre_DAV_SimpleDirectory('principals', array(new Sabre_DAVACL_MockPrincipal('admin', 'principals/admin')))); $server = new Sabre_DAV_Server($tree); $aclPlugin = new Sabre_DAVACL_Plugin(); $server->addPlugin($aclPlugin); $auth = new Sabre_DAV_Auth_Plugin(new Sabre_DAV_Auth_MockBackend(), 'SabreDAV'); $server->addPlugin($auth); //forcing login $auth->beforeMethod('GET', '/'); $expected = array('{DAV:}read', '{DAV:}read-acl', '{DAV:}read-current-user-privilege-set', '{DAV:}write', '{DAV:}write-acl', '{DAV:}write-properties', '{DAV:}write-content', '{DAV:}bind', '{DAV:}unbind', '{DAV:}unlock'); $this->assertEquals($expected, $aclPlugin->getCurrentUserPrivilegeSet('foo')); }
/** * Adds in extra information in the xml response. * * This method adds the {DAV:}need-privileges element as defined in rfc3744 * * @param Sabre_DAV_Server $server * @param DOMElement $errorNode * @return void */ public function serialize(Sabre_DAV_Server $server, DOMElement $errorNode) { $doc = $errorNode->ownerDocument; $np = $doc->createElementNS('DAV:', 'd:need-privileges'); $errorNode->appendChild($np); foreach ($this->privileges as $privilege) { $resource = $doc->createElementNS('DAV:', 'd:resource'); $np->appendChild($resource); $resource->appendChild($doc->createElementNS('DAV:', 'd:href', $server->getBaseUri() . $this->uri)); $priv = $doc->createElementNS('DAV:', 'd:privilege'); $resource->appendChild($priv); preg_match('/^{([^}]*)}(.*)$/', $privilege, $privilegeParts); $priv->appendChild($doc->createElementNS($privilegeParts[1], 'd:' . $privilegeParts[2])); } }
/** * This function handles the calendar-query REPORT * * This report is used by clients to request calendar objects based on * complex conditions. * * @param DOMNode $dom * @return void */ public function calendarQueryReport($dom) { $requestedProperties = array_keys(Sabre_DAV_XMLUtil::parseProperties($dom->firstChild)); $filterNode = $dom->getElementsByTagNameNS('urn:ietf:params:xml:ns:caldav', 'filter'); if ($filterNode->length !== 1) { throw new Sabre_DAV_Exception_BadRequest('The calendar-query report must have a filter element'); } $filters = Sabre_CalDAV_XMLUtil::parseCalendarQueryFilters($filterNode->item(0)); $requestedCalendarData = true; if (!in_array('{urn:ietf:params:xml:ns:caldav}calendar-data', $requestedProperties)) { // We always retrieve calendar-data, as we need it for filtering. $requestedProperties[] = '{urn:ietf:params:xml:ns:caldav}calendar-data'; // If calendar-data wasn't explicitly requested, we need to remove // it after processing. $requestedCalendarData = false; } // These are the list of nodes that potentially match the requirement $candidateNodes = $this->server->getPropertiesForPath($this->server->getRequestUri(), $requestedProperties, $this->server->getHTTPDepth(0)); $verifiedNodes = array(); foreach ($candidateNodes as $node) { // If the node didn't have a calendar-data property, it must not be a calendar object if (!isset($node[200]['{urn:ietf:params:xml:ns:caldav}calendar-data'])) { continue; } if ($this->validateFilters($node[200]['{urn:ietf:params:xml:ns:caldav}calendar-data'], $filters)) { if (!$requestedCalendarData) { unset($node[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']); } $verifiedNodes[] = $node; } } $this->server->httpResponse->sendStatus(207); $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); $this->server->httpResponse->sendBody($this->server->generateMultiStatus($verifiedNodes)); }
function getServer() { $backend = new Sabre_DAVACL_MockPrincipalBackend(); $dir = new Sabre_DAV_SimpleDirectory('root'); $principals = new Sabre_DAVACL_PrincipalCollection($backend); $dir->addChild($principals); $fakeServer = new Sabre_DAV_Server(new Sabre_DAV_ObjectTree($dir)); $fakeServer->httpResponse = new Sabre_HTTP_ResponseMock(); $fakeServer->debugExceptions = true; $plugin = new Sabre_DAVACL_MockPlugin($backend, 'realm'); $plugin->allowAccessToNodesWithoutACL = true; $this->assertTrue($plugin instanceof Sabre_DAVACL_Plugin); $fakeServer->addPlugin($plugin); $this->assertEquals($plugin, $fakeServer->getPlugin('acl')); return $fakeServer; }
function testSerializeNoPrefix() { $href = new Sabre_DAV_Property_HrefList(array('foo', 'bar'), false); $this->assertEquals(array('foo', 'bar'), $href->getHrefs()); $doc = new DOMDocument(); $root = $doc->createElement('d:anything'); $root->setAttribute('xmlns:d', 'DAV:'); $doc->appendChild($root); $server = new Sabre_DAV_Server(); $server->setBaseUri('/bla/'); $href->serialize($server, $root); $xml = $doc->saveXML(); $this->assertEquals('<?xml version="1.0"?> <d:anything xmlns:d="DAV:"><d:href>foo</d:href><d:href>bar</d:href></d:anything> ', $xml); }