예제 #1
1
 /**
  * '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 IAddressBook) {
         return;
     }
     // Checking ACL, if available.
     if ($aclPlugin = $this->server->getPlugin('acl')) {
         $aclPlugin->checkPrivileges($uri, '{DAV:}read');
     }
     $this->server->httpResponse->setHeader('Content-Type', 'text/directory');
     $this->server->httpResponse->sendStatus(200);
     $nodes = $this->server->getPropertiesForPath($uri, array('{' . Plugin::NS_CARDDAV . '}address-data'), 1);
     $this->server->httpResponse->sendBody($this->generateVCF($nodes));
     // Returning false to break the event chain
     return false;
 }
 /**
  * test testGetProperties method
  */
 public function testGetProperties()
 {
     $body = '<?xml version="1.0" encoding="utf-8"?>
              <propfind xmlns="DAV:">
                 <prop>
                     <default-alarm-vevent-date xmlns="urn:ietf:params:xml:ns:caldav"/>
                     <default-alarm-vevent-datetime xmlns="urn:ietf:params:xml:ns:caldav"/>
                     <default-alarm-vtodo-date xmlns="urn:ietf:params:xml:ns:caldav"/>
                     <default-alarm-vtodo-datetime xmlns="urn:ietf:params:xml:ns:caldav"/>
                 </prop>
              </propfind>';
     $request = new Sabre\HTTP\Request(array('REQUEST_METHOD' => 'PROPFIND', 'REQUEST_URI' => '/calendars/' . Tinebase_Core::getUser()->contact_id, 'HTTP_DEPTH' => '0'));
     $request->setBody($body);
     $this->server->httpRequest = $request;
     $this->server->exec();
     //var_dump($this->response->body);
     $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status);
     $responseDoc = new DOMDocument();
     $responseDoc->loadXML($this->response->body);
     //$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
     $xpath = new DomXPath($responseDoc);
     $xpath->registerNamespace('cal', 'urn:ietf:params:xml:ns:caldav');
     $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vevent-datetime');
     $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
     $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vevent-date');
     $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
     $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vtodo-datetime');
     $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
     $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vtodo-date');
     $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
 }
 /**
  * test testGetProperties method
  */
 public function testGetProperties()
 {
     $body = '<?xml version="1.0" encoding="utf-8"?>
              <propfind xmlns="DAV:">
                 <prop>
                     <getlastmodified xmlns="DAV:"/>
                     <getcontentlength xmlns="DAV:"/>
                     <resourcetype xmlns="DAV:"/>
                     <getetag xmlns="DAV:"/>
                     <id xmlns="http://owncloud.org/ns"/>
                 </prop>
              </propfind>';
     $request = new Sabre\HTTP\Request(array('REQUEST_METHOD' => 'PROPFIND', 'REQUEST_URI' => '/remote.php/webdav/' . Tinebase_Core::getUser()->accountDisplayName, 'HTTP_DEPTH' => '0'));
     $request->setBody($body);
     $this->server->httpRequest = $request;
     $this->server->exec();
     //var_dump($this->response->body);
     $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status);
     $responseDoc = new DOMDocument();
     $responseDoc->loadXML($this->response->body);
     //$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
     $xpath = new DomXPath($responseDoc);
     $xpath->registerNamespace('owncloud', 'http://owncloud.org/ns');
     $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/owncloud:id');
     $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
 }
예제 #4
0
 function process($source_id, $pmb_user_id)
 {
     global $class_path;
     global $webdav_current_user_id, $webdav_current_user_name;
     global $pmb_url_base;
     $source_object = $this->instantiate_source_class($source_id);
     $webdav_current_user_id = 0;
     $webdav_current_user_name = "Anonymous";
     $rootDir = new Sabre\PMB\Tree($source_object->config);
     $server = new Sabre\DAV\Server($rootDir);
     if ($source_object->config['allow_web']) {
         $web = new Sabre\PMB\BrowserPlugin();
         $server->addPlugin($web);
     }
     if ($source_object->config['authentication'] != "anonymous") {
         $auth = new Sabre\PMB\Auth($source_object->config['authentication']);
         $authPlugin = new Sabre\DAV\Auth\Plugin($auth, md5($pmb_url_base));
         // Adding the plugin to the server
         $server->addPlugin($authPlugin);
     }
     // We're required to set the base uri, it is recommended to put your webdav server on a root of a domain
     $server->setBaseUri($source_object->config['base_uri']);
     // And off we go!
     $server->exec();
 }
