|
15 | 15 | <html lang="en"> |
16 | 16 | <head> |
17 | 17 | <link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico"> |
18 | | - <title><?php if (defined('DEFAULT_WSTYPE') && DEFAULT_WSTYPE == 1) echo 'JSON-RPC'; else echo 'XML-RPC'; ?> Debugger</title> |
| 18 | + <title><?php if (defined('DEFAULT_WSTYPE') && (DEFAULT_WSTYPE == 1 || DEFAULT_WSTYPE == 2)) echo 'JSON-RPC'; else echo 'XML-RPC'; ?> Debugger</title> |
19 | 19 | <meta name="robots" content="index,nofollow"/> |
20 | 20 | <style type="text/css"> |
21 | 21 | <!-- |
|
78 | 78 | <body> |
79 | 79 | <?php |
80 | 80 |
|
| 81 | +global $inputcharset, $debug, $protocol, $run, $hasjsonrpcclient, $wstype, $id, $host, $port, $path, $action, $method, $methodsig, |
| 82 | + $payload, $alt_payload, $username, $password, $authtype, $verifyhost, $verifypeer, $cainfo, $proxy, $proxyuser, |
| 83 | + $proxypwd, $timeout, $requestcompression, $responsecompression, $clientcookies; |
| 84 | + |
81 | 85 | include __DIR__ . '/common.php'; |
82 | 86 |
|
83 | 87 | if ($action) { |
|
100 | 104 | set_time_limit($timeout + 10); |
101 | 105 | } |
102 | 106 |
|
103 | | - if ($wstype == 1) { |
| 107 | + if ($wstype == 1 || $wstype == 2) { |
104 | 108 | $clientClass = '\PhpXmlRpc\JsonRpc\Client'; |
105 | 109 | $requestClass = '\PhpXmlRpc\JsonRpc\Request'; |
106 | 110 | $protoName = 'JSON-RPC'; |
|
197 | 201 | // fall thru intentionally |
198 | 202 | case 'describe': |
199 | 203 | case 'wrap': |
200 | | - $msg[0] = new $requestClass('system.methodHelp', array(), $id); |
| 204 | + $msg[0] = new $requestClass('system.methodHelp', array(), (int)$id); |
201 | 205 | $msg[0]->addparam(new PhpXmlRpc\Value($method)); |
202 | 206 | $msg[1] = new $requestClass('system.methodSignature', array(), (int)$id + 1); |
203 | 207 | $msg[1]->addparam(new PhpXmlRpc\Value($method)); |
| 208 | + if ($wstype == 2) { |
| 209 | + $msg[0]->setJsonRpcVersion('2.0'); |
| 210 | + $msg[1]->setJsonRpcVersion('2.0'); |
| 211 | + } elseif ($wstype == 1) { |
| 212 | + $msg[0]->setJsonRpcVersion('1.0'); |
| 213 | + $msg[1]->setJsonRpcVersion('1.0'); |
| 214 | + } |
204 | 215 | $actionname = 'Description of method "' . $method . '"'; |
205 | 216 | break; |
206 | 217 | case 'list': |
207 | | - $msg[0] = new $requestClass('system.listMethods', array(), $id); |
| 218 | + $msg[0] = new $requestClass('system.listMethods', array(), (int)$id); |
| 219 | + if ($wstype == 2) { |
| 220 | + $msg[0]->setJsonRpcVersion('2.0'); |
| 221 | + } elseif ($wstype == 1) { |
| 222 | + $msg[0]->setJsonRpcVersion('1.0'); |
| 223 | + } |
208 | 224 | $actionname = 'List of available methods'; |
209 | 225 | break; |
210 | 226 | case 'execute': |
|
213 | 229 | } |
214 | 230 | $msg[0] = new $requestClass($method, array(), $id); |
215 | 231 | // hack! build payload by hand |
216 | | - if ($wstype == 1) { |
| 232 | + if ($wstype == 2) { |
| 233 | + $payload = "{\n" . |
| 234 | + '"jsonrpc": "2.0"' . "\n" . |
| 235 | + '"method": "' . $method . "\",\n\"params\": [" . |
| 236 | + $payload . |
| 237 | + "\n],\n"; |
| 238 | + // fix: if user gave an empty string, use NULL, or we'll break json syntax |
| 239 | + if ($id != "") { |
| 240 | + if (is_numeric($id) || $id == 'false' || $id == 'true') { |
| 241 | + $payload .= "\"id\": $id\n"; |
| 242 | + } else { |
| 243 | + $payload .= "\"id\": \"$id\"\n"; |
| 244 | + } |
| 245 | + } |
| 246 | + $payload .= '}'; |
| 247 | + $msg[0]->setPayload($payload); |
| 248 | + $msg[0]->setJsonRpcVersion('2.0'); |
| 249 | + } elseif ($wstype == 1) { |
217 | 250 | $payload = "{\n" . |
218 | 251 | '"method": "' . $method . "\",\n\"params\": [" . |
219 | 252 | $payload . |
|
229 | 262 | } |
230 | 263 | } |
231 | 264 | $msg[0]->setPayload($payload); |
| 265 | + $msg[0]->setJsonRpcVersion('1.0'); |
232 | 266 | } else { |
233 | 267 | $msg[0]->setPayload( |
234 | 268 | $msg[0]->xml_header($inputcharset) . |
|
372 | 406 | foreach($x as $k => $y) { |
373 | 407 | if ($k == 0) continue; |
374 | 408 | echo htmlspecialchars($y->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding); |
375 | | - if ($wstype == 1) { |
| 409 | + if ($wstype == 1 || $wstype == 2) { |
376 | 410 | switch($y->scalarval()) { |
377 | 411 | case 'string': |
378 | 412 | case 'dateTime.iso8601': |
|
423 | 457 | $alt_payload .= $y->scalarval(); |
424 | 458 | if ($k < $x->count() - 1) { |
425 | 459 | $alt_payload .= ';'; |
426 | | - if ($wstype == 1) { |
| 460 | + if ($wstype == 1 || $wstype == 2) { |
427 | 461 | $payload .= ', '; |
428 | 462 | } |
429 | 463 | echo ", "; |
|
519 | 553 | } else { |
520 | 554 | $opts = 0; // complete client copy in stub code |
521 | 555 | } |
522 | | - if ($wstype == 1) { |
| 556 | + if ($wstype == 1 || $wstype == 2) { |
523 | 557 | $prefix = 'jsonrpc'; |
524 | 558 | } else { |
525 | 559 | $prefix = 'xmlrpc'; |
526 | 560 | } |
527 | | - if ($wstype == 1) { |
| 561 | + if ($wstype == 1 || $wstype == 2) { |
528 | 562 | $wrapper = new PhpXmlRpc\JsonRpc\Wrapper(); |
529 | 563 | } else { |
530 | 564 | $wrapper = new PhpXmlRpc\Wrapper(); |
|
586 | 620 |
|
587 | 621 | <h3>Changelog</h3> |
588 | 622 | <ul> |
| 623 | + <li>2025-10-08: added support for json-rpc 2.0. The debugger now require phpjsonrpc 1.0.0-beta3 or later for json-rpc support</li> |
589 | 624 | <li>2023-02-11: display in the top row the version of the libraries in use; made the generated code throw instead |
590 | 625 | of returning a Response object on error; fixes for the json-rpc debugger</li> |
591 | 626 | <li>2022-12-18: fix XSS vulnerability in the debugger; load jsxmlrpc from CDN; minor improvements</li> |
|
0 commit comments