summaryrefslogtreecommitdiffstats
path: root/public/dav.php
blob: 3c2ffee1d1b6fd4eb21d83de7cf5a44b972d1ba9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
error_reporting(E_ALL);
ini_set("log_errors", true);
ini_set('display_errors', true);
ini_set('error_log', './error.log'); 
ini_set('memory_limit', '1024M');

define("PATH", __DIR__.'/');
date_default_timezone_set('Europe/Berlin');

if (!file_exists('vendor/')) {
    die('<h1>Incomplete installation</h1>Dependencies have not been installed.');
}

require 'vendor/autoload.php';
require PATH.'lib/JSONDB.php';
require PATH.'lib/Helpers.php';
require PATH.'lib/UserManager.php';
require PATH.'lib/GenericCollectionManager.php';
require PATH.'lib/AddressbookCollectionManager.php';
require PATH.'lib/CalendarCollectionManager.php';

require PATH.'lib/Sabre/SabrePrincipalJsonBackend.php';
require PATH.'lib/Sabre/SabreAuthenticationJsonBackend.php';
require PATH.'lib/Sabre/SabrePropertyStorageJsonBackend.php';
require PATH.'lib/Sabre/SabreCardDAVJsonBackend.php';
require PATH.'lib/Sabre/SabreCalDAVJsonBackend.php';
require PATH.'lib/Sabre/FilesPlugin.php';

$db      = new JSONDB(PATH.'/data');

$userMgr = new UserManager($db);
$cardMgr = new AddressbookCollectionManager($db);
$calMgr  = new CalendarCollectionManager($db);

$authBackend            = new SabreAuthenticationJsonBackend($userMgr);
$propertyStorageBackend = new SabrePropertyStorageJsonBackend($db);
$principalBackend       = new SabrePrincipalJsonBackend($userMgr);
$cardDavBackend         = new SabreCardDAVJsonBackend($cardMgr);
$calDavBackend          = new SabreCalDAVJsonBackend($calMgr);

$server = new Sabre\DAV\Server([
		new Sabre\DAVACL\PrincipalCollection($principalBackend),
		//CardDAV-Sever
		new Sabre\CardDAV\AddressBookRoot($principalBackend, $cardDavBackend),
		//CalDAV-Server
		new Sabre\CalDAV\CalendarRoot($principalBackend, $calDavBackend),
		//WebDAV-Server
		new FilesPlugin\FilesCollection($principalBackend, PATH.'data/files/'),
	]);


$server->setBaseUri('/dav/');

$server->addPlugin(new Sabre\DAV\Auth\Plugin($authBackend, 'tinyDAV'));
$server->addPlugin(new Sabre\DAVACL\Plugin());
$server->addPlugin(new Sabre\DAV\PropertyStorage\Plugin($propertyStorageBackend));
$server->addPlugin(new Sabre\DAV\Sync\Plugin());

//CardDAV-Server
$server->addPlugin(new Sabre\CardDAV\Plugin());
$server->addPlugin(new Sabre\CardDAV\VCFExportPlugin());

//CalDAV-Server
$server->addPlugin(new Sabre\CalDAV\Plugin());
$server->addPlugin(new Sabre\CalDAV\ICSExportPlugin());
$server->addPlugin(new Sabre\CalDAV\Schedule\Plugin());

//WebDAV-Server
$server->addPlugin(new FilesPlugin\Plugin(PATH.'data/files/'));

//Fancy Web
$server->addPlugin(new Sabre\DAV\Browser\Plugin());

$server->exec();