Improve testsuite to make it easily executable by Travis
[plcapi.git] / debugger / controller.php
1 <?php
2 /**
3  * @author Gaetano Giunta
4  * @copyright (C) 2005-2014 G. Giunta
5  * @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/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  *
12  * @todo parse content of payload textarea to be fed to visual editor
13  * @todo add http no-cache headers
14  **/
15
16   include(dirname(__FILE__).'/common.php');
17   if ($action == '')
18     $action = 'list';
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 {overflow: -moz-scrollbars-vertical;}
40 body {padding: 0.5em; background-color: #EEEEEE; font-family: Verdana, Arial, Helvetica; font-size: 8pt;}
41 h1 {font-size: 12pt; margin: 0.5em;}
42 h2 {font-size: 10pt; display: inline; vertical-align: top;}
43 table {border: 1px solid gray; margin-bottom: 0.5em; padding: 0.25em; width: 100%;}
44 #methodpayload {display: inline;}
45 td {vertical-align: top; font-family: Verdana, Arial, Helvetica; font-size: 8pt;}
46 .labelcell {text-align: right;}
47 -->
48 </style>
49 <script language="JavaScript" type="text/javascript">
50 <!--
51   function verifyserver()
52   {
53     if (document.frmaction.host.value == '')
54     {
55       alert('Please insert a server name or address');
56       return false;
57     }
58     if (document.frmaction.path.value == '')
59       document.frmaction.path.value = '/';
60     var action = '';
61     for (counter = 0; counter < document.frmaction.action.length; counter++)
62       if (document.frmaction.action[counter].checked)
63       {
64         action = document.frmaction.action[counter].value;
65       }
66     if (document.frmaction.method.value == '' && (action == 'execute' || action == 'wrap' || action == 'describe'))
67     {
68       alert('Please insert a method name');
69       return false;
70     }
71     if (document.frmaction.authtype.value != '1' && document.frmaction.username.value == '')
72     {
73       alert('No username for authenticating to server: authentication disabled');
74     }
75     return true;
76   }
77
78   function switchaction()
79   {
80     // reset html layout depending on action to be taken
81     var action = '';
82     for (counter = 0; counter < document.frmaction.action.length; counter++)
83       if (document.frmaction.action[counter].checked)
84       {
85         action = document.frmaction.action[counter].value;
86       }
87     if (action == 'execute')
88     {
89       document.frmaction.methodpayload.disabled = false;
90       displaydialogeditorbtn(true);//if (document.getElementById('methodpayloadbtn') != undefined) document.getElementById('methodpayloadbtn').disabled = false;
91       document.frmaction.method.disabled = false;
92       document.frmaction.methodpayload.rows = 10;
93     }
94     else
95     {
96       document.frmaction.methodpayload.rows = 1;
97       if (action == 'describe' || action == 'wrap')
98       {
99         document.frmaction.methodpayload.disabled = true;
100         displaydialogeditorbtn(false); //if (document.getElementById('methodpayloadbtn') != undefined) document.getElementById('methodpayloadbtn').disabled = true;
101         document.frmaction.method.disabled = false;
102       }
103       else // list
104       {
105         document.frmaction.methodpayload.disabled = true;
106         displaydialogeditorbtn(false); //if (document.getElementById('methodpayloadbtn') != undefined) document.getElementById('methodpayloadbtn').disabled = false;
107         document.frmaction.method.disabled = true;
108       }
109     }
110   }
111
112   function switchssl()
113   {
114     if (document.frmaction.protocol.value != '2')
115     {
116       document.frmaction.verifypeer.disabled = true;
117       document.frmaction.verifyhost.disabled = true;
118       document.frmaction.cainfo.disabled = true;
119     }
120     else
121     {
122       document.frmaction.verifypeer.disabled = false;
123       document.frmaction.verifyhost.disabled = false;
124       document.frmaction.cainfo.disabled = false;
125     }
126   }
127
128   function switchauth()
129   {
130     if (document.frmaction.protocol.value != '0')
131     {
132       document.frmaction.authtype.disabled = false;
133     }
134     else
135     {
136       document.frmaction.authtype.disabled = true;
137       document.frmaction.authtype.value = 1;
138     }
139   }
140
141   function swicthcainfo()
142   {
143     if (document.frmaction.verifypeer.checked == true)
144     {
145       document.frmaction.cainfo.disabled = false;
146     }
147     else
148     {
149       document.frmaction.cainfo.disabled = true;
150     }
151   }
152
153   function switchtransport(is_json)
154   {
155     if (is_json == 0)
156     {
157       document.getElementById("idcell").style.visibility = 'hidden';
158       document.frmjsonrpc.yes.checked = false;
159       document.frmxmlrpc.yes.checked = true;
160       document.frmaction.wstype.value="0";
161     }
162     else
163     {
164       document.getElementById("idcell").style.visibility = 'visible';
165       document.frmjsonrpc.yes.checked = true;
166       document.frmxmlrpc.yes.checked = false;
167       document.frmaction.wstype.value="1";
168     }
169   }
170
171   function displaydialogeditorbtn(show)
172   {
173     if (show && ((typeof base64_decode) == 'function'))
174     {
175           document.getElementById('methodpayloadbtn').innerHTML = '[<a href="#" onclick="activateeditor(); return false;">Edit</a>]';
176         }
177         else
178     {
179           document.getElementById('methodpayloadbtn').innerHTML = '';
180         }
181   }
182
183   function activateeditor()
184   {
185           var url = '<?php echo $editorpath; ?>visualeditor.php?params=<?php echo $alt_payload; ?>';
186           if (document.frmaction.wstype.value == "1")
187             url += '&type=jsonrpc';
188           var wnd = window.open(url, '_blank', 'width=750, height=400, location=0, resizable=1, menubar=0, scrollbars=1');
189   }
190
191   // if javascript version of the lib is found, allow it to send us params
192   function buildparams(base64data)
193   {
194     if (typeof base64_decode == 'function')
195     {
196           if (base64data == '0') // workaround for bug in base64_encode...
197             document.getElementById('methodpayload').value = '';
198           else
199         document.getElementById('methodpayload').value = base64_decode(base64data);
200     }
201   }
202
203   // 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/)
204   function switchFormMethod()
205   {
206       /// @todo use a more precise calculation, adding the rest of the fields to the actual generated url lenght
207       if (document.frmaction.methodpayload.value.length > 1536 )
208       {
209           document.frmaction.action = 'action.php?usepost=true';
210           document.frmaction.method = 'post';
211       }
212   }
213
214 //-->
215 </script>
216 </head>
217 <body onload="switchtransport(<?php echo $wstype;?>); switchaction(); switchssl(); switchauth(); swicthcainfo();<?php if ($run) echo ' document.forms[2].submit();'; ?>">
218 <h1>XMLRPC <form name="frmxmlrpc" style="display: inline;" action="."><input name="yes" type="radio" onclick="switchtransport(0);"/></form>
219 /<form name="frmjsonrpc" style="display: inline;" action="."><input name="yes" type="radio" onclick="switchtransport(1);"/></form>JSONRPC Debugger (based on the <a href="http://phpxmlrpc.sourceforge.net">PHP-XMLRPC</a> library)</h1>
220 <form name="frmaction" method="get" action="action.php" target="frmaction" onSubmit="switchFormMethod();"
221 >
222
223 <table id="serverblock">
224 <tr>
225 <td><h2>Target server</h2></td>
226 <td class="labelcell">Address:</td><td><input type="text" name="host" value="<?php echo htmlspecialchars($host); ?>" /></td>
227 <td class="labelcell">Port:</td><td><input type="text" name="port" value="<?php echo htmlspecialchars($port); ?>" size="5" maxlength="5" /></td>
228 <td class="labelcell">Path:</td><td><input type="text" name="path" value="<?php echo htmlspecialchars($path); ?>" /></td>
229 </tr>
230 </table>
231
232 <table id="actionblock">
233 <tr>
234 <td><h2>Action</h2></td>
235 <td>List available methods<input type="radio" name="action" value="list"<?php if ($action=='list') echo ' checked="checked"'; ?> onclick="switchaction();" /></td>
236 <td>Describe method<input type="radio" name="action" value="describe"<?php if ($action=='describe') echo ' checked="checked"'; ?> onclick="switchaction();" /></td>
237 <td>Execute method<input type="radio" name="action" value="execute"<?php if ($action=='execute') echo ' checked="checked"'; ?> onclick="switchaction();" /></td>
238 <td>Generate stub for method call<input type="radio" name="action" value="wrap"<?php if ($action=='wrap') echo ' checked="checked"'; ?> onclick="switchaction();" /></td>
239 </tr>
240 </table>
241 <input type="hidden" name="methodsig" value="<?php echo htmlspecialchars($methodsig); ?>" />
242
243 <table id="methodblock">
244 <tr>
245 <td><h2>Method</h2></td>
246 <td class="labelcell">Name:</td><td><input type="text" name="method" value="<?php echo htmlspecialchars($method); ?>" /></td>
247 <td class="labelcell">Payload:<br/><div id="methodpayloadbtn"></div></td><td><textarea id="methodpayload" name="methodpayload" rows="1" cols="40"><?php echo htmlspecialchars($payload); ?></textarea></td>
248 <td class="labelcell" id="idcell">Msg id: <input type="text" name="id" size="3" value="<?php echo htmlspecialchars($id); ?>"/></td>
249 <td><input type="hidden" name="wstype" value="<?php echo $wstype;?>" />
250 <input type="submit" value="Execute" onclick="return verifyserver();"/></td>
251 </tr>
252 </table>
253
254 <table id="optionsblock">
255 <tr>
256 <td><h2>Client options</h2></td>
257 <td class="labelcell">Show debug info:</td><td><select name="debug">
258 <option value="0"<?php if ($debug == 0) echo ' selected="selected"'; ?>>No</option>
259 <option value="1"<?php if ($debug == 1) echo ' selected="selected"'; ?>>Yes</option>
260 <option value="2"<?php if ($debug == 2) echo ' selected="selected"'; ?>>More</option>
261 </select>
262 </td>
263 <td class="labelcell">Timeout:</td><td><input type="text" name="timeout" size="3" value="<?php if ($timeout > 0) echo $timeout; ?>" /></td>
264 <td class="labelcell">Protocol:</td><td><select name="protocol" onchange="switchssl(); switchauth(); swicthcainfo();">
265 <option value="0"<?php if ($protocol == 0) echo ' selected="selected"'; ?>>HTTP 1.0</option>
266 <option value="1"<?php if ($protocol == 1) echo ' selected="selected"'; ?>>HTTP 1.1</option>
267 <option value="2"<?php if ($protocol == 2) echo ' selected="selected"'; ?>>HTTPS</option>
268 </select></td>
269 </tr>
270 <tr>
271 <td class="labelcell">AUTH:</td>
272 <td class="labelcell">Username:</td><td><input type="text" name="username" value="<?php echo htmlspecialchars($username); ?>" /></td>
273 <td class="labelcell">Pwd:</td><td><input type="password" name="password" value="<?php echo htmlspecialchars($password); ?>" /></td>
274 <td class="labelcell">Type</td><td><select name="authtype">
275 <option value="1"<?php if ($authtype == 1) echo ' selected="selected"'; ?>>Basic</option>
276 <option value="2"<?php if ($authtype == 2) echo ' selected="selected"'; ?>>Digest</option>
277 <option value="8"<?php if ($authtype == 8) echo ' selected="selected"'; ?>>NTLM</option>
278 </select></td>
279 <td></td>
280 </tr>
281 <tr>
282 <td class="labelcell">SSL:</td>
283 <td class="labelcell">Verify Host's CN:</td><td><select name="verifyhost">
284 <option value="0"<?php if ($verifyhost == 0) echo ' selected="selected"'; ?>>No</option>
285 <option value="1"<?php if ($verifyhost == 1) echo ' selected="selected"'; ?>>Check CN existance</option>
286 <option value="2"<?php if ($verifyhost == 2) echo ' selected="selected"'; ?>>Check CN match</option>
287 </select></td>
288 <td class="labelcell">Verify Cert:</td><td><input type="checkbox" value="1" name="verifypeer" onclick="swicthcainfo();"<?php if ($verifypeer) echo ' checked="checked"'; ?> /></td>
289 <td class="labelcell">CA Cert file:</td><td><input type="text" name="cainfo" value="<?php echo htmlspecialchars($cainfo); ?>" /></td>
290 </tr>
291 <tr>
292 <td class="labelcell">PROXY:</td>
293 <td class="labelcell">Server:</td><td><input type="text" name="proxy" value="<?php echo htmlspecialchars($proxy); ?>" /></td>
294 <td class="labelcell">Proxy user:</td><td><input type="text" name="proxyuser" value="<?php echo htmlspecialchars($proxyuser); ?>" /></td>
295 <td class="labelcell">Proxy pwd:</td><td><input type="password" name="proxypwd" value="<?php echo htmlspecialchars($proxypwd); ?>" /></td>
296 </tr>
297 <tr>
298 <td class="labelcell">COMPRESSION:</td>
299 <td class="labelcell">Request:</td><td><select name="requestcompression">
300 <option value="0"<?php if ($requestcompression == 0) echo ' selected="selected"'; ?>>None</option>
301 <option value="1"<?php if ($requestcompression == 1) echo ' selected="selected"'; ?>>Gzip</option>
302 <option value="2"<?php if ($requestcompression == 2) echo ' selected="selected"'; ?>>Deflate</option>
303 </select></td>
304 <td class="labelcell">Response:</td><td><select name="responsecompression">
305 <option value="0"<?php if ($responsecompression == 0) echo ' selected="selected"'; ?>>None</option>
306 <option value="1"<?php if ($responsecompression == 1) echo ' selected="selected"'; ?>>Gzip</option>
307 <option value="2"<?php if ($responsecompression == 2) echo ' selected="selected"'; ?>>Deflate</option>
308 <option value="3"<?php if ($responsecompression == 3) echo ' selected="selected"'; ?>>Any</option>
309 </select></td>
310 <td></td>
311 </tr>
312 <tr>
313 <td class="labelcell">COOKIES:</td>
314 <td colspan="4" class="labelcell"><input type="text" name="clientcookies" size="80" value="<?php echo htmlspecialchars($clientcookies); ?>" /></td>
315 <td colspan="2">Format: 'cookie1=value1, cookie2=value2'</td>
316 </tr>
317 </table>
318
319 </form>
320 </body>
321 </html>