forked from tikiorg/tiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tiki-webdav.php
127 lines (106 loc) · 3.69 KB
/
tiki-webdav.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
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
* @package tikiwiki
*/
// (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
// If Apache is calling PHP in CGI mode, authentication HTTP Headers are not
// set.
// In this case, you have to add the following lines inside your Apache
// VirtualHost config :
// RewriteEngine on
// RewriteCond %{HTTP:Authorization} ^(.*)
// RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
//
// The two lines below are used to set PHP_AUTH_USER and PHP_AUTH_PW from
// HTTP_AUTHORIZATION to allow Basic Authentication in Tiki WebDAV
if(isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']))
$_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
$ha = base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6));
$parts = explode(':', $ha);
while (count($parts) < 2) {
$parts[] = null;
}
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = $parts;
}
$webdav_access = false;
require_once 'tiki-setup.php';
$debug = false;
$debug_file= '/tmp/tiki4log';
/**
* @param $string
*/
function print_debug($string)
{
global $debug, $debug_file;
if ( $debug !== false) {
if (empty($debug_file)) {
$debug_file = "/tmp/tiki.log";
}
@file_put_contents($debug_file, $string, FILE_APPEND);
}
}
/**
* @param $errno
* @param $errmsg
* @param $filename
* @param $linenum
* @param $vars
*/
function error_handler($errno, $errmsg, $filename, $linenum, $vars)
{
print_debug("\n=== ERROR ===\n");
print_debug("$filename\n$linenum\n$errmsg\n");
print_debug("\n=== BACTRACE ===\n");
print_debug(print_r(debug_backtrace(false), true));
print_debug("\n=== BACTRACE END ===\n");
print_debug("\n=== ERROR END ===\n");
}
if ($debug === true) {
$old_error_handler = set_error_handler("error_handler");
}
$access->check_feature('feature_webdav');
// Check if we come here with a browser
if ( $_SERVER['REQUEST_METHOD'] === 'GET' && $_SERVER['REQUEST_URI'] === $_SERVER['SCRIPT_NAME'] ) {
$smarty->assign('mid', 'tiki-webdav.tpl');
$smarty->display("tiki.tpl");
} else {
if ( empty($_SERVER['PATH_INFO']) ) {
$_SERVER['PATH_INFO'] = '/';
}
$path = preg_replace('#.*tiki-webdav\.php#', '', rawurldecode(trim($_SERVER['REQUEST_URI'])));
$path = rtrim($path, '?');
print_debug("\n=== _SERVER() ===\n".print_r($_SERVER, true)."\n");
$server = TikiWebdav_Server::getInstance();
$server->options->realm = tra('Tiki WebDAV access');
print_debug("\n====PATH : $path ====\n");
if (preg_match('/^\/Wiki Pages\//', $path)) {
print_debug("\n====Wiki====\n");
$pathFactory = new TikiWebdav_PathFactories_Wiki();
$backend = new TikiWebdav_Backends_Wiki();
$path = preg_replace('/^\/Wiki Pages\//', '', $path);
if (empty($path)) {
$path = '/';
}
print_debug("\n====PATH : $path ====\n");
print_debug("\n TOKENFile=". $backend->getRoot().'/.webdav-token.php'."\n");
$server->auth = new TikiWebdav_Auth_Wiki($backend->getRoot().'/.webdav-token.php');
} else {
$pathFactory = new TikiWebdav_PathFactories_File;
$backend = new TikiWebdav_Backends_File;
print_debug("\n TOKENFile=". $backend->getRoot().'/.webdav-token.php'."\n");
$server->auth = new TikiWebdav_Auth_Default($backend->getRoot().'/.webdav-token.php');
$server->pluginRegistry->registerPlugin(new ezcWebdavLockPluginConfiguration());
}
foreach ( $server->configurations as $conf ) {
$conf->pathFactory = $pathFactory;
}
print_debug("\n=== handle() ===\n");
$filegallib = TikiLib::lib('filegal');
$server->handle($backend, $path);
print_debug("\n=== end handle() ===\n");
}