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