1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* SabreDav init file. |
4
|
|
|
* |
5
|
|
|
* @package Integrations |
6
|
|
|
* |
7
|
|
|
* @copyright YetiForce S.A. |
8
|
|
|
* @license YetiForce Public License 6.5 (licenses/LicenseEN.txt or yetiforce.com) |
9
|
|
|
* @author Mariusz Krzaczkowski <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
require __DIR__ . '/include/ConfigUtils.php'; |
12
|
|
|
|
13
|
|
|
if (!\in_array('dav', \App\Config::api('enabledServices', []))) { |
14
|
|
|
require __DIR__ . '/include/main/WebUI.php'; |
15
|
|
|
$apiLog = new \App\Exceptions\NoPermittedToApi(); |
16
|
|
|
$apiLog->stop('Dav - Service is not active'); |
17
|
|
|
return; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
// DataBase |
21
|
|
|
$dbConfig = \App\Config::db('base'); |
22
|
|
|
$pdo = new PDO($dbConfig['dsn'] . ';charset=' . $dbConfig['charset'], $dbConfig['username'], $dbConfig['password']); |
23
|
|
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
24
|
|
|
|
25
|
|
|
$enableCalDAV = \App\Config::api('enableCalDAV'); |
26
|
|
|
$enableCardDAV = \App\Config::api('enableCardDAV'); |
27
|
|
|
set_error_handler(['App\Integrations\Dav\Debug', 'exceptionErrorHandler']); |
28
|
|
|
$enableWebDAV = false; |
29
|
|
|
|
30
|
|
|
// Backends |
31
|
|
|
$authBackend = new \App\Integrations\Dav\Backend\Auth($pdo); |
32
|
|
|
$principalBackend = new \App\Integrations\Dav\Backend\AclPrincipal($pdo); |
33
|
|
|
$nodes = [ |
34
|
|
|
new Sabre\DAVACL\PrincipalCollection($principalBackend), |
35
|
|
|
]; |
36
|
|
|
if ($enableCalDAV) { |
37
|
|
|
$calendarBackend = new \App\Integrations\Dav\Backend\Calendar($pdo); |
38
|
|
|
$nodes[] = new Sabre\CalDAV\Principal\Collection($principalBackend); |
39
|
|
|
$nodes[] = new Sabre\CalDAV\CalendarRoot($principalBackend, $calendarBackend); |
40
|
|
|
} |
41
|
|
|
if ($enableCardDAV) { |
42
|
|
|
$cardBackend = new \App\Integrations\Dav\Backend\Card($pdo); |
43
|
|
|
$nodes[] = new Sabre\CardDAV\AddressBookRoot($principalBackend, $cardBackend); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
// The object tree needs in turn to be passed to the server class |
47
|
|
|
\App\Integrations\Dav\Server::$exposeVersion = false; |
48
|
|
|
$server = new \App\Integrations\Dav\Server($nodes); |
49
|
|
|
$server->setBaseUri($_SERVER['SCRIPT_NAME']); |
50
|
|
|
$server->debugExceptions = \App\Config::debug('davDebugExceptions', false); |
51
|
|
|
|
52
|
|
|
// Plugins |
53
|
|
|
$server->addPlugin(new Sabre\DAV\Auth\Plugin($authBackend)); |
54
|
|
|
$aclPlugin = new Sabre\DAVACL\Plugin(); |
55
|
|
|
$aclPlugin->adminPrincipals = []; |
56
|
|
|
$server->addPlugin($aclPlugin); |
57
|
|
|
if (\App\Config::api('enableBrowser')) { |
58
|
|
|
// Web/Browser interface for exploring DAV |
59
|
|
|
$server->addPlugin(new Sabre\DAV\Browser\Plugin()); |
60
|
|
|
} |
61
|
|
|
if ($enableCardDAV) { |
62
|
|
|
// CardDav integration |
63
|
|
|
$server->addPlugin(new Sabre\CardDAV\Plugin()); |
64
|
|
|
} |
65
|
|
|
if ($enableCalDAV) { |
66
|
|
|
// CalDAV integration |
67
|
|
|
$server->addPlugin(new Sabre\CalDAV\Plugin()); |
68
|
|
|
$server->addPlugin(new Sabre\CalDAV\Subscriptions\Plugin()); |
69
|
|
|
$server->addPlugin(new Sabre\CalDAV\Schedule\Plugin()); |
70
|
|
|
} |
71
|
|
|
if ($enableWebDAV) { |
|
|
|
|
72
|
|
|
// WebDAV integration |
73
|
|
|
$server->addPlugin(new Sabre\DAV\Sync\Plugin()); |
74
|
|
|
} |
75
|
|
|
if (\App\Config::debug('davDebugPlugin')) { |
76
|
|
|
$server->addPlugin(new \App\Integrations\Dav\Debug()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
// Starts the DAV Server. |
80
|
|
|
$server->start(); |
81
|
|
|
|