d5c8610968d5173c90a04edd882b0d9ac56fb58a
[plcapi.git] / debugger / controller.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 add links to documentation from every option caption
8  * @todo switch params for http compression from 0,1,2 to values to be used directly
9  * @todo add a little bit more CSS formatting: we broke IE box model getting a width > 100%...
10  * @todo add support for more options, such as ntlm auth to proxy, or request charset encoding
11  * @todo parse content of payload textarea to be fed to visual editor
12  * @todo add http no-cache headers
13  **/
14
15 include __DIR__ . '/common.php';
16 if ($action == '') {
17     $action = 'list';
18 }
19
20 // relative path to the visual xmlrpc editing dialog
21 $editorpath = '../../javascript/debugger/';
22 $editorlibs = '../../javascript/lib/';
23 ?>
24 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
25     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
26 <html xmlns="http://www.w3.org/1999/xhtml">
27 <head>
28     <title>XMLRPC Debugger</title>
29     <meta name="robots" content="index,nofollow"/>
30     <script type="text/javascript" language="Javascript">
31         if (window.name != 'frmcontroller')
32             top.location.replace('index.php?run=' + escape(self.location));
33     </script>
34     <!-- xmlrpc/jsonrpc base library -->
35     <script type="text/javascript" src="<?php echo $editorlibs; ?>xmlrpc_lib.js"></script>
36     <script type="text/javascript" src="<?php echo $editorlibs; ?>jsonrpc_lib.js"></script>
37     <style type="text/css">
38         <!--
39         html {
40             overflow: -moz-scrollbars-vertical;
41         }
42
43         body {
44             padding: 0.5em;
45             background-color: #EEEEEE;
46             font-family: Verdana, Arial, Helvetica;
47             font-size: 8pt;
48         }
49
50         h1 {
51             font-size: 12pt;
52             margin: 0.5em;
53         }
54
55         h2 {
56             font-size: 10pt;
57             display: inline;
58             vertical-align: top;
59         }
60
61         table {
62             border: 1px solid gray;
63             margin-bottom: 0.5em;
64             padding: 0.25em;
65             width: 100%;
66         }
67
68         #methodpayload {
69             display: inline;
70         }
71
72         td {
73             vertical-align: top;
74             font-family: Verdana, Arial, Helvetica;
75             font-size: 8pt;
76         }
77
78         .labelcell {
79             text-align: right;
80         }
81
82         -->
83     </style>
84     <script language="JavaScript" type="text/javascript">
85         <!--
86         function verifyserver() {
87             if (document.frmaction.host.value == '') {
88                 alert('Please insert a server name or address');
89                 return false;
90             }
91             if (document.frmaction.path.value == '')
92                 document.frmaction.path.value = '/';
93             var action = '';
94             for (counter = 0; counter < document.frmaction.action.length; counter++)
95                 if (document.frmaction.action[counter].checked) {
96                     action = document.frmaction.action[counter].value;
97                 }
98             if (document.frmaction.method.value == '' && (action == 'execute' || action == 'wrap' || action == 'describe')) {
99                 alert('Please insert a method name');
100                 return false;
101             }
102             if (document.frmaction.authtype.value != '1' && document.frmaction.username.value == '') {
103                 alert('No username for authenticating to server: authentication disabled');
104             }
105             return true;
106         }
107
108         function switchaction() {
109             // reset html layout depending on action to be taken
110             var action = '';
111             for (counter = 0; counter < document.frmaction.action.length; counter++)
112                 if (document.frmaction.action[counter].checked) {
113                     action = document.frmaction.action[counter].value;
114                 }
115             if (action == 'execute') {
116                 document.frmaction.methodpayload.disabled = false;
117                 displaydialogeditorbtn(true);//if (document.getElementById('methodpayloadbtn') != undefined) document.getElementById('methodpayloadbtn').disabled = false;
118                 document.frmaction.method.disabled = false;
119                 document.frmaction.methodpayload.rows = 10;
120             }
121             else {
122                 document.frmaction.methodpayload.rows = 1;
123                 if (action == 'describe' || action == 'wrap') {
124                     document.frmaction.methodpayload.disabled = true;
125                     displaydialogeditorbtn(false); //if (document.getElementById('methodpayloadbtn') != undefined) document.getElementById('methodpayloadbtn').disabled = true;
126                     document.frmaction.method.disabled = false;
127                 }
128                 else // list
129                 {
130                     document.frmaction.methodpayload.disabled = true;
131                     displaydialogeditorbtn(false); //if (document.getElementById('methodpayloadbtn') != undefined) document.getElementById('methodpayloadbtn').disabled = false;
132                     document.frmaction.method.disabled = true;
133                 }
134             }
135         }
136
137         function switchssl() {
138             if (document.frmaction.protocol.value != '2') {
139                 document.frmaction.verifypeer.disabled = true;
140                 document.frmaction.verifyhost.disabled = true;
141                 document.frmaction.cainfo.disabled = true;
142             }
143             else {
144                 document.frmaction.verifypeer.disabled = false;
145                 document.frmaction.verifyhost.disabled = false;
146                 document.frmaction.cainfo.disabled = false;
147             }
148         }
149
150         function switchauth() {
151             if (document.frmaction.protocol.value != '0') {
152                 document.frmaction.authtype.disabled = false;
153             }
154             else {
155                 document.frmaction.authtype.disabled = true;
156                 document.frmaction.authtype.value = 1;
157             }
158         }
159
160         function swicthcainfo() {
161             if (document.frmaction.verifypeer.checked == true) {
162                 document.frmaction.cainfo.disabled = false;
163             }
164             else {
165                 document.frmaction.cainfo.disabled = true;
166             }
167         }
168
169         function switchtransport(is_json) {
170             if (is_json == 0) {
171                 document.getElementById("idcell").style.visibility = 'hidden';
172                 document.frmjsonrpc.yes.checked = false;
173                 document.frmxmlrpc.yes.checked = true;
174                 document.frmaction.wstype.value = "0";
175             }
176             else {
177                 document.getElementById("idcell").style.visibility = 'visible';
178                 document.frmjsonrpc.yes.checked = true;
179                 document.frmxmlrpc.yes.checked = false;
180                 document.frmaction.wstype.value = "1";
181             }
182         }
183
184         function displaydialogeditorbtn(show) {
185             if (show && ((typeof base64_decode) == 'function')) {
186                 document.getElementById('methodpayloadbtn').innerHTML = '[<a href="#" onclick="activateeditor(); return false;">Edit</a>]';
187             }
188             else {
189                 document.getElementById('methodpayloadbtn').innerHTML = '';
190             }
191         }
192
193         function activateeditor() {
194             var url = '<?php echo $editorpath; ?>visualeditor.php?params=<?php echo $alt_payload; ?>';
195             if (document.frmaction.wstype.value == "1")
196                 url += '&type=jsonrpc';
197             var wnd = window.open(url, '_blank', 'width=750, height=400, location=0, resizable=1, menubar=0, scrollbars=1');
198         }
199
200         // if javascript version of the lib is found, allow it to send us params
201         function buildparams(base64data) {
202             if (typeof base64_decode == 'function') {
203                 if (base64data == '0') // workaround for bug in base64_encode...
204                     document.getElementById('methodpayload').value = '';
205                 else
206                     document.getElementById('methodpayload').value = base64_decode(base64data);
207             }
208         }
209
210         // use GET for ease of refresh, switch to POST when payload is too big to fit in url (in IE: 2048 bytes! see http://support.microsoft.com/kb/q208427/)
211         function switchFormMethod() {
212             /// @todo use a more precise calculation, adding the rest of the fields to the actual generated url lenght
213             if (document.frmaction.methodpayload.value.length > 1536) {
214                 document.frmaction.action = 'action.php?usepost=true';
215                 document.frmaction.method = 'post';
216             }
217         }
218
219         //-->
220     </script>
221 </head>
222 <body
223     onload="switchtransport(<?php echo $wstype; ?>); switchaction(); switchssl(); switchauth(); swicthcainfo();<?php if ($run) {
224         echo ' document.forms[2].submit();';
225     } ?>">
226 <h1>XMLRPC
227     <form name="frmxmlrpc" style="display: inline;" action="."><input name="yes" type="radio"
228                                                                       onclick="switchtransport(0);"/></form>
229     /
230     <form name="frmjsonrpc" style="display: inline;" action="."><input name="yes" type="radio"
231                                                                        onclick="switchtransport(1);"/></form>
232     JSONRPC Debugger (based on the <a href="http://phpxmlrpc.sourceforge.net">PHP-XMLRPC</a> library)
233 </h1>
234 <form name="frmaction" method="get" action="action.php" target="frmaction" onSubmit="switchFormMethod();"
235     >
236
237     <table id="serverblock">
238         <tr>
239             <td><h2>Target server</h2></td>
240             <td class="labelcell">Address:</td>
241             <td><input type="text" name="host" value="<?php echo htmlspecialchars($host); ?>"/></td>
242             <td class="labelcell">Port:</td>
243             <td><input type="text" name="port" value="<?php echo htmlspecialchars($port); ?>" size="5" maxlength="5"/>
244             </td>
245             <td class="labelcell">Path:</td>
246             <td><input type="text" name="path" value="<?php echo htmlspecialchars($path); ?>"/></td>
247         </tr>
248     </table>
249
250     <table id="actionblock">
251         <tr>
252             <td><h2>Action</h2></td>
253             <td>List available methods<input type="radio" name="action" value="list"<?php if ($action == 'list') {
254                     echo ' checked="checked"';
255                 } ?> onclick="switchaction();"/></td>
256             <td>Describe method<input type="radio" name="action" value="describe"<?php if ($action == 'describe') {
257                     echo ' checked="checked"';
258                 } ?> onclick="switchaction();"/></td>
259             <td>Execute method<input type="radio" name="action" value="execute"<?php if ($action == 'execute') {
260                     echo ' checked="checked"';
261                 } ?> onclick="switchaction();"/></td>
262             <td>Generate stub for method call<input type="radio" name="action"
263                                                     value="wrap"<?php if ($action == 'wrap') {
264                     echo ' checked="checked"';
265                 } ?> onclick="switchaction();"/></td>
266         </tr>
267     </table>
268     <input type="hidden" name="methodsig" value="<?php echo htmlspecialchars($methodsig); ?>"/>
269
270     <table id="methodblock">
271         <tr>
272             <td><h2>Method</h2></td>
273             <td class="labelcell">Name:</td>
274             <td><input type="text" name="method" value="<?php echo htmlspecialchars($method); ?>"/></td>
275             <td class="labelcell">Payload:<br/>
276
277                 <div id="methodpayloadbtn"></div>
278             </td>
279             <td><textarea id="methodpayload" name="methodpayload" rows="1"
280                           cols="40"><?php echo htmlspecialchars($payload); ?></textarea></td>
281             <td class="labelcell" id="idcell">Msg id: <input type="text" name="id" size="3"
282                                                              value="<?php echo htmlspecialchars($id); ?>"/></td>
283             <td><input type="hidden" name="wstype" value="<?php echo $wstype; ?>"/>
284                 <input type="submit" value="Execute" onclick="return verifyserver();"/></td>
285         </tr>
286     </table>
287
288     <table id="optionsblock">
289         <tr>
290             <td><h2>Client options</h2></td>
291             <td class="labelcell">Show debug info:</td>
292             <td><select name="debug">
293                     <option value="0"<?php if ($debug == 0) {
294                         echo ' selected="selected"';
295                     } ?>>No
296                     </option>
297                     <option value="1"<?php if ($debug == 1) {
298                         echo ' selected="selected"';
299                     } ?>>Yes
300                     </option>
301                     <option value="2"<?php if ($debug == 2) {
302                         echo ' selected="selected"';
303                     } ?>>More
304                     </option>
305                 </select>
306             </td>
307             <td class="labelcell">Timeout:</td>
308             <td><input type="text" name="timeout" size="3" value="<?php if ($timeout > 0) {
309                     echo $timeout;
310                 } ?>"/></td>
311             <td class="labelcell">Protocol:</td>
312             <td><select name="protocol" onchange="switchssl(); switchauth(); swicthcainfo();">
313                     <option value="0"<?php if ($protocol == 0) {
314                         echo ' selected="selected"';
315                     } ?>>HTTP 1.0
316                     </option>
317                     <option value="1"<?php if ($protocol == 1) {
318                         echo ' selected="selected"';
319                     } ?>>HTTP 1.1
320                     </option>
321                     <option value="2"<?php if ($protocol == 2) {
322                         echo ' selected="selected"';
323                     } ?>>HTTPS
324                     </option>
325                 </select></td>
326         </tr>
327         <tr>
328             <td class="labelcell">AUTH:</td>
329             <td class="labelcell">Username:</td>
330             <td><input type="text" name="username" value="<?php echo htmlspecialchars($username); ?>"/></td>
331             <td class="labelcell">Pwd:</td>
332             <td><input type="password" name="password" value="<?php echo htmlspecialchars($password); ?>"/></td>
333             <td class="labelcell">Type</td>
334             <td><select name="authtype">
335                     <option value="1"<?php if ($authtype == 1) {
336                         echo ' selected="selected"';
337                     } ?>>Basic
338                     </option>
339                     <option value="2"<?php if ($authtype == 2) {
340                         echo ' selected="selected"';
341                     } ?>>Digest
342                     </option>
343                     <option value="8"<?php if ($authtype == 8) {
344                         echo ' selected="selected"';
345                     } ?>>NTLM
346                     </option>
347                 </select></td>
348             <td></td>
349         </tr>
350         <tr>
351             <td class="labelcell">SSL:</td>
352             <td class="labelcell">Verify Host's CN:</td>
353             <td><select name="verifyhost">
354                     <option value="0"<?php if ($verifyhost == 0) {
355                         echo ' selected="selected"';
356                     } ?>>No
357                     </option>
358                     <option value="1"<?php if ($verifyhost == 1) {
359                         echo ' selected="selected"';
360                     } ?>>Check CN existance
361                     </option>
362                     <option value="2"<?php if ($verifyhost == 2) {
363                         echo ' selected="selected"';
364                     } ?>>Check CN match
365                     </option>
366                 </select></td>
367             <td class="labelcell">Verify Cert:</td>
368             <td><input type="checkbox" value="1" name="verifypeer" onclick="swicthcainfo();"<?php if ($verifypeer) {
369                     echo ' checked="checked"';
370                 } ?> /></td>
371             <td class="labelcell">CA Cert file:</td>
372             <td><input type="text" name="cainfo" value="<?php echo htmlspecialchars($cainfo); ?>"/></td>
373         </tr>
374         <tr>
375             <td class="labelcell">PROXY:</td>
376             <td class="labelcell">Server:</td>
377             <td><input type="text" name="proxy" value="<?php echo htmlspecialchars($proxy); ?>"/></td>
378             <td class="labelcell">Proxy user:</td>
379             <td><input type="text" name="proxyuser" value="<?php echo htmlspecialchars($proxyuser); ?>"/></td>
380             <td class="labelcell">Proxy pwd:</td>
381             <td><input type="password" name="proxypwd" value="<?php echo htmlspecialchars($proxypwd); ?>"/></td>
382         </tr>
383         <tr>
384             <td class="labelcell">COMPRESSION:</td>
385             <td class="labelcell">Request:</td>
386             <td><select name="requestcompression">
387                     <option value="0"<?php if ($requestcompression == 0) {
388                         echo ' selected="selected"';
389                     } ?>>None
390                     </option>
391                     <option value="1"<?php if ($requestcompression == 1) {
392                         echo ' selected="selected"';
393                     } ?>>Gzip
394                     </option>
395                     <option value="2"<?php if ($requestcompression == 2) {
396                         echo ' selected="selected"';
397                     } ?>>Deflate
398                     </option>
399                 </select></td>
400             <td class="labelcell">Response:</td>
401             <td><select name="responsecompression">
402                     <option value="0"<?php if ($responsecompression == 0) {
403                         echo ' selected="selected"';
404                     } ?>>None
405                     </option>
406                     <option value="1"<?php if ($responsecompression == 1) {
407                         echo ' selected="selected"';
408                     } ?>>Gzip
409                     </option>
410                     <option value="2"<?php if ($responsecompression == 2) {
411                         echo ' selected="selected"';
412                     } ?>>Deflate
413                     </option>
414                     <option value="3"<?php if ($responsecompression == 3) {
415                         echo ' selected="selected"';
416                     } ?>>Any
417                     </option>
418                 </select></td>
419             <td></td>
420         </tr>
421         <tr>
422             <td class="labelcell">COOKIES:</td>
423             <td colspan="4" class="labelcell"><input type="text" name="clientcookies" size="80"
424                                                      value="<?php echo htmlspecialchars($clientcookies); ?>"/></td>
425             <td colspan="2">Format: 'cookie1=value1, cookie2=value2'</td>
426         </tr>
427     </table>
428
429 </form>
430 </body>
431 </html>