Commit a5887e1c authored by Hugh Davenport's avatar Hugh Davenport

Fix autogen of wwwroot to detect symbolic links correctly

Test by appending each directory in PHP_SELF to DOCUMENT_ROOT
when the realpath of that is the same as dirname(__FILE__) then
stop processing.

For most users there is little performance hit, only a few will
have more than say two levels above DOCUMENT_ROOT

If nothing can be autoconfigured, use a default of root (ie no
path)

Bug #780237

Change-Id: I60339a180ac043ab0b89c3a49ff5f2485112f567
Signed-off-by: default avatarHugh Davenport <hugh@catalyst.net.nz>
parent f8abf68b
......@@ -169,6 +169,23 @@ if (!isset($CFG->wwwroot) && isset($_SERVER['HTTP_HOST'])) {
if (strpos(dirname(__FILE__), strlen($_SERVER['DOCUMENT_ROOT'])) === 0) {
$path = substr(dirname(__FILE__), strlen($_SERVER['DOCUMENT_ROOT']));
}
else {
$self = explode('/', $_SERVER['PHP_SELF']);
$dir = dirname(__FILE__);
$i = 0;
while (realpath($_SERVER['DOCUMENT_ROOT'].$path) != $dir) {
if ($i >= count($self) - 1) {
$path = '';
break;
}
if (empty($self[$i])) {
$i ++;
continue;
}
$path .= '/'.$self[$i];
$i ++;
}
}
if ($path) {
$path = str_replace('\\', '/', $path); // windows
if (substr($path, 0, 1) != '/') {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment