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