source: darkpeak-services/roles/sabredav/templates/server.php @ 0c882bec

ansiblekeycloakmatrixpleroma
Last change on this file since 0c882bec was 0c882bec, checked in by Caolan McMahon <caolan.mcmahon@…>, 19 months ago

Switch sabredav to mysql so we can copy over existing data

  • Property mode set to 100644
File size: 3.3 KB
Line 
1<?php
2// vim: filetype=php
3
4// serve blank page for OPTIONS requests to root and do not require auth
5// (for caldavzap and carddavmate CORS check)
6//if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
7//    return;
8//}
9
10/**
11 * This server combines both CardDAV and CalDAV functionality into a single
12 * server. It is assumed that the server runs at the root of a HTTP domain (be
13 * that a domainname-based vhost or a specific TCP port.
14 *
15 * This example also assumes that you're using SQLite and the database has
16 * already been setup (along with the database tables).
17 *
18 * You may choose to use MySQL instead, just change the PDO connection
19 * statement.
20 */
21
22/**
23 * UTC or GMT is easy to work with, and usually recommended for any
24 * application.
25 */
26date_default_timezone_set('UTC');
27
28/**
29 * Make sure this setting is turned on and reflect the root url for your WebDAV
30 * server.
31 *
32 * This can be for example the root / or a complete path to your server script.
33 */
34$baseUri = '/';
35
36/**
37 * Database
38 *
39 * Feel free to switch this to MySQL, it will definitely be better for higher
40 * concurrency.
41 */
42//$pdo = new \PDO('sqlite:data/db.sqlite');
43$pdo = new PDO('mysql:dbname={{ db.name }};host={{ db.server }}', '{{ db.user }}', '{{ db.password }}');
44$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
45
46/**
47 * Mapping PHP errors to exceptions.
48 *
49 * While this is not strictly needed, it makes a lot of sense to do so. If an
50 * E_NOTICE or anything appears in your code, this allows SabreDAV to intercept
51 * the issue and send a proper response back to the client (HTTP/1.1 500).
52 */
53function exception_error_handler($errno, $errstr, $errfile, $errline ) {
54    throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
55}
56set_error_handler("exception_error_handler");
57
58// Autoloader
59require_once 'vendor/autoload.php';
60require_once 'LDAPBackend.php';
61
62/**
63 * The backends. Yes we do really need all of them.
64 *
65 * This allows any developer to subclass just any of them and hook into their
66 * own backend systems.
67 */
68//$authBackend      = new \Sabre\DAV\Auth\Backend\PDO($pdo);
69$authBackend      = new \Sabre\DAV\Auth\Backend\Apache();
70$principalBackend = new \Sabre\DAVACL\PrincipalBackend\LDAPBackend();
71$carddavBackend   = new \Sabre\CardDAV\Backend\PDO($pdo);
72$caldavBackend    = new \Sabre\CalDAV\Backend\PDO($pdo);
73
74/**
75 * The directory tree
76 *
77 * Basically this is an array which contains the 'top-level' directories in the
78 * WebDAV server.
79 */
80$nodes = [
81    // /principals
82    new \Sabre\CalDAV\Principal\Collection($principalBackend),
83    // /calendars
84    new \Sabre\CalDAV\CalendarRoot($principalBackend, $caldavBackend),
85    // /addressbook
86    new \Sabre\CardDAV\AddressBookRoot($principalBackend, $carddavBackend),
87];
88
89// The object tree needs in turn to be passed to the server class
90$server = new \Sabre\DAV\Server($nodes);
91if (isset($baseUri)) $server->setBaseUri($baseUri);
92
93// Plugins
94$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend,'SabreDAV'));
95$server->addPlugin(new \Sabre\DAV\Browser\Plugin());
96$server->addPlugin(new \Sabre\CalDAV\Plugin());
97$server->addPlugin(new \Sabre\CardDAV\Plugin());
98
99$aclPlugin = new \Sabre\DAVACL\Plugin();
100//$aclPlugin->hideNodesFromListings = true;
101$server->addPlugin($aclPlugin);
102
103$server->addPlugin(new \Sabre\DAV\Sync\Plugin());
104
105// And off we go!
106$server->exec();
Note: See TracBrowser for help on using the repository browser.