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