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