Issues (319)

debugger/controller.php (4 issues)

Labels
Severity
1
<?php
2
/**
3
 * @author Gaetano Giunta
4
 * @copyright (C) 2005-2024 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
$haseditor = false;
26
$editorurlpath = null;
27
// @const JSXMLRPC_BASEURL Url to the visual xml-rpc editing dialog's containing folder. We allow to easily configure this
28
if (defined('JSXMLRPC_BASEURL')) {
29
    $editorurlpath = JSXMLRPC_BASEURL;
0 ignored issues
show
The constant JSXMLRPC_BASEURL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
30
    $haseditor = true;
31
} else {
32
    /// @deprecated
33
    /// @const JSXMLRPC_PATH Path to the visual xml-rpc editing dialog's containing folder. Can be absolute, or
34
    ///         relative to this debugger's folder.
35
    if (defined('JSXMLRPC_PATH')) {
36
        $editorpaths = array(JSXMLRPC_PATH[0] === '/' ? JSXMLRPC_PATH : (__DIR__ . '/' . JSXMLRPC_PATH));
0 ignored issues
show
The constant JSXMLRPC_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
37
    } else {
38
        $editorpaths = array(
39
            __DIR__ . '/jsxmlrpc/debugger/', // this package is top-level, jsxmlrpc installed via taskfile
40
            __DIR__ . '/vendor/phpxmlrpc/jsxmlrpc/debugger/', // this package is top-level, jsxmlrpc installed via composer inside the debugger
41
            __DIR__ . '/node_modules/@jsxmlrpc/jsxmlrpc/debugger/', // this package is top-level, jsxmlrpc installed via npm inside the debugger
42
            __DIR__ . '/../vendor/phpxmlrpc/jsxmlrpc/debugger/', // this package is top-level, jsxmlrpc installed via composer
43
            __DIR__ . '/../node_modules/@jsxmlrpc/jsxmlrpc/debugger/', // this package is top-level, jsxmlrpc installed via npm
44
            __DIR__ . '/../../jsxmlrpc/debugger/', // this package is a composer dependency, jsxmlrpc too
45
            __DIR__ . '/../../../../debugger/jsxmlrpc/debugger/', // this package is a composer dependency, jsxmlrpc installed in the top-level via taskfile (ie. jsonrpc)
46
            __DIR__ . '/../../../../debugger/vendor/phpxmlrpc/jsxmlrpc/debugger/', // this package is a composer dependency, jsxmlrpc installed in the top-level debugger via composer
47
            __DIR__ . '/../../../../debugger/node_modules/@jsxmlrpc/jsxmlrpc/debugger/', // this package is a composer dependency, jsxmlrpc installed in the top-level debugger via npm
48
            __DIR__ . '/../../../../node_modules/@jsxmlrpc/jsxmlrpc/debugger/', // this package is a composer dependency, jsxmlrpc installed via npm in the top-level project
49
        );
50
    }
51
    foreach($editorpaths as $editorpath) {
52
        if (is_file(realpath($editorpath . 'visualeditor.html'))) {
53
            $haseditor = true;
54
            break;
55
        }
56
    }
57
    if ($haseditor) {
58
        $controllerRootUrl = str_replace('/controller.php', '', parse_url($_SERVER['REQUEST_URI'],  PHP_URL_PATH));
59
        $editorurlpath = $controllerRootUrl . '/' . preg_replace('|^' . preg_quote(__DIR__, '|') .'|', '', $editorpath);
60
        /// @todo for cases above 4 and up, look at $controllerRootUrl and check if the web root is not pointing directly
61
        ///       at this folder, as in that case the link to the visualeditor will not
62
        ///       work, as it will be in the form http(s)://domain/../../jsxmlrpc/debugger/visualeditor.html
63
    }
64
}
65
?><!DOCTYPE html>
66
<html lang="en">
67
<head>
68
    <link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico">
69
    <title><?php if (defined('DEFAULT_WSTYPE') && DEFAULT_WSTYPE == 1) echo 'JSON-RPC'; else echo 'XML-RPC'; ?> Debugger</title>
0 ignored issues
show
The constant DEFAULT_WSTYPE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
70
    <meta name="robots" content="index,nofollow"/>
71
    <script type="text/javascript" language="Javascript">
72
        if (window.name != 'frmcontroller')
73
            top.location.replace('index.php?run=' + escape(self.location));
74
    </script>
75
    <!-- xml-rpc/json-rpc base library -->
76
    <script type="module">
77
        import {base64_decode} from 'https://cdn.jsdelivr.net/npm/@jsxmlrpc/[email protected]/lib/index.js';
78
        window.base64_decode = base64_decode;
79
    </script>
80
    <style>
81
        <!--
82
        html {
83
            overflow: -moz-scrollbars-vertical;
84
        }
85
        body {
86
            padding: 0.5em;
87
            background-color: #EEEEEE;
88
            font-family: Verdana, Arial, Helvetica, sans-serif;
89
            font-size: 8pt;
90
        }
91
        h1 {
92
            font-size: 12pt;
93
            margin: 0.5em;
94
            display: inline-block;
95
        }
96
        h2 {
97
            font-size: 10pt;
98
            display: inline;
99
            vertical-align: top;
100
        }
101
        h3 {
102
            display: inline;
103
        }
104
        table {
105
            border: 1px solid gray;
106
            margin-bottom: 0.5em;
107
            padding: 0.25em;
108
            width: 100%;
109
        }
110
        #methodpayload {
111
            display: inline;
112
        }
113
        #idcell {
114
            visibility: hidden;
115
        }
116
        td {
117
            vertical-align: top;
118
            font-family: Verdana, Arial, Helvetica, sans-serif;
119
            font-size: 8pt;
120
        }
121
        .labelcell {
122
            text-align: right;
123
        }
124
        -->
125
    </style>
126
    <script type="text/javascript">
127
        function verifyserver() {
128
            if (document.frmaction.host.value == '') {
129
                alert('Please insert a server name or address');
130
                return false;
131
            }
132
            if (document.frmaction.path.value == '')
133
                document.frmaction.path.value = '/';
134
            var action = '';
135
            for (counter = 0; counter < document.frmaction.action.length; counter++)
136
                if (document.frmaction.action[counter].checked) {
137
                    action = document.frmaction.action[counter].value;
138
                }
139
            if (document.frmaction.method.value == '' && (action == 'execute' || action == 'wrap' || action == 'describe')) {
140
                alert('Please insert a method name');
141
                return false;
142
            }
143
            if (document.frmaction.authtype.value != '1' && document.frmaction.username.value == '') {
144
                alert('No username for authenticating to server: authentication disabled');
145
            }
146
147
            return true;
148
        }
149
150
        function switchaction() {
151
            // reset html layout depending on action to be taken
152
            var action = '';
153
            for (counter = 0; counter < document.frmaction.action.length; counter++)
154
                if (document.frmaction.action[counter].checked) {
155
                    action = document.frmaction.action[counter].value;
156
                }
157
            if (action == 'execute') {
158
                document.frmaction.methodpayload.disabled = false;
159
                displaydialogeditorbtn(true);//if (document.getElementById('methodpayloadbtn') != undefined) document.getElementById('methodpayloadbtn').disabled = false;
160
                document.frmaction.method.disabled = false;
161
                document.frmaction.methodpayload.rows = 10;
162
            }
163
            else {
164
                document.frmaction.methodpayload.rows = 1;
165
                if (action == 'describe' || action == 'wrap') {
166
                    document.frmaction.methodpayload.disabled = true;
167
                    displaydialogeditorbtn(false); //if (document.getElementById('methodpayloadbtn') != undefined) document.getElementById('methodpayloadbtn').disabled = true;
168
                    document.frmaction.method.disabled = false;
169
                }
170
                else // list
171
                {
172
                    document.frmaction.methodpayload.disabled = true;
173
                    displaydialogeditorbtn(false); //if (document.getElementById('methodpayloadbtn') != undefined) document.getElementById('methodpayloadbtn').disabled = false;
174
                    document.frmaction.method.disabled = true;
175
                }
176
            }
177
        }
178
179
        function switchssl() {
180
            if (document.frmaction.protocol.value != '2' && document.frmaction.protocol.value != '3') {
181
                document.frmaction.verifypeer.disabled = true;
182
                document.frmaction.verifyhost.disabled = true;
183
                document.frmaction.cainfo.disabled = true;
184
            }
185
            else {
186
                document.frmaction.verifypeer.disabled = false;
187
                document.frmaction.verifyhost.disabled = false;
188
                document.frmaction.cainfo.disabled = false;
189
            }
190
        }
191
192
        function switchauth() {
193
            if (document.frmaction.protocol.value != '0') {
194
                document.frmaction.authtype.disabled = false;
195
            }
196
            else {
197
                document.frmaction.authtype.disabled = true;
198
                document.frmaction.authtype.value = 1;
199
            }
200
        }
201
202
        function swicthcainfo() {
203
            if (document.frmaction.verifypeer.checked == true) {
204
                document.frmaction.cainfo.disabled = false;
205
            }
206
            else {
207
                document.frmaction.cainfo.disabled = true;
208
            }
209
        }
210
211
        function switchtransport(is_json) {
212
            if (is_json == 0) {
213
                document.getElementById("idcell").style.visibility = 'hidden';
214
                document.frmjsonrpc.yes.checked = false;
215
                document.frmxmlrpc.yes.checked = true;
216
                document.frmaction.wstype.value = "0";
217
            }
218
            else {
219
                document.getElementById("idcell").style.visibility = 'visible';
220
                document.frmjsonrpc.yes.checked = true;
221
                document.frmxmlrpc.yes.checked = false;
222
                document.frmaction.wstype.value = "1";
223
            }
224
        }
225
226
        function displaydialogeditorbtn(show) {
227
            if (show && <?php echo $haseditor ? 'true' : 'false'; ?>) {
228
                document.getElementById('methodpayloadbtn').innerHTML = '[<a href="#" onclick="activateeditor(); return false;">Edit</a>]';
229
            }
230
            else {
231
                document.getElementById('methodpayloadbtn').innerHTML = '';
232
            }
233
        }
234
235
        function activateeditor() {
236
            var url = '<?php echo $editorurlpath; ?>visualeditor.html?params=<?php echo str_replace(array("\\", "'"), array( "\\\\", "\\'"), $alt_payload); ?>';
237
            if (document.frmaction.wstype.value == "1")
238
                url += '&type=jsonrpc';
239
            var wnd = window.open(url, '_blank', 'width=750, height=400, location=0, resizable=1, menubar=0, scrollbars=1');
240
        }
241
242
        // if javascript version of the lib is found, allow it to send us params
243
        function buildparams(base64data) {
244
            if (typeof base64_decode == 'function') {
245
                if (base64data == '0') // workaround for bug in base64_encode...
246
                    document.getElementById('methodpayload').value = '';
247
                else
248
                    document.getElementById('methodpayload').value = base64_decode(base64data);
249
            }
250
        }
251
252
        // 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/)
253
        function switchFormMethod() {
254
            /// @todo use a more precise calculation, adding the rest of the fields to the actual generated url length -
255
            ///       retrieve first max url length for current browsers and webservers
256
            if (document.frmaction.methodpayload.value.length > 1536) {
257
                document.frmaction.action = 'action.php?usepost=true';
258
                document.frmaction.method = 'post';
259
            }
260
            /*let form = document.forms[0];
261
            let formData = new FormData(form);
262
            let search = new URLSearchParams(formData);
263
            let queryString = search.toString();
264
            alert(queryString);alert(queryString.length);*/
