-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.php
More file actions
104 lines (77 loc) · 3.41 KB
/
server.php
File metadata and controls
104 lines (77 loc) · 3.41 KB
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
<?php
/************************************************************
* Copyright 2023-2025 ISub Softwares (OPC) Private Limited
************************************************************/
/********************************************************************************
*
* WebDAV server
*
* Provides CardDAV support for contacts stored in LDAP
*
*********************************************************************************/
// Initialize
require_once __DIR__ . '/src/App/include/bootstrap.php';
// Loader
require_once __BASE_DIR__ . '/vendor/autoload.php';
// Set log level
error_reporting($GLOBALS['log_level']);
$GLOBALS['currentUserPrincipalUri'] = null;
$GLOBALS['currentUserPrincipalId'] = null;
$GLOBALS['currentUserPrincipalLdapConn'] = null;
// Cache
$entityCache = [];
// Create object for active cache backends.
$cacheMaster = new ISubsoft\Cache\Master($config, $pdo);
$resetCache = [];
foreach(CACHED_ENTITIES as $entityId) {
$cacheBackendId = $cacheMaster->getBackendId($entityId);
$entityCache[$entityId] = $cacheMaster->cache[$cacheBackendId];
if($cacheMaster->wasBackendNotActive($entityId, $cacheBackendId)) {
if($cacheBackendId != ISubsoft\Cache\Master::$dummyBackend)
$resetCache[$cacheBackendId] = true;
if(!$cacheMaster->setActiveBackend($entityId, $cacheBackendId))
trigger_error("Cache backend '$cacheBackendId' could not be set active for $entityId.", E_USER_WARNING);
}
}
foreach($resetCache as $backendId => $value)
trigger_error("Cache backend '$backendId' was not used before. Make sure that this cache backend does not contain any previous cache from this application as it may contain data which is inconsistent with current application state.", E_USER_WARNING);
// Destroy what is no longer required.
unset($cacheMaster, $resetCache);
// Backends
$authBackend = new ISubsoft\DAV\Auth\Backend\LDAP($config);
$principalBackend = new ISubsoft\DAV\DAVACL\PrincipalBackend\LDAP($config, $pdo, $entityCache['principal']);
$propStoreBackend = new Sabre\DAV\PropertyStorage\Backend\PDO($pdo);
$carddavBackend = new ISubsoft\DAV\CardDAV\Backend\LDAP($config, $pdo, $principalBackend, $entityCache['card']);
// Setting up the directory tree //
$nodes = [
new ISubsoft\DAV\DAVACL\PrincipalCollection($principalBackend),
new ISubsoft\DAV\CardDAV\AddressBookRoot($principalBackend, $carddavBackend)
];
// The object tree needs in turn to be passed to the server class
$server = new Sabre\DAV\Server($nodes);
// Setting the base uri
$server->setBaseUri($GLOBALS['base_uri']);
//// Plugins ////
// Add authentication plugin
$server->addPlugin(new ISubsoft\DAV\Auth\Plugin($authBackend));
// Add ACL plugin
$aclPlugin = new Sabre\DAVACL\Plugin();
$aclPlugin->allowUnauthenticatedAccess = false;
$aclPlugin->allowAccessToNodesWithoutACL = false;
$aclPlugin->hideNodesFromListings = true;
$server->addPlugin($aclPlugin);
// Add carddav plugin
$cardDavPlugin = new ISubsoft\DAV\CardDAV\Plugin($carddavBackend);
if($GLOBALS['max_payload_size'] != null)
$cardDavPlugin->setResourceSize($GLOBALS['max_payload_size']);
$server->addPlugin($cardDavPlugin);
// Add property storage plugin
$server->addPlugin(new ISubsoft\DAV\PropertyStorage\Plugin($propStoreBackend));
// Add webdav sync plugin
if($GLOBALS['enable_incremental_sync'])
$server->addPlugin(new Sabre\DAV\Sync\Plugin());
// Add browser plugin
if($GLOBALS['environment'] != 'prod')
$server->addPlugin(new Sabre\DAV\Browser\Plugin());
// And off we go!
$server->exec();