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