265
        }
266
    </script>
267
</head>
268
<body
269
    onload="<?php if ($hasjsonrpcclient) echo "switchtransport($wstype); " ?>switchaction(); switchssl(); switchauth(); swicthcainfo();<?php if ($run) {
270
        echo ' document.frmaction.submit();';
271
    } ?>">
272
<h1>XML-RPC
273
<?php if ($hasjsonrpcclient) {
274
    echo '<form name="frmxmlrpc" style="display: inline;" action="."><input name="yes" type="radio" onclick="switchtransport(0);"';
275
    // q: does this if make sense at all?
276
    if (!class_exists('\PhpXmlRpc\Client')) echo ' disabled="disabled"';
277
    echo ' /></form> / <form name="frmjsonrpc" style="display: inline;" action="."><input name="yes" type="radio" onclick="switchtransport(1);"/></form>
278
    JSON-RPC';
279
} ?>
280
Debugger</h1><h3>(based on <a href="https://gggeek.github.io/phpxmlrpc/">PHPXMLRPC</a>, ver. <?php echo htmlspecialchars(\PhpXmlRpc\PhpXmlRpc::$xmlrpcVersion)?>
281
<?php if (class_exists('\PhpXmlRpc\JsonRpc\PhpJsonRpc')) echo ' and <a href="https://gggeek.github.io/phpxmlrpc-jsonrpc/">PHPJOSNRPC</a>, ver. ' . htmlspecialchars(\PhpXmlRpc\JsonRpc\PhpJsonRpc::$jsonrpcVersion); ?>)</h3>
0 ignored issues
show
The type PhpXmlRpc\JsonRpc\PhpJsonRpc was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
282
<form name="frmaction" method="get" action="action.php" target="frmaction" onSubmit="switchFormMethod();">
283
284
    <table id="serverblock">
