Completed
Push — 16.1 ( b39e15...d98aac )
by Klaus
18:52
created

remote.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * FileManger - WebDAV access for ownCloud clients
4
 *
5
 * ownCloud clients sync by default local ownCloud dir to /clientsync on server.
6
 *
7
 * EGroupware now temporary mounts vfs://default/home/$user on /clientsync,
8
 * so ownCloud clients syncs with users home-dir, unless admin mounts an other directory.
9
 *
10
 * @link http://owncloud.org/sync-clients/
11
 * @link http://www.egroupware.org
12
 * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
13
 * @package api
14
 * @subpackage vfs
15
 * @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
16
 * @copyright (c) 2006-16 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
17
 * @version $Id$
18
 */
19
20
use EGroupware\Api;
21
use EGroupware\Vfs;
22
23
$starttime = microtime(true);
24
25
/**
26
 * check if the given user has access
27
 *
28
 * Create a session or if the user has no account return authenticate header and 401 Unauthorized
29
 *
30
 * @param array &$account
31
 * @return int session-id
32
 */
33 View Code Duplication
function check_access(&$account)
0 ignored issues
show
The function check_access() has been defined more than once; this definition is ignored, only the first definition in api/ntlm/index.php (L49-77) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
34
{
35
	if (isset($_GET['auth']))
36
	{
37
		list($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW']) = explode(':',base64_decode($_GET['auth']),2);
38
	}
39
	return Api\Header\Authenticate::autocreate_session_callback($account);
40
}
41
42
$GLOBALS['egw_info'] = array(
43
	'flags' => array(
44
		'disable_Template_class' => True,
45
		'noheader'  => True,
46
		'currentapp' => preg_match('|/remote.php/webdav/apps/([A-Za-z0-9_-]+)/|', $_SERVER['REQUEST_URI'], $matches) ? $matches[1] : 'filemanager',
47
		'autocreate_session_callback' => 'check_access',
48
		'no_exception_handler' => 'basic_auth',	// we use a basic auth exception handler (sends exception message as basic auth realm)
49
		'auth_realm' => 'EGroupware WebDAV server',	// cant use Vfs\WebDAV::REALM as autoloading and include path not yet setup!
50
	)
51
);
52
53
// if you move this file somewhere else, you need to adapt the path to the header!
54
try
55
{
56
	include(__DIR__.'/header.inc.php');
57
}
58
catch (Api\Exception\NoPermission\App $e)
59
{
60 View Code Duplication
	if (isset($GLOBALS['egw_info']['user']['apps']['filemanager']))
61
	{
62
		$GLOBALS['egw_info']['currentapp'] = 'filemanager';
63
	}
64
	elseif (isset($GLOBALS['egw_info']['user']['apps']['sitemgr-link']))
65
	{
66
		$GLOBALS['egw_info']['currentapp'] = 'sitemgr-link';
67
	}
68
	else
69
	{
70
		throw $e;
71
	}
72
}
73
//$headertime = microtime(true);
74
75
// temporary mount ownCloud default /clientsync as /home/$user, if not explicitly mounted
76
// so ownCloud dir contains users home-dir by default
77 View Code Duplication
if (strpos($_SERVER['REQUEST_URI'],'/remote.php/webdav/clientsync') !== false &&
78
	($fstab=Vfs::mount()) && !isset($fstab['/clientsync']))
79
{
80
	$is_root_backup = Vfs::$is_root;
81
	Vfs::$is_root = true;
82
	$ok = Vfs::mount($url='vfs://default/home/$user', $clientsync='/clientsync', null, false);
83
	Vfs::$is_root = $is_root_backup;
84
	//error_log("mounting ownCloud default '$clientsync' as '$url' ".($ok ? 'successful' : 'failed!'));
85
}
86
87
// webdav is stateless: we dont need to keep the session open, it only blocks other calls to same basic-auth session
88
$GLOBALS['egw']->session->commit_session();
89
90
$webdav_server = new Vfs\WebDAV();
91
$webdav_server->ServeRequest('/webdav');
92
//error_log(sprintf('WebDAV %s request: status "%s", took %5.3f s'.($headertime?' (header include took %5.3f s)':''),$_SERVER['REQUEST_METHOD'].' '.$_SERVER['PATH_INFO'],$webdav_server->_http_status,microtime(true)-$starttime,$headertime-$starttime));
93