diff --git a/include/class.misc.php b/include/class.misc.php index d49970e9f9ca8a92d5e16e29c146f329ad7bda60..27e259e330da365c96979017677c4cce695e4d61 100644 --- a/include/class.misc.php +++ b/include/class.misc.php @@ -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; - } - } ?> diff --git a/include/class.osticket.php b/include/class.osticket.php index 8755d3278fda537bd02e4454251b35a1dcbc1e58..aa571e9b1e259708e9f2d39d69ddcd6956098b42 100644 --- a/include/class.osticket.php +++ b/include/class.osticket.php @@ -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 */ diff --git a/include/ost-sampleconfig.php b/include/ost-sampleconfig.php index 65ff21c0d053e78c6b49a1e0647b881a1bff57f3..a5f896769fb81a931571e9afa5f98c0a8ef81967 100644 --- a/include/ost-sampleconfig.php +++ b/include/ost-sampleconfig.php @@ -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); diff --git a/main.inc.php b/main.inc.php index 323a0a4550cbf2fed30e9e8843c37bc7b5f3451b..ce874b26cb6920ff9e08fdcf9e1ce22e143cbd96 100644 --- a/main.inc.php +++ b/main.inc.php @@ -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!