From 5ac1fdf32717d0c82cca7e7660dd4fd316a6a1b8 Mon Sep 17 00:00:00 2001 From: John Reese Date: Mon, 19 Apr 2010 09:28:34 -0400 Subject: [PATCH] Fix #11534: Incorrect path/short_path detection Rather than attempting to try and decipher the path and short_path by comparing the file's location on the filesytem with the document_root, MantisBT should be looking at the PHP_SELF server var provided by PHP. This variable is based on the current URL used to access the file, and is not confused by symlinks or the document_root pointing directly to the installation. It is also much simpler than the old method. Tested on Linux and Windows with the following setups: - installed as subdomain, eg http://mantis.host/foo.php - installed in subdirectory, eg http://host/mantisbt/foo.php - accessed by symlink (Linux), eg http://host/mantis/foo.php where /var/www/mantis -> /usr/share/mantisbt --- config_defaults_inc.php | 40 +++++----------------------------------- 1 file changed, 5 insertions(+), 35 deletions(-) diff --git a/config_defaults_inc.php b/config_defaults_inc.php index e87210acd1..11a53df3f5 100644 --- a/config_defaults_inc.php +++ b/config_defaults_inc.php @@ -123,42 +123,12 @@ } else if ( isset( $_SERVER['SERVER_ADDR'] ) ) { $t_host = $_SERVER['SERVER_ADDR'] . $t_port; } else { - $t_host = 'www.example.com'; + $t_host = 'localhost'; } - // Get server root to compare with path to this file - if( !isset( $_SERVER['DOCUMENT_ROOT'] ) ) { - if( isset( $_SERVER['SCRIPT_FILENAME'] ) ) { - $_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr( $_SERVER['SCRIPT_FILENAME'], 0, 0 - strlen( $_SERVER['SCRIPT_NAME'] ) ) ); - } - } - - if( !isset( $_SERVER['DOCUMENT_ROOT'] ) ) { - if( isset( $_SERVER['PATH_TRANSLATED'] ) ) { - $_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr( str_replace( '\\\\', '\\', $_SERVER['PATH_TRANSLATED'] ), 0, 0 - strlen( $_SERVER['SCRIPT_NAME'] ) ) ); - } - } - - $t_docroot = rtrim( $_SERVER['DOCUMENT_ROOT'], '/' ); - $t_file_path = str_replace( DIRECTORY_SEPARATOR, '/', __FILE__ ); - - // Extract the unique directory path of this file relative to the server's documunt root - if ( preg_match( '@' . preg_quote( $t_docroot ) . '(.*)@', $t_file_path, $t_matches ) ) { - $t_path = dirname( strip_tags( $t_matches[1] ) ); - } else { - $t_path = dirname( strip_tags( $_SERVER['SCRIPT_NAME'] ) ); - if ( '/' == $t_path || '\\' == $t_path ) { - $t_path = ''; - } - } - $t_path = rtrim($t_path, '/'); - - $inc_files = get_included_files(); - - $t_relative_path = str_replace( dirname($t_file_path), '', str_replace( DIRECTORY_SEPARATOR, '/', dirname($inc_files[0]))); - $t_path = str_replace( $t_relative_path, '', $t_path ); + $t_path = str_replace( basename( $_SERVER['PHP_SELF'] ), '', $_SERVER['PHP_SELF'] ); + $t_url = $t_protocol . '://' . $t_host . $t_path; - $t_url = $t_protocol . '://' . $t_host . $t_path.'/'; } else { $t_path = ''; $t_host = ''; @@ -170,7 +140,7 @@ * requires trailing / * @global string $g_path */ -$g_path = isset( $t_url ) ? $t_url : 'http://www.example.com/mantisbt/'; +$g_path = isset( $t_url ) ? $t_url : 'http://localhost/mantisbt/'; /** * path to your images directory (for icons) @@ -184,7 +154,7 @@ * requires trailing / * @global string $g_short_path */ -$g_short_path = $t_path . '/'; +$g_short_path = $t_path; /** * absolute path to your installation. Requires trailing / or \