예제 #5
0
 /**
  * Intercepts GET requests on addressbook urls ending with ?export.
  *
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @return bool
  */
 function httpGet(RequestInterface $request, ResponseInterface $response)
 {
     $queryParams = $request->getQueryParameters();
     if (!array_key_exists('export', $queryParams)) {
         return;
     }
     $path = $request->getPath();
     $node = $this->server->tree->getNodeForPath($path);
     if (!$node instanceof IAddressBook) {
         return;
     }
     $this->server->transactionType = 'get-addressbook-export';
     // Checking ACL, if available.
     if ($aclPlugin = $this->server->getPlugin('acl')) {
         $aclPlugin->checkPrivileges($path, '{DAV:}read');
     }
     $nodes = $this->server->getPropertiesForPath($path, ['{' . Plugin::NS_CARDDAV . '}address-data'], 1);
     $format = 'text/directory';
     $output = null;
     $filenameExtension = null;
     switch ($format) {
         case 'text/directory':
             $output = $this->generateVCF($nodes);
             $filenameExtension = '.vcf';
             break;
     }
     $filename = preg_replace('/[^a-zA-Z0-9-_ ]/um', '', $node->getName());
     $filename .= '-' . date('Y-m-d') . $filenameExtension;
     $response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
     $response->setHeader('Content-Type', $format);
     $response->setStatus(200);
     $response->setBody($output);
     // Returning false to break the event chain
     return false;
 }
 /**
  * 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'));
     /* Namespaces */
     $server->xmlNamespaces[self::NS_OWNCLOUD] = 'owncloud';
     array_push($server->protectedProperties, '{' . self::NS_OWNCLOUD . '}id');
 }
예제 #7
0
 function testInit()
 {
     $server = new \Sabre\DAV\Server();
     $plugin = new Plugin();
     $server->addPlugin($plugin);
     $this->assertEquals('{http://calendarserver.org/ns/}subscribed', $server->resourceTypeMapping['Sabre\\CalDAV\\Subscriptions\\ISubscription']);
     $this->assertEquals('Sabre\\DAV\\Property\\Href', $server->propertyMap['{http://calendarserver.org/ns/}source']);
     $this->assertEquals(['calendarserver-subscribed'], $plugin->getFeatures());
 }
 /**
  * This method intercepts GET requests to non-files, and changes it into an HTTP PROPFIND request
  *
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @return bool
  */
 function httpGet(RequestInterface $request, ResponseInterface $response)
 {
     $node = $this->server->tree->getNodeForPath($request->getPath());
     if ($node instanceof DAV\IFile) {
         return;
     }
     $subRequest = clone $request;
     $subRequest->setMethod('PROPFIND');
     $this->server->invokeMethod($subRequest, $response);
     return false;
 }
예제 #9
0
 function testPrincipalProperties()
 {
     $httpRequest = HTTP\Sapi::createFromServerArray(array('HTTP_HOST' => 'sabredav.org'));
     $this->server->httpRequest = $httpRequest;
     $props = $this->server->getPropertiesForPath('/principals/user1', array('{' . Plugin::NS_CALENDARSERVER . '}notification-URL'));
     $this->assertArrayHasKey(0, $props);
     $this->assertArrayHasKey(200, $props[0]);
     $this->assertArrayHasKey('{' . Plugin::NS_CALENDARSERVER . '}notification-URL', $props[0][200]);
     $prop = $props[0][200]['{' . Plugin::NS_CALENDARSERVER . '}notification-URL'];
     $this->assertTrue($prop instanceof DAV\Property\Href);
     $this->assertEquals('calendars/user1/notifications/', $prop->getHref());
 }
