3 * @author Gaetano Giunta
4 * @copyright (C) 2005-2020 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" lang="en">
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';
98 // make sure the script waits long enough for the call to complete...
100 set_time_limit($timeout + 10);
104 //@include 'jsonrpc.inc';
105 if (!class_exists('\PhpXmlRpc\JsonRpc\Client')) {
106 die('Error: to debug the jsonrpc protocol the phpxmlrpc/jsonrpc package is needed');
108 $clientClass = '\PhpXmlRpc\JsonRpc\Client';
109 $requestClass = '\PhpXmlRpc\JsonRpc\Request';
110 $protoName = 'JSONRPC';
112 $clientClass = '\PhpXmlRpc\Client';
113 $requestClass = '\PhpXmlRpc\Request';
114 $protoName = 'XMLRPC';
118 $client = new $clientClass($path, $host, $port);
119 $server = "$host:$port$path";
121 $client = new $clientClass($path, $host);
122 $server = "$host$path";
124 if ($protocol == 2) {
125 $server = 'https://' . $server;
127 $server = 'http://' . $server;
130 $pproxy = explode(':', $proxy);
131 if (count($pproxy) > 1) {
136 $client->setProxy($pproxy[0], $pport, $proxyuser, $proxypwd);
139 if ($protocol == 2) {
140 $client->setSSLVerifyPeer($verifypeer);
141 $client->setSSLVerifyHost($verifyhost);
143 $client->setCaCertificate($cainfo);
145 $httpprotocol = 'https';
146 } elseif ($protocol == 1) {
147 $httpprotocol = 'http11';
149 $httpprotocol = 'http';
153 $client->setCredentials($username, $password, $authtype);
156 $client->setDebug($debug);
158 switch ($requestcompression) {
160 $client->request_compression = '';
163 $client->request_compression = 'gzip';
166 $client->request_compression = 'deflate';
170 switch ($responsecompression) {
172 $client->accepted_compression = '';
175 $client->accepted_compression = array('gzip');
178 $client->accepted_compression = array('deflate');
181 $client->accepted_compression = array('gzip', 'deflate');
185 $cookies = explode(',', $clientcookies);
186 foreach ($cookies as $cookie) {
187 if (strpos($cookie, '=')) {
188 $cookie = explode('=', $cookie);
189 $client->setCookie(trim($cookie[0]), trim(@$cookie[1]));
195 // fall thru intentionally
198 $msg[0] = new $requestClass('system.methodHelp', array(), $id);
199 $msg[0]->addparam(new PhpXmlRpc\Value($method));
200 $msg[1] = new $requestClass('system.methodSignature', array(), (int)$id + 1);
201 $msg[1]->addparam(new PhpXmlRpc\Value($method));
202 $actionname = 'Description of method "' . $method . '"';
205 $msg[0] = new $requestClass('system.listMethods', array(), $id);
206 $actionname = 'List of available methods';
209 if (!payload_is_safe($payload)) {
210 die("Tsk tsk tsk, please stop it or I will have to call in the cops!");
212 $msg[0] = new $requestClass($method, array(), $id);
213 // hack! build xml payload by hand
215 $msg[0]->payload = "{\n" .
216 '"method": "' . $method . "\",\n\"params\": [" .
219 // fix: if user gave an empty string, use NULL, or we'll break json syntax
221 $msg[0]->payload .= "null\n}";
223 if (is_numeric($id) || $id == 'false' || $id == 'true' || $id == 'null') {
224 $msg[0]->payload .= "$id\n}";
226 $msg[0]->payload .= "\"$id\"\n}";
230 $msg[0]->payload = $msg[0]->xml_header($inputcharset) .
231 '<methodName>' . $method . "</methodName>\n<params>" .
233 "</params>\n" . $msg[0]->xml_footer();
235 $actionname = 'Execution of method ' . $method;
237 default: // give a warning
238 $actionname = '[ERROR: unknown action] "' . $action . '"';
241 // Before calling execute, echo out brief description of action taken + date and time ???
242 // this gives good user feedback for long-running methods...
243 echo '<h2>' . htmlspecialchars($actionname, ENT_COMPAT, $inputcharset) . ' on server ' . htmlspecialchars($server, ENT_COMPAT, $inputcharset) . " ...</h2>\n";
249 echo '<div class="dbginfo"><h2>Debug info:</h2>';
250 } /// @todo use ob_start instead
252 $time = microtime(true);
253 foreach ($msg as $message) {
254 // catch errors: for older xmlrpc libs, send does not return by ref
255 @$response = $client->send($message, $timeout, $httpprotocol);
257 if (!$response || $response->faultCode()) {
261 $time = microtime(true) - $time;
267 if ($response->faultCode()) {
268 // call failed! echo out error msg!
269 //echo '<h2>'.htmlspecialchars($actionname, ENT_COMPAT, $inputcharset).' on server '.htmlspecialchars($server, ENT_COMPAT, $inputcharset).'</h2>';
270 echo "<h3>$protoName call FAILED!</h3>\n";
271 echo "<p>Fault code: [" . htmlspecialchars($response->faultCode(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
272 "] Reason: '" . htmlspecialchars($response->faultString(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "'</p>\n";
273 echo(strftime("%d/%b/%Y:%H:%M:%S\n"));
275 // call succeeded: parse results
276 //echo '<h2>'.htmlspecialchars($actionname, ENT_COMPAT, $inputcharset).' on server '.htmlspecialchars($server, ENT_COMPAT, $inputcharset).'</h2>';
277 printf("<h3>%s call(s) OK (%.2f secs.)</h3>\n", $protoName, $time);
278 echo(strftime("%d/%b/%Y:%H:%M:%S\n"));
283 $v = $response->value();
284 if ($v->kindOf() == "array") {
286 echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
287 echo "<thead>\n<tr><th>Method ($max)</th><th>Description</th></tr>\n</thead>\n<tbody>\n";
288 foreach($v as $i => $rec) {
290 $class = ' class="oddrow"';
292 $class = ' class="evenrow"';
294 echo("<tr><td$class>" . htmlspecialchars($rec->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "</td><td$class><form action=\"controller.php\" method=\"get\" target=\"frmcontroller\">" .
295 "<input type=\"hidden\" name=\"host\" value=\"" . htmlspecialchars($host, ENT_COMPAT, $inputcharset) . "\" />" .
296 "<input type=\"hidden\" name=\"port\" value=\"" . htmlspecialchars($port, ENT_COMPAT, $inputcharset) . "\" />" .
297 "<input type=\"hidden\" name=\"path\" value=\"" . htmlspecialchars($path, ENT_COMPAT, $inputcharset) . "\" />" .
298 "<input type=\"hidden\" name=\"id\" value=\"" . htmlspecialchars($id, ENT_COMPAT, $inputcharset) . "\" />" .
299 "<input type=\"hidden\" name=\"debug\" value=\"$debug\" />" .
300 "<input type=\"hidden\" name=\"username\" value=\"" . htmlspecialchars($username, ENT_COMPAT, $inputcharset) . "\" />" .
301 "<input type=\"hidden\" name=\"password\" value=\"" . htmlspecialchars($password, ENT_COMPAT, $inputcharset) . "\" />" .
302 "<input type=\"hidden\" name=\"authtype\" value=\"$authtype\" />" .
303 "<input type=\"hidden\" name=\"verifyhost\" value=\"$verifyhost\" />" .
304 "<input type=\"hidden\" name=\"verifypeer\" value=\"$verifypeer\" />" .
305 "<input type=\"hidden\" name=\"cainfo\" value=\"" . htmlspecialchars($cainfo, ENT_COMPAT, $inputcharset) . "\" />" .
306 "<input type=\"hidden\" name=\"proxy\" value=\"" . htmlspecialchars($proxy, ENT_COMPAT, $inputcharset) . "\" />" .
307 "<input type=\"hidden\" name=\"proxyuser\" value=\"" . htmlspecialchars($proxyuser, ENT_COMPAT, $inputcharset) . "\" />" .
308 "<input type=\"hidden\" name=\"proxypwd\" value=\"" . htmlspecialchars($proxypwd, ENT_COMPAT, $inputcharset) . "\" />" .
309 "<input type=\"hidden\" name=\"responsecompression\" value=\"$responsecompression\" />" .
310 "<input type=\"hidden\" name=\"requestcompression\" value=\"$requestcompression\" />" .
311 "<input type=\"hidden\" name=\"clientcookies\" value=\"" . htmlspecialchars($clientcookies, ENT_COMPAT, $inputcharset) . "\" />" .
312 "<input type=\"hidden\" name=\"protocol\" value=\"$protocol\" />" .
313 "<input type=\"hidden\" name=\"timeout\" value=\"" . htmlspecialchars($timeout, ENT_COMPAT, $inputcharset) . "\" />" .
314 "<input type=\"hidden\" name=\"method\" value=\"" . htmlspecialchars($rec->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "\" />" .
315 "<input type=\"hidden\" name=\"wstype\" value=\"$wstype\" />" .
316 "<input type=\"hidden\" name=\"action\" value=\"describe\" />" .
317 "<input type=\"hidden\" name=\"run\" value=\"now\" />" .
318 "<input type=\"submit\" value=\"Describe\" /></form></td>");
321 // generate the skeleton for method payload per possible tests
322 //$methodpayload="<methodCall>\n<methodName>".$rec->scalarval()."</methodName>\n<params>\n<param><value></value></param>\n</params>\n</methodCall>";
324 /*echo ("<form action=\"{$_SERVER['PHP_SELF']}\" method=\"get\"><td>".
325 "<input type=\"hidden\" name=\"host\" value=\"$host\" />".
326 "<input type=\"hidden\" name=\"port\" value=\"$port\" />".
327 "<input type=\"hidden\" name=\"path\" value=\"$path\" />".
328 "<input type=\"hidden\" name=\"method\" value=\"".$rec->scalarval()."\" />".
329 "<input type=\"hidden\" name=\"methodpayload\" value=\"$payload\" />".
330 "<input type=\"hidden\" name=\"action\" value=\"execute\" />".
331 "<input type=\"submit\" value=\"Test\" /></td></form>");*/
334 echo "</tbody>\n</table>";
340 $r1 = $resp[0]->value();
341 $r2 = $resp[1]->value();
343 echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
344 echo "<thead>\n<tr><th>Method</th><th>" . htmlspecialchars($method, ENT_COMPAT, $inputcharset) . "</th><th> </th><th> </th></tr>\n</thead>\n<tbody>\n";
345 $desc = htmlspecialchars($r1->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding);
349 echo "<tr><td class=\"evenrow\">Description</td><td colspan=\"3\" class=\"evenrow\">$desc</td></tr>\n";
351 if ($r2->kindOf() != "array") {
352 echo "<tr><td class=\"oddrow\">Signature</td><td class=\"oddrow\">Unknown</td><td class=\"oddrow\"> </td></tr>\n";
354 foreach($r2 as $i => $x) {
358 $class = ' class="oddrow"';
360 $class = ' class="evenrow"';
362 echo "<tr><td$class>Signature " . ($i + 1) . "</td><td$class>";
363 if ($x->kindOf() == "array") {
365 echo "<code>OUT: " . htmlspecialchars($ret->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "<br />IN: (";
366 if ($x->count() > 1) {
367 foreach($x as $k => $y) {
368 if ($k == 0) continue;
369 echo htmlspecialchars($y->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding);
371 $type = $y->scalarval();
372 $payload .= '<param><value>';
378 // fall thru intentionally
381 htmlspecialchars($type, ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
382 '></' . htmlspecialchars($type, ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
385 $payload .= "</value></param>\n";
387 $alt_payload .= $y->scalarval();
388 if ($k < $x->count() - 1) {
399 // button to test this method
400 //$payload="<methodCall>\n<methodName>$method</methodName>\n<params>\n$payload</params>\n</methodCall>";
401 echo "<td$class><form action=\"controller.php\" target=\"frmcontroller\" method=\"get\">" .
402 "<input type=\"hidden\" name=\"host\" value=\"" . htmlspecialchars($host, ENT_COMPAT, $inputcharset) . "\" />" .
403 "<input type=\"hidden\" name=\"port\" value=\"" . htmlspecialchars($port, ENT_COMPAT, $inputcharset) . "\" />" .
404 "<input type=\"hidden\" name=\"path\" value=\"" . htmlspecialchars($path, ENT_COMPAT, $inputcharset) . "\" />" .
405 "<input type=\"hidden\" name=\"id\" value=\"" . htmlspecialchars($id, ENT_COMPAT, $inputcharset) . "\" />" .
406 "<input type=\"hidden\" name=\"debug\" value=\"$debug\" />" .
407 "<input type=\"hidden\" name=\"username\" value=\"" . htmlspecialchars($username, ENT_COMPAT, $inputcharset) . "\" />" .
408 "<input type=\"hidden\" name=\"password\" value=\"" . htmlspecialchars($password, ENT_COMPAT, $inputcharset) . "\" />" .
409 "<input type=\"hidden\" name=\"authtype\" value=\"$authtype\" />" .
410 "<input type=\"hidden\" name=\"verifyhost\" value=\"$verifyhost\" />" .
411 "<input type=\"hidden\" name=\"verifypeer\" value=\"$verifypeer\" />" .
412 "<input type=\"hidden\" name=\"cainfo\" value=\"" . htmlspecialchars($cainfo, ENT_COMPAT, $inputcharset) . "\" />" .
413 "<input type=\"hidden\" name=\"proxy\" value=\"" . htmlspecialchars($proxy, ENT_COMPAT, $inputcharset) . "\" />" .
414 "<input type=\"hidden\" name=\"proxyuser\" value=\"" . htmlspecialchars($proxyuser, ENT_COMPAT, $inputcharset) . "\" />" .
415 "<input type=\"hidden\" name=\"proxypwd\" value=\"" . htmlspecialchars($proxypwd, ENT_COMPAT, $inputcharset) . "\" />" .
416 "<input type=\"hidden\" name=\"responsecompression\" value=\"$responsecompression\" />" .
417 "<input type=\"hidden\" name=\"requestcompression\" value=\"$requestcompression\" />" .
418 "<input type=\"hidden\" name=\"clientcookies\" value=\"" . htmlspecialchars($clientcookies, ENT_COMPAT, $inputcharset) . "\" />" .
419 "<input type=\"hidden\" name=\"protocol\" value=\"$protocol\" />" .
420 "<input type=\"hidden\" name=\"timeout\" value=\"" . htmlspecialchars($timeout, ENT_COMPAT, $inputcharset) . "\" />" .
421 "<input type=\"hidden\" name=\"method\" value=\"" . htmlspecialchars($method, ENT_COMPAT, $inputcharset) . "\" />" .
422 "<input type=\"hidden\" name=\"methodpayload\" value=\"" . htmlspecialchars($payload, ENT_COMPAT, $inputcharset) . "\" />" .
423 "<input type=\"hidden\" name=\"altmethodpayload\" value=\"" . htmlspecialchars($alt_payload, ENT_COMPAT, $inputcharset) . "\" />" .
424 "<input type=\"hidden\" name=\"wstype\" value=\"$wstype\" />" .
425 "<input type=\"hidden\" name=\"action\" value=\"execute\" />";
427 echo "<input type=\"submit\" value=\"Load method synopsis\" />";
429 echo "</form></td>\n";
431 echo "<td$class><form action=\"controller.php\" target=\"frmcontroller\" method=\"get\">" .
432 "<input type=\"hidden\" name=\"host\" value=\"" . htmlspecialchars($host, ENT_COMPAT, $inputcharset) . "\" />" .
433 "<input type=\"hidden\" name=\"port\" value=\"" . htmlspecialchars($port, ENT_COMPAT, $inputcharset) . "\" />" .
434 "<input type=\"hidden\" name=\"path\" value=\"" . htmlspecialchars($path, ENT_COMPAT, $inputcharset) . "\" />" .
435 "<input type=\"hidden\" name=\"id\" value=\"" . htmlspecialchars($id, ENT_COMPAT, $inputcharset) . "\" />" .
436 "<input type=\"hidden\" name=\"debug\" value=\"$debug\" />" .
437 "<input type=\"hidden\" name=\"username\" value=\"" . htmlspecialchars($username, ENT_COMPAT, $inputcharset) . "\" />" .
438 "<input type=\"hidden\" name=\"password\" value=\"" . htmlspecialchars($password, ENT_COMPAT, $inputcharset) . "\" />" .
439 "<input type=\"hidden\" name=\"authtype\" value=\"$authtype\" />" .
440 "<input type=\"hidden\" name=\"verifyhost\" value=\"$verifyhost\" />" .
441 "<input type=\"hidden\" name=\"verifypeer\" value=\"$verifypeer\" />" .
442 "<input type=\"hidden\" name=\"cainfo\" value=\"" . htmlspecialchars($cainfo, ENT_COMPAT, $inputcharset) . "\" />" .
443 "<input type=\"hidden\" name=\"proxy\" value=\"" . htmlspecialchars($proxy, ENT_COMPAT, $inputcharset) . "\" />" .
444 "<input type=\"hidden\" name=\"proxyuser\" value=\"" . htmlspecialchars($proxyuser, ENT_COMPAT, $inputcharset) . "\" />" .
445 "<input type=\"hidden\" name=\"proxypwd\" value=\"" . htmlspecialchars($proxypwd, ENT_COMPAT, $inputcharset) . "\" />" .
446 "<input type=\"hidden\" name=\"responsecompression\" value=\"$responsecompression\" />" .
447 "<input type=\"hidden\" name=\"requestcompression\" value=\"$requestcompression\" />" .
448 "<input type=\"hidden\" name=\"clientcookies\" value=\"" . htmlspecialchars($clientcookies, ENT_COMPAT, $inputcharset) . "\" />" .
449 "<input type=\"hidden\" name=\"protocol\" value=\"$protocol\" />" .
450 "<input type=\"hidden\" name=\"timeout\" value=\"" . htmlspecialchars($timeout, ENT_COMPAT, $inputcharset) . "\" />" .
451 "<input type=\"hidden\" name=\"method\" value=\"" . htmlspecialchars($method, ENT_COMPAT, $inputcharset) . "\" />" .
452 "<input type=\"hidden\" name=\"methodsig\" value=\"" . $i . "\" />" .
453 "<input type=\"hidden\" name=\"methodpayload\" value=\"" . htmlspecialchars($payload, ENT_COMPAT, $inputcharset) . "\" />" .
454 "<input type=\"hidden\" name=\"altmethodpayload\" value=\"" . htmlspecialchars($alt_payload, ENT_COMPAT, $inputcharset) . "\" />" .
455 "<input type=\"hidden\" name=\"wstype\" value=\"$wstype\" />" .
456 "<input type=\"hidden\" name=\"run\" value=\"now\" />" .
457 "<input type=\"hidden\" name=\"action\" value=\"wrap\" />" .
458 "<input type=\"submit\" value=\"Generate method call stub code\" />";
459 echo "</form></td></tr>\n";
462 echo "</tbody>\n</table>";
467 $r1 = $resp[0]->value();
468 $r2 = $resp[1]->value();
469 if ($r2->kindOf() != "array" || $r2->count() <= $methodsig) {
470 echo "Error: signature unknown\n";
472 $mdesc = $r1->scalarval();
473 $encoder = new PhpXmlRpc\Encoder();
474 $msig = $encoder->decode($r2);
475 $msig = $msig[$methodsig];
476 $proto = $protocol == 2 ? 'https' : ( $protocol == 1 ? 'http11' : '' );
477 if ($proxy == '' && $username == '' && !$requestcompression && !$responsecompression &&
480 $opts = 1; // simple client copy in stub code
482 $opts = 0; // complete client copy in stub code
489 $wrapper = new PhpXmlRpc\Wrapper();
490 $code = $wrapper->buildWrapMethodSource($client, $method, array('timeout' => $timeout, 'protocol' => $proto, 'simple_client_copy' => $opts, 'prefix' => $prefix), str_replace('.', '_', $prefix . '_' . $method), $msig, $mdesc);
493 echo "<div id=\"phpcode\">\n";
494 highlight_string("<?php\n" . $code['docstring'] . $code['source'] . '?>');
499 // echo 'Error while building php code stub...';
505 echo '<div id="response"><h2>Response:</h2>' . htmlspecialchars($response->serialize()) . '</div>';
508 default: // give a warning
510 } // if !$response->faultCode()
513 // no action taken yet: give some instructions on debugger usage
516 <h3>Instructions on usage of the debugger</h3>
518 <li>Run a 'list available methods' action against desired server</li>
519 <li>If list of methods appears, click on 'describe method' for desired method</li>
520 <li>To run method: click on 'load method synopsis' for desired method. This will load a skeleton for method call
521 parameters in the form above. Complete all xmlrpc values with appropriate data and click 'Execute'
525 if (!extension_loaded('curl')) {
526 echo "<p class=\"evidence\">You will need to enable the CURL extension to use the HTTPS and HTTP 1.1 transports</p>\n";
532 Server Address: phpxmlrpc.sourceforge.net<br/>
537 <p>all usernames and passwords entered on the above form will be written to the web server logs of this server. Use
542 <li>2020-12-11: fix problems with running the debugger on php 8</li>
543 <li>2015-05-30: fix problems with generating method payloads for NIL and Undefined parameters</li>
544 <li>2015-04-19: fix problems with LATIN-1 characters in payload</li>
545 <li>2007-02-20: add visual editor for method payload; allow strings, bools as jsonrpc msg id</li>
546 <li>2006-06-26: support building php code stub for calling remote methods</li>
547 <li>2006-05-25: better support for long running queries; check for no-curl installs</li>
548 <li>2006-05-02: added support for JSON-RPC. Note that many interesting json-rpc features are not implemented
549 yet, such as notifications or multicall.
551 <li>2006-04-22: added option for setting custom CA certs to verify peer with in SSLmode</li>
552 <li>2006-03-05: added option for setting Basic/Digest/NTLM auth type</li>
553 <li>2006-01-18: added option echoing to screen xmlrpc request before sending it ('More' debug)</li>
554 <li>2005-10-01: added option for setting cookies to be sent to server</li>
555 <li>2005-08-07: added switches for compression of requests and responses and http 1.1</li>
556 <li>2005-06-27: fixed possible security breach in parsing malformed xml</li>
557 <li>2005-06-24: fixed error with calling methods having parameters...</li>