summaryrefslogblamecommitdiffstats
path: root/index.php
blob: 6b7c3d8c2580a4beeb802fea7dedf7487f51d360 (plain) (tree)
1
2
3
4
5
6
7
8
9



                                                             




                              






                                                                                                                



























































                                                                                           
                                                                          




































                                                                                             
                                   
                               






                                                                               
                                                                      
 

                                                       


                                                                              
                                                                              
         

 

                       
<?php

$dest = @readlink($_SERVER['SCRIPT_FILENAME']);
if (!empty($dest) && $dest !== $_SERVER['SCRIPT_FILENAME']) {
	chdir(dirname($dest));
}

require_once 'config.php';

if (defined('CONFIG_FORCE_DOMAIN')) {
	if (!empty($_SERVER['SERVER_NAME']) && strcasecmp($_SERVER['SERVER_NAME'], CONFIG_FORCE_DOMAIN) !== 0) {
		Header('HTTP/1.1 400 Bad Request');
		die('<h1>Bad Request</h1>');
	}
}


/**
 * Page class which all "modules" must be extending from
 */
abstract class Page
{

	protected function doPreprocess()
	{
		
	}

	protected function doRender()
	{
		
	}

	protected function doAjax()
	{
		
	}

	public static function preprocess()
	{
		self::$instance->doPreprocess();
	}

	public static function render()
	{
		self::$instance->doRender();
	}

	public static function ajax()
	{
		self::$instance->doAjax();
	}

	/**
	 *
	 * @var \Page
	 */
	private static $instance = false;

	public static function set($name)
	{
		$name = preg_replace('/[^A-Za-z]/', '', $name);
		$modulePath = 'modules/' . strtolower($name) . '.inc.php';
		if (!file_exists($modulePath)) {
			Util::traceError('Invalid module file: ' . $modulePath);
		}
		require_once $modulePath;
		$className = 'Page_' . $name;
		if (!class_exists($className) || get_parent_class($className) !== 'Page') {
			Util::traceError('Module not found: ' . $name);
		}
		self::$instance = new $className();
	}

}

// Error reporting (hopefully going to stderr, not being printed on pages)
error_reporting(E_ALL);

// Autoload classes from ./inc which adhere to naming scheme <lowercasename>.inc.php
function slxAutoloader($class)
{
	$file = 'inc/' . preg_replace('/[^a-z0-9]/', '', mb_strtolower($class)) . '.inc.php';
	if (!file_exists($file))
		return;
	require_once $file;
}

spl_autoload_register('slxAutoloader');

// Now determine which module to run
Page::set(empty($_REQUEST['do']) ? 'Main' : $_REQUEST['do']);

// Deserialize any messages to display
if (isset($_REQUEST['message'])) {
	Message::fromRequest();
}

// CSRF/XSS check
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
	User::load();
	if (!Util::verifyToken()) {
		Util::redirect('?do=Main');
	}
}

// Normal mode - preprocess first....
Page::preprocess();

// Generate Main menu
User::load();
Render::addTemplate('main-menu', array(
	'url' => urlencode($_SERVER['REQUEST_URI']),
	'user' => User::getName(),
	'admin' => User::isAdmin(),
	'suite' => CONFIG_SUITE
));

Message::renderList();

// Render page. If the module wants to output anything, it will be done here...
Page::render();

Render::addTemplate('footer', array('help' => CONFIG_FOOTER_SUPPORT));

if (defined('CONFIG_DEBUG') && CONFIG_DEBUG) {
	Message::addWarning('!! Debug-Modus aktiv !!');
	if(User::isAdmin()) {
		Message::addWarning(User::getShibId());
		Message::addWarning('<pre>'.print_r($_SERVER, true).'</pre>');
		Message::addWarning('<pre>'.print_r($_COOKIE, true).'</pre>');
	}
}

// Send page to client.
Render::output();