예제 #10
0
 function testPrincipalProperties()
 {
     $httpRequest = new Request('GET', '/', ['Host' => 'sabredav.org']);
     $this->server->httpRequest = $httpRequest;
     $props = $this->server->getPropertiesForPath('principals/admin', ['{' . Plugin::NS_CALENDARSERVER . '}notification-URL']);
     $this->assertArrayHasKey(0, $props);
     $this->assertArrayHasKey(200, $props[0]);
     $this->assertArrayHasKey('{' . Plugin::NS_CALENDARSERVER . '}notification-URL', $props[0][200]);
     $prop = $props[0][200]['{' . Plugin::NS_CALENDARSERVER . '}notification-URL'];
     $this->assertTrue($prop instanceof DAV\Xml\Property\Href);
     $this->assertEquals('calendars/admin/notifications/', $prop->getHref());
 }
예제 #11
0
 function setUp()
 {
     $this->backend = new Backend\Mock();
     $principalBackend = new DAVACL\PrincipalBackend\Mock();
     $tree = array(new AddressBookRoot($principalBackend, $this->backend), new DAVACL\PrincipalCollection($principalBackend));
     $this->plugin = new Plugin();
     $this->plugin->directories = array('directory');
     $this->server = new DAV\Server($tree);
     $this->server->sapi = new HTTP\SapiMock();
     $this->server->addPlugin($this->plugin);
     $this->server->debugExceptions = true;
 }
예제 #12
0
 /**
  * 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 DAV\IFile) {
         return;
     }
     $this->server->invokeMethod('PROPFIND', $uri);
     return false;
 }
    /**
     * @depends testSimple
     */
    function testSerialize()
    {
        $property = new EmailAddressSet(['*****@*****.**']);
        $doc = new \DOMDocument();
        $root = $doc->createElement('d:root');
        $root->setAttribute('xmlns:d', 'DAV:');
        $root->setAttribute('xmlns:cs', \Sabre\CalDAV\Plugin::NS_CALENDARSERVER);
        $doc->appendChild($root);
        $server = new \Sabre\DAV\Server();
        $server->addPlugin(new \Sabre\CalDAV\Plugin());
        $property->serialize($server, $root);
        $xml = $doc->saveXML();
        $this->assertEquals('<?xml version="1.0"?>
<d:root xmlns:d="DAV:" xmlns:cs="' . \Sabre\CalDAV\Plugin::NS_CALENDARSERVER . '">' . '<cs:email-address>foo@example.org</cs:email-address>' . '</d:root>
', $xml);
    }
 /**
  * Implementing Principal Match
  * 
  * @param DOMDocument $dom
  */
 public function principalMatch(DOMDocument $dom)
 {
     $xml = array(array('href' => 'principals/users/' . Tinebase_Core::getUser()->contact_id));
     $this->server->httpResponse->sendStatus(207);
     $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
     $this->server->httpResponse->sendBody($this->server->generateMultiStatus($xml));
 }
예제 #15
0
 /**
  * aclPrincipalPropSet REPORT
  *
  * This method is responsible for handling the {DAV:}acl-principal-prop-set
  * REPORT, as defined in:
  *
  * https://tools.ietf.org/html/rfc3744#section-9.2
  *
  * This REPORT allows a user to quickly fetch information about all
  * principals specified in the access control list. Most commonly this
  * is used to for example generate a UI with ACL rules, allowing you
  * to show names for principals for every entry.
  *
  * @param string $path
  * @param Xml\Request\AclPrincipalPropSetReport $report
  * @return void
  */
 protected function aclPrincipalPropSetReport($path, Xml\Request\AclPrincipalPropSetReport $report)
 {
     if ($this->server->getHTTPDepth(0) !== 0) {
         throw new BadRequest('The {DAV:}acl-principal-prop-set REPORT only supports Depth 0');
     }
     // Fetching ACL rules for the given path. We're using the property
     // API and not the local getACL, because it will ensure that all
     // business rules and restrictions are applied.
     $acl = $this->server->getProperties($path, '{DAV:}acl');
     if (!$acl || !isset($acl['{DAV:}acl'])) {
         throw new Forbidden('Could not fetch ACL rules for this path');
     }
     $principals = [];
     foreach ($acl['{DAV:}acl']->getPrivileges() as $ace) {
         if ($ace['principal'][0] === '{') {
             // It's not a principal, it's one of the special rules such as {DAV:}authenticated
             continue;
         }
         $principals[] = $ace['principal'];
     }
     $properties = $this->server->getPropertiesForMultiplePaths($principals, $report->properties);
     $this->server->httpResponse->setStatus(207);
     $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
     $this->server->httpResponse->setBody($this->server->generateMultiStatus($properties));
 }
예제 #16
0
 /**
  * @depends testCalendarMultiGetReport
  */
 function testCalendarMultiGetReportEndBeforeStart()
 {
     $body = '<?xml version="1.0"?>' . '<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' . '<d:prop>' . '  <c:calendar-data>' . '     <c:expand start="20200101T000000Z" end="20110101T000000Z" />' . '  </c:calendar-data>' . '  <d:getetag />' . '</d:prop>' . '<d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>' . '</c:calendar-multiget>';
     $request = new HTTP\Request(array('REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/calendars/user1', 'HTTP_DEPTH' => '1'));
     $request->setBody($body);
     $this->server->httpRequest = $request;
     $this->server->exec();
     $this->assertEquals('HTTP/1.1 400 Bad request', $this->response->status, 'Invalid HTTP status received. Full response body: ' . $this->response->body);
 }
예제 #17
0
파일: server.php 프로젝트: pinoniq/core
 protected function httpGet($uri)
 {
     $range = $this->getHTTPRange();
     if (OC_App::isEnabled('files_encryption') && $range) {
         // encryption does not support range requests
         $this->ignoreRangeHeader = true;
     }
     return parent::httpGet($uri);
 }
예제 #18
0
 /**
  * Makes a request, and returns a response object.
  *
  * You can either pass an instance 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 HTTP\Request($request);
     }
     $this->server->httpRequest = $request;
     $this->server->httpResponse = new HTTP\ResponseMock();
     $this->server->exec();
     return $this->server->httpResponse;
 }
예제 #19
0
 /**
  * Parses the 'invite-reply' POST request.
  *
  * This method returns an array, containing the following properties:
  *   * href - The sharee who is replying
  *   * status - One of the self::STATUS_* constants
  *   * calendarUri - The url of the shared calendar
  *   * inReplyTo - The unique id of the share invitation.
  *   * summary - Optional description of the reply.
  *
  * @param \DOMDocument $dom
  * @return array
  */
 protected function parseInviteReplyRequest(\DOMDocument $dom)
 {
     $xpath = new \DOMXPath($dom);
     $xpath->registerNamespace('cs', Plugin::NS_CALENDARSERVER);
     $xpath->registerNamespace('d', 'urn:DAV');
     $hostHref = $xpath->evaluate('string(cs:hosturl/d:href)');
     if (!$hostHref) {
         throw new DAV\Exception\BadRequest('The {' . Plugin::NS_CALENDARSERVER . '}hosturl/{DAV:}href element is required');
     }
     return array('href' => $xpath->evaluate('string(d:href)'), 'calendarUri' => $this->server->calculateUri($hostHref), 'inReplyTo' => $xpath->evaluate('string(cs:in-reply-to)'), 'summary' => $xpath->evaluate('string(cs:summary)'), 'status' => $xpath->evaluate('boolean(cs:invite-accepted)') ? self::STATUS_ACCEPTED : self::STATUS_DECLINED);
 }
 /**
  * This function handles the calendar-multiget REPORT.
  *
  * prefetch events into calendar container class, to avoid single lookup of events
  *
  * @param \DOMNode $dom
  * @return void
  */
 public function calendarMultiGetReport($dom)
 {
     $properties = array_keys(\Sabre\DAV\XMLUtil::parseProperties($dom->firstChild));
     $hrefElems = $dom->getElementsByTagNameNS('urn:DAV', 'href');
     $filters = array('name' => 'VCALENDAR', 'comp-filters' => array(array('name' => 'VEVENT', 'prop-filters' => array())));
     foreach ($hrefElems as $elem) {
         list($dirName, $baseName) = \Sabre\DAV\URLUtil::splitPath($elem->nodeValue);
         $filters['comp-filters'][0]['prop-filters'][] = array('name' => 'UID', 'text-match' => array('value' => $baseName));
     }
     $node = $this->server->tree->getNodeForPath($this->server->getRequestUri());
     $node->calendarQuery($filters);
 }
예제 #21
0
 /**
  * This function handles the addressbook-query REPORT
  *
  * This report is used by the client to filter an addressbook based on a
  * complex query.
  *
  * @param Xml\Request\AddressBookQueryReport $report
  * @return void
  */
 protected function addressbookQueryReport($report)
 {
     $depth = $this->server->getHTTPDepth(0);
     if ($depth == 0) {
         $candidateNodes = [$this->server->tree->getNodeForPath($this->server->getRequestUri())];
         if (!$candidateNodes[0] instanceof ICard) {
             throw new ReportNotSupported('The addressbook-query report is not supported on this url with Depth: 0');
         }
     } else {
         $candidateNodes = $this->server->tree->getChildren($this->server->getRequestUri());
     }
     $contentType = $report->contentType;
     if ($report->version) {
         $contentType .= '; version=' . $report->version;
     }
     $vcardType = $this->negotiateVCard($contentType);
     $validNodes = [];
     foreach ($candidateNodes as $node) {
         if (!$node instanceof ICard) {
             continue;
         }
         $blob = $node->get();
         if (is_resource($blob)) {
             $blob = stream_get_contents($blob);
         }
         if (!$this->validateFilters($blob, $report->filters, $report->test)) {
             continue;
         }
         $validNodes[] = $node;
         if ($report->limit && $report->limit <= count($validNodes)) {
             // We hit the maximum number of items, we can stop now.
             break;
         }
     }
     $result = [];
     foreach ($validNodes as $validNode) {
         if ($depth == 0) {
             $href = $this->server->getRequestUri();
         } else {
             $href = $this->server->getRequestUri() . '/' . $validNode->getName();
         }
         list($props) = $this->server->getPropertiesForPath($href, $report->properties, 0);
         if (isset($props[200]['{' . self::NS_CARDDAV . '}address-data'])) {
             $props[200]['{' . self::NS_CARDDAV . '}address-data'] = $this->convertVCard($props[200]['{' . self::NS_CARDDAV . '}address-data'], $vcardType);
         }
         $result[] = $props;
     }
     $prefer = $this->server->getHTTPPrefer();
     $this->server->httpResponse->setStatus(207);
     $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
     $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer');
     $this->server->httpResponse->setBody($this->server->generateMultiStatus($result, $prefer['return'] === 'minimal'));
 }
 /**
  * test testGetProperties method
  */
 public function testGetProperties()
 {
     $body = '<?xml version="1.0" encoding="utf-8"?>
              <A:calendarserver-principal-search xmlns:A="http://calendarserver.org/ns/" context="attendee">
                 <A:search-token>Administrators</A:search-token>
                 <A:limit>
                     <A:nresults>50</A:nresults>
                 </A:limit>
                 <B:prop xmlns:B="DAV:">
                     <C:calendar-user-address-set xmlns:C="urn:ietf:params:xml:ns:caldav"/>
                     <C:calendar-user-type xmlns:C="urn:ietf:params:xml:ns:caldav"/>
                     <A:record-type/>
                     <A:first-name/>
                     <A:last-name/>
                 </B:prop>
             </A:calendarserver-principal-search>';
     $request = new Sabre\HTTP\Request(array('REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/principals'));
     $request->setBody($body);
     $this->server->httpRequest = $request;
     $this->server->exec();
     //var_dump($this->response->body);
     $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status);
     $responseDoc = new DOMDocument();
     $responseDoc->loadXML($this->response->body);
     #$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
     $xpath = new DomXPath($responseDoc);
     $xpath->registerNamespace('cal', 'urn:ietf:params:xml:ns:caldav');
     $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:calendar-user-address-set');
     $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
     $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:calendar-user-type');
     $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
     #$nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vtodo-datetime');
     #$this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     #$this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
     #$nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vtodo-date');
     #$this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     #$this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
 }
예제 #23
0
파일: Plugin.php 프로젝트: samj1912/repo
 /**
  * This method allows us to intercept the 'mkaddressbook' sabreAction. This
  * action enables the user to create new addressbooks from the browser plugin.
  *
  * @param string $uri
  * @param string $action
  * @param array $postVars
  * @return bool
  */
 function browserPostAction($uri, $action, array $postVars)
 {
     if ($action !== 'mkaddressbook') {
         return;
     }
     $resourceType = ['{DAV:}collection', '{urn:ietf:params:xml:ns:carddav}addressbook'];
     $properties = [];
     if (isset($postVars['{DAV:}displayname'])) {
         $properties['{DAV:}displayname'] = $postVars['{DAV:}displayname'];
     }
     $this->server->createCollection($uri . '/' . $postVars['name'], $resourceType, $properties);
     return false;
 }
예제 #24
0
 /**
  * This function takes a username and sets the server in a state where
  * this user is logged in, and no longer requires an authentication check.
  *
  * @param string $userName
  */
 function autoLogin($userName)
 {
     $authBackend = new DAV\Auth\Backend\Mock();
     $authBackend->setPrincipal('principals/' . $userName);
     $this->authPlugin = new DAV\Auth\Plugin($authBackend);
     // If the auth plugin already exists, we're removing its hooks:
     if ($oldAuth = $this->server->getPlugin('auth')) {
         $this->server->removeListener('beforeMethod', [$oldAuth, 'beforeMethod']);
     }
     $this->server->addPlugin($this->authPlugin);
     // This will trigger the actual login procedure
     $this->authPlugin->beforeMethod(new Request(), new Response());
 }
 public function testDropBoxPut()
 {
     $event = $this->calDAVTests->testCreateEventWithInternalOrganizer();
     $request = new Sabre\HTTP\Request(array('REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/calendars/' . Tinebase_Core::getUser()->contact_id . '/dropbox/' . $event->getRecord()->getId() . '.dropbox/agenda.txt'));
     $agenda = 'HELLO WORLD';
     $request->setBody($agenda);
     $this->server->httpRequest = $request;
     $this->server->exec();
     //         echo $this->response->body;
     $attachments = Tinebase_FileSystem_RecordAttachments::getInstance()->getRecordAttachments($event->getRecord());
     $this->assertEquals(1, $attachments->count());
     $this->assertEquals('agenda.txt', $attachments[0]->name);
 }
 /**
  * This method handles the PROPFIND method.
  *
  * It's a very lazy method, it won't bother checking the request body
  * for which properties were requested, and just sends back a default
  * set of properties.
  *
  * @param RequestInterface $request
  * @param ResponseInterface $hR
  * @param string $tempLocation
  * @return bool
  */
 function httpPropfind(RequestInterface $request, ResponseInterface $hR, $tempLocation)
 {
     if (!file_exists($tempLocation)) {
         return;
     }
     $hR->setHeader('X-Sabre-Temp', 'true');
     $hR->setStatus(207);
     $hR->setHeader('Content-Type', 'application/xml; charset=utf-8');
     $properties = ['href' => $request->getPath(), 200 => ['{DAV:}getlastmodified' => new Xml\Property\GetLastModified(filemtime($tempLocation)), '{DAV:}getcontentlength' => filesize($tempLocation), '{DAV:}resourcetype' => new Xml\Property\ResourceType(null), '{' . Server::NS_SABREDAV . '}tempFile' => true]];
     $data = $this->server->generateMultiStatus([$properties]);
     $hR->setBody($data);
     return false;
 }
 /**
  * test userQuery method
  */
 public function testUserQuery()
 {
     $body = '<?xml version="1.0" encoding="UTF-8"?>
              <user-query xmlns="urn:inverse:params:xml:ns:inverse-dav">
                  <users match-name="' . Tinebase_Core::getUser()->accountFullName . '"/>
              </user-query>';
     $request = new Sabre\HTTP\Request(array('REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/calendars/' . Tinebase_Core::getUser()->contact_id . '/' . $this->objects['initialContainer']->id, 'HTTP_DEPTH' => '1'));
     $request->setBody($body);
     $this->server->httpRequest = $request;
     $this->server->exec();
     $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status);
     $this->assertContains('<displayName>' . Tinebase_Core::getUser()->accountDisplayName . '</displayName>', $this->response->body);
     $this->assertContains('<id>' . Tinebase_Core::getUser()->contact_id . '</id>', $this->response->body);
 }
예제 #28
0
    /**
     * @expectedException Sabre\DAV\Exception
     */
    function testFreeBusyReportNoACLPlugin()
    {
        $this->server = new DAV\Server();
        $this->plugin = new Plugin();
        $this->server->addPlugin($this->plugin);
        $reportXML = <<<XML
<?xml version="1.0"?>
<c:free-busy-query xmlns:c="urn:ietf:params:xml:ns:caldav">
    <c:time-range start="20111001T000000Z" end="20111101T000000Z" />
</c:free-busy-query>
XML;
        $report = $this->server->xml->parse($reportXML, null, $rootElem);
        $this->plugin->report($rootElem, $report);
    }
예제 #29
0
    /**
     * @expectedException Sabre\DAV\Exception
     */
    function testFreeBusyReportNoACLPlugin()
    {
        $this->server = new DAV\Server();
        $this->plugin = new Plugin();
        $this->server->addPlugin($this->plugin);
        $reportXML = <<<XML
<?xml version="1.0"?>
<c:free-busy-query xmlns:c="urn:ietf:params:xml:ns:caldav">
    <c:time-range start="20111001T000000Z" end="20111101T000000Z" />
</c:free-busy-query>
XML;
        $dom = DAV\XMLUtil::loadDOMDocument($reportXML);
        $this->plugin->report('{urn:ietf:params:xml:ns:caldav}free-busy-query', $dom);
    }
 /**
  * Intercepts GET requests on addressbook urls ending with ?export.
  *
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @return bool
  */
 function httpGet(RequestInterface $request, ResponseInterface $response)
 {
     $queryParams = $request->getQueryParameters();
     if (!array_key_exists('export', $queryParams)) {
         return;
     }
     $path = $request->getPath();
     $node = $this->server->tree->getNodeForPath($path);
     if (!$node instanceof IAddressBook) {
         return;
     }
     $this->server->transactionType = 'get-addressbook-export';
     // Checking ACL, if available.
     if ($aclPlugin = $this->server->getPlugin('acl')) {
         $aclPlugin->checkPrivileges($path, '{DAV:}read');
     }
     $response->setHeader('Content-Type', 'text/directory');
     $response->setStatus(200);
     $nodes = $this->server->getPropertiesForPath($path, ['{' . Plugin::NS_CARDDAV . '}address-data'], 1);
     $response->setBody($this->generateVCF($nodes));
     // Returning false to break the event chain
     return false;
 }