-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathrpc.php
More file actions
218 lines (198 loc) · 8.14 KB
/
Copy pathrpc.php
File metadata and controls
218 lines (198 loc) · 8.14 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?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-2026 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (LGPL-2). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl.
*
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl LGPL-2
* @package Horde
*/
use Horde\Util\Util;
use Psr\Log\LoggerInterface;
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 = [];
/* 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') !== false)) {
/* ActiveSync Request */
$conf['cookie']['path'] = '/Microsoft-Server-ActiveSync';
// Avoid session timeout errors for short max_time values and potentially
// long running EAS ping requests.
$conf['session']['max_time'] = 0;
$serverType = 'ActiveSync';
$nocompress = true;
$session_control = 'none';
$cache_control = 'private';
} elseif (!empty($_SERVER['PATH_INFO'])
|| in_array($_SERVER['REQUEST_METHOD'], ['DELETE', 'PROPFIND', 'PUT', 'OPTIONS', 'REPORT'])) {
$serverType = 'Webdav';
$session_control = 'none';
} 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 = file_get_contents('php://input');
/* Check for SOAP namespace URI. */
if (strpos($input, 'http://schemas.xmlsoap.org/soap/envelope/') !== false) {
// SOAP requires soap extension
if (!class_exists('SoapServer')) {
header('HTTP/1.0 501 Not Implemented');
header('Content-Type: text/plain; charset=utf-8');
echo "SOAP Error: The soap PHP extension is not installed.\n\n";
echo "The SOAP protocol requires the soap PHP extension.\n";
echo "Install with: apt-get install php-soap\n";
exit;
}
$serverType = 'Soap';
} else {
// XML-RPC requires xmlrpc extension
if (!function_exists('xmlrpc_server_create')) {
header('HTTP/1.0 501 Not Implemented');
header('Content-Type: text/plain; charset=utf-8');
echo "XML-RPC Error: The xmlrpc PHP extension is not installed.\n\n";
echo "The XML-RPC protocol requires the xmlrpc PHP extension, which is deprecated and not installed.\n";
echo "Install with: apt-get install php-xmlrpc (if available for your PHP version)\n\n";
echo "Note: The xmlrpc extension is deprecated. Consider using JSON-RPC instead (Content-Type: application/json).\n";
exit;
}
$serverType = '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';
$session_control = 'none';
}
/* Initialize Horde environment. */
Horde_Registry::appInit('horde', [
'authentication' => 'none',
'nocompress' => $nocompress,
'session_control' => $session_control,
'session_cache_limiter' => $cache_control,
'nonotificationinit' => true,
]);
$request = $injector->getInstance('Horde_Controller_Request');
$logger = $injector->getInstance(LoggerInterface::class);
$params['logger'] = $injector->getInstance('Horde_Log_Logger');
/* Check to see if we want to exit if required credentials are not
* present. */
if (($ra = 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;
}
// Check if ActiveSync library is actually installed
if (!class_exists('Horde_ActiveSync')) {
header('HTTP/1.0 500 Internal Server Error');
header('Content-Type: text/plain; charset=utf-8');
echo "ActiveSync Error: Horde_ActiveSync library is not installed.\n\n";
echo "ActiveSync is enabled in configuration but the required library is missing.\n";
echo "Install the ActiveSync component to enable this functionality.\n";
exit;
}
$params['server'] = $injector->getInstance('Horde_ActiveSyncServer');
// Stream Sync response bodies incrementally (chunked) instead of
// buffering the full WBXML; see horde/ActiveSync#83.
$params['streaming'] = !empty($conf['activesync']['sync']['streaming']);
$params['requireAuthorization'] = true;
break;
case 'Soap':
$serverVars = $request->getServerVars();
if (!$serverVars['REQUEST_METHOD']
|| ($serverVars['REQUEST_METHOD'] != 'POST')) {
$params['requireAuthorization'] = false;
$input = (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) {
$logger->error($e->getMessage(), ['exception' => $e]);
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) {
$logger->error($e->getMessage(), ['exception' => $e]);
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) {
$logger->error($e->getMessage(), ['exception' => $e]);
header('HTTP/1.0 500 Internal Server Error');
echo $e->getMessage();
exit;
}
}
try {
$out = $server->getResponse($input);
} catch (Horde_Rpc_Exception $e) {
$logger->error($e->getMessage(), ['exception' => $e]);
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);