3 * @author Gaetano Giunta
4 * @copyright (C) 2005-2015 G. Giunta
5 * @license code licensed under the BSD License: see file license.txt
7 * @todo switch params for http compression from 0,1,2 to values to be used directly
8 * @todo use ob_start to catch debug info and echo it AFTER method call results?
9 * @todo be smarter in creating client stub for proxy/auth cases: only set appropriate property of client obj
12 header('Content-Type: text/html; charset=utf-8');
15 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
16 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
17 <html xmlns="http://www.w3.org/1999/xhtml">
19 <title>XMLRPC Debugger</title>
20 <meta name="robots" content="index,nofollow"/>
21 <style type="text/css">
24 border-top: 1px solid gray;
26 font-family: Verdana, Arial, Helvetica;
40 background-color: #EEEEEE;
41 border: 1px dashed silver;
42 font-family: monospace;
48 background-color: #DDDDDD;
49 border: 1px solid gray;
51 font-family: monospace;
60 background-color: navy;
67 font-family: monospace;
75 background-color: #EEEEEE;
83 background-color: #EEEEEE;
94 include __DIR__ . '/common.php';
97 include_once __DIR__ . "/../src/Autoloader.php";
98 PhpXmlRpc\Autoloader::register();
100 // make sure the script waits long enough for the call to complete...
102 set_time_limit($timeout + 10);
106 @include 'jsonrpc.inc';
107 if (!class_exists('jsonrpc_client')) {
108 die('Error: to debug the jsonrpc protocol the jsonrpc.inc file is needed');
110 $clientClass = 'PhpJsRpc\Client';
111 $requestClass = 'PhpJsRpc\Request';
112 $protoName = 'JSONRPC';
114 $clientClass = 'PhpXmlRpc\Client';
115 $requestClass = 'PhpXmlRpc\Request';
116 $protoName = 'XMLRPC';
120 $client = new $clientClass($path, $host, $port);
121 $server = "$host:$port$path";
123 $client = new $clientClass($path, $host);
124 $server = "$host$path";
126 if ($protocol == 2) {
127 $server = 'https://' . $server;
129 $server = 'http://' . $server;
132 $pproxy = explode(':', $proxy);
133 if (count($pproxy) > 1) {
138 $client->setProxy($pproxy[0], $pport, $proxyuser, $proxypwd);
141 if ($protocol == 2) {
142 $client->setSSLVerifyPeer($verifypeer);
143 $client->setSSLVerifyHost($verifyhost);
145 $client->setCaCertificate($cainfo);
147 $httpprotocol = 'https';
148 } elseif ($protocol == 1) {
149 $httpprotocol = 'http11';
151 $httpprotocol = 'http';
155 $client->setCredentials($username, $password, $authtype);
158 $client->setDebug($debug);
160 switch ($requestcompression) {
162 $client->request_compression = '';
165 $client->request_compression = 'gzip';
168 $client->request_compression = 'deflate';
172 switch ($responsecompression) {
174 $client->accepted_compression = '';
177 $client->accepted_compression = array('gzip');
180 $client->accepted_compression = array('deflate');
183 $client->accepted_compression = array('gzip', 'deflate');
187 $cookies = explode(',', $clientcookies);
188 foreach ($cookies as $cookie) {
189 if (strpos($cookie, '=')) {
190 $cookie = explode('=', $cookie);
191 $client->setCookie(trim($cookie[0]), trim(@$cookie[1]));
197 // fall thru intentionally
200 $msg[0] = new $requestClass('system.methodHelp', array(), $id);
201 $msg[0]->addparam(new PhpXmlRpc\Value($method));
202 $msg[1] = new $requestClass('system.methodSignature', array(), $id + 1);
203 $msg[1]->addparam(new PhpXmlRpc\Value($method));
204 $actionname = 'Description of method "' . $method . '"';
207 $msg[0] = new $requestClass('system.listMethods', array(), $id);
208 $actionname = 'List of available methods';
211 if (!payload_is_safe($payload)) {
212 die("Tsk tsk tsk, please stop it or I will have to call in the cops!");
214 $msg[0] = new $requestClass($method, array(), $id);
215 // hack! build xml payload by hand
217 $msg[0]->payload = "{\n" .
218 '"method": "' . $method . "\",\n\"params\": [" .
221 // fix: if user gave an empty string, use NULL, or we'll break json syntax
223 $msg[0]->payload .= "null\n}";
225 if (is_numeric($id) || $id == 'false' || $id == 'true' || $id == 'null') {
226 $msg[0]->payload .= "$id\n}";
228 $msg[0]->payload .= "\"$id\"\n}";
232 $msg[0]->payload = $msg[0]->xml_header($inputcharset) .
233 '<methodName>' . $method . "</methodName>\n<params>" .
235 "</params>\n" . $msg[0]->xml_footer();
237 $actionname = 'Execution of method ' . $method;
239 default: // give a warning
240 $actionname = '[ERROR: unknown action] "' . $action . '"';
243 // Before calling execute, echo out brief description of action taken + date and time ???
244 // this gives good user feedback for long-running methods...
245 echo '<h2>' . htmlspecialchars($actionname, ENT_COMPAT, $inputcharset) . ' on server ' . htmlspecialchars($server, ENT_COMPAT, $inputcharset) . " ...</h2>\n";
251 echo '<div class="dbginfo"><h2>Debug info:</h2>';
252 } /// @todo use ob_start instead
254 $time = microtime(true);
255 foreach ($msg as $message) {
256 // catch errors: for older xmlrpc libs, send does not return by ref
257 @$response = $client->send($message, $timeout, $httpprotocol);
259 if (!$response || $response->faultCode()) {
263 $time = microtime(true) - $time;
269 if ($response->faultCode()) {
270 // call failed! echo out error msg!
271 //echo '<h2>'.htmlspecialchars($actionname, ENT_COMPAT, $inputcharset).' on server '.htmlspecialchars($server, ENT_COMPAT, $inputcharset).'</h2>';
272 echo "<h3>$protoName call FAILED!</h3>\n";
273 echo "<p>Fault code: [" . htmlspecialchars($response->faultCode(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
274 "] Reason: '" . htmlspecialchars($response->faultString(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "'</p>\n";
275 echo(strftime("%d/%b/%Y:%H:%M:%S\n"));
277 // call succeeded: parse results
278 //echo '<h2>'.htmlspecialchars($actionname, ENT_COMPAT, $inputcharset).' on server '.htmlspecialchars($server, ENT_COMPAT, $inputcharset).'</h2>';
279 printf("<h3>%s call(s) OK (%.2f secs.)</h3>\n", $protoName, $time);
280 echo(strftime("%d/%b/%Y:%H:%M:%S\n"));
285 $v = $response->value();
286 if ($v->kindOf() == "array") {
288 echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
289 echo "<thead>\n<tr><th>Method ($max)</th><th>Description</th></tr>\n</thead>\n<tbody>\n";
290 for ($i = 0; $i < $max; $i++) {
291 $rec = $v->arraymem($i);
293 $class = ' class="oddrow"';
295 $class = ' class="evenrow"';
297 echo("<tr><td$class>" . htmlspecialchars($rec->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "</td><td$class><form action=\"controller.php\" method=\"get\" target=\"frmcontroller\">" .
298 "<input type=\"hidden\" name=\"host\" value=\"" . htmlspecialchars($host, ENT_COMPAT, $inputcharset) . "\" />" .
299 "<input type=\"hidden\" name=\"port\" value=\"" . htmlspecialchars($port, ENT_COMPAT, $inputcharset) . "\" />" .
300 "<input type=\"hidden\" name=\"path\" value=\"" . htmlspecialchars($path, ENT_COMPAT, $inputcharset) . "\" />" .
301 "<input type=\"hidden\" name=\"id\" value=\"" . htmlspecialchars($id, ENT_COMPAT, $inputcharset) . "\" />" .
302 "<input type=\"hidden\" name=\"debug\" value=\"$debug\" />" .
303 "<input type=\"hidden\" name=\"username\" value=\"" . htmlspecialchars($username, ENT_COMPAT, $inputcharset) . "\" />" .
304 "<input type=\"hidden\" name=\"password\" value=\"" . htmlspecialchars($password, ENT_COMPAT, $inputcharset) . "\" />" .
305 "<input type=\"hidden\" name=\"authtype\" value=\"$authtype\" />" .
306 "<input type=\"hidden\" name=\"verifyhost\" value=\"$verifyhost\" />" .
307 "<input type=\"hidden\" name=\"verifypeer\" value=\"$verifypeer\" />" .
308 "<input type=\"hidden\" name=\"cainfo\" value=\"" . htmlspecialchars($cainfo, ENT_COMPAT, $inputcharset) . "\" />" .
309 "<input type=\"hidden\" name=\"proxy\" value=\"" . htmlspecialchars($proxy, ENT_COMPAT, $inputcharset) . "\" />" .
310 "<input type=\"hidden\" name=\"proxyuser\" value=\"" . htmlspecialchars($proxyuser, ENT_COMPAT, $inputcharset) . "\" />" .
311 "<input type=\"hidden\" name=\"proxypwd\" value=\"" . htmlspecialchars($proxypwd, ENT_COMPAT, $inputcharset) . "\" />" .
312 "<input type=\"hidden\" name=\"responsecompression\" value=\"$responsecompression\" />" .
313 "<input type=\"hidden\" name=\"requestcompression\" value=\"$requestcompression\" />" .
314 "<input type=\"hidden\" name=\"clientcookies\" value=\"" . htmlspecialchars($clientcookies, ENT_COMPAT, $inputcharset) . "\" />" .
315 "<input type=\"hidden\" name=\"protocol\" value=\"$protocol\" />" .
316 "<input type=\"hidden\" name=\"timeout\" value=\"" . htmlspecialchars($timeout, ENT_COMPAT, $inputcharset) . "\" />" .
317 "<input type=\"hidden\" name=\"method\" value=\"" . htmlspecialchars($rec->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "\" />" .
318 "<input type=\"hidden\" name=\"wstype\" value=\"$wstype\" />" .
319 "<input type=\"hidden\" name=\"action\" value=\"describe\" />" .
320 "<input type=\"hidden\" name=\"run\" value=\"now\" />" .
321 "<input type=\"submit\" value=\"Describe\" /></form></td>");
324 // generate the skeleton for method payload per possible tests
325 //$methodpayload="<methodCall>\n<methodName>".$rec->scalarval()."</methodName>\n<params>\n<param><value></value></param>\n</params>\n</methodCall>";
327 /*echo ("<form action=\"{$_SERVER['PHP_SELF']}\" method=\"get\"><td>".
328 "<input type=\"hidden\" name=\"host\" value=\"$host\" />".
329 "<input type=\"hidden\" name=\"port\" value=\"$port\" />".
330 "<input type=\"hidden\" name=\"path\" value=\"$path\" />".
331 "<input type=\"hidden\" name=\"method\" value=\"".$rec->scalarval()."\" />".
332 "<input type=\"hidden\" name=\"methodpayload\" value=\"$payload\" />".
333 "<input type=\"hidden\" name=\"action\" value=\"execute\" />".
334 "<input type=\"submit\" value=\"Test\" /></td></form>");*/
337 echo "</tbody>\n</table>";
343 $r1 = $resp[0]->value();
344 $r2 = $resp[1]->value();
346 echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
347 echo "<thead>\n<tr><th>Method</th><th>" . htmlspecialchars($method, ENT_COMPAT, $inputcharset) . "</th><th> </th><th> </th></tr>\n</thead>\n<tbody>\n";
348 $desc = htmlspecialchars($r1->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding);
352 echo "<tr><td class=\"evenrow\">Description</td><td colspan=\"3\" class=\"evenrow\">$desc</td></tr>\n";
354 if ($r2->kindOf() != "array") {
355 echo "<tr><td class=\"oddrow\">Signature</td><td class=\"oddrow\">Unknown</td><td class=\"oddrow\"> </td></tr>\n";
357 for ($i = 0; $i < $r2->arraysize(); $i++) {
361 $class = ' class="oddrow"';
363 $class = ' class="evenrow"';
365 echo "<tr><td$class>Signature " . ($i + 1) . "</td><td$class>";
366 $x = $r2->arraymem($i);
367 if ($x->kindOf() == "array") {
368 $ret = $x->arraymem(0);
369 echo "<code>OUT: " . htmlspecialchars($ret->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "<br />IN: (";
370 if ($x->count() > 1) {
371 for ($k = 1; $k < $x->arraysize(); $k++) {
372 $y = $x->arraymem($k);
373 echo htmlspecialchars($y->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding);
375 $type = $y->scalarval();
376 $payload .= '<param><value>';
382 // fall thru intentionally
385 htmlspecialchars($type, ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
386 '></' . htmlspecialchars($type, ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
389 $payload .= "</value></param>\n";
391 $alt_payload .= $y->scalarval();
392 if ($k < $x->count() - 1) {
403 // button to test this method
404 //$payload="<methodCall>\n<methodName>$method</methodName>\n<params>\n$payload</params>\n</methodCall>";
405 echo "<td$class><form action=\"controller.php\" target=\"frmcontroller\" method=\"get\">" .
406 "<input type=\"hidden\" name=\"host\" value=\"" . htmlspecialchars($host, ENT_COMPAT, $inputcharset) . "\" />" .
407 "<input type=\"hidden\" name=\"port\" value=\"" . htmlspecialchars($port, ENT_COMPAT, $inputcharset) . "\" />" .
408 "<input type=\"hidden\" name=\"path\" value=\"" . htmlspecialchars($path, ENT_COMPAT, $inputcharset) . "\" />" .
409 "<input type=\"hidden\" name=\"id\" value=\"" . htmlspecialchars($id, ENT_COMPAT, $inputcharset) . "\" />" .
410 "<input type=\"hidden\" name=\"debug\" value=\"$debug\" />" .
411 "<input type=\"hidden\" name=\"username\" value=\"" . htmlspecialchars($username, ENT_COMPAT, $inputcharset) . "\" />" .
412 "<input type=\"hidden\" name=\"password\" value=\"" . htmlspecialchars($password, ENT_COMPAT, $inputcharset) . "\" />" .
413 "<input type=\"hidden\" name=\"authtype\" value=\"$authtype\" />" .
414 "<input type=\"hidden\" name=\"verifyhost\" value=\"$verifyhost\" />" .
415 "<input type=\"hidden\" name=\"verifypeer\" value=\"$verifypeer\" />" .
416 "<input type=\"hidden\" name=\"cainfo\" value=\"" . htmlspecialchars($cainfo, ENT_COMPAT, $inputcharset) . "\" />" .
417 "<input type=\"hidden\" name=\"proxy\" value=\"" . htmlspecialchars($proxy, ENT_COMPAT, $inputcharset) . "\" />" .
418 "<input type=\"hidden\" name=\"proxyuser\" value=\"" . htmlspecialchars($proxyuser, ENT_COMPAT, $inputcharset) . "\" />" .
419 "<input type=\"hidden\" name=\"proxypwd\" value=\"" . htmlspecialchars($proxypwd, ENT_COMPAT, $inputcharset) . "\" />" .
420 "<input type=\"hidden\" name=\"responsecompression\" value=\"$responsecompression\" />" .
421 "<input type=\"hidden\" name=\"requestcompression\" value=\"$requestcompression\" />" .
422 "<input type=\"hidden\" name=\"clientcookies\" value=\"" . htmlspecialchars($clientcookies, ENT_COMPAT, $inputcharset) . "\" />" .
423 "<input type=\"hidden\" name=\"protocol\" value=\"$protocol\" />" .
424 "<input type=\"hidden\" name=\"timeout\" value=\"" . htmlspecialchars($timeout, ENT_COMPAT, $inputcharset) . "\" />" .
425 "<input type=\"hidden\" name=\"method\" value=\"" . htmlspecialchars($method, ENT_COMPAT, $inputcharset) . "\" />" .
426 "<input type=\"hidden\" name=\"methodpayload\" value=\"" . htmlspecialchars($payload, ENT_COMPAT, $inputcharset) . "\" />" .
427 "<input type=\"hidden\" name=\"altmethodpayload\" value=\"" . htmlspecialchars($alt_payload, ENT_COMPAT, $inputcharset) . "\" />" .
428 "<input type=\"hidden\" name=\"wstype\" value=\"$wstype\" />" .
429 "<input type=\"hidden\" name=\"action\" value=\"execute\" />";
431 echo "<input type=\"submit\" value=\"Load method synopsis\" />";
433 echo "</form></td>\n";
435 echo "<td$class><form action=\"controller.php\" target=\"frmcontroller\" method=\"get\">" .
436 "<input type=\"hidden\" name=\"host\" value=\"" . htmlspecialchars($host, ENT_COMPAT, $inputcharset) . "\" />" .
437 "<input type=\"hidden\" name=\"port\" value=\"" . htmlspecialchars($port, ENT_COMPAT, $inputcharset) . "\" />" .
438 "<input type=\"hidden\" name=\"path\" value=\"" . htmlspecialchars($path, ENT_COMPAT, $inputcharset) . "\" />" .
439 "<input type=\"hidden\" name=\"id\" value=\"" . htmlspecialchars($id, ENT_COMPAT, $inputcharset) . "\" />" .
440 "<input type=\"hidden\" name=\"debug\" value=\"$debug\" />" .
441 "<input type=\"hidden\" name=\"username\" value=\"" . htmlspecialchars($username, ENT_COMPAT, $inputcharset) . "\" />" .
442 "<input type=\"hidden\" name=\"password\" value=\"" . htmlspecialchars($password, ENT_COMPAT, $inputcharset) . "\" />" .
443 "<input type=\"hidden\" name=\"authtype\" value=\"$authtype\" />" .
444 "<input type=\"hidden\" name=\"verifyhost\" value=\"$verifyhost\" />" .
445 "<input type=\"hidden\" name=\"verifypeer\" value=\"$verifypeer\" />" .
446 "<input type=\"hidden\" name=\"cainfo\" value=\"" . htmlspecialchars($cainfo, ENT_COMPAT, $inputcharset) . "\" />" .
447 "<input type=\"hidden\" name=\"proxy\" value=\"" . htmlspecialchars($proxy, ENT_COMPAT, $inputcharset) . "\" />" .
448 "<input type=\"hidden\" name=\"proxyuser\" value=\"" . htmlspecialchars($proxyuser, ENT_COMPAT, $inputcharset) . "\" />" .
449 "<input type=\"hidden\" name=\"proxypwd\" value=\"" . htmlspecialchars($proxypwd, ENT_COMPAT, $inputcharset) . "\" />" .
450 "<input type=\"hidden\" name=\"responsecompression\" value=\"$responsecompression\" />" .
451 "<input type=\"hidden\" name=\"requestcompression\" value=\"$requestcompression\" />" .
452 "<input type=\"hidden\" name=\"clientcookies\" value=\"" . htmlspecialchars($clientcookies, ENT_COMPAT, $inputcharset) . "\" />" .
453 "<input type=\"hidden\" name=\"protocol\" value=\"$protocol\" />" .
454 "<input type=\"hidden\" name=\"timeout\" value=\"" . htmlspecialchars($timeout, ENT_COMPAT, $inputcharset) . "\" />" .
455 "<input type=\"hidden\" name=\"method\" value=\"" . htmlspecialchars($method, ENT_COMPAT, $inputcharset) . "\" />" .
456 "<input type=\"hidden\" name=\"methodsig\" value=\"" . $i . "\" />" .
457 "<input type=\"hidden\" name=\"methodpayload\" value=\"" . htmlspecialchars($payload, ENT_COMPAT, $inputcharset) . "\" />" .
458 "<input type=\"hidden\" name=\"altmethodpayload\" value=\"" . htmlspecialchars($alt_payload, ENT_COMPAT, $inputcharset) . "\" />" .
459 "<input type=\"hidden\" name=\"wstype\" value=\"$wstype\" />" .
460 "<input type=\"hidden\" name=\"run\" value=\"now\" />" .
461 "<input type=\"hidden\" name=\"action\" value=\"wrap\" />" .
462 "<input type=\"submit\" value=\"Generate method call stub code\" />";
463 echo "</form></td></tr>\n";
466 echo "</tbody>\n</table>";
471 $r1 = $resp[0]->value();
472 $r2 = $resp[1]->value();
473 if ($r2->kindOf() != "array" || $r2->count() <= $methodsig) {
474 echo "Error: signature unknown\n";
476 $mdesc = $r1->scalarval();
477 $encoder = new PhpXmlRpc\Encoder();
478 $msig = $encoder->decode($r2);
479 $msig = $msig[$methodsig];
480 $proto = $protocol == 2 ? 'https' : $protocol == 1 ? 'http11' : '';
481 if ($proxy == '' && $username == '' && !$requestcompression && !$responsecompression &&
484 $opts = 1; // simple client copy in stub code
486 $opts = 0; // complete client copy in stub code
493 $wrapper = new PhpXmlRpc\Wrapper();
494 $code = $wrapper->buildWrapMethodSource($client, $method, array('timeout' => $timeout, 'protocol' => $proto, 'simple_client_copy' => $opts, 'prefix' => $prefix), str_replace('.', '_', $prefix . '_' . $method), $msig, $mdesc);
497 echo "<div id=\"phpcode\">\n";
498 highlight_string("<?php\n" . $code['docstring'] . $code['source'] . '?>');
503 // echo 'Error while building php code stub...';
509 echo '<div id="response"><h2>Response:</h2>' . htmlspecialchars($response->serialize()) . '</div>';
512 default: // give a warning
514 } // if !$response->faultCode()
517 // no action taken yet: give some instructions on debugger usage
520 <h3>Instructions on usage of the debugger</h3>
522 <li>Run a 'list available methods' action against desired server</li>
523 <li>If list of methods appears, click on 'describe method' for desired method</li>
524 <li>To run method: click on 'load method synopsis' for desired method. This will load a skeleton for method call
525 parameters in the form above. Complete all xmlrpc values with appropriate data and click 'Execute'
529 if (!extension_loaded('curl')) {
530 echo "<p class=\"evidence\">You will need to enable the CURL extension to use the HTTPS and HTTP 1.1 transports</p>\n";
536 Server Address: phpxmlrpc.sourceforge.net<br/>
541 <p>all usernames and passwords entered on the above form will be written to the web server logs of this server. Use
546 <li>2015-05-30: fix problems with generating method payloads for NIL and Undefined parameters</li>
547 <li>2015-04-19: fix problems with LATIN-1 characters in payload</li>
548 <li>2007-02-20: add visual editor for method payload; allow strings, bools as jsonrpc msg id</li>
549 <li>2006-06-26: support building php code stub for calling remote methods</li>
550 <li>2006-05-25: better support for long running queries; check for no-curl installs</li>
551 <li>2006-05-02: added support for JSON-RPC. Note that many interesting json-rpc features are not implemented
552 yet, such as notifications or multicall.
554 <li>2006-04-22: added option for setting custom CA certs to verify peer with in SSLmode</li>
555 <li>2006-03-05: added option for setting Basic/Digest/NTLM auth type</li>
556 <li>2006-01-18: added option echoing to screen xmlrpc request before sending it ('More' debug)</li>
557 <li>2005-10-01: added option for setting cookies to be sent to server</li>
558 <li>2005-08-07: added switches for compression of requests and responses and http 1.1</li>
559 <li>2005-06-27: fixed possible security breach in parsing malformed xml</li>
560 <li>2005-06-24: fixed error with calling methods having parameters...</li>