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