-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileserver.php
76 lines (56 loc) · 2.06 KB
/
fileserver.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
<?php
use Sabre\DAV;
require 'vendor/autoload.php';
require 'config.php';
ob_start();
require 'sql/sqlite.full.sql';
$sql = ob_get_clean();
ob_end_clean();
/*************************** Setup ****************************/
// settings
if (!file_exists($home)) {
throw new RuntimeException("Home does not exist: '$home'", 1);
}
if (!is_dir($home)) {
throw new RuntimeException("Home exists but is not a directory: '$home'", 2);
}
date_default_timezone_set('Europe/Paris');
$tmpDir = "$home/.local/share/dav";
if (!file_exists($tmpDir)) {
mkdir($tmpDir, 0775, true);
}
$pdo = new PDO("sqlite:$tmpDir/dav.sqlite");
$pdo->exec($sql);
// Backends
$authBackend = new DAV\Auth\Backend\Apache(); // Let apache manage the auth.
$lockBackend = new DAV\Locks\Backend\PDO($pdo);
$storageBackend = new DAV\PropertyStorage\Backend\PDO($pdo);
$server = new DAV\Server([
new DAV\SimpleCollection('files', [
new DAV\FSExt\Directory($home),
]),
]);
$server->setBaseUri('/');
/********************** General Plugins ***********************/
// Auth plugin
$server->addPlugin(new DAV\Auth\Plugin($authBackend));
// The lock manager is reponsible for making sure users don't overwrite
// each others changes.
$server->addPlugin(new DAV\Locks\Plugin($lockBackend));
// Custom properties storage plugin
$server->addPlugin(new DAV\PropertyStorage\Plugin($storageBackend));
// WebDAV-Sync plugin
$server->addPlugin(new DAV\Sync\Plugin());
// Support for html frontend
$server->addPlugin(new DAV\Browser\Plugin());
/************************ File Plugins ************************/
// Automatically guess (some) contenttypes, based on extension
$mimePlugin = new DAV\Browser\GuessContentType();
$mimePlugin->extensionMap["mp4"] = "video/mp4";
$server->addPlugin($mimePlugin);
// Add Posix properties to files
$server->addPlugin(new PosixPropertiesPlugin($home, "files/$user", $ids));
// Temporary file filter to store garbage OS files elsewhere
$server->addPlugin(new DAV\TemporaryFileFilterPlugin($tmpDir));
/************************ Start server ************************/
$server->start();