/** * 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()); }
/** * 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()); }
/** * @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); }
/** * 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; }
/** * 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()); }
public static function handleRequest() { if (extension_loaded('newrelic')) { newrelic_disable_autorum(); } // retrieve authentication attempt if ($GLOBALS['Session']->hasAccountLevel('Developer')) { $User = $GLOBALS['Session']->Person; } else { $authEngine = new \Sabre\HTTP\BasicAuth(); $authEngine->setRealm('Develop ' . \Site::$title); $authUserPass = $authEngine->getUserPass(); // try to get user $userClass = \User::$defaultClass; $User = $userClass::getByLogin($authUserPass[0], $authUserPass[1]); // send auth request if login is inadiquate if (!$User || !$User->hasAccountLevel('Developer')) { $authEngine->requireLogin(); die("You must login using a " . \Site::getConfig('primary_hostname') . " account with Developer access\n"); } } // store login to session if (isset($GLOBALS['Session'])) { $GLOBALS['Session'] = $GLOBALS['Session']->changeClass('UserSession', array('PersonID' => $User->ID)); } // detect base path $basePath = array_slice(\Site::$requestPath, 0, count(\Site::$resolvedPath)); // switch to JSON response mode if (static::peekPath() == 'json') { $basePath[] = static::$responseMode = static::shiftPath(); } // handle /develop request if ($_SERVER['REQUEST_METHOD'] == 'GET' && static::getResponseMode() == 'html' && !static::peekPath()) { \RequestHandler::respond('app/ext', array('App' => \Sencha_App::getByName('EmergenceEditor'), 'mode' => 'production', 'title' => 'EmergenceEditor')); } // initial and configure SabreDAV $server = new \Sabre\DAV\Server(new RootCollection()); $server->setBaseUri('/' . join('/', $basePath)); // 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_FS('/tmp/dav-lock'); # $lockPlugin = new Sabre_DAV_Locks_Plugin($lockBackend); # $server->addPlugin($lockPlugin); // filter temporary files $server->addPlugin(new \Sabre\DAV\TemporaryFileFilterPlugin('/tmp/dav-tmp')); // ?mount support $server->addPlugin(new \Sabre\DAV\Mount\Plugin()); // emergence :) $server->addPlugin(new \Emergence\DAV\ServerPlugin()); // All we need to do now, is to fire up the server $server->exec(); }
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); }
/** * 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); }
/** * 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. * * If $expectedStatus is set, we'll compare it with the HTTP status of * the returned response. If it doesn't match, we'll immediately fail * the test. * * @param array|\Sabre\HTTP\Request $request * @param int $expectedStatus * @return \Sabre\HTTP\Response */ function request($request, $expectedStatus = null) { if (is_array($request)) { $request = HTTP\Request::createFromServerArray($request); } $response = new HTTP\ResponseMock(); $this->server->httpRequest = $request; $this->server->httpResponse = $response; $this->server->exec(); if ($expectedStatus) { $responseBody = $expectedStatus !== $response->getStatus() ? $response->getBodyAsString() : ''; $this->assertEquals($expectedStatus, $response->getStatus(), 'Incorrect HTTP status received for request. Response body: ' . $responseBody); } return $this->server->httpResponse; }
/** * test testGetProperties method */ public function testGetPropertiesSharedUserPrincipal() { $body = '<?xml version="1.0" encoding="UTF-8"?> <A:propfind xmlns:A="DAV:"> <A:prop> <B:calendar-home-set xmlns:B="urn:ietf:params:xml:ns:caldav"/> <B:calendar-user-address-set xmlns:B="urn:ietf:params:xml:ns:caldav"/> <A:current-user-principal/> <A:displayname/> <C:dropbox-home-URL xmlns:C="http://calendarserver.org/ns/"/> <C:email-address-set xmlns:C="http://calendarserver.org/ns/"/> <C:notification-URL xmlns:C="http://calendarserver.org/ns/"/> <A:principal-collection-set/> <A:principal-URL/> <A:resource-id/> <B:schedule-inbox-URL xmlns:B="urn:ietf:params:xml:ns:caldav"/> <B:schedule-outbox-URL xmlns:B="urn:ietf:params:xml:ns:caldav"/> <A:supported-report-set/> </A:prop> </A:propfind>'; $request = new Sabre\HTTP\Request(array('REQUEST_METHOD' => 'PROPFIND', 'REQUEST_URI' => '/' . Tinebase_WebDav_PrincipalBackend::PREFIX_USERS . '/' . Tinebase_WebDav_PrincipalBackend::SHARED, 'HTTP_BRIEF' => 't', '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'); $xpath->registerNamespace('cs', 'http://calendarserver.org/ns/'); $xpath->registerNamespace('d', 'DAV'); $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:calendar-home-set'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); #$this->assertEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML()); $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/d:principal-URL'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); #$this->assertEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML()); }
function init() { if (argv(1) !== 'calendar' && argv(1) !== 'addressbook') { if (\DBA::$dba && \DBA::$dba->connected) { $pdovars = \DBA::$dba->pdo_get(); } else { killme(); } // 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; } } /** * This server combines both CardDAV and CalDAV functionality into a single * server. It is assumed that the server runs at the root of a HTTP domain (be * that a domainname-based vhost or a specific TCP port. * * This example also assumes that you're using SQLite and the database has * already been setup (along with the database tables). * * You may choose to use MySQL instead, just change the PDO connection * statement. */ /** * UTC or GMT is easy to work with, and usually recommended for any * application. */ date_default_timezone_set('UTC'); /** * Make sure this setting is turned on and reflect the root url for your WebDAV * server. * * This can be for example the root / or a complete path to your server script. */ $baseUri = '/cdav/'; /** * Database * */ $pdo = new \PDO($pdovars[0], $pdovars[1], $pdovars[2]); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); // Autoloader require_once 'vendor/autoload.php'; /** * The backends. Yes we do really need all of them. * * This allows any developer to subclass just any of them and hook into their * own backend systems. */ $auth = new \Zotlabs\Storage\BasicAuth(); $auth->setRealm(ucfirst(\Zotlabs\Lib\System::get_platform_name()) . 'CalDAV/CardDAV'); // $ob_hash = get_observer_hash(); // if ($ob_hash) { if (local_channel()) { logger('loggedin'); $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 = $channel['channel_hash']; } // $auth->observer = $ob_hash; // } //$authBackend = new \Sabre\DAV\Auth\Backend\PDO($pdo); $principalBackend = new \Sabre\DAVACL\PrincipalBackend\PDO($pdo); $carddavBackend = new \Sabre\CardDAV\Backend\PDO($pdo); $caldavBackend = new \Sabre\CalDAV\Backend\PDO($pdo); /** * The directory tree * * Basically this is an array which contains the 'top-level' directories in the * WebDAV server. */ $nodes = [new \Sabre\CalDAV\Principal\Collection($principalBackend), new \Sabre\CalDAV\CalendarRoot($principalBackend, $caldavBackend), new \Sabre\CardDAV\AddressBookRoot($principalBackend, $carddavBackend)]; // The object tree needs in turn to be passed to the server class $server = new \Sabre\DAV\Server($nodes); if (isset($baseUri)) { $server->setBaseUri($baseUri); } // Plugins $server->addPlugin(new \Sabre\DAV\Auth\Plugin($auth)); //$server->addPlugin(new \Sabre\DAV\Browser\Plugin()); $server->addPlugin(new \Sabre\DAV\Sync\Plugin()); $server->addPlugin(new \Sabre\DAV\Sharing\Plugin()); $server->addPlugin(new \Sabre\DAVACL\Plugin()); // CalDAV plugins $server->addPlugin(new \Sabre\CalDAV\Plugin()); $server->addPlugin(new \Sabre\CalDAV\SharingPlugin()); //$server->addPlugin(new \Sabre\CalDAV\Schedule\Plugin()); $server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); // CardDAV plugins $server->addPlugin(new \Sabre\CardDAV\Plugin()); $server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin()); // And off we go! $server->exec(); killme(); } }
$rootDir = new AJXP_Sabre_RootCollection("root"); $server = new Sabre\DAV\Server($rootDir); $server->setBaseUri($baseURI); } if ((AJXP_Sabre_AuthBackendBasic::detectBasicHeader() || ConfService::getCoreConf("WEBDAV_FORCE_BASIC")) && ConfService::getAuthDriverImpl()->getOption("TRANSMIT_CLEAR_PASS")) { $authBackend = new AJXP_Sabre_AuthBackendBasic($rId); } else { $authBackend = new AJXP_Sabre_AuthBackendDigest($rId); } $authPlugin = new Sabre\DAV\Auth\Plugin($authBackend, ConfService::getCoreConf("WEBDAV_DIGESTREALM")); $server->addPlugin($authPlugin); if (!is_dir(AJXP_DATA_PATH . "/plugins/server.sabredav")) { mkdir(AJXP_DATA_PATH . "/plugins/server.sabredav", 0755); $fp = fopen(AJXP_DATA_PATH . "/plugins/server.sabredav/locks", "w"); fwrite($fp, ""); fclose($fp); } $lockBackend = new Sabre\DAV\Locks\Backend\File(AJXP_DATA_PATH . "/plugins/server.sabredav/locks"); $lockPlugin = new Sabre\DAV\Locks\Plugin($lockBackend); $server->addPlugin($lockPlugin); if (ConfService::getCoreConf("WEBDAV_BROWSER_LISTING")) { $browerPlugin = new AJXP_Sabre_BrowserPlugin(isset($repository) ? $repository->getDisplay() : null); $extPlugin = new Sabre\DAV\Browser\GuessContentType(); $server->addPlugin($browerPlugin); $server->addPlugin($extPlugin); } try { $server->exec(); } catch (Exception $e) { AJXP_Logger::error(__CLASS__, "Exception", $e->getMessage()); }
public function webdavAction() { $homeDir = Asset::getById(1); try { $publicDir = new Asset\WebDAV\Folder($homeDir); $objectTree = new Asset\WebDAV\Tree($publicDir); $server = new \Sabre\DAV\Server($objectTree); $lockBackend = new \Sabre\DAV\Locks\Backend\File(PIMCORE_WEBDAV_TEMP . '/locks.dat'); $lockPlugin = new \Sabre\DAV\Locks\Plugin($lockBackend); $server->addPlugin($lockPlugin); $server->exec(); } catch (\Exception $e) { \Logger::error($e); } exit; }
function cdav_init(&$a) { if (DBA::$dba && DBA::$dba->connected) { $pdovars = DBA::$dba->pdo_get(); } else { killme(); } // 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; } } /** * This server combines both CardDAV and CalDAV functionality into a single * server. It is assumed that the server runs at the root of a HTTP domain (be * that a domainname-based vhost or a specific TCP port. * * This example also assumes that you're using SQLite and the database has * already been setup (along with the database tables). * * You may choose to use MySQL instead, just change the PDO connection * statement. */ /** * UTC or GMT is easy to work with, and usually recommended for any * application. */ date_default_timezone_set('UTC'); /** * Make sure this setting is turned on and reflect the root url for your WebDAV * server. * * This can be for example the root / or a complete path to your server script. */ $baseUri = '/cdav'; /** * Database * */ $pdo = new \PDO($pdovars[0], $pdovars[1], $pdovars[2]); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); /** * Mapping PHP errors to exceptions. * * While this is not strictly needed, it makes a lot of sense to do so. If an * E_NOTICE or anything appears in your code, this allows SabreDAV to intercept * the issue and send a proper response back to the client (HTTP/1.1 500). */ function exception_error_handler($errno, $errstr, $errfile, $errline) { throw new ErrorException($errstr, 0, $errno, $errfile, $errline); } set_error_handler("exception_error_handler"); // Autoloader require_once 'vendor/autoload.php'; /** * The backends. Yes we do really need all of them. * * This allows any developer to subclass just any of them and hook into their * own backend systems. */ $auth = new \Zotlabs\Storage\BasicAuth(); $auth->setRealm(ucfirst(\Zotlabs\Lib\System::get_platform_name()) . 'CalDAV/CardDAV'); //$authBackend = new \Sabre\DAV\Auth\Backend\PDO($pdo); $principalBackend = new \Sabre\DAVACL\PrincipalBackend\PDO($pdo); $carddavBackend = new \Sabre\CardDAV\Backend\PDO($pdo); $caldavBackend = new \Sabre\CalDAV\Backend\PDO($pdo); /** * The directory tree * * Basically this is an array which contains the 'top-level' directories in the * WebDAV server. */ $nodes = [new \Sabre\CalDAV\Principal\Collection($principalBackend), new \Sabre\CalDAV\CalendarRoot($principalBackend, $caldavBackend), new \Sabre\CardDAV\AddressBookRoot($principalBackend, $carddavBackend)]; // The object tree needs in turn to be passed to the server class $server = new \Sabre\DAV\Server($nodes); if (isset($baseUri)) { $server->setBaseUri($baseUri); } // Plugins $server->addPlugin(new \Sabre\DAV\Auth\Plugin($auth)); // $browser = new \Zotlabs\Storage\Browser($auth); // $auth->setBrowserPlugin($browser); // $server->addPlugin($browser); $server->addPlugin(new \Sabre\DAV\Browser\Plugin()); $server->addPlugin(new \Sabre\CalDAV\Plugin()); $server->addPlugin(new \Sabre\CardDAV\Plugin()); $server->addPlugin(new \Sabre\DAVACL\Plugin()); $server->addPlugin(new \Sabre\DAV\Sync\Plugin()); // And off we go! $server->exec(); killme(); }
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(); }
/** * handle webdav request * * @param bool $body * * @note this init procedure is copied from /apps/files/appinfo/remote.php */ function handleWebdavRequest($body = false) { // Backends $authBackend = new OC_Connector_Sabre_Auth(); $lockBackend = new OC_Connector_Sabre_Locks(); $requestBackend = new OC_Connector_Sabre_Request(); // Create ownCloud Dir $root = '/' . $this->userId . '/files'; $view = new \OC\Files\View($root); $publicDir = new OC_Connector_Sabre_Directory($view, $view->getFileInfo('')); $objectTree = new \OC\Connector\Sabre\ObjectTree(); $mountManager = \OC\Files\Filesystem::getMountManager(); $objectTree->init($publicDir, $view, $mountManager); // Fire up server $server = new \Sabre\DAV\Server($publicDir); $server->httpRequest = $requestBackend; $server->setBaseUri('/remote.php/webdav/'); // Load plugins $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud')); $server->addPlugin(new \Sabre\DAV\Locks\Plugin($lockBackend)); $server->addPlugin(new \Sabre\DAV\Browser\Plugin(false)); // Show something in the Browser, but no upload $server->addPlugin(new OC_Connector_Sabre_QuotaPlugin($view)); $server->addPlugin(new OC_Connector_Sabre_MaintenancePlugin()); $server->debugExceptions = true; // And off we go! if ($body) { $server->httpRequest->setBody($body); } // turn on output buffering ob_start(); // handle request $server->exec(); // file content is written in the output buffer $content = ob_get_contents(); // flush the output buffer and turn off output buffering ob_end_clean(); // return captured content return $content; }
/** * Sends an RPC request to the server and returns the result. * * @param string The raw request string. * * @return string The XML encoded response from the server. */ public function getResponse($request) { $this->_server->exec(); }
function request(HTTP\Request $request) { $this->server->httpRequest = $request; $this->server->exec(); return $this->server->httpResponse; }
public function webdavAction() { $homeDir = Asset::getById(1); try { $publicDir = new Asset\WebDAV\Folder($homeDir); $objectTree = new Asset\WebDAV\Tree($publicDir); $server = new \Sabre\DAV\Server($objectTree); $server->setBaseUri("/admin/asset/webdav/"); // lock plugin $lockBackend = new \Sabre\DAV\Locks\Backend\File(PIMCORE_WEBDAV_TEMP . '/locks.dat'); $lockPlugin = new \Sabre\DAV\Locks\Plugin($lockBackend); $server->addPlugin($lockPlugin); // sync plugin $server->addPlugin(new \Sabre\DAV\Sync\Plugin()); // browser plugin $server->addPlugin(new Sabre\DAV\Browser\Plugin()); $server->exec(); } catch (\Exception $e) { Logger::error($e); } exit; }