-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpc.php
174 lines (156 loc) · 5.71 KB
/
rpc.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/**
* RPC processing script.
*
* Possible GET values:
* - requestMissingAuthorization: Whether or not to request authentication
* credentials if they are not already
* present.
* - wsdl: TODO
*
* Copyright 2002-2015 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL-2). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl.
*
* @author Jan Schneider <[email protected]>
* @category Horde
* @license http://www.horde.org/licenses/lgpl LGPL-2
* @package Horde
*/
require_once __DIR__ . '/lib/Application.php';
// Since different RPC servers have different session requirements, we can't
// call appInit() until we know which server we are requesting. We don't
// initialize the application until after we know the rpc server we want.
$input = $session_control = $cache_control = null;
$nocompress = false;
$params = array();
/* Look at the Content-type of the request, if it is available, to try
* and determine what kind of request this is. */
if ((!empty($_SERVER['CONTENT_TYPE']) &&
(strpos($_SERVER['CONTENT_TYPE'], 'application/vnd.ms-sync.wbxml') !== false)) ||
(strpos($_SERVER['REQUEST_URI'], 'Microsoft-Server-ActiveSync') !== false) ||
(stripos($_SERVER['REQUEST_URI'], 'autodiscover/autodiscover.xml') !== false)) {
/* ActiveSync Request */
$conf['cookie']['path'] = '/Microsoft-Server-ActiveSync';
$serverType = 'ActiveSync';
$nocompress = true;
$session_control = 'none';
$cache_control = 'private';
} elseif (!empty($_SERVER['PATH_INFO']) ||
in_array($_SERVER['REQUEST_METHOD'], array('DELETE', 'PROPFIND', 'PUT', 'OPTIONS', 'REPORT'))) {
$serverType = 'Webdav';
} elseif (!empty($_SERVER['CONTENT_TYPE'])) {
if (strpos($_SERVER['CONTENT_TYPE'], 'application/vnd.syncml+xml') !== false) {
$serverType = 'Syncml';
$nocompress = true;
$session_control = 'none';
} elseif (strpos($_SERVER['CONTENT_TYPE'], 'application/vnd.syncml+wbxml') !== false) {
$serverType = 'Syncml_Wbxml';
$nocompress = true;
$session_control = 'none';
} elseif (strpos($_SERVER['CONTENT_TYPE'], 'text/xml') !== false) {
$input = Horde_Rpc::getInput();
/* Check for SOAP namespace URI. */
$serverType = (strpos($input, 'http://schemas.xmlsoap.org/soap/envelope/') !== false)
? 'Soap'
: 'Xmlrpc';
} elseif (strpos($_SERVER['CONTENT_TYPE'], 'application/json') !== false) {
$serverType = 'Jsonrpc';
} else {
header('HTTP/1.0 501 Not Implemented');
exit;
}
} elseif ($_SERVER['QUERY_STRING'] && $_SERVER['QUERY_STRING'] == 'phpgw') {
$serverType = 'Phpgw';
} else {
$serverType = 'Webdav';
}
/* Initialize Horde environment. */
Horde_Registry::appInit('horde', array(
'authentication' => 'none',
'nocompress' => $nocompress,
'session_control' => $session_control,
'session_cache_limiter' => $cache_control,
'nonotificationinit' => true
));
$request = $injector->getInstance('Horde_Controller_Request');
$params['logger'] = $injector->getInstance('Horde_Log_Logger');
/* Check to see if we want to exit if required credentials are not
* present. */
if (($ra = Horde_Util::getGet('requestMissingAuthorization')) !== null) {
$params['requestMissingAuthorization'] = $ra;
}
/* Driver specific tasks that require Horde environment. */
switch ($serverType) {
case 'ActiveSync':
// Check if AS is enabled. Note that we can't check the user perms for it
// here since the user is not yet logged into horde at this point.
if (empty($conf['activesync']['enabled'])) {
exit;
}
$params['server'] = $injector->getInstance('Horde_ActiveSyncServer');
$params['requireAuthorization'] = true;
break;
case 'Soap':
$serverVars = $request->getServerVars();
if (!$serverVars['REQUEST_METHOD'] ||
($serverVars['REQUEST_METHOD'] != 'POST')) {
$params['requireAuthorization'] = false;
$input = (Horde_Util::getGet('wsdl') === null)
? 'disco'
: 'wsdl';
}
break;
}
/* Load the RPC backend based on $serverType. */
try {
$server = Horde_Rpc::factory($serverType, $request, $params);
} catch (Horde_Rpc_Exception $e) {
Horde::log($e, 'ERR');
header('HTTP/1.1 501 Not Implemented');
exit;
}
// Let the backend check authentication. By default, we look for HTTP
// basic authentication against Horde, but backends can override this
// as needed. Must reset the authentication argument since we delegate
// auth to the RPC server.
$registry->setAuthenticationSetting(
(array_key_exists('requireAuthorization', $params) && $params['requireAuthorization'] === false)
? 'none'
: 'Authenticate');
try {
$server->authorize();
} catch (Horde_Rpc_Exception $e) {
Horde::log($e, 'ERR');
header('HTTP/1.0 500 Internal Server Error');
echo $e->getMessage();
exit;
}
/* Get the server's response. We call $server->getInput() to allow
* backends to handle input processing differently. */
if (is_null($input)) {
try {
$input = $server->getInput();
} catch (Horde_Rpc_Exception $e) {
Horde::log($e, 'ERR');
header('HTTP/1.0 500 Internal Server Error');
echo $e->getMessage();
exit;
}
}
try {
$out = $server->getResponse($input);
} catch (Horde_Rpc_Exception $e) {
Horde::log($e, 'ERR');
header('HTTP/1.0 500 Internal Server Error');
echo $e->getMessage();
exit;
}
if ($out instanceof PEAR_Error) {
header('HTTP/1.0 500 Internal Server Error');
echo $out->getMessage();
exit;
}
// Allow backends to determine how and when to send output.
$server->sendOutput($out);