Skip to content
Snippets Groups Projects
Commit 301558cb authored by Peter Rotich's avatar Peter Rotich Committed by Jared Hancock
Browse files

Revisit root path to better handle chrooted installs

Also, allow for the administrator to manually define the ROOT_PATH in the
config file (the very last mile).
parent 7aa4e6f8
No related branches found
No related tags found
No related merge requests found
......@@ -139,25 +139,5 @@ class Misc {
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,39 @@ class osTicket {
return null;
}
/* static */
function get_root_path($dir) {
if(!$_SERVER['DOCUMENT_ROOT']
|| !strcasecmp($_SERVER['DOCUMENT_ROOT'], $dir))
return '/';
$dir = str_replace('\\', '/', $dir);
$root = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']);
if(strpos($dir, $root)!==false)
return substr($dir, strlen($dir));
$origdir = $dir;
$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;
$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
*/
......
......@@ -16,8 +16,22 @@
$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.
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
define('OSTINSTALLED',FALSE);
......
......@@ -68,17 +68,19 @@
define('UPGRADE_DIR', INCLUDE_DIR.'upgrader/');
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 ##############*/
#Current version && schema signature (Changes from version to version)
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
$configfile='';
if(file_exists(ROOT_DIR.'ostconfig.php')) //Old installs prior to v 1.6 RC5
......@@ -98,6 +100,10 @@
require($configfile);
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
if(!defined('PATH_SEPARATOR')){
if(strpos($_ENV['OS'],'Win')!==false || !strcasecmp(substr(PHP_OS, 0, 3),'WIN'))
......@@ -111,7 +117,7 @@
#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.usersession.php');
require(INCLUDE_DIR.'class.pagenate.php'); //Pagenate helper!
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment