XDebug connect back Allows xdebug to connect back to the client making the HTTP request. This is useful for an environment where multiple developers are using the same machine and need the server to dynamically connect back to their machine for debugging. Adds an ini option "xdebug.remote_connectback=[On|Off]" You shouldn't enable this in an environment where anyone but the developer can access the machine, as it will allow them to view all your source code! diff --git a/php_xdebug.h b/php_xdebug.h index 57532d6..d4b6368 100644 --- a/php_xdebug.h +++ b/php_xdebug.h @@ -196,6 +196,7 @@ ZEND_BEGIN_MODULE_GLOBALS(xdebug) zend_bool remote_autostart; /* Disables the requirement for XDEBUG_SESSION_START */ char *remote_log; /* Filename to log protocol communication to */ FILE *remote_log_file; /* File handler for protocol log */ + zend_bool remote_connectback; /* connect back to the HTTP requestor */ char *ide_key; /* from environment, USER, USERNAME or empty */ diff --git a/xdebug.c b/xdebug.c index 463f891..661eb66 100644 --- a/xdebug.c +++ b/xdebug.c @@ -320,6 +320,7 @@ PHP_INI_BEGIN() #endif STD_PHP_INI_BOOLEAN("xdebug.remote_autostart","0", PHP_INI_ALL, OnUpdateBool, remote_autostart, zend_xdebug_globals, xdebug_globals) STD_PHP_INI_ENTRY("xdebug.remote_log", "", PHP_INI_ALL, OnUpdateString, remote_log, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_BOOLEAN("xdebug.remote_connectback","0", PHP_INI_ALL, OnUpdateBool, remote_connectback, zend_xdebug_globals, xdebug_globals) PHP_INI_ENTRY("xdebug.idekey", "", PHP_INI_ALL, OnUpdateIDEKey) /* Variable display settings */ @@ -1426,7 +1427,13 @@ void xdebug_execute(zend_op_array *op_array TSRMLS_DC) (XG(remote_mode) == XDEBUG_REQ) ) { /* Initialize debugging session */ - XG(context).socket = xdebug_create_socket(XG(remote_host), XG(remote_port)); + if(XG(remote_connectback)) { + zval** remote_addr = NULL; + zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "REMOTE_ADDR", 12, (void**)&remote_addr); + XG(context).socket = xdebug_create_socket(Z_STRVAL_PP(remote_addr), XG(remote_port)); + } else { + XG(context).socket = xdebug_create_socket(XG(remote_host), XG(remote_port)); + } if (XG(context).socket >= 0) { XG(remote_enabled) = 1; @@ -2184,7 +2191,13 @@ static char* return_trace_stack_frame_end(function_stack_entry* i, int fnr TSRML static void xdebug_do_jit(TSRMLS_D) { if (!XG(remote_enabled) && XG(remote_enable) && (XG(remote_mode) == XDEBUG_JIT)) { - XG(context).socket = xdebug_create_socket(XG(remote_host), XG(remote_port)); + if(XG(remote_connectback)) { + zval** remote_addr = NULL; + zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "REMOTE_ADDR", 12, (void**)&remote_addr); + XG(context).socket = xdebug_create_socket(Z_STRVAL_PP(remote_addr), XG(remote_port)); + } else { + XG(context).socket = xdebug_create_socket(XG(remote_host), XG(remote_port)); + } if (XG(context).socket >= 0) { XG(remote_enabled) = 0;