forked from YetiForceCompany/YetiForceCRM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dav.php
79 lines (72 loc) · 2.62 KB
/
dav.php
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
76
77
78
79
<?php
/**
* SabreDav init file.
*
* @package Integrations
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
*/
require __DIR__ . '/include/ConfigUtils.php';
if (!\in_array('dav', \App\Config::api('enabledServices', []))) {
require __DIR__ . '/include/main/WebUI.php';
$apiLog = new \App\Exceptions\NoPermittedToApi();
$apiLog->stop('Dav - Service is not active');
return;
}
// Database
$dbConfig = \App\Config::db('base');
$pdo = new PDO($dbConfig['dsn'] . ';charset=' . $dbConfig['charset'], $dbConfig['username'], $dbConfig['password']);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$enableCalDAV = \App\Config::api('enableCalDAV');
$enableCardDAV = \App\Config::api('enableCardDAV');
$enableBrowser = \App\Config::api('enableBrowser');
set_error_handler(['App\Integrations\Dav\Debug', 'exceptionErrorHandler']);
$enableWebDAV = false;
// Backends
$authBackend = new \App\Integrations\Dav\Backend\Auth($pdo);
$principalBackend = new \App\Integrations\Dav\Backend\AclPrincipal($pdo);
$nodes = [
new Sabre\DAVACL\PrincipalCollection($principalBackend),
];
if ($enableCalDAV) {
$calendarBackend = new \App\Integrations\Dav\Backend\Calendar($pdo);
$nodes[] = new Sabre\CalDAV\Principal\Collection($principalBackend);
$nodes[] = new Sabre\CalDAV\CalendarRoot($principalBackend, $calendarBackend);
}
if ($enableCardDAV) {
$cardBackend = new \App\Integrations\Dav\Backend\Card($pdo);
$nodes[] = new Sabre\CardDAV\AddressBookRoot($principalBackend, $cardBackend);
}
// The object tree needs in turn to be passed to the server class
$server = new \App\Integrations\Dav\Server($nodes);
$server->setBaseUri($_SERVER['SCRIPT_NAME']);
$server->debugExceptions = \App\Config::debug('DAV_DEBUG_EXCEPTIONS');
// Plugins
$server->addPlugin(new Sabre\DAV\Auth\Plugin($authBackend));
$aclPlugin = new Sabre\DAVACL\Plugin();
$aclPlugin->adminPrincipals = [];
$server->addPlugin($aclPlugin);
if ($enableBrowser) {
$server->addPlugin(new Sabre\DAV\Browser\Plugin());
}
if ($enableCardDAV) {
//CardDav integration
$server->addPlugin(new Sabre\CardDAV\Plugin());
}
if ($enableCalDAV) {
//CalDAV integration
$server->addPlugin(new Sabre\CalDAV\Plugin());
$server->addPlugin(new Sabre\CalDAV\Subscriptions\Plugin());
$server->addPlugin(new Sabre\CalDAV\Schedule\Plugin());
}
if ($enableWebDAV) {
//WebDAV integration
$server->addPlugin(new Sabre\DAV\Sync\Plugin());
}
if (\App\Config::debug('DAV_DEBUG_PLUGIN')) {
$server->addPlugin(new \App\Integrations\Dav\Debug());
}
// Starts the DAV Server.
$server->start();