//Run only once
if (isset($handler_run) && $handler_run) return;
if (!isset($handler_run)) $handler_run = true;
// Includes
require ('includes/defines.inc.php');
require ('includes/utils.inc.php');
require ('includes/errorhandling.inc.php');
// Get Base Classes
require ('./classes/error.class.php');
require ('./classes/sql.class.php');
require ('./classes/phpmailer/class.phpmailer.php');
// start sessions to keep state of things
ob_start();
session_name('GLOBALPMS');
session_start();
// We Dont allow direct .php acess (why? because i dont want to, thats why!)
$parsed_url = parse_url ($_SERVER ['REQUEST_URI']);
if (! empty($parsed_url['path']) && !preg_match("/backoffice/i", $parsed_url['path'])) {
$path_parts = pathinfo($parsed_url['path']);
if (! empty($path_parts['extension']) && $path_parts['extension'] == 'php') {
if (DEBUG) {
echo $_SERVER ['REQUEST_URI'].'
';
echo 'direct call to php';
} else {
header("Location: /");
}
die();
}
}
// Parse Request
if (! isset($_SERVER ['REQUEST_URI'])) $_SERVER ['REQUEST_URI'] = '';
$script = parse_url ($_SERVER ['REQUEST_URI']);
// Default page
if ($script['path'][strlen($script['path'])-1] == '/')
$script['path'] = $script['path'].'hp.php';
if (empty($script['path']))
$script['path'] = $script['path'].'/hp.php';
// get script parts
$script_parts = explode ("/", $_SERVER ['REQUEST_URI']);
// clean empty keys
foreach($script_parts as $key=>$row)
if ($row == '') unset($script_parts[$key]);
// sort
$tmp = array();
foreach($script_parts as $row) {
$tmp[] = $row;
}
$script_parts = $tmp;
if(empty($script_parts))
$script_parts[] = "hp";
// set origin
if(isset($_GET['o']) && strlen($_GET['o']) < 255) {
if(!isset($_SESSION['origin']) || $_SESSION['origin'] != $_GET['o'])
$_SESSION['origin'] = $_GET['o'];
header("Location: /");
die();
}
if(!isset($_SESSION['origin']))
$_SESSION['origin'] = "unknown";
// parsing directories
if (count($script_parts))
switch ($script_parts[0]) {
case "taf":
$script['path'] = '/taf.php';
break;
}
// Execute Script
if (substr($_SERVER['DOCUMENT_ROOT'], -1, 1) == '/')
$_SERVER['DOCUMENT_ROOT'] = substr($_SERVER['DOCUMENT_ROOT'], 0, -1);
if ($script['path'][0] == '/')
$script['path'] = substr($script['path'], 1);
if (file_exists ($_SERVER['DOCUMENT_ROOT'].'/'.$script['path'])) {
// includes
include($_SERVER['DOCUMENT_ROOT'].'/'.$script['path']);
} else {
// error 404
if (DEBUG) {
echo $_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'].'
';
echo 'error 404';
} else {
header("Location: /");
die();
}
}
// Output HTML
$html = ob_get_clean();
// Any post processing html changes here
ob_start('ob_gzhandler');
//header("Content-type: text/html; charset=UTF-8");
echo $html;
?>