function setup() { $this->caldavBackend = new Backend\Mock(array(array('id' => 1, 'uri' => 'UUID-123467', 'principaluri' => 'principals/user1', '{DAV:}displayname' => 'user1 calendar', '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar description', '{http://apple.com/ns/ical/}calendar-order' => '1', '{http://apple.com/ns/ical/}calendar-color' => '#FF0000', '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Property\SupportedCalendarComponentSet(array('VEVENT', 'VTODO'))), array('id' => 2, 'uri' => 'UUID-123468', 'principaluri' => 'principals/user1', '{DAV:}displayname' => 'user1 calendar2', '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar description', '{http://apple.com/ns/ical/}calendar-order' => '1', '{http://apple.com/ns/ical/}calendar-color' => '#FF0000', '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Property\SupportedCalendarComponentSet(array('VEVENT', 'VTODO')))), array(1 => array('UUID-2345' => array('calendardata' => TestUtil::getTestCalendarData())))); $principalBackend = new DAVACL\PrincipalBackend\Mock(); $principalBackend->setGroupMemberSet('principals/admin/calendar-proxy-read', array('principals/user1')); $principalBackend->setGroupMemberSet('principals/admin/calendar-proxy-write', array('principals/user1')); $principalBackend->addPrincipal(array('uri' => 'principals/admin/calendar-proxy-read')); $principalBackend->addPrincipal(array('uri' => 'principals/admin/calendar-proxy-write')); $calendars = new CalendarRootNode($principalBackend, $this->caldavBackend); $principals = new Principal\Collection($principalBackend); $root = new DAV\SimpleCollection('root'); $root->addChild($calendars); $root->addChild($principals); $objectTree = new DAV\ObjectTree($root); $this->server = new DAV\Server($objectTree); $this->server->debugExceptions = true; $this->server->setBaseUri('/'); $this->plugin = new Plugin(); $this->server->addPlugin($this->plugin); // Adding ACL plugin $this->server->addPlugin(new DAVACL\Plugin()); // Adding Auth plugin, and ensuring that we are logged in. $authBackend = new DAV\Auth\Backend\Mock(); $authBackend->defaultUser = '******'; $authPlugin = new DAV\Auth\Plugin($authBackend, 'SabreDAV'); $this->server->addPlugin($authPlugin); $authPlugin->beforeMethod('GET', '/'); $this->response = new HTTP\ResponseMock(); $this->server->httpResponse = $this->response; }
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(); }
function setUp() { $this->setUpBackends(); $this->setUpTree(); $this->server = new DAV\Server($this->tree); $this->server->debugExceptions = true; if ($this->setupCalDAV) { $this->caldavPlugin = new CalDAV\Plugin(); $this->server->addPlugin($this->caldavPlugin); } if ($this->setupCalDAVSharing) { $this->caldavSharingPlugin = new CalDAV\SharingPlugin(); $this->server->addPlugin($this->caldavSharingPlugin); } if ($this->setupCardDAV) { $this->carddavPlugin = new CardDAV\Plugin(); $this->server->addPlugin($this->carddavPlugin); } if ($this->setupACL) { $this->aclPlugin = new DAVACL\Plugin(); $this->server->addPlugin($this->aclPlugin); } if ($this->autoLogin) { $authBackend = new DAV\Auth\Backend\Mock(); $authBackend->defaultUser = $this->autoLogin; $this->authPlugin = new DAV\Auth\Plugin($authBackend, 'SabreDAV'); $this->server->addPlugin($this->authPlugin); // This will trigger the actual login procedure $this->authPlugin->beforeMethod('OPTIONS', '/'); } }
function setup() { $this->caldavBackend = new CalDAV\Backend\MockSharing(); $principalBackend = new DAVACL\PrincipalBackend\Mock(); $calendars = new CalDAV\CalendarRoot($principalBackend, $this->caldavBackend); $principals = new CalDAV\Principal\Collection($principalBackend); $root = new DAV\SimpleCollection('root'); $root->addChild($calendars); $root->addChild($principals); $this->server = new DAV\Server($root); $this->server->sapi = new HTTP\SapiMock(); $this->server->debugExceptions = true; $this->server->setBaseUri('/'); $this->plugin = new Plugin(); $this->server->addPlugin($this->plugin); // Adding ACL plugin $this->server->addPlugin(new DAVACL\Plugin()); // CalDAV is also required. $this->server->addPlugin(new CalDAV\Plugin()); // Adding Auth plugin, and ensuring that we are logged in. $authBackend = new DAV\Auth\Backend\Mock(); $authBackend->defaultUser = '******'; $authPlugin = new DAV\Auth\Plugin($authBackend, 'SabreDAV'); $this->server->addPlugin($authPlugin); // This forces a login $authPlugin->beforeMethod(new HTTP\Request(), new HTTP\Response()); $this->response = new HTTP\ResponseMock(); $this->server->httpResponse = $this->response; }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { parent::setUp(); $this->server = new Sabre\DAV\Server(new Tinebase_WebDav_Root()); $this->plugin = new Calendar_Frontend_CalDAV_PluginDefaultAlarms(); $this->server->addPlugin($this->plugin); $this->response = new Sabre\HTTP\ResponseMock(); $this->server->httpResponse = $this->response; }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { parent::setUp(); $this->server = new Sabre\DAV\Server(new Tinebase_WebDav_Root()); $this->plugin = new Tinebase_WebDav_Plugin_OwnCloud(); $this->server->addPlugin($this->plugin); $this->response = new Sabre\HTTP\ResponseMock(); $this->server->httpResponse = $this->response; }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { parent::setUp(); $this->objects['initialContainer'] = Tinebase_Container::getInstance()->addContainer(new Tinebase_Model_Container(array('name' => Tinebase_Record_Abstract::generateUID(), 'type' => Tinebase_Model_Container::TYPE_PERSONAL, 'backend' => 'Sql', 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId()))); $this->server = new Sabre\DAV\Server(new Tinebase_WebDav_Root()); $this->plugin = new Tinebase_WebDav_Plugin_Inverse(); $this->server->addPlugin($this->plugin); $this->response = new Sabre\HTTP\ResponseMock(); $this->server->httpResponse = $this->response; }
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; }
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(); }
function setUp() { $calendars = array(array('id' => 'calendar1', 'principaluri' => 'principals/admin', 'uri' => 'calendar1', '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Property\SupportedCalendarComponentSet(array('VEVENT', 'VTODO', 'VJOURNAL'))), array('id' => 'calendar2', 'principaluri' => 'principals/admin', 'uri' => 'calendar2', '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Property\SupportedCalendarComponentSet(array('VTODO', 'VJOURNAL')))); $this->calBackend = new Backend\Mock($calendars, array()); $principalBackend = new DAVACL\PrincipalBackend\Mock(); $tree = array(new CalendarRootNode($principalBackend, $this->calBackend)); $this->server = new DAV\Server($tree); $this->server->debugExceptions = true; $plugin = new Plugin(); $this->server->addPlugin($plugin); $response = new HTTP\ResponseMock(); $this->server->httpResponse = $response; }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ public function setUp() { $this->calDAVTests = new Calendar_Frontend_WebDAV_EventTest(); $this->calDAVTests->setup(); parent::setUp(); $this->hostname = 'tine.example.com'; $this->originalHostname = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; $_SERVER['HTTP_HOST'] = $this->hostname; $this->server = new Sabre\DAV\Server(new Tinebase_WebDav_Root()); $this->plugin = new Calendar_Frontend_CalDAV_PluginManagedAttachments(); $this->server->addPlugin($this->plugin); $this->response = new Sabre\HTTP\ResponseMock(); $this->server->httpResponse = $this->response; }
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()); }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { parent::setUp(); // create shared folder and other users folder $this->sharedContainer = Tinebase_Container::getInstance()->addContainer(new Tinebase_Model_Container(array('name' => __CLASS__ . Tinebase_Record_Abstract::generateUID(), 'type' => Tinebase_Model_Container::TYPE_SHARED, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId(), 'backend' => 'Sql'))); $sclever = Tinebase_Helper::array_value('sclever', Zend_Registry::get('personas')); $this->otherUsersContainer = Tinebase_Container::getInstance()->addContainer(new Tinebase_Model_Container(array('name' => __CLASS__ . Tinebase_Record_Abstract::generateUID(), 'type' => Tinebase_Model_Container::TYPE_PERSONAL, 'owner_id' => $sclever->getId(), 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId(), 'backend' => 'Sql'))); Tinebase_Container::getInstance()->addGrants($this->otherUsersContainer, Tinebase_Acl_Rights::ACCOUNT_TYPE_USER, Tinebase_Core::getUser(), array(Tinebase_Model_Grants::GRANT_READ, Tinebase_Model_Grants::GRANT_SYNC), true); // clear container caches (brute force) Tinebase_Core::getCache()->clean(Zend_Cache::CLEANING_MODE_ALL); $this->server = new Sabre\DAV\Server(new Tinebase_WebDav_Root()); $this->server->debugExceptions = true; $this->server->addPlugin(new \Sabre\CalDAV\Plugin()); $this->server->addPlugin(new \Sabre\CalDAV\SharingPlugin()); $aclPlugin = new \Sabre\DAVACL\Plugin(); $aclPlugin->defaultUsernamePath = Tinebase_WebDav_PrincipalBackend::PREFIX_USERS; $aclPlugin->principalCollectionSet = array(Tinebase_WebDav_PrincipalBackend::PREFIX_USERS, Tinebase_WebDav_PrincipalBackend::PREFIX_GROUPS); $this->server->addPlugin($aclPlugin); $this->response = new Sabre\HTTP\ResponseMock(); $this->server->httpResponse = $this->response; }
function testSupportedReportSetUserCalendars() { $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); $props = $this->server->getPropertiesForPath('/calendars/user1', array('{DAV:}supported-report-set')); $this->assertArrayHasKey(0, $props); $this->assertArrayHasKey(200, $props[0]); $this->assertArrayHasKey('{DAV:}supported-report-set', $props[0][200]); $prop = $props[0][200]['{DAV:}supported-report-set']; $this->assertTrue($prop instanceof \Sabre\DAV\Property\SupportedReportSet); $value = array('{DAV:}sync-collection', '{DAV:}expand-property', '{DAV:}principal-property-search', '{DAV:}principal-search-property-set'); $this->assertEquals($value, $prop->getValue()); }
/** * 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()); }
function setUp() { $this->setUpBackends(); $this->setUpTree(); $this->server = new DAV\Server($this->tree); $this->server->sapi = new HTTP\SapiMock(); $this->server->debugExceptions = true; if ($this->setupCalDAV) { $this->caldavPlugin = new CalDAV\Plugin(); $this->server->addPlugin($this->caldavPlugin); } if ($this->setupCalDAVSharing) { $this->caldavSharingPlugin = new CalDAV\SharingPlugin(); $this->server->addPlugin($this->caldavSharingPlugin); } if ($this->setupCalDAVScheduling) { $this->caldavSchedulePlugin = new CalDAV\Schedule\Plugin(); $this->server->addPlugin($this->caldavSchedulePlugin); } if ($this->setupCalDAVSubscriptions) { $this->server->addPlugin(new CalDAV\Subscriptions\Plugin()); } if ($this->setupCalDAVICSExport) { $this->caldavICSExportPlugin = new CalDAV\ICSExportPlugin(); $this->server->addPlugin($this->caldavICSExportPlugin); } if ($this->setupCardDAV) { $this->carddavPlugin = new CardDAV\Plugin(); $this->server->addPlugin($this->carddavPlugin); } if ($this->setupACL) { $this->aclPlugin = new DAVACL\Plugin(); $this->server->addPlugin($this->aclPlugin); } if ($this->setupLocks) { $this->locksPlugin = new DAV\Locks\Plugin($this->locksBackend); $this->server->addPlugin($this->locksPlugin); } if ($this->setupPropertyStorage) { $this->propertyStoragePlugin = new DAV\PropertyStorage\Plugin($this->propertyStorageBackend); $this->server->addPlugin($this->propertyStoragePlugin); } if ($this->autoLogin) { $authBackend = new DAV\Auth\Backend\Mock(); $authBackend->setPrincipal('principals/' . $this->autoLogin); $this->authPlugin = new DAV\Auth\Plugin($authBackend); $this->server->addPlugin($this->authPlugin); // This will trigger the actual login procedure $this->authPlugin->beforeMethod(new Request(), new Response()); } }
/** * @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); }
/** * @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); }
/** * @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); }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { parent::setUp(); $this->server = new Sabre\DAV\Server(new Tinebase_WebDav_Root()); $mockBackend = new Sabre\DAV\Auth\Backend\Mock(); $mockBackend->defaultUser = Tinebase_Core::getUser()->contact_id; $plugin = new Sabre\DAV\Auth\Plugin($mockBackend, 'realm'); $this->server->addPlugin($plugin); $aclPlugin = new \Sabre\DAVACL\Plugin(); $aclPlugin->defaultUsernamePath = Tinebase_WebDav_PrincipalBackend::PREFIX_USERS; $aclPlugin->principalCollectionSet = array(Tinebase_WebDav_PrincipalBackend::PREFIX_USERS, Tinebase_WebDav_PrincipalBackend::PREFIX_GROUPS); $this->server->addPlugin($aclPlugin); $this->server->addPlugin(new \Sabre\CalDAV\Plugin()); $this->server->addPlugin(new \Sabre\CalDAV\SharingPlugin()); $this->plugin = new Tinebase_WebDav_Plugin_PrincipalSearch(); $this->server->addPlugin($this->plugin); $this->response = new Sabre\HTTP\ResponseMock(); $this->server->httpResponse = $this->response; }
$pdo = new PDO('mysql:dbname=my_mailcowdb;host=localhost', 'my_mailcowuser', 'my_mailcowpass'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); function exception_error_handler($errno, $errstr, $errfile, $errline) { throw new ErrorException($errstr, 0, $errno, $errfile, $errline); } set_error_handler("exception_error_handler"); 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. */ $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); $nodes = [new \Sabre\CalDAV\Principal\Collection($principalBackend), new \Sabre\CalDAV\CalendarRoot($principalBackend, $caldavBackend), new \Sabre\CardDAV\AddressBookRoot($principalBackend, $carddavBackend)]; $server = new \Sabre\DAV\Server($nodes); if (isset($baseUri)) { $server->setBaseUri($baseUri); } $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'SabreDAV')); $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()); $server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin()); $server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); $server->exec();
<?php /** * This example shows the smallest possible sabre/dav server. */ include 'vendor/autoload.php'; $server = new Sabre\DAV\Server([new Sabre\DAV\FS\Directory(__DIR__)]); /** * Ok. Perhaps not the smallest possible. The browser plugin is 100% optional, * but it really helps understanding the server. */ $server->addPlugin(new Sabre\DAV\Browser\Plugin()); $server->exec();
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; }
use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\Connector\Sabre\Auth; use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin; use OCA\DAV\Connector\Sabre\MaintenancePlugin; use OCA\DAV\Connector\Sabre\Principal; use Sabre\CalDAV\CalendarRoot; $authBackend = new Auth(\OC::$server->getSession(), \OC::$server->getUserSession(), 'principals/'); $principalBackend = new Principal(\OC::$server->getUserManager(), \OC::$server->getGroupManager(), 'principals/'); $db = \OC::$server->getDatabaseConnection(); $calDavBackend = new CalDavBackend($db, $principalBackend); // Root nodes $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend); $principalCollection->disableListing = true; // Disable listing $addressBookRoot = new CalendarRoot($principalBackend, $calDavBackend); $addressBookRoot->disableListing = true; // Disable listing $nodes = array($principalCollection, $addressBookRoot); // Fire up server $server = new \Sabre\DAV\Server($nodes); $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri()); $server->setBaseUri($baseuri); // Add plugins $server->addPlugin(new MaintenancePlugin()); $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud')); $server->addPlugin(new \Sabre\CalDAV\Plugin()); $server->addPlugin(new \Sabre\DAVACL\Plugin()); $server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); $server->addPlugin(new ExceptionLoggerPlugin('caldav', \OC::$server->getLogger())); // And off we go! $server->exec();
use Sabre\CardDAV\Plugin; $authBackend = new Auth(\OC::$server->getSession(), \OC::$server->getUserSession(), \OC::$server->getRequest(), \OC::$server->getTwoFactorAuthManager(), 'principals/'); $principalBackend = new Principal(\OC::$server->getUserManager(), \OC::$server->getGroupManager(), 'principals/'); $db = \OC::$server->getDatabaseConnection(); $cardDavBackend = new CardDavBackend($db, $principalBackend); $debugging = \OC::$server->getConfig()->getSystemValue('debug', false); // Root nodes $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend); $principalCollection->disableListing = !$debugging; // Disable listing $addressBookRoot = new AddressBookRoot($principalBackend, $cardDavBackend); $addressBookRoot->disableListing = !$debugging; // Disable listing $nodes = array($principalCollection, $addressBookRoot); // Fire up server $server = new \Sabre\DAV\Server($nodes); $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri()); $server->setBaseUri($baseuri); // Add plugins $server->addPlugin(new MaintenancePlugin()); $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud')); $server->addPlugin(new Plugin()); $server->addPlugin(new LegacyDAVACL()); if ($debugging) { $server->addPlugin(new Sabre\DAV\Browser\Plugin()); } $server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin()); $server->addPlugin(new \OCA\DAV\CardDAV\ImageExportPlugin(\OC::$server->getLogger())); $server->addPlugin(new ExceptionLoggerPlugin('carddav', \OC::$server->getLogger())); // And off we go! $server->exec();
// settings date_default_timezone_set('Europe/Berlin'); // 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 = '/server.php'; /* Database */ $pdo = new PDO('mysql:host=localhost;dbname=carddav', 'carddav', 'carddav'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //Mapping PHP errors to exceptions function exception_error_handler($errno, $errstr, $errfile, $errline) { throw new ErrorException($errstr, 0, $errno, $errfile, $errline); } set_error_handler("exception_error_handler"); // Backends $authBackend = new Sabre\DAV\Auth\Backend\PDO($pdo); $principalBackend = new Sabre\DAVACL\PrincipalBackend\PDO($pdo); $carddavBackend = new Sabre\CardDAV\Backend\PDO($pdo); // Setting up the directory tree // $nodes = [new Sabre\DAVACL\PrincipalCollection($principalBackend), 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); $server->setBaseUri($baseUri); // Plugins $server->addPlugin(new Sabre\DAV\Auth\Plugin($authBackend)); $server->addPlugin(new Sabre\CardDAV\Plugin()); $server->addPlugin(new Sabre\DAV\Browser\Plugin()); $server->addPlugin(new Sabre\DAVACL\Plugin()); $server->addPlugin(new Sabre\DAV\Sync\Plugin()); // And off we go! $server->exec();
$rId = $repositoryId; $rootDir = new AJXP_Sabre_Collection("/", $repository, null); $server = new Sabre\DAV\Server($rootDir); $server->setBaseUri($baseURI . "/" . $pathBase); } else { $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); }
/** * 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; }
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(); } }
$tmpDir = 'tmpdata'; // If you want to run the SabreDAV server in a custom location (using mod_rewrite for instance) // You can override the baseUri here. // $baseUri = '/'; // Files we need require_once 'vendor/autoload.php'; // Create the root node $root = new \Sabre\DAV\FS\Directory($publicDir); // The rootnode needs in turn to be passed to the server class $server = new \Sabre\DAV\Server($root); if (isset($baseUri)) { $server->setBaseUri($baseUri); } // Support for LOCK and UNLOCK $lockBackend = new \Sabre\DAV\Locks\Backend\File($tmpDir . '/locksdb'); $lockPlugin = new \Sabre\DAV\Locks\Plugin($lockBackend); $server->addPlugin($lockPlugin); // Support for html frontend $browser = new \Sabre\DAV\Browser\Plugin(); $server->addPlugin($browser); // Automatically guess (some) contenttypes, based on extesion $server->addPlugin(new \Sabre\DAV\Browser\GuessContentType()); // Authentication backend $authBackend = new \Sabre\DAV\Auth\Backend\File('.htdigest'); $auth = new \Sabre\DAV\Auth\Plugin($authBackend); $server->addPlugin($auth); // Temporary file filter $tempFF = new \Sabre\DAV\TemporaryFileFilterPlugin($tmpDir); $server->addPlugin($tempFF); // And off we go! $server->exec();