-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.php
115 lines (93 loc) · 3.99 KB
/
server.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/***********************************************
* File : server.php
* Project : KopanoDAV
* Descr : This is the entry point
* through which all requests
* are processed.
*
* Created : 13.12.2016
*
* Copyright 2016 - 2018 Kopano b.v.
*
* This file is part of kDAV. kDAV is free software; you can redistribute
* it and/or modify it under the terms of the GNU Affero General Public
* License as published by the Free Software Foundation; either version 3
* or (at your option) any later version.
*
* This software uses SabreDAV, an open source software distributed
* under three-clause BSD-license. Please see <http://sabre.io/dav/>
* for more information about SabreDAV.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Consult LICENSE file for details
************************************************/
namespace Kopano\DAV;
// require composer auto-loader
require __DIR__ . '/vendor/autoload.php';
// Configure & create main logger
KLogger::configure(__DIR__ . '/log4php.xml');
$logger = new KLogger('main');
// don't log any Sabre asset requests (images etc)
if (isset($_REQUEST['sabreAction']) && $_REQUEST['sabreAction'] == 'asset') {
$logger->resetConfiguration();
}
// log the start data
$logger->debug('------------------ Start');
$logger->debug('%s %s', $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
$logger->debug('KDAV version %s', KDAV_VERSION);
$logger->debug('SabreDAV version %s',\Sabre\DAV\Version::VERSION);
$kdavBackend = new KopanoDavBackend(new KLogger(('dav')));
$authBackend = new AuthBasicBackend($kdavBackend);
$authBackend->setRealm(SABRE_AUTH_REALM);
$principalBackend = new PrincipalsBackend($kdavBackend);
$kCarddavBackend = new KopanoCardDavBackend($kdavBackend, new KLogger('card'));
$kCaldavBackend = new KopanoCalDavBackend($kdavBackend, new KLogger('cal'));
// Setting up the directory tree
$nodes = array(
new \Sabre\DAVACL\PrincipalCollection($principalBackend),
new \Sabre\CardDAV\AddressBookRoot($principalBackend, $kCarddavBackend),
new \Sabre\CalDAV\CalendarRoot($principalBackend, $kCaldavBackend),
);
// initialize the server
$server = new \Sabre\DAV\Server($nodes);
$server->setBaseUri(DAV_ROOT_URI);
$server->setLogger(new KPSR3Logger($logger));
$authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend, SABRE_AUTH_REALM);
$server->addPlugin($authPlugin);
// add our version to the headers
$server->httpResponse->addHeader('X-KDAV-Version', KDAV_VERSION);
// log the incoming request (only if authenticated)
$logger->LogIncoming($server->httpRequest);
$aclPlugin = new DAVACL();
$aclPlugin->allowUnauthenticatedAccess = false;
$server->addPlugin($aclPlugin);
$schedulePlugin = new KopanoSchedulePlugin($kdavBackend, new KLogger('schedule'));
$server->addPlugin($schedulePlugin);
$imipPlugin = new KopanoIMipPlugin($kdavBackend, new KLogger('imip'));
$server->addPlugin($imipPlugin);
$server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
$server->addPlugin(new \Sabre\CardDAV\Plugin());
// TODO: do we need $caldavPlugin for anything?
$caldavPlugin = new \Sabre\CalDAV\Plugin();
$server->addPlugin($caldavPlugin);
if (strlen(SYNC_DB) > 0) {
$server->addPlugin(new \Sabre\DAV\Sync\Plugin());
}
if (DEVELOPER_MODE) {
$server->addPlugin(new \Sabre\DAV\Browser\Plugin(false));
}
$server->exec();
// Log outgoing data
$logger->LogOutgoing($server->httpResponse);
$logger->debug("httpcode='%s' memory='%s/%s' time='%ss'",
http_response_code(), $logger->FormatBytes(memory_get_peak_usage(false)), $logger->FormatBytes(memory_get_peak_usage(true)),
number_format(microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"], 2));
$logger->debug('------------------ End');