3 * XMLRPC server acting as proxy for requests to other servers
4 * (useful e.g. for ajax-originated calls that can only connect back to
5 * the originating server).
7 * @author Gaetano Giunta
8 * @copyright (C) 2006-2015 G. Giunta
9 * @license code licensed under the BSD License: see file license.txt
12 include_once __DIR__ . "/../../src/Autoloader.php";
13 PhpXmlRpc\Autoloader::register();
16 * Forward an xmlrpc request to another server, and return to client the response received.
18 * DO NOT RUN AS IS IN PRODUCTION - this is an open relay !!!
20 * @param PhpXmlRpc\Request $req (see method docs below for a description of the expected parameters)
22 * @return PhpXmlRpc\Response
24 function forward_request($req)
26 $encoder = new \PhpXmlRpc\Encoder();
30 $url = $encoder->decode($req->getParam(0));
31 $client = new PhpXmlRpc\Client($url);
33 if ($req->getNumParams() > 3) {
34 // we have to set some options onto the client.
35 // Note that if we do not untaint the received values, warnings might be generated...
36 $options = $encoder->decode($req->getParam(3));
37 foreach ($options as $key => $val) {
43 case 'RequestCompression':
44 $client->setRequestCompression($val);
47 $client->setSSLVerifyHost($val);
50 $client->setSSLVerifyPeer($val);
53 $timeout = (integer)$val;
59 // build call for remote server
60 /// @todo find a way to forward client info (such as IP) to server, either
61 /// - as xml comments in the payload, or
62 /// - using std http header conventions, such as X-forwarded-for...
63 $reqMethod = $encoder->decode($req->getParam(1));
64 $pars = $req->getParam(2);
65 $req = new PhpXmlRpc\Request($reqMethod);
66 for ($i = 0; $i < $pars->arraySize(); $i++) {
67 $req->addParam($pars->arraymem($i));
70 // add debug info into response we give back to caller
71 PhpXmlRpc\Server::xmlrpc_debugmsg("Sending to server $url the payload: " . $req->serialize());
73 return $client->send($req, $timeout);
77 $server = new PhpXmlRpc\Server(
79 'xmlrpcproxy.call' => array(
80 'function' => 'forward_request',
82 array('mixed', 'string', 'string', 'array'),
83 array('mixed', 'string', 'string', 'array', 'struct'),
85 'docstring' => 'forwards xmlrpc calls to remote servers. Returns remote method\'s response. Accepts params: remote server url (might include basic auth credentials), method name, array of params, and (optionally) a struct containing call options',