-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.php
68 lines (51 loc) · 2.1 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
<?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/Bootstrap.php';
// Loader
require_once __BASE_DIR__ . '/vendor/autoload.php';
$GLOBALS['currentUserPrincipalId'] = null;
$GLOBALS['currentUserPrincipalBackendId'] = null;
$GLOBALS['currentUserPrincipalLdapConn'] = null;
// Backends
$authBackend = new ISubsoft\DAV\Auth\Backend\LDAP($config);
$principalBackend = new ISubsoft\DAV\DAVACL\PrincipalBackend\LDAP($config, $pdo);
$carddavBackend = new ISubsoft\DAV\CardDAV\Backend\LDAP($config, $pdo);
// We're assuming that the realm name is called 'SabreDAV'.
$authBackend->setRealm('SabreDAV');
// Setting up the directory tree //
$nodes = [
new Sabre\DAVACL\PrincipalCollection($principalBackend),
new ISubsoft\DAV\CardDAV\AddressBookRoot($principalBackend, $carddavBackend)
];
// settings
// Make sure this setting is turned on and reflect the root url for your WebDAV server.
// This can be for example the root / or a complete path to your server script
$baseUri = '/';
// The object tree needs in turn to be passed to the server class
$server = new Sabre\DAV\Server($nodes);
$server->setBaseUri($baseUri);
// Plugins
$aclPlugin = new Sabre\DAVACL\Plugin();
$aclPlugin->allowUnauthenticatedAccess = false;
$aclPlugin->hideNodesFromListings = true;
$server->addPlugin(new ISubsoft\DAV\Auth\Plugin($authBackend));
$server->addPlugin($aclPlugin);
if($GLOBALS['environment'] != 'prod')
$server->addPlugin(new Sabre\DAV\Browser\Plugin());
$cardDavPlugin = new ISubsoft\DAV\CardDAV\Plugin();
// Set global max resource size
// $cardDavPlugin->setResourceSize(<size_in_bytes>);
$server->addPlugin($cardDavPlugin);
$server->addPlugin(new Sabre\DAV\Sync\Plugin());
// And off we go!
$server->exec();