Make the debugger tolerate latin-1 characters in all fields, not just method payload
[plcapi.git] / debugger / action.php
1 <?php
2 /**
3  * @author Gaetano Giunta
4  * @copyright (C) 2005-2015 G. Giunta
5  * @license code licensed under the BSD License: see file license.txt
6  *
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
10  **/
11 ?>
12 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
13     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
14 <html xmlns="http://www.w3.org/1999/xhtml">
15 <head>
16     <title>XMLRPC Debugger</title>
17     <meta name="robots" content="index,nofollow"/>
18     <style type="text/css">
19         <!--
20         body {
21             border-top: 1px solid gray;
22             padding: 1em;
23             font-family: Verdana, Arial, Helvetica;
24             font-size: 8pt;
25         }
26
27         h3 {
28             font-size: 9.5pt;
29         }
30
31         h2 {
32             font-size: 12pt;
33         }
34
35         .dbginfo {
36             padding: 1em;
37             background-color: #EEEEEE;
38             border: 1px dashed silver;
39             font-family: monospace;
40         }
41
42         #response {
43             padding: 1em;
44             margin-top: 1em;
45             background-color: #DDDDDD;
46             border: 1px solid gray;
47             white-space: pre;
48             font-family: monospace;
49         }
50
51         table {
52             padding: 2px;
53             margin-top: 1em;
54         }
55
56         th {
57             background-color: navy;
58             color: white;
59             padding: 0.5em;
60         }
61
62         td {
63             padding: 0.5em;
64             font-family: monospace;
65         }
66
67         td form {
68             margin: 0;
69         }
70
71         .oddrow {
72             background-color: #EEEEEE;
73         }
74
75         .evidence {
76             color: blue;
77         }
78
79         #phpcode {
80             background-color: #EEEEEE;
81             padding: 1em;
82             margin-top: 1em;
83         }
84
85         -->
86     </style>
87 </head>
88 <body>
89 <?php
90
91 include __DIR__ . '/common.php';
92 if ($action) {
93
94     include_once __DIR__ . "/../src/Autoloader.php";
95     PhpXmlRpc\Autoloader::register();
96
97     // make sure the script waits long enough for the call to complete...
98     if ($timeout) {
99         set_time_limit($timeout + 10);
100     }
101
102     if ($wstype == 1) {
103         @include 'jsonrpc.inc';
104         if (!class_exists('jsonrpc_client')) {
105             die('Error: to debug the jsonrpc protocol the jsonrpc.inc file is needed');
106         }
107         $clientClass = 'PhpJsRpc\Client';
108         $requestClass = 'PhpJsRpc\Request';
109         $protoName = 'JSONRPC';
110     } else {
111         $clientClass = 'PhpXmlRpc\Client';
112         $requestClass = 'PhpXmlRpc\Request';
113         $protoName = 'XMLRPC';
114     }
115
116     if ($port != "") {
117         $client = new $clientClass($path, $host, $port);
118         $server = "$host:$port$path";
119     } else {
120         $client = new $clientClass($path, $host);
121         $server = "$host$path";
122     }
123     if ($protocol == 2) {
124         $server = 'https://' . $server;
125     } else {
126         $server = 'http://' . $server;
127     }
128     if ($proxy != '') {
129         $pproxy = explode(':', $proxy);
130         if (count($pproxy) > 1) {
131             $pport = $pproxy[1];
132         } else {
133             $pport = 8080;
134         }
135         $client->setProxy($pproxy[0], $pport, $proxyuser, $proxypwd);
136     }
137
138     if ($protocol == 2) {
139         $client->setSSLVerifyPeer($verifypeer);
140         $client->setSSLVerifyHost($verifyhost);
141         if ($cainfo) {
142             $client->setCaCertificate($cainfo);
143         }
144         $httpprotocol = 'https';
145     } elseif ($protocol == 1) {
146         $httpprotocol = 'http11';
147     } else {
148         $httpprotocol = 'http';
149     }
150
151     if ($username) {
152         $client->setCredentials($username, $password, $authtype);
153     }
154
155     $client->setDebug($debug);
156
157     switch ($requestcompression) {
158         case 0:
159             $client->request_compression = '';
160             break;
161         case 1:
162             $client->request_compression = 'gzip';
163             break;
164         case 2:
165             $client->request_compression = 'deflate';
166             break;
167     }
168
169     switch ($responsecompression) {
170         case 0:
171             $client->accepted_compression = '';
172             break;
173         case 1:
174             $client->accepted_compression = array('gzip');
175             break;
176         case 2:
177             $client->accepted_compression = array('deflate');
178             break;
179         case 3:
180             $client->accepted_compression = array('gzip', 'deflate');
181             break;
182     }
183
184     $cookies = explode(',', $clientcookies);
185     foreach ($cookies as $cookie) {
186         if (strpos($cookie, '=')) {
187             $cookie = explode('=', $cookie);
188             $client->setCookie(trim($cookie[0]), trim(@$cookie[1]));
189         }
190     }
191
192     $msg = array();
193     switch ($action) {
194         // fall thru intentionally
195         case 'describe':
196         case 'wrap':
197             $msg[0] = new $requestClass('system.methodHelp', array(), $id);
198             $msg[0]->addparam(new PhpXmlRpc\Value($method));
199             $msg[1] = new $requestClass('system.methodSignature', array(), $id + 1);
200             $msg[1]->addparam(new PhpXmlRpc\Value($method));
201             $actionname = 'Description of method "' . $method . '"';
202             break;
203         case 'list':
204             $msg[0] = new $requestClass('system.listMethods', array(), $id);
205             $actionname = 'List of available methods';
206             break;
207         case 'execute':
208             if (!payload_is_safe($payload)) {
209                 die("Tsk tsk tsk, please stop it or I will have to call in the cops!");
210             }
211             $msg[0] = new $requestClass($method, array(), $id);
212             // hack! build xml payload by hand
213             if ($wstype == 1) {
214                 $msg[0]->payload = "{\n" .
215                     '"method": "' . $method . "\",\n\"params\": [" .
216                     $payload .
217                     "\n],\n\"id\": ";
218                 // fix: if user gave an empty string, use NULL, or we'll break json syntax
219                 if ($id == "") {
220                     $msg[0]->payload .= "null\n}";
221                 } else {
222                     if (is_numeric($id) || $id == 'false' || $id == 'true' || $id == 'null') {
223                         $msg[0]->payload .= "$id\n}";
224                     } else {
225                         $msg[0]->payload .= "\"$id\"\n}";
226                     }
227                 }
228             } else {
229                 $msg[0]->payload = $msg[0]->xml_header($inputcharset) .
230                     '<methodName>' . $method . "</methodName>\n<params>" .
231                     $payload .
232                     "</params>\n" . $msg[0]->xml_footer();
233             }
234             $actionname = 'Execution of method ' . $method;
235             break;
236         default: // give a warning
237             $actionname = '[ERROR: unknown action] "' . $action . '"';
238     }
239
240     // Before calling execute, echo out brief description of action taken + date and time ???
241     // this gives good user feedback for long-running methods...
242     echo '<h2>' . htmlspecialchars($actionname, ENT_COMPAT, $inputcharset) . ' on server ' . htmlspecialchars($server, ENT_COMPAT, $inputcharset) . " ...</h2>\n";
243     flush();
244
245     $response = null;
246     // execute method(s)
247     if ($debug) {
248         echo '<div class="dbginfo"><h2>Debug info:</h2>';
249     }  /// @todo use ob_start instead
250     $resp = array();
251     $time = microtime(true);
252     foreach ($msg as $message) {
253         // catch errors: for older xmlrpc libs, send does not return by ref
254         @$response = $client->send($message, $timeout, $httpprotocol);
255         $resp[] = $response;
256         if (!$response || $response->faultCode()) {
257             break;
258         }
259     }
260     $time = microtime(true) - $time;
261     if ($debug) {
262         echo "</div>\n";
263     }
264
265     if ($response) {
266         if ($response->faultCode()) {
267             // call failed! echo out error msg!
268             //echo '<h2>'.htmlspecialchars($actionname, ENT_COMPAT, $inputcharset).' on server '.htmlspecialchars($server, ENT_COMPAT, $inputcharset).'</h2>';
269             echo "<h3>$protoName call FAILED!</h3>\n";
270             echo "<p>Fault code: [" . htmlspecialchars($response->faultCode(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
271                 "] Reason: '" . htmlspecialchars($response->faultString(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "'</p>\n";
272             echo(strftime("%d/%b/%Y:%H:%M:%S\n"));
273         } else {
274             // call succeeded: parse results
275             //echo '<h2>'.htmlspecialchars($actionname, ENT_COMPAT, $inputcharset).' on server '.htmlspecialchars($server, ENT_COMPAT, $inputcharset).'</h2>';
276             printf("<h3>%s call(s) OK (%.2f secs.)</h3>\n", $protoName, $time);
277             echo(strftime("%d/%b/%Y:%H:%M:%S\n"));
278
279             switch ($action) {
280                 case 'list':
281
282                     $v = $response->value();
283                     if ($v->kindOf() == "array") {
284                         $max = $v->arraysize();
285                         echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
286                         echo "<thead>\n<tr><th>Method</th><th>Description</th></tr>\n</thead>\n<tbody>\n";
287                         for ($i = 0; $i < $max; $i++) {
288                             $rec = $v->arraymem($i);
289                             if ($i % 2) {
290                                 $class = ' class="oddrow"';
291                             } else {
292                                 $class = ' class="evenrow"';
293                             }
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>");
319                             //echo("</tr>\n");
320
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>";
323
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>");*/
332                             echo("</tr>\n");
333                         }
334                         echo "</tbody>\n</table>";
335                     }
336                     break;
337
338                 case 'describe':
339
340                     $r1 = $resp[0]->value();
341                     $r2 = $resp[1]->value();
342
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>&nbsp;</th><th>&nbsp;</th></tr>\n</thead>\n<tbody>\n";
345                     $desc = htmlspecialchars($r1->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding);
346                     if ($desc == "") {
347                         $desc = "-";
348                     }
349                     echo "<tr><td class=\"evenrow\">Description</td><td colspan=\"3\" class=\"evenrow\">$desc</td></tr>\n";
350                     $payload = "";
351                     $alt_payload = "";
352                     if ($r2->kindOf() != "array") {
353                         echo "<tr><td class=\"oddrow\">Signature</td><td class=\"oddrow\">Unknown</td><td class=\"oddrow\">&nbsp;</td></tr>\n";
354                     } else {
355                         for ($i = 0; $i < $r2->arraysize(); $i++) {
356                             if ($i + 1 % 2) {
357                                 $class = ' class="oddrow"';
358                             } else {
359                                 $class = ' class="evenrow"';
360                             }
361                             echo "<tr><td$class>Signature&nbsp;" . ($i + 1) . "</td><td$class>";
362                             $x = $r2->arraymem($i);
363                             if ($x->kindOf() == "array") {
364                                 $ret = $x->arraymem(0);
365                                 echo "<code>OUT:&nbsp;" . htmlspecialchars($ret->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "<br />IN: (";
366                                 if ($x->arraysize() > 1) {
367                                     for ($k = 1; $k < $x->arraysize(); $k++) {
368                                         $y = $x->arraymem($k);
369                                         echo htmlspecialchars($y->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding);
370                                         if ($wstype != 1) {
371                                             $payload = $payload . '<param><value><' .
372                                                 htmlspecialchars($y->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
373                                                 '></' . htmlspecialchars($y->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
374                                                 "></value></param>\n";
375                                         }
376                                         $alt_payload .= $y->scalarval();
377                                         if ($k < $x->arraysize() - 1) {
378                                             $alt_payload .= ';';
379                                             echo ", ";
380                                         }
381                                     }
382                                 }
383                                 echo ")</code>";
384                             } else {
385                                 echo 'Unknown';
386                             }
387                             echo '</td>';
388                             // button to test this method
389                             //$payload="<methodCall>\n<methodName>$method</methodName>\n<params>\n$payload</params>\n</methodCall>";
390                             echo "<td$class><form action=\"controller.php\" target=\"frmcontroller\" method=\"get\">" .
391                                 "<input type=\"hidden\" name=\"host\" value=\"" . htmlspecialchars($host, ENT_COMPAT, $inputcharset) . "\" />" .
392                                 "<input type=\"hidden\" name=\"port\" value=\"" . htmlspecialchars($port, ENT_COMPAT, $inputcharset) . "\" />" .
393                                 "<input type=\"hidden\" name=\"path\" value=\"" . htmlspecialchars($path, ENT_COMPAT, $inputcharset) . "\" />" .
394                                 "<input type=\"hidden\" name=\"id\" value=\"" . htmlspecialchars($id, ENT_COMPAT, $inputcharset) . "\" />" .
395                                 "<input type=\"hidden\" name=\"debug\" value=\"$debug\" />" .
396                                 "<input type=\"hidden\" name=\"username\" value=\"" . htmlspecialchars($username, ENT_COMPAT, $inputcharset) . "\" />" .
397                                 "<input type=\"hidden\" name=\"password\" value=\"" . htmlspecialchars($password, ENT_COMPAT, $inputcharset) . "\" />" .
398                                 "<input type=\"hidden\" name=\"authtype\" value=\"$authtype\" />" .
399                                 "<input type=\"hidden\" name=\"verifyhost\" value=\"$verifyhost\" />" .
400                                 "<input type=\"hidden\" name=\"verifypeer\" value=\"$verifypeer\" />" .
401                                 "<input type=\"hidden\" name=\"cainfo\" value=\"" . htmlspecialchars($cainfo, ENT_COMPAT, $inputcharset) . "\" />" .
402                                 "<input type=\"hidden\" name=\"proxy\" value=\"" . htmlspecialchars($proxy, ENT_COMPAT, $inputcharset) . "\" />" .
403                                 "<input type=\"hidden\" name=\"proxyuser\" value=\"" . htmlspecialchars($proxyuser, ENT_COMPAT, $inputcharset) . "\" />" .
404                                 "<input type=\"hidden\" name=\"proxypwd\" value=\"" . htmlspecialchars($proxypwd, ENT_COMPAT, $inputcharset) . "\" />" .
405                                 "<input type=\"hidden\" name=\"responsecompression\" value=\"$responsecompression\" />" .
406                                 "<input type=\"hidden\" name=\"requestcompression\" value=\"$requestcompression\" />" .
407                                 "<input type=\"hidden\" name=\"clientcookies\" value=\"" . htmlspecialchars($clientcookies, ENT_COMPAT, $inputcharset) . "\" />" .
408                                 "<input type=\"hidden\" name=\"protocol\" value=\"$protocol\" />" .
409                                 "<input type=\"hidden\" name=\"timeout\" value=\"" . htmlspecialchars($timeout, ENT_COMPAT, $inputcharset) . "\" />" .
410                                 "<input type=\"hidden\" name=\"method\" value=\"" . htmlspecialchars($method, ENT_COMPAT, $inputcharset) . "\" />" .
411                                 "<input type=\"hidden\" name=\"methodpayload\" value=\"" . htmlspecialchars($payload, ENT_COMPAT, $inputcharset) . "\" />" .
412                                 "<input type=\"hidden\" name=\"altmethodpayload\" value=\"" . htmlspecialchars($alt_payload, ENT_COMPAT, $inputcharset) . "\" />" .
413                                 "<input type=\"hidden\" name=\"wstype\" value=\"$wstype\" />" .
414                                 "<input type=\"hidden\" name=\"action\" value=\"execute\" />";
415                             if ($wstype != 1) {
416                                 echo "<input type=\"submit\" value=\"Load method synopsis\" />";
417                             }
418                             echo "</form></td>\n";
419
420                             echo "<td$class><form action=\"controller.php\" target=\"frmcontroller\" method=\"get\">" .
421                                 "<input type=\"hidden\" name=\"host\" value=\"" . htmlspecialchars($host, ENT_COMPAT, $inputcharset) . "\" />" .
422                                 "<input type=\"hidden\" name=\"port\" value=\"" . htmlspecialchars($port, ENT_COMPAT, $inputcharset) . "\" />" .
423                                 "<input type=\"hidden\" name=\"path\" value=\"" . htmlspecialchars($path, ENT_COMPAT, $inputcharset) . "\" />" .
424                                 "<input type=\"hidden\" name=\"id\" value=\"" . htmlspecialchars($id, ENT_COMPAT, $inputcharset) . "\" />" .
425                                 "<input type=\"hidden\" name=\"debug\" value=\"$debug\" />" .
426                                 "<input type=\"hidden\" name=\"username\" value=\"" . htmlspecialchars($username, ENT_COMPAT, $inputcharset) . "\" />" .
427                                 "<input type=\"hidden\" name=\"password\" value=\"" . htmlspecialchars($password, ENT_COMPAT, $inputcharset) . "\" />" .
428                                 "<input type=\"hidden\" name=\"authtype\" value=\"$authtype\" />" .
429                                 "<input type=\"hidden\" name=\"verifyhost\" value=\"$verifyhost\" />" .
430                                 "<input type=\"hidden\" name=\"verifypeer\" value=\"$verifypeer\" />" .
431                                 "<input type=\"hidden\" name=\"cainfo\" value=\"" . htmlspecialchars($cainfo, ENT_COMPAT, $inputcharset) . "\" />" .
432                                 "<input type=\"hidden\" name=\"proxy\" value=\"" . htmlspecialchars($proxy, ENT_COMPAT, $inputcharset) . "\" />" .
433                                 "<input type=\"hidden\" name=\"proxyuser\" value=\"" . htmlspecialchars($proxyuser, ENT_COMPAT, $inputcharset) . "\" />" .
434                                 "<input type=\"hidden\" name=\"proxypwd\" value=\"" . htmlspecialchars($proxypwd, ENT_COMPAT, $inputcharset) . "\" />" .
435                                 "<input type=\"hidden\" name=\"responsecompression\" value=\"$responsecompression\" />" .
436                                 "<input type=\"hidden\" name=\"requestcompression\" value=\"$requestcompression\" />" .
437                                 "<input type=\"hidden\" name=\"clientcookies\" value=\"" . htmlspecialchars($clientcookies, ENT_COMPAT, $inputcharset) . "\" />" .
438                                 "<input type=\"hidden\" name=\"protocol\" value=\"$protocol\" />" .
439                                 "<input type=\"hidden\" name=\"timeout\" value=\"" . htmlspecialchars($timeout, ENT_COMPAT, $inputcharset) . "\" />" .
440                                 "<input type=\"hidden\" name=\"method\" value=\"" . htmlspecialchars($method, ENT_COMPAT, $inputcharset) . "\" />" .
441                                 "<input type=\"hidden\" name=\"methodsig\" value=\"" . $i . "\" />" .
442                                 "<input type=\"hidden\" name=\"methodpayload\" value=\"" . htmlspecialchars($payload, ENT_COMPAT, $inputcharset) . "\" />" .
443                                 "<input type=\"hidden\" name=\"altmethodpayload\" value=\"" . htmlspecialchars($alt_payload, ENT_COMPAT, $inputcharset) . "\" />" .
444                                 "<input type=\"hidden\" name=\"wstype\" value=\"$wstype\" />" .
445                                 "<input type=\"hidden\" name=\"run\" value=\"now\" />" .
446                                 "<input type=\"hidden\" name=\"action\" value=\"wrap\" />" .
447                                 "<input type=\"submit\" value=\"Generate method call stub code\" />";
448                             echo "</form></td></tr>\n";
449                         }
450                     }
451                     echo "</tbody>\n</table>";
452
453                     break;
454
455                 case 'wrap':
456                     $r1 = $resp[0]->value();
457                     $r2 = $resp[1]->value();
458                     if ($r2->kindOf() != "array" || $r2->arraysize() <= $methodsig) {
459                         echo "Error: signature unknown\n";
460                     } else {
461                         $mdesc = $r1->scalarval();
462                         $encoder = new PhpXmlRpc\Encoder();
463                         $msig = $encoder->decode($r2);
464                         $msig = $msig[$methodsig];
465                         $proto = $protocol == 2 ? 'https' : $protocol == 1 ? 'http11' : '';
466                         if ($proxy == '' && $username == '' && !$requestcompression && !$responsecompression &&
467                             $clientcookies == ''
468                         ) {
469                             $opts = 0; // simple client copy in stub code
470                         } else {
471                             $opts = 1; // complete client copy in stub code
472                         }
473                         if ($wstype == 1) {
474                             $prefix = 'jsonrpc';
475                         } else {
476                             $prefix = 'xmlrpc';
477                         }
478                         //$code = wrap_xmlrpc_method($client, $method, $methodsig, 0, $proto, '', $opts);
479                         $wrapper = new PhpXmlRpc\Wrapper();
480                         $code = $wrapper->build_remote_method_wrapper_code($client, $method, str_replace('.', '_', $prefix . '_' . $method), $msig, $mdesc, $timeout, $proto, $opts, $prefix);
481                         //if ($code)
482                         //{
483                         echo "<div id=\"phpcode\">\n";
484                         highlight_string("<?php\n" . $code['docstring'] . $code['source'] . '?>');
485                         echo "\n</div>";
486                         //}
487                         //else
488                         //{
489                         //  echo 'Error while building php code stub...';
490                     }
491
492                     break;
493
494                 case 'execute':
495                     echo '<div id="response"><h2>Response:</h2>' . htmlspecialchars($response->serialize()) . '</div>';
496                     break;
497
498                 default: // give a warning
499             }
500         } // if !$response->faultCode()
501     } // if $response
502 } else {
503     // no action taken yet: give some instructions on debugger usage
504     ?>
505
506     <h3>Instructions on usage of the debugger</h3>
507     <ol>
508         <li>Run a 'list available methods' action against desired server</li>
509         <li>If list of methods appears, click on 'describe method' for desired method</li>
510         <li>To run method: click on 'load method synopsis' for desired method. This will load a skeleton for method call
511             parameters in the form above. Complete all xmlrpc values with appropriate data and click 'Execute'
512         </li>
513     </ol>
514     <?php
515     if (!extension_loaded('curl')) {
516         echo "<p class=\"evidence\">You will need to enable the CURL extension to use the HTTPS and HTTP 1.1 transports</p>\n";
517     }
518     ?>
519
520     <h3>Example</h3>
521     <p>
522         Server Address: phpxmlrpc.sourceforge.net<br/>
523         Path: /server.php
524     </p>
525
526     <h3>Notice</h3>
527     <p>all usernames and passwords entered on the above form will be written to the web server logs of this server. Use
528         with care.</p>
529
530     <h3>Changelog</h3>
531     <ul>
532         <li>2007-02-20: add visual editor for method payload; allow strings, bools as jsonrpc msg id</li>
533         <li>2006-06-26: support building php code stub for calling remote methods</li>
534         <li>2006-05-25: better support for long running queries; check for no-curl installs</li>
535         <li>2006-05-02: added support for JSON-RPC. Note that many interesting json-rpc features are not implemented
536             yet, such as notifications or multicall.
537         </li>
538         <li>2006-04-22: added option for setting custom CA certs to verify peer with in SSLmode</li>
539         <li>2006-03-05: added option for setting Basic/Digest/NTLM auth type</li>
540         <li>2006-01-18: added option echoing to screen xmlrpc request before sending it ('More' debug)</li>
541         <li>2005-10-01: added option for setting cookies to be sent to server</li>
542         <li>2005-08-07: added switches for compression of requests and responses and http 1.1</li>
543         <li>2005-06-27: fixed possible security breach in parsing malformed xml</li>
544         <li>2005-06-24: fixed error with calling methods having parameters...</li>
545     </ul>
546 <?php
547
548 }
549 ?>
550 </body>
551 </html>