Beispiel #1
0
/**
 * Forward an xmlrpc request to another server, and return to client the response received.
 *
 * DO NOT RUN AS IS IN PRODUCTION - this is an open relay !!!
 *
 * @param PhpXmlRpc\Request $req (see method docs below for a description of the expected parameters)
 *
 * @return PhpXmlRpc\Response
 */
function forward_request($req)
{
    $encoder = new \PhpXmlRpc\Encoder();
    // create client
    $timeout = 0;
    $url = $encoder->decode($req->getParam(0));
    $client = new PhpXmlRpc\Client($url);
    if ($req->getNumParams() > 3) {
        // we have to set some options onto the client.
        // Note that if we do not untaint the received values, warnings might be generated...
        $options = $encoder->decode($req->getParam(3));
        foreach ($options as $key => $val) {
            switch ($key) {
                case 'Cookie':
                    break;
                case 'Credentials':
                    break;
                case 'RequestCompression':
                    $client->setRequestCompression($val);
                    break;
                case 'SSLVerifyHost':
                    $client->setSSLVerifyHost($val);
                    break;
                case 'SSLVerifyPeer':
                    $client->setSSLVerifyPeer($val);
                    break;
                case 'Timeout':
                    $timeout = (int) $val;
                    break;
            }
            // switch
        }
    }
    // build call for remote server
    /// @todo find a way to forward client info (such as IP) to server, either
    /// - as xml comments in the payload, or
    /// - using std http header conventions, such as X-forwarded-for...
    $reqMethod = $encoder->decode($req->getParam(1));
    $pars = $req->getParam(2);
    $req = new PhpXmlRpc\Request($reqMethod);
    foreach ($pars as $par) {
        $req->addParam($par);
    }
    // add debug info into response we give back to caller
    PhpXmlRpc\Server::xmlrpc_debugmsg("Sending to server {$url} the payload: " . $req->serialize());
    return $client->send($req, $timeout);
}
print "<h3>methods available at http://" . $client->server . $client->path . "</h3>\n";
$req = new PhpXmlRpc\Request('system.listMethods');
$resp = $client->send($req);
if ($resp->faultCode()) {
    display_error($resp);
} else {
    $v = $resp->value();
    // Then, retrieve the signature and help text of each available method
    foreach ($v as $methodName) {
        print "<h4>" . $methodName->scalarval() . "</h4>\n";
        // build messages first, add params later
        $m1 = new PhpXmlRpc\Request('system.methodHelp');
        $m2 = new PhpXmlRpc\Request('system.methodSignature');
        $val = new PhpXmlRpc\Value($methodName->scalarval(), "string");
        $m1->addParam($val);
        $m2->addParam($val);
        // Send multiple requests in one http call.
        // If server does not support multicall, client will automatically fall back to 2 separate calls
        $ms = array($m1, $m2);
        $rs = $client->send($ms);
        if ($rs[0]->faultCode()) {
            display_error($rs[0]);
        } else {
            $val = $rs[0]->value();
            $txt = $val->scalarval();
            if ($txt != "") {
                print "<h4>Documentation</h4><p>{$txt}</p>\n";
            } else {
                print "<p>No documentation available.</p>\n";
            }
        }
Beispiel #3
0
print "<h3>Testing value serialization</h3>\n";
$v = new PhpXmlRpc\Value(23, "int");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new PhpXmlRpc\Value("What are you saying? >> << &&");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new PhpXmlRpc\Value(array(new PhpXmlRpc\Value("ABCDEFHIJ"), new PhpXmlRpc\Value(1234, 'int'), new PhpXmlRpc\Value(1, 'boolean')), "array");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new PhpXmlRpc\Value(array("thearray" => new PhpXmlRpc\Value(array(new PhpXmlRpc\Value("ABCDEFHIJ"), new PhpXmlRpc\Value(1234, 'int'), new PhpXmlRpc\Value(1, 'boolean'), new PhpXmlRpc\Value(0, 'boolean'), new PhpXmlRpc\Value(true, 'boolean'), new PhpXmlRpc\Value(false, 'boolean')), "array"), "theint" => new PhpXmlRpc\Value(23, 'int'), "thestring" => new PhpXmlRpc\Value("foobarwhizz"), "thestruct" => new PhpXmlRpc\Value(array("one" => new PhpXmlRpc\Value(1, 'int'), "two" => new PhpXmlRpc\Value(2, 'int')), "struct")), "struct");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$w = new PhpXmlRpc\Value(array($v, new PhpXmlRpc\Value("That was the struct!")), "array");
print "<PRE>" . htmlentities($w->serialize()) . "</PRE>";
$w = new PhpXmlRpc\Value("Mary had a little lamb,\nWhose fleece was white as snow,\nAnd everywhere that Mary went\nthe lamb was sure to go.\n\nMary had a little lamb\nShe tied it to a pylon\nTen thousand volts went down its back\nAnd turned it into nylon", "base64");
print "<PRE>" . htmlentities($w->serialize()) . "</PRE>";
print "<PRE>Value of base64 string is: '" . $w->scalarval() . "'</PRE>";
$req->method('');
$req->addParam(new PhpXmlRpc\Value("41", "int"));
print "<h3>Testing request serialization</h3>\n";
$op = $req->serialize();
print "<PRE>" . htmlentities($op) . "</PRE>";
print "<h3>Testing ISO date format</h3><pre>\n";
$t = time();
$date = PhpXmlRpc\Helper\Date::iso8601Encode($t);
print "Now is {$t} --> {$date}\n";
print "Or in UTC, that is " . PhpXmlRpc\Helper\Date::iso8601Encode($t, 1) . "\n";
$tb = PhpXmlRpc\Helper\Date::iso8601Decode($date);
print "That is to say {$date} --> {$tb}\n";
print "Which comes out at " . PhpXmlRpc\Helper\Date::iso8601Encode($tb) . "\n";
print "Which was the time in UTC at " . PhpXmlRpc\Helper\Date::iso8601Encode($date, 1) . "\n";
print "</pre>\n";
?>
</body>