-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrpc.php
115 lines (104 loc) · 3.64 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
<?php
/**
* RPC processing script.
*
* Possible GET values:
*
* 'requestMissingAuthorization' -- Whether or not to request
* authentication credentials if they are not already present.
*
* 'wsdl' -- TODO
*
* $Horde: horde/rpc.php,v 1.30.10.12 2009-06-16 15:30:42 jan Exp $
*
* Copyright 2002-2009 The Horde Project (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Jan Schneider <[email protected]>
*/
define('AUTH_HANDLER', true);
define('HORDE_BASE', dirname(__FILE__));
require_once HORDE_BASE . '/lib/core.php';
require_once 'Horde/RPC.php';
$input = null;
$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['PATH_INFO']) ||
in_array($_SERVER['REQUEST_METHOD'], array('DELETE', 'PROPFIND', 'PUT', 'OPTIONS'))) {
$serverType = 'webdav';
} elseif (!empty($_SERVER['CONTENT_TYPE'])) {
if (strpos($_SERVER['CONTENT_TYPE'], 'application/vnd.syncml+xml') !== false) {
$serverType = 'syncml';
/* Syncml does its own session handling. */
$session_control = 'none';
$no_compress = true;
} elseif (strpos($_SERVER['CONTENT_TYPE'], 'application/vnd.syncml+wbxml') !== false) {
$serverType = 'syncml_wbxml';
/* Syncml does its own session handling. */
$session_control = 'none';
$no_compress = true;
} elseif (strpos($_SERVER['CONTENT_TYPE'], 'text/xml') !== false) {
$input = Horde_RPC::getInput();
/* Check for SOAP namespace URI. */
if (strpos($input, 'http://schemas.xmlsoap.org/soap/envelope/') !== false) {
$serverType = 'soap';
} else {
$serverType = 'xmlrpc';
}
} elseif (strpos($_SERVER['CONTENT_TYPE'], 'application/json') !== false) {
$serverType = 'jsonrpc';
} else {
header('HTTP/1.0 501 Not Implemented');
exit;
}
} elseif (!empty($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] == 'phpgw') {
$serverType = 'phpgw';
} else {
$serverType = 'soap';
}
if ($serverType == 'soap') {
if (!isset($_SERVER['REQUEST_METHOD']) ||
$_SERVER['REQUEST_METHOD'] != 'POST') {
$session_control = 'none';
$params['requireAuthorization'] = false;
if (Util::getGet('wsdl') !== null) {
$input = 'wsdl';
} else {
$input = 'disco';
}
} elseif (class_exists('SoapServer')) {
$serverType = 'PhpSoap';
}
}
/* Check to see if we want to exit if required credentials are not
* present. */
if (($ra = Util::getGet('requestMissingAuthorization')) !== null) {
$params['requestMissingAuthorization'] = $ra;
}
/* Load base libraries. */
require_once HORDE_BASE . '/lib/base.php';
/* Load the RPC backend based on $serverType. */
$server = Horde_RPC::factory($serverType, $params);
/* Let the backend check authentication. By default, we look for HTTP
* basic authentication against Horde, but backends can override this
* as needed. */
$server->authorize();
/* Get the server's response. We call $server->getInput() to allow
* backends to handle input processing differently. */
if ($input === null) {
$input = $server->getInput();
}
$out = $server->getResponse($input);
if (is_a($out, 'PEAR_Error')) {
header('HTTP/1.0 500 Internal Server Error');
echo $out->getMessage();
exit;
}
/* Return the response to the client. */
header('Content-Type: ' . $server->getResponseContentType());
header('Content-length: ' . strlen($out));
header('Accept-Charset: UTF-8');
echo $out;