/** * 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 Server $server * @return void */ function initialize(Server $server) { $server->on('propFind', [$this, 'propFind'], 130); $server->on('propPatch', [$this, 'propPatch'], 300); $server->on('afterMove', [$this, 'afterMove']); $server->on('afterUnbind', [$this, 'afterUnbind']); }
function testBrief() { $httpRequest = HTTP\Sapi::createFromServerArray(array('HTTP_BRIEF' => 't')); $server = new Server(); $server->httpRequest = $httpRequest; $this->assertEquals(array('strict' => false, 'lenient' => false, 'wait' => null, 'return-asynch' => false, 'return-minimal' => true, 'return-representation' => false), $server->getHTTPPrefer()); }
/** * Constructor. * * @param Server $dav * @param EventDispatcherInterface $dispatcher * @param RouterInterface $router */ public function __construct(Server $dav, EventDispatcherInterface $dispatcher, RouterInterface $router) { $this->dav = $dav; $this->dav->setBaseUri($router->generate('secotrust_sabre_dav', array())); $this->dispatcher = $dispatcher; // TODO needed? }
/** * Initializes the plugin * * @param \Sabre\DAV\Server $server * @return void */ public function initialize(\Sabre\DAV\Server $server) { $this->server = $server; $this->server->subscribeEvent('beforeMethod', array($this, 'beforeMethod')); $this->server->subscribeEvent('beforeBind', array($this, 'beforeBind'), 30); $this->server->subscribeEvent('afterUnbind', array($this, 'afterUnbind'), 30); }
/** * serialize * * @param DAV\Server $server * @param \DOMElement $prop * @return void */ public function serialize(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 == 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 == 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)); } }
/** * Initializes the plugin * * @param DAV\Server $server * @return void */ function initialize(DAV\Server $server) { /* Events */ $server->on('propFind', [$this, 'propFindEarly']); $server->on('propFind', [$this, 'propFindLate'], 150); $server->on('propPatch', [$this, 'propPatch']); $server->on('report', [$this, 'report']); $server->on('onHTMLActionsPanel', [$this, 'htmlActionsPanel']); $server->on('onBrowserPostAction', [$this, 'browserPostAction']); $server->on('beforeWriteContent', [$this, 'beforeWriteContent']); $server->on('beforeCreateFile', [$this, 'beforeCreateFile']); $server->on('afterMethod:GET', [$this, 'httpAfterGet']); /* Namespaces */ $server->xmlNamespaces[self::NS_CARDDAV] = 'card'; /* Mapping Interfaces to {DAV:}resourcetype values */ $server->resourceTypeMapping['Sabre\\CardDAV\\IAddressBook'] = '{' . self::NS_CARDDAV . '}addressbook'; $server->resourceTypeMapping['Sabre\\CardDAV\\IDirectory'] = '{' . self::NS_CARDDAV . '}directory'; /* Adding properties that may never be changed */ $server->protectedProperties[] = '{' . self::NS_CARDDAV . '}supported-address-data'; $server->protectedProperties[] = '{' . self::NS_CARDDAV . '}max-resource-size'; $server->protectedProperties[] = '{' . self::NS_CARDDAV . '}addressbook-home-set'; $server->protectedProperties[] = '{' . self::NS_CARDDAV . '}supported-collation-set'; $server->propertyMap['{http://calendarserver.org/ns/}me-card'] = 'Sabre\\DAV\\Property\\Href'; $this->server = $server; }
/** * '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 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('{' . Plugin::NS_CALDAV . '}calendar-data'), 1); $this->server->httpResponse->sendBody($this->generateICS($nodes)); // Returning false to break the event chain return false; }
public function initialize(\Sabre\DAV\Server $server) { $this->server = $server; $server->subscribeEvent('beforeMethod', array($this, 'httpGetInterceptor')); $server->subscribeEvent('beforeMethod', array($this, 'beforeMethod')); $server->subscribeEvent('beforeCreateFile', array($this, 'beforeCreateFile')); }
function testBrief() { $httpRequest = HTTP\Sapi::createFromServerArray(['HTTP_BRIEF' => 't']); $server = new Server(); $server->httpRequest = $httpRequest; $this->assertEquals(['respond-async' => false, 'return' => 'minimal', 'handling' => null, 'wait' => null], $server->getHTTPPrefer()); }
/** * serialize * * @param DAV\Server $server * @param \DOMElement $dom * @return void */ public function serialize(DAV\Server $server, \DOMElement $dom) { $document = $dom->ownerDocument; $properties = $this->responseProperties; $xresponse = $document->createElement('d:response'); $dom->appendChild($xresponse); $uri = 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 DAV\PropertyInterface) { $propertyValue->serialize($server, $currentProperty); } elseif (!is_null($propertyValue)) { throw new DAV\Exception('Unknown property value type: ' . gettype($propertyValue) . ' for property: ' . $propertyName); } } $xpropstat->appendChild($document->createElement('d:status', $server->httpResponse->getStatusMessage($httpStatus))); } }
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); }
/** * Serializes this property. * * It will additionally prepend the href property with the server's base uri. * * @param DAV\Server $server * @param \DOMElement $dom * @return void */ public function serialize(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 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); }
/** * Initializes the plugin * * This method is automatically called by the Server class after addPlugin. * * @param DAV\Server $server * @return void */ public function initialize(DAV\Server $server) { $this->server = $server; $server->subscribeEvent('unknownMethod', array($this, 'unknownMethod')); $server->subscribeEvent('beforeMethod', array($this, 'beforeMethod'), 50); $server->subscribeEvent('afterGetProperties', array($this, 'afterGetProperties')); }
/** * Intercepts GET requests on addressbook urls ending with ?photo. * * @param RequestInterface $request * @param ResponseInterface $response * @return bool|void */ function httpGet(RequestInterface $request, ResponseInterface $response) { $queryParams = $request->getQueryParameters(); // TODO: in addition to photo we should also add logo some point in time if (!array_key_exists('photo', $queryParams)) { return true; } $path = $request->getPath(); $node = $this->server->tree->getNodeForPath($path); if (!$node instanceof Card) { return true; } $this->server->transactionType = 'carddav-image-export'; // Checking ACL, if available. if ($aclPlugin = $this->server->getPlugin('acl')) { /** @var \Sabre\DAVACL\Plugin $aclPlugin */ $aclPlugin->checkPrivileges($path, '{DAV:}read'); } if ($result = $this->getPhoto($node)) { $response->setHeader('Content-Type', $result['Content-Type']); $response->setStatus(200); $response->setBody($result['body']); // Returning false to break the event chain return false; } return true; }
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(); }
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); }
public function idAction($id) { $server = new Server(new RootId($id)); $server->setBaseUri(WEBDAV_BASE_URI . "id/" . $id . "/"); $this->initDavPlugins($server); $server->exec(); exit; }
/** * 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->propertyMap[self::TAGS_PROPERTYNAME] = 'OC\\Connector\\Sabre\\TagList'; $this->server = $server; $this->server->on('propFind', array($this, 'handleGetProperties')); $this->server->on('propPatch', array($this, 'handleUpdateProperties')); }
/** {@inheritDoc} */ public function initialize(\Sabre\DAV\Server $server) { $this->server = $server; $this->server->on('method:LOCK', [$this, 'fakeLockProvider'], 1); $this->server->on('method:UNLOCK', [$this, 'fakeUnlockProvider'], 1); $server->on('propFind', [$this, 'propFind']); $server->on('validateTokens', [$this, 'validateTokens']); }
function schedule(Message $message) { $plugin = new IMip\MockPlugin('*****@*****.**'); $server = new Server(); $server->addPlugin($plugin); $server->emit('schedule', [$message]); return $plugin->getSentEmails(); }
/** * Initializes the plugin * * @param \Sabre\DAV\Server $server * @return void */ public function initialize(\Sabre\DAV\Server $server) { $this->server = $server; $this->server->subscribeEvent('unknownMethod', array($this, 'httpPOSTHandler')); $server->subscribeEvent('beforeGetProperties', array($this, 'beforeGetProperties')); $server->xmlNamespaces[\Sabre\CalDAV\Plugin::NS_CALENDARSERVER] = 'cs'; $server->resourceTypeMapping['\\Sabre\\CalDAV\\ICalendar'] = '{urn:ietf:params:xml:ns:caldav}calendar'; }
/** * @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()); }
/** * @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()); }
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); }
/** * This test makes sure that a path like /foo cannot be copied into a path * like /foo/bar/ * * @expectedException \Sabre\DAV\Exception\Conflict */ public function testCopyIntoSubPath() { $dir = new FS\Directory(SABRE_TEMPDIR); $server = new Server($dir); $dir->createDirectory('foo'); $request = new HTTP\Request('COPY', '/foo', ['Destination' => '/foo/bar']); $response = new HTTP\ResponseMock(); $server->invokeMethod($request, $response); }
protected function getUser() { $user = null; $authPlugin = $this->server->getPlugin('auth'); if ($authPlugin !== null) { $user = $authPlugin->getCurrentUser(); } return $user; }
/** * 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->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; $server->protectedProperties[] = self::ID_PROPERTYNAME; $server->on('propFind', array($this, 'handleGetProperties')); $server->on('propPatch', array($this, 'handleUpdateProperties')); $server->on('method:POST', [$this, 'httpPost']); $this->server = $server; }
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; }
/** * 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->propertyMap[self::TAGS_PROPERTYNAME] = 'OC\\Connector\\Sabre\\TagList'; $this->server = $server; $this->server->subscribeEvent('beforeGetProperties', array($this, 'beforeGetProperties')); $this->server->subscribeEvent('beforeGetPropertiesForPath', array($this, 'beforeGetPropertiesForPath')); $this->server->subscribeEvent('updateProperties', array($this, 'updateProperties')); }