285
        <tr>
286
            <td><h2>Target server</h2></td>
287
            <td class="labelcell">Protocol:</td>
288
            <td><select name="protocol" onchange="switchssl(); switchauth(); swicthcainfo();">
289
                <option value="0"<?php if ($protocol == 0) { echo ' selected="selected"'; } ?>>HTTP 1.0</option>
290
                <option value="1"<?php if ($protocol == 1) { echo ' selected="selected"'; } ?>>HTTP 1.1</option>
291
                <option value="2"<?php if ($protocol == 2) { echo ' selected="selected"'; } ?>>HTTPS</option>
292
                <option value="3"<?php if ($protocol == 3) { echo ' selected="selected"'; } ?>>HTTP2</option>
293
                <option value="4"<?php if ($protocol == 3) { echo ' selected="selected"'; } ?>>HTTP2 no TLS</option>
294
            </select></td>
295
            <td class="labelcell">Address:</td>
296
            <td><input type="text" name="host" value="<?php echo htmlspecialchars($host, ENT_COMPAT, $inputcharset); ?>"/></td>
297
            <td class="labelcell">Port:</td>
298
            <td><input type="text" name="port" value="<?php echo htmlspecialchars($port, ENT_COMPAT, $inputcharset); ?>" size="5" maxlength="5"/>
299
            </td>
300
            <td class="labelcell">Path:</td>
301
            <td><input type="text" name="path" value="<?php echo htmlspecialchars($path, ENT_COMPAT, $inputcharset); ?>"/></td>
302
        </tr>
303
    </table>
304
305
    <table id="actionblock">
306
        <tr>
307
            <td><h2>Action</h2></td>
308
            <td>List available methods<input type="radio" name="action" value="list"<?php if ($action == 'list') { echo ' checked="checked"'; } ?> onclick="switchaction();"/></td>
309
            <td>Describe method<input type="radio" name="action" value="describe"<?php if ($action == 'describe') { echo ' checked="checked"'; } ?> onclick="switchaction();"/></td>
310
            <td>Execute method<input type="radio" name="action" value="execute"<?php if ($action == 'execute') { echo ' checked="checked"'; } ?> onclick="switchaction();"/></td>
311
            <td>Generate stub for method call<input type="radio" name="action" value="wrap"<?php if ($action == 'wrap') { echo ' checked="checked"'; } ?> onclick="switchaction();"/></td>
312
        </tr>
313
    </table>
314
    <input type="hidden" name="methodsig" value="<?php echo htmlspecialchars($methodsig, ENT_COMPAT, $inputcharset); ?>"/>
315
316
    <table id="methodblock">
317
        <tr>
318
            <td><h2>Method</h2></td>
319
            <td class="labelcell">Name:</td>
320
            <td><input type="text" name="method" value="<?php echo htmlspecialchars($method, ENT_COMPAT, $inputcharset); ?>"/></td>
321
            <td class="labelcell">Payload:<br/>
322
                <div id="methodpayloadbtn"></div>
323
            </td>
324
            <td><textarea id="methodpayload" name="methodpayload" rows="1" cols="40"><?php echo htmlspecialchars($payload, ENT_COMPAT, $inputcharset); ?></textarea></td>
325
            <td class="labelcell" id="idcell">Msg id: <input type="text" name="id" size="3" value="<?php echo htmlspecialchars($id, ENT_COMPAT, $inputcharset); ?>"/></td>
326
            <td><input type="hidden" name="wstype" value="<?php echo $wstype; ?>"/>
327
                <input type="submit" value="Execute" onclick="return verifyserver();"/></td>
328
        </tr>
329
    </table>
330
331
    <table id="optionsblock">
332
        <tr>
333
            <td><h2>Client options</h2></td>
334
            <td class="labelcell">Show debug info:</td>
335
            <td><select name="debug">
336
                    <option value="0"<?php if ($debug == 0) { echo ' selected="selected"'; } ?>>No</option>
337
                    <option value="1"<?php if ($debug == 1) { echo ' selected="selected"'; } ?>>Yes</option>
338
                    <option value="2"<?php if ($debug == 2) { echo ' selected="selected"'; } ?>>More</option>
339
                </select>
340
            </td>
341
            <td class="labelcell">Timeout:</td>
342
            <td><input type="text" name="timeout" size="3" value="<?php if ($timeout > 0) { echo $timeout; } ?>"/></td>
343
            <td></td>
344
            <td></td>
345
        </tr>
346
        <tr>
347
            <td class="labelcell">AUTH:</td>
348
            <td class="labelcell">Username:</td>
349
            <td><input type="text" name="username" value="<?php echo htmlspecialchars($username, ENT_COMPAT, $inputcharset); ?>"/></td>
350
            <td class="labelcell">Pwd:</td>
351
            <td><input type="password" name="password" value="<?php echo htmlspecialchars($password, ENT_COMPAT, $inputcharset); ?>"/></td>
352
            <td class="labelcell">Type</td>
353
            <td><select name="authtype">
354
                    <option value="1"<?php if ($authtype == 1) { echo ' selected="selected"'; } ?>>Basic</option>
355
                    <option value="2"<?php if ($authtype == 2) { echo ' selected="selected"'; } ?>>Digest</option>
356
                    <option value="8"<?php if ($authtype == 8) { echo ' selected="selected"'; } ?>>NTLM</option>
357
                </select></td>
358
            <td></td>
359
        </tr>
360
        <tr>
361
            <td class="labelcell">SSL:</td>
362
            <td class="labelcell">Verify Host's CN:</td>
363
            <td><select name="verifyhost">
364
                    <option value="0"<?php if ($verifyhost == 0) { echo ' selected="selected"'; } ?>>No</option>
365
                    <option value="1"<?php if ($verifyhost == 1) { echo ' selected="selected"'; } ?>>Check CN existence</option>
366
                    <option value="2"<?php if ($verifyhost == 2) { echo ' selected="selected"'; } ?>>Check CN match</option>
367
                </select></td>
368
            <td class="labelcell">Verify Cert:</td>
369
            <td><input type="checkbox" value="1" name="verifypeer" onclick="swicthcainfo();"<?php if ($verifypeer) { echo ' checked="checked"'; } ?> /></td>
370
            <td class="labelcell">CA Cert file:</td>
371
            <td><input type="text" name="cainfo" value="<?php echo htmlspecialchars($cainfo, ENT_COMPAT, $inputcharset); ?>"/></td>
372
        </tr>
373
        <tr>
374
            <td class="labelcell">PROXY:</td>
375
            <td class="labelcell">Server:</td>
376
            <td><input type="text" name="proxy" value="<?php echo htmlspecialchars($proxy, ENT_COMPAT, $inputcharset); ?>"/></td>
377
            <td class="labelcell">Proxy user:</td>
378
            <td><input type="text" name="proxyuser" value="<?php echo htmlspecialchars($proxyuser, ENT_COMPAT, $inputcharset); ?>"/></td>
379
            <td class="labelcell">Proxy pwd:</td>
380
            <td><input type="password" name="proxypwd" value="<?php echo htmlspecialchars($proxypwd, ENT_COMPAT, $inputcharset); ?>"/></td>
381
        </tr>
382
        <tr>
383
            <td class="labelcell">COMPRESSION:</td>
384
            <td class="labelcell">Request:</td>
385
            <td><select name="requestcompression">
386
                    <option value="0"<?php if ($requestcompression == 0) { echo ' selected="selected"'; } ?>>None </option>
387
                    <option value="1"<?php if ($requestcompression == 1) { echo ' selected="selected"'; } ?>>Gzip</option>
388
                    <option value="2"<?php if ($requestcompression == 2) { echo ' selected="selected"'; } ?>>Deflate</option>
389
                </select></td>
390
            <td class="labelcell">Response:</td>
391
            <td><select name="responsecompression">
392
                    <option value="0"<?php if ($responsecompression == 0) { echo ' selected="selected"'; } ?>>None</option>
393
                    <option value="1"<?php if ($responsecompression == 1) { echo ' selected="selected"'; } ?>>Gzip</option>
394
                    <option value="2"<?php if ($responsecompression == 2) { echo ' selected="selected"'; } ?>>Deflate</option>
395
                    <option value="3"<?php if ($responsecompression == 3) { echo ' selected="selected"'; } ?>>Any</option>
396
                </select></td>
397
            <td></td>
398
        </tr>
399
        <tr>
400
            <td class="labelcell">COOKIES:</td>
401
            <td colspan="4" class="labelcell"><input type="text" name="clientcookies" size="80" value="<?php echo htmlspecialchars($clientcookies, ENT_COMPAT, $inputcharset); ?>"/></td>
402
            <td colspan="2">Format: 'cookie1=value1, cookie2=value2'</td>
403
        </tr>
404
    </table>
405
406
</form>
407
</body>
408
</html>
409