View Issue Details

IDProjectCategoryView StatusLast Update
0009577mantisbtinstallationpublic2010-09-19 03:12
Reporterdominik Assigned Tojreese  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionduplicate 
OSCentOsOS Version4.X 
Product Version1.2.0a2 
Summary0009577: "Wrong" Links when using symlink for Mantis directory
Description

I installed Mantis in a directory named mantis-1.2.0a2 and created a symlink called mantis which links to mantis-1.2.0a2. The idea is that Mantis can be always accessed by calling https://xyz.com/mantis and with the symlink one can "switch" between the different versions of mantis (eg /mantis => /mantis-1.2.0a1 | /mantis => mantis-1.2.0a2). I plan to use this for easy Mantis upgrading...

So far it works but Mantis will sooner or later (usually right after the login) redirect from https://xyz.com/mantis to https://xyz.com/mantis-1.2.0a2 or when calling a specific page directly it will place links which leads to the "wrong" directory...

I found out that the reason for this seems to be the following two lines of code in config_defaults.inc.php:

L114: $t_file_path = str_replace( DIRECTORY_SEPARATOR, '/', FILE );
L146: $g_absolute_path = dirname( FILE ) . DIRECTORY_SEPARATOR;

According to the PHP-Manual (http://ch2.php.net/manual/en/language.constants.predefined.php) the FILE constant will resolve symlinks, so that makes sence so far. I changed this two lines to use $_SERVER['SCRIPT_FILENAME'] instead of FILE and it works for me now:

L114: $t_file_path = str_replace( DIRECTORY_SEPARATOR, '/', $_SERVER['SCRIPT_FILENAME'] );
L146: $g_absolute_path = dirname( $_SERVER['SCRIPT_FILENAME'] ) . DIRECTORY_SEPARATOR;

My question is: Is there any reason to use FILE instead of $_SERVER['SCRIPT_FILENAME']? If not, would it be a good idea to make these changes in the Mantis as well?

TagsNo tags attached.
Attached Files
config_defaults_inc.php.patch (1,113 bytes)   
114c114,120
< 		$t_file_path = str_replace( DIRECTORY_SEPARATOR, '/', __FILE__ );
---
> 		# with apache use SCRIPT_FILENAME because __FILE__ does resolve symbolic links
> 		if( isset( $_SERVER['SERVER_SOFTWARE'] ) && stristr( $_SERVER['SERVER_SOFTWARE'], 'apache' ) ) { 
> 			$t_file_path = str_replace( DIRECTORY_SEPARATOR, '/', $_SERVER['SCRIPT_FILENAME'] );
> 		}
> 		else {
> 			$t_file_path = str_replace( DIRECTORY_SEPARATOR, '/', __FILE__ );
> 		}
116c122
< 		# Extract the unique directory path of this file relative to the server's documunt root
---
> 		# Extract the unique directory path of this file relative to the server's document root
146c152,158
< 	$g_absolute_path		= dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
---
> 	# with apache use SCRIPT_FILENAME because __FILE__ does resolve symbolic links
> 	if( isset( $_SERVER['SERVER_SOFTWARE'] ) && stristr( $_SERVER['SERVER_SOFTWARE'], 'apache' ) ) { 
> 		$g_absolute_path		= dirname( $_SERVER['SCRIPT_FILENAME'] ) . DIRECTORY_SEPARATOR;
> 	}
> 	else {
> 		$g_absolute_path		= dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
> 	}
config_defaults_inc.php.patch (1,113 bytes)   
0001-Minor-enhancement-when-using-symlinks-with-Apache-g.patch (1,151 bytes)   
From a47b7e5abcae6ba23dbe45442cd0d3a0dc9f53ca Mon Sep 17 00:00:00 2001
From: Dominik Blunk <dominik.blunk@acc-solutions.ch>
Date: Thu, 23 Apr 2009 18:06:02 +0200
Subject: [PATCH] Minor enhancement when using symlinks with Apache (g_absolute_path)

---
 config_defaults_inc.php |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/config_defaults_inc.php b/config_defaults_inc.php
index 82f16f4..89f09db 100644
--- a/config_defaults_inc.php
+++ b/config_defaults_inc.php
@@ -171,9 +171,15 @@
 
 	/**
 	 * absolute path to your installation.  Requires trailing / or \
+	 * with apache use SCRIPT_FILENAME because __FILE__ does resolve symbolic links
 	 * @global string $g_absolute_path
 	 */
-	$g_absolute_path		= dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
+	if( isset( $_SERVER['SERVER_SOFTWARE'] ) && stristr( $_SERVER['SERVER_SOFTWARE'], 'apache' ) ) { 
+		$g_absolute_path		= dirname( $_SERVER['SCRIPT_FILENAME'] ) . DIRECTORY_SEPARATOR;
+	}
+	else {
+		$g_absolute_path		= dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
+	}
 
 	/**
 	 * absolute patch to your core files. The default is usually OK,
-- 
1.6.2.2.1669.g7eaf8

Relationships

duplicate of 0011534 closedjreese Incorrect url/path detection 

Activities

dominik

dominik

2008-08-26 11:25

reporter   ~0019242

Last edited: 2008-08-26 11:25

Related to 0005137 and 0009266

Unfortunately I cannot add bug relationships thats why I add them here ;-)

jreese

jreese

2008-08-26 11:29

reporter   ~0019244

$_SERVER['SCRIPT_FILENAME'] is specific to Apache, which is why we do not use it. As a workaround until we can figure out a better way to generate proper paths/urls across all platforms, you can set $g_short_path = "/mantis/" which should take care of any problems you have.

dominik

dominik

2008-08-26 15:59

reporter   ~0019246

When I revert my changes and set $g_short_path = "/mantis/" as mentioned above
I will get links like this:

https://xyz.com/mantis-1.2.0a2/mantis/view_all_bug_page.php

which unfortunately do not work as required...

dominik

dominik

2008-08-27 14:31

reporter   ~0019256

What about a little selection if apache is used or another webserver?
I provided a small patch for this and would appreciate if you could check this one because I'm still learning on that cvs/diff/patch stuff...

Please let me know if everything is (technically) ok and your thoughts about applying this patch.

Thanks!

dominik

dominik

2009-04-23 12:32

reporter   ~0021648

Added patch created with GIT based on HEAD

fpruis

fpruis

2010-04-22 07:05

reporter   ~0025195

Last edited: 2010-04-22 07:12

The real problem is not in the webserver, but the fact that virtual ($_SERVER['DOCUMENT_ROOT) and physical (FILE) paths are mixed up in config_defaults_inc.php:132.

This patch for 1.2.0 stable fixes that:

[patch]
--- config_defaults_inc.php
+++ config_defaults_inc.org.php
@@ -125,7 +125,7 @@
}
}

  • $t_docroot = dirname(FILE);
  • $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

    [/patch]

I've also posted this patch in http://www.mantisbt.org/forums/viewtopic.php?f=3&t=10266
Apologies if doing something wrong, I'm new to contributing :)