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-2014 G. Giunta
9 * @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/license.txt
12 include_once(__DIR__."/../../vendor/autoload.php");
14 include_once(__DIR__."/../../lib/xmlrpc.inc");
15 include_once(__DIR__."/../../lib/xmlrpcs.inc");
18 * Forward an xmlrpc request to another server, and return to client the response received.
19 * @param xmlrpcmsg $m (see method docs below for a description of the expected parameters)
22 function forward_request($m)
26 $url = php_xmlrpc_decode($m->getParam(0));
27 $c = new xmlrpc_client($url);
28 if ($m->getNumParams() > 3)
30 // we have to set some options onto the client.
31 // Note that if we do not untaint the received values, warnings might be generated...
32 $options = php_xmlrpc_decode($m->getParam(3));
33 foreach($options as $key => $val)
41 case 'RequestCompression':
42 $c->setRequestCompression($val);
45 $c->setSSLVerifyHost($val);
48 $c->setSSLVerifyPeer($val);
51 $timeout = (integer) $val;
57 // build call for remote server
58 /// @todo find a weay to forward client info (such as IP) to server, either
59 /// - as xml comments in the payload, or
60 /// - using std http header conventions, such as X-forwarded-for...
61 $method = php_xmlrpc_decode($m->getParam(1));
62 $pars = $m->getParam(2);
63 $m = new xmlrpcmsg($method);
64 for ($i = 0; $i < $pars->arraySize(); $i++)
66 $m->addParam($pars->arraymem($i));
69 // add debug info into response we give back to caller
70 xmlrpc_debugmsg("Sending to server $url the payload: ".$m->serialize());
71 return $c->send($m, $timeout);
75 $server = new xmlrpc_server(
77 'xmlrpcproxy.call' => array(
78 'function' => 'forward_request',
80 array('mixed', 'string', 'string', 'array'),
81 array('mixed', 'string', 'string', 'array', 'stuct'),
83 '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'