From c819791510c6a9d39e095dc8b832ca8299027237 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Thu, 12 Sep 2013 15:22:06 +0000 Subject: [PATCH] Fix up ROOT_PATH, yet again The previous implementation did not work correctly for symlinked folders. The new approach uses debug_backtrace() and ROOT_DIR to determine the difference between ROOT_DIR and the osTicket installation path. This thing is like a turd that won't flush --- include/class.osticket.php | 58 ++++++++------------------------------ 1 file changed, 11 insertions(+), 47 deletions(-) diff --git a/include/class.osticket.php b/include/class.osticket.php index f23dc824c..d481ee60c 100644 --- a/include/class.osticket.php +++ b/include/class.osticket.php @@ -367,63 +367,27 @@ class osTicket { || !strcasecmp($_SERVER['DOCUMENT_ROOT'], $dir)) return '/'; - /* If DOCUMENT_ROOT is set and isn't the same as the directory for - * main.inc.php, then assume that the two have something in common. - * For instance, you might have the following configurations - * - * +-----------------+-----------------------+------------+----------+ - * | DOCUMENT_ROOT | dirname(main.inc.php) | ROOT_PATH | Comments | - * +-----------------+-----------------------+------------+----------+ - * | /var/www | /var/www/osticket | /osticket/ | vanilla | - * | /srv/httpd/www | /httpd/www | / | chrooted | - * | /srv/httpd/www | /httpd/www/osticket | /osticket/ | chrooted | - * +-----------------+-----------------------+------------+----------+ - * - * This algorithm will walk the two paths right to left, chipping - * away at the path of main.inc.php. When the two paths are equal, - * the part removed from the main.inc.php path is the ROOT_PATH - */ - $dir = str_replace('\\', '/', $dir); - $root = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']); - - // Not chrooted - if(strpos($dir, $root)!==false) - return substr($dir, strlen($root)); - - // Chrooted ? - $path = ''; - while (strpos($root, $dir) === false) { - $lastslash = strrpos($dir, '/'); - $path = substr($dir, $lastslash) . $path; - $dir = substr($dir, 0, $lastslash); - if (!$dir) - break; - } - - if($dir && $path) - return $path; - - /* The last resort is to try and use SCRIPT_FILENAME and - * SCRIPT_NAME. The SCRIPT_FILENAME server variable should be the - * full path of the originally-executed-script. The SCRIPT_NAME - * should be the path of that script inside the DOCUMENT_ROOT. This - * is most likely useful if osTicket is run using something like - * Apache UserDir setting where the DOCUMENT_ROOT of Apache and the - * installation path of osTicket have nothing in comon. + /* The main idea is to try and use full-path filename of PHP_SELF and + * SCRIPT_NAME. The SCRIPT_NAME should be the path of that script + * inside the DOCUMENT_ROOT. This is most likely useful if osTicket + * is run using something like Apache UserDir setting where the + * DOCUMENT_ROOT of Apache and the installation path of osTicket + * have nothing in comon. * * +---------------------------+-------------------+----------------+ - * | SCRIPT_FILENAME | SCRIPT_NAME | ROOT_PATH | + * | PHP Script | SCRIPT_NAME | ROOT_PATH | * +---------------------------+-------------------+----------------+ * | /home/u1/www/osticket/... | /~u1/osticket/... | /~u1/osticket/ | * +---------------------------+-------------------+----------------+ * * The algorithm will remove the directory of main.inc.php from - * SCRIPT_FILENAME. What's left should be the script executed inside + * as seen. What's left should be the script executed inside * the osTicket installation. That is removed from SCRIPT_NAME. * What's left is the ROOT_PATH. */ - $path = substr($_SERVER['SCRIPT_FILENAME'], strlen(ROOT_DIR)); - if($path && ($pos=strpos($_SERVER['SCRIPT_NAME'], $path))!==false) + $frame = array_pop(debug_backtrace(false)); + $path = substr($frame['file'], strlen(ROOT_DIR)); + if($path && ($pos=strpos($_SERVER['SCRIPT_NAME'], $path))!==false) return substr($_SERVER['SCRIPT_NAME'], 0, $pos); return null; -- GitLab