minor improvements in the debugger to allow easier integration of phpxmlrpc/jsonrpc...
authorgggeek <giunta.gaetano@gmail.com>
Wed, 30 Dec 2020 18:56:59 +0000 (18:56 +0000)
committergggeek <giunta.gaetano@gmail.com>
Wed, 30 Dec 2020 18:56:59 +0000 (18:56 +0000)
debugger/action.php
debugger/common.php
debugger/controller.php

index 076b1c0..7a2b61d 100644 (file)
@@ -92,10 +92,8 @@ header('Content-Type: text/html; charset=utf-8');
 <?php
 
 include __DIR__ . '/common.php';
-if ($action) {
 
-    include_once __DIR__ . "/../src/Autoloader.php";
-    PhpXmlRpc\Autoloader::register();
+if ($action) {
 
     // make sure the script waits long enough for the call to complete...
     if ($timeout) {
@@ -103,16 +101,16 @@ if ($action) {
     }
 
     if ($wstype == 1) {
-        @include 'jsonrpc.inc';
-        if (!class_exists('jsonrpc_client')) {
-            die('Error: to debug the jsonrpc protocol the jsonrpc.inc file is needed');
+        //@include 'jsonrpc.inc';
+        if (!class_exists('\PhpXmlRpc\JsonRpc\Client')) {
+            die('Error: to debug the jsonrpc protocol the phpxmlrpc/jsonrpc package is needed');
         }
-        $clientClass = 'PhpJsRpc\Client';
-        $requestClass = 'PhpJsRpc\Request';
+        $clientClass = '\PhpXmlRpc\JsonRpc\Client';
+        $requestClass = '\PhpXmlRpc\JsonRpc\Request';
         $protoName = 'JSONRPC';
     } else {
-        $clientClass = 'PhpXmlRpc\Client';
-        $requestClass = 'PhpXmlRpc\Request';
+        $clientClass = '\PhpXmlRpc\Client';
+        $requestClass = '\PhpXmlRpc\Request';
         $protoName = 'XMLRPC';
     }
 
index 2ce760b..5097a39 100644 (file)
  * @todo move parameters away from global namespace
  */
 
+// handle class autoloading:
+if (file_exists(__DIR__.'/../vendor/autoload.php')) {
+    // if the debugger is installed as top-level project with Composer, allow finding classes from dependencies
+    include_once(__DIR__.'/../vendor/autoload.php');
+} else {
+    // assume this is either a standalone install, or installed as Composer dependency
+    /// @todo if the latter is true, should we just not skip using the custom Autoloader, and let a top-level
+    ///       debugger include this one, taking care of autoloading ?
+    include_once __DIR__ . "/../src/Autoloader.php";
+    PhpXmlRpc\Autoloader::register();
+}
+
+// work around register globals - @see https://www.php.net/manual/en/faq.misc.php#faq.misc.registerglobals
+if (ini_get('register_globals')) {
+    function unregister_globals()
+    {
+        // Might want to change this perhaps to a nicer error
+        if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {
+            die('GLOBALS overwrite attempt detected');
+        }
+
+        // Variables that shouldn't be unset
+        $noUnset = array('GLOBALS',  '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES');
+
+        $input = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES,
+            isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array()
+        );
+
+        foreach ($input as $k => $v) {
+            if (!in_array($k, $noUnset) && isset($GLOBALS[$k])) {
+                unset($GLOBALS[$k]);
+            }
+        }
+    }
+    unregister_globals();
+}
+
 // work around magic quotes
 if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
     function stripslashes_deep($value)
@@ -35,10 +72,11 @@ if (isset($_GET['usepost']) && $_GET['usepost'] === 'true') {
 /// @todo if $inputcharset is not UTF8, we should probably re-encode $_GET to make it UTF-8
 
 // recover input parameters
+/// @todo instead of using globals, move them to an array. Also: use a class for this parsing...
 $debug = false;
 $protocol = 0;
 $run = false;
-$wstype = 0;
+$wstype = defined('DEFAULT_WSTYPE') ? DEFAULT_WSTYPE : 0;
 $id = '';
 if (isset($_GET['action'])) {
     if (isset($_GET['wstype']) && $_GET['wstype'] == '1') {
index 444028d..8656526 100644 (file)
  * @todo add support for more options, such as ntlm auth to proxy, or request charset encoding
  * @todo parse content of payload textarea to be fed to visual editor
  * @todo add http no-cache headers
- * @todo if jsonrpc php classes are not available, do not display the JSONRPC option
+ * @todo if jsonrpc php classes are not available, gray out or hide altogether the JSONRPC option & title
  * @todo if js libs are not available, do not try to load them
  **/
 
-// make sure we set the correct charset type for output, so that we can display all characters
+// Make sure we set the correct charset type for output, so that we can display all characters
 header('Content-Type: text/html; charset=utf-8');
 
 include __DIR__ . '/common.php';
@@ -22,9 +22,10 @@ if ($action == '') {
     $action = 'list';
 }
 
-// relative path to the visual xmlrpc editing dialog
-$editorpath = '../../phpjsrpc/debugger/';
-$editorlibs = '../../phpjsrpc/lib/';
+// Relative path to the visual xmlrpc editing dialog
+// We allow to easily configure this path via defines
+$editorpath = (defined('JSXMLRPC_PATH') ? JSXMLRPC_PATH : '../..') . '/jsxmlrpc/debugger/';
+$editorlibs = (defined('JSXMLRPC_PATH') ? JSXMLRPC_PATH : '../..') . '/jsxmlrpc/lib/';
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@@ -229,9 +230,9 @@ $editorlibs = '../../phpjsrpc/lib/';
         echo ' document.forms[2].submit();';
     } ?>">
 <h1>XMLRPC
-    <form name="frmxmlrpc" style="display: inline;" action="."><input name="yes" type="radio" onclick="switchtransport(0);"/></form>
+    <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>
     /
-    <form name="frmjsonrpc" style="display: inline;" action="."><input name="yes" type="radio" onclick="switchtransport(1);"/></form>
+    <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>
     JSONRPC Debugger (based on the <a href="http://gggeek.github.io/phpxmlrpc/">PHP-XMLRPC</a> library)
 </h1>
 <form name="frmaction" method="get" action="action.php" target="frmaction" onSubmit="switchFormMethod();">