Skip to content
Snippets Groups Projects
Commit 443ccec1 authored by Jared Hancock's avatar Jared Hancock
Browse files

Merge pull request #716 from protich/feature/root_path_revisited


Feature/root path revisited -- hopefully this issue will die here

Reviewed-By: default avatarJared Hancock <jared@osticket.com>
parents 7aa4e6f8 6771a114
No related branches found
No related tags found
No related merge requests found
...@@ -139,25 +139,5 @@ class Misc { ...@@ -139,25 +139,5 @@ class Misc {
return $output; return $output;
} }
/* static */
function siteRootPath($main_inc_path) {
if (!$_SERVER['DOCUMENT_ROOT'])
// Probably run from the command-line
return './';
$root = str_replace('\\', '/', $main_inc_path);
$root2 = str_replace('\\','/', $_SERVER['DOCUMENT_ROOT']);
$path = '';
while (strpos($_SERVER['DOCUMENT_ROOT'], $root) === false) {
$lastslash = strrpos($root, '/');
if ($lastslash === false)
// Unable to find any commonality between $root and
// DOCUMENT_ROOT
return './';
$path = substr($root, $lastslash) . $path;
$root = substr($root, 0, $lastslash);
}
return $path;
}
} }
?> ?>
...@@ -352,6 +352,82 @@ class osTicket { ...@@ -352,6 +352,82 @@ class osTicket {
return null; return null;
} }
/* static */
function get_root_path($dir) {
/* If run from the commandline, DOCUMENT_ROOT will not be set. It is
* also likely that the ROOT_PATH will not be necessary, so don't
* bother attempting to figure it out.
*
* Secondly, if the directory of main.inc.php is the same as the
* document root, the the ROOT path truly is '/'
*/
if(!$_SERVER['DOCUMENT_ROOT']
|| !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($dir));
// 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.
*
* +---------------------------+-------------------+----------------+
* | SCRIPT_FILENAME | 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
* 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)
return substr($_SERVER['SCRIPT_NAME'], 0, $pos);
return null;
}
/** /**
* Returns TRUE if the request was made via HTTPS and false otherwise * Returns TRUE if the request was made via HTTPS and false otherwise
*/ */
......
...@@ -16,8 +16,22 @@ ...@@ -16,8 +16,22 @@
$Id: $ $Id: $
**********************************************************************/ **********************************************************************/
/**
* If you have a strange HTTP server configuration and osTicket cannot
* discover the URL path of where your osTicket is installed, define
* ROOT_PATH here.
*
* The ROOT_PATH is the part of the URL used to access your osTicket
* helpdesk before the '/scp' part and after the hostname. For instance, for
* http://mycompany.com/support', the ROOT_PATH should be '/support/'
*
* ROOT_PATH *must* end with a forward-slash!
*/
# define('ROOT_PATH', '/support/');
#Disable direct access. #Disable direct access.
if(!strcasecmp(basename($_SERVER['SCRIPT_NAME']),basename(__FILE__)) || !defined('ROOT_PATH')) die('kwaheri rafiki!'); if(!strcasecmp(basename($_SERVER['SCRIPT_NAME']),basename(__FILE__)) || !defined('INCLUDE_DIR'))
die('kwaheri rafiki!');
#Install flag #Install flag
define('OSTINSTALLED',FALSE); define('OSTINSTALLED',FALSE);
......
...@@ -68,17 +68,19 @@ ...@@ -68,17 +68,19 @@
define('UPGRADE_DIR', INCLUDE_DIR.'upgrader/'); define('UPGRADE_DIR', INCLUDE_DIR.'upgrader/');
define('I18N_DIR', INCLUDE_DIR.'i18n/'); define('I18N_DIR', INCLUDE_DIR.'i18n/');
require(INCLUDE_DIR.'class.misc.php');
// Determine the path in the URI used as the base of the osTicket
// installation
if (!defined('ROOT_PATH'))
define('ROOT_PATH', Misc::siteRootPath(realpath(dirname(__file__))).'/'); //root path. Damn directories
/*############## Do NOT monkey with anything else beyond this point UNLESS you really know what you are doing ##############*/ /*############## Do NOT monkey with anything else beyond this point UNLESS you really know what you are doing ##############*/
#Current version && schema signature (Changes from version to version) #Current version && schema signature (Changes from version to version)
define('THIS_VERSION','1.7.0+'); //Shown on admin panel define('THIS_VERSION','1.7.0+'); //Shown on admin panel
require(INCLUDE_DIR.'class.osticket.php');
// Determine the path in the URI used as the base of the osTicket
// installation
if (!defined('ROOT_PATH') && ($rp = osTicket::get_root_path(dirname(__file__))))
define('ROOT_PATH', rtrim($rp, '/').'/');
#load config info #load config info
$configfile=''; $configfile='';
if(file_exists(ROOT_DIR.'ostconfig.php')) //Old installs prior to v 1.6 RC5 if(file_exists(ROOT_DIR.'ostconfig.php')) //Old installs prior to v 1.6 RC5
...@@ -98,6 +100,10 @@ ...@@ -98,6 +100,10 @@
require($configfile); require($configfile);
define('CONFIG_FILE',$configfile); //used in admin.php to check perm. define('CONFIG_FILE',$configfile); //used in admin.php to check perm.
//Die if root path is not defined
if(!defined('ROOT_PATH') || !ROOT_PATH)
die("<b>Fatal Error:</b> unknown root path. Define it in your 'ost-config.php'");
//Path separator //Path separator
if(!defined('PATH_SEPARATOR')){ if(!defined('PATH_SEPARATOR')){
if(strpos($_ENV['OS'],'Win')!==false || !strcasecmp(substr(PHP_OS, 0, 3),'WIN')) if(strpos($_ENV['OS'],'Win')!==false || !strcasecmp(substr(PHP_OS, 0, 3),'WIN'))
...@@ -111,7 +117,7 @@ ...@@ -111,7 +117,7 @@
#include required files #include required files
require(INCLUDE_DIR.'class.osticket.php'); require(INCLUDE_DIR.'class.misc.php');
require(INCLUDE_DIR.'class.ostsession.php'); require(INCLUDE_DIR.'class.ostsession.php');
require(INCLUDE_DIR.'class.usersession.php'); require(INCLUDE_DIR.'class.usersession.php');
require(INCLUDE_DIR.'class.pagenate.php'); //Pagenate helper! require(INCLUDE_DIR.'class.pagenate.php'); //Pagenate helper!
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment