c7f88decc9f0a5d56d6e06bda939709711a6c243
[plcapi.git] / debugger / action.php
1 <?php
2 /**
3  * @author Gaetano Giunta
4  * @copyright (C) 2005-2021 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" lang="en">
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
96 if ($action) {
97
98     // make sure the script waits long enough for the call to complete...
99     if ($timeout) {
100         set_time_limit($timeout + 10);
101     }
102
103     if ($wstype == 1) {
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');
107         }
108         $clientClass = '\PhpXmlRpc\JsonRpc\Client';
109         $requestClass = '\PhpXmlRpc\JsonRpc\Request';
110         $protoName = 'JSONRPC';
111     } else {
112         $clientClass = '\PhpXmlRpc\Client';
113         $requestClass = '\PhpXmlRpc\Request';
114         $protoName = 'XMLRPC';
115     }
116
117     if ($port != "") {
118         $client = new $clientClass($path, $host, $port);
119         $server = "$host:$port$path";
120     } else {
121         $client = new $clientClass($path, $host);
122         $server = "$host$path";
123     }
124     if ($protocol == 2) {
125         $server = 'https://' . $server;
126     } else {
127         $server = 'http://' . $server;
128     }
129     if ($proxy != '') {
130         $pproxy = explode(':', $proxy);
131         if (count($pproxy) > 1) {
132             $pport = $pproxy[1];
133         } else {
134             $pport = 8080;
135         }
136         $client->setProxy($pproxy[0], $pport, $proxyuser, $proxypwd);
137     }
138
139     if ($protocol == 2) {
140         $client->setSSLVerifyPeer($verifypeer);
141         $client->setSSLVerifyHost($verifyhost);
142         if ($cainfo) {
143             $client->setCaCertificate($cainfo);
144         }
145         $httpprotocol = 'https';
146     } elseif ($protocol == 1) {
147         $httpprotocol = 'http11';
148     } else {
149         $httpprotocol = 'http';
150     }
151
152     if ($username) {
153         $client->setCredentials($username, $password, $authtype);
154     }
155
156     $client->setDebug($debug);
157
158     switch ($requestcompression) {
159         case 0:
160             $client->request_compression = '';
161             break;
162         case 1:
163             $client->request_compression = 'gzip';
164             break;
165         case 2:
166             $client->request_compression = 'deflate';
167             break;
168     }
169
170     switch ($responsecompression) {
171         case 0:
172             $client->accepted_compression = '';
173             break;
174         case 1:
175             $client->accepted_compression = array('gzip');
176             break;
177         case 2:
178             $client->accepted_compression = array('deflate');
179             break;
180         case 3:
181             $client->accepted_compression = array('gzip', 'deflate');
182             break;
183     }
184
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]));
190         }
191     }
192
193     $msg = array();
194     switch ($action) {
195         // fall thru intentionally
196         case 'describe':
197         case 'wrap':
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 . '"';
203             break;
204         case 'list':
205             $msg[0] = new $requestClass('system.listMethods', array(), $id);
206             $actionname = 'List of available methods';
207             break;
208         case 'execute':
209             if (!payload_is_safe($payload)) {
210                 die("Tsk tsk tsk, please stop it or I will have to call in the cops!");
211             }
212             $msg[0] = new $requestClass($method, array(), $id);
213             // hack! build xml payload by hand
214             if ($wstype == 1) {
215                 $msg[0]->payload = "{\n" .
216                     '"method": "' . $method . "\",\n\"params\": [" .
217                     $payload .
218                     "\n],\n\"id\": ";
219                 // fix: if user gave an empty string, use NULL, or we'll break json syntax
220                 if ($id == "") {
221                     $msg[0]->payload .= "null\n}";
222                 } else {
223                     if (is_numeric($id) || $id == 'false' || $id == 'true' || $id == 'null') {
224                         $msg[0]->payload .= "$id\n}";
225                     } else {
226                         $msg[0]->payload .= "\"$id\"\n}";
227                     }
228                 }
229             } else {
230                 $msg[0]->payload = $msg[0]->xml_header($inputcharset) .
231                     '<methodName>' . $method . "</methodName>\n<params>" .
232                     $payload .
233                     "</params>\n" . $msg[0]->xml_footer();
234             }
235             $actionname = 'Execution of method ' . $method;
236             break;
237         default: // give a warning
238             $actionname = '[ERROR: unknown action] "' . $action . '"';
239     }
240
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";
244     flush();
245
246     $response = null;
247     // execute method(s)
248     if ($debug) {
249         echo '<div class="dbginfo"><h2>Debug info:</h2>';
250     }  /// @todo use ob_start instead
251     $resp = array();
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);
256         $resp[] = $response;
257         if (!$response || $response->faultCode()) {
258             break;
259         }
260     }
261     $time = microtime(true) - $time;
262     if ($debug) {
263         echo "</div>\n";
264     }
265
266     if ($response) {
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"));
274         } else {
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"));
279
280             switch ($action) {
281                 case 'list':
282
283                     $v = $response->value();
284                     if ($v->kindOf() == "array") {
285                         $max = $v->count();
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) {
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
351                     if ($r2->kindOf() != "array") {
352                         echo "<tr><td class=\"oddrow\">Signature</td><td class=\"oddrow\">Unknown</td><td class=\"oddrow\">&nbsp;</td></tr>\n";
353                     } else {
354                         foreach($r2 as $i => $x) {
355                             $payload = "";
356                             $alt_payload = "";
357                             if ($i + 1 % 2) {
358                                 $class = ' class="oddrow"';
359                             } else {
360                                 $class = ' class="evenrow"';
361                             }
362                             echo "<tr><td$class>Signature&nbsp;" . ($i + 1) . "</td><td$class>";
363                             if ($x->kindOf() == "array") {
364                                 $ret = $x[0];
365                                 echo "<code>OUT:&nbsp;" . 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);
370                                         if ($wstype != 1) {
371                                             $type = $y->scalarval();
372                                             $payload .= '<param><value>';
373                                             switch($type) {
374                                                 case 'undefined':
375                                                     break;
376                                                 case 'null';
377                                                     $type = 'nil';
378                                                     // fall thru intentionally
379                                                 default:
380                                                     $payload .= '<' .
381                                                         htmlspecialchars($type, ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
382                                                         '></' . htmlspecialchars($type, ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
383                                                         '>';
384                                             }
385                                             $payload .= "</value></param>\n";
386                                         }
387                                         $alt_payload .= $y->scalarval();
388                                         if ($k < $x->count() - 1) {
389                                             $alt_payload .= ';';
390                                             echo ", ";
391                                         }
392                                     }
393                                 }
394                                 echo ")</code>";
395                             } else {
396                                 echo 'Unknown';
397                             }
398                             echo '</td>';
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\" />";
426                             if ($wstype != 1) {
427                                 echo "<input type=\"submit\" value=\"Load method synopsis\" />";
428                             }
429                             echo "</form></td>\n";
430
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";
460                         }
461                     }
462                     echo "</tbody>\n</table>";
463
464                     break;
465
466                 case 'wrap':
467                     $r1 = $resp[0]->value();
468                     $r2 = $resp[1]->value();
469                     if ($r2->kindOf() != "array" || $r2->count() <= $methodsig) {
470                         echo "Error: signature unknown\n";
471                     } else {
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 &&
478                             $clientcookies == ''
479                         ) {
480                             $opts = 1; // simple client copy in stub code
481                         } else {
482                             $opts = 0; // complete client copy in stub code
483                         }
484                         if ($wstype == 1) {
485                             $prefix = 'jsonrpc';
486                         } else {
487                             $prefix = 'xmlrpc';
488                         }
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);
491                         //if ($code)
492                         //{
493                         echo "<div id=\"phpcode\">\n";
494                         highlight_string("<?php\n" . $code['docstring'] . $code['source'] . '?>');
495                         echo "\n</div>";
496                         //}
497                         //else
498                         //{
499                         //  echo 'Error while building php code stub...';
500                     }
501
502                     break;
503
504                 case 'execute':
505                     echo '<div id="response"><h2>Response:</h2>' . htmlspecialchars($response->serialize()) . '</div>';
506                     break;
507
508                 default: // give a warning
509             }
510         } // if !$response->faultCode()
511     } // if $response
512 } else {
513     // no action taken yet: give some instructions on debugger usage
514     ?>
515
516     <h3>Instructions on usage of the debugger</h3>
517     <ol>
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'
522         </li>
523     </ol>
524     <?php
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";
527     }
528     ?>
529
530     <h3>Example</h3>
531     <p>
532         Server Address: phpxmlrpc.sourceforge.net<br/>
533         Path: /server.php
534     </p>
535
536     <h3>Notice</h3>
537     <p>all usernames and passwords entered on the above form will be written to the web server logs of this server. Use
538         with care.</p>
539
540     <h3>Changelog</h3>
541     <ul>
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.
550         </li>
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>
558     </ul>
559 <?php
560
561 }
562 ?>
563 </body>
564 </html>