administrator/index.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /*******************************************************************************
00004  * Aliro - the modern, accessible content management system
00005  *
00006  * Aliro is open source software, free to use, and licensed under GPL.
00007  * You can find the full licence at http://www.gnu.org/copyleft/gpl.html GNU/GPL
00008  *
00009  * The author freely draws attention to the fact that Aliro derives from Mambo,
00010  * software that is controlled by the Mambo Foundation.  However, this section
00011  * of code is totally new.  If it should contain any fragments that are similar
00012  * to Mambo, please bear in mind (1) there are only so many ways to do things
00013  * and (2) the author of Aliro is also the author and copyright owner for large
00014  * parts of Mambo 4.6.
00015  *
00016  * Tribute should be paid to all the developers who took Mambo to the stage
00017  * it had reached at the time Aliro was created.  It is a feature rich system
00018  * that contains a good deal of innovation.
00019  *
00020  * Your attention is also drawn to the fact that Aliro relies on other items of
00021  * open source software, which is very much in the spirit of open source.  Aliro
00022  * wishes to give credit to those items of code.  Please refer to
00023  * http://aliro.org/credits for details.  The credits are not included within
00024  * the Aliro package simply to avoid providing a marker that allows hackers to
00025  * identify the system.
00026  *
00027  * Copyright in this code is strictly reserved by its author, Martin Brampton.
00028  * If it seems appropriate, the copyright will be vested in the Aliro Organisation
00029  * at a suitable time.
00030  *
00031  * Copyright (c) 2007 Martin Brampton
00032  *
00033  * http://aliro.org
00034  *
00035  * counterpoint@aliro.org
00036  *
00037  * This is the starting point for all admin interactions with Aliro, the index.php
00038  * file for the admin side.  It contains a minimum of code.  It is designed so that
00039  * it should be possible to vary the name of the administrator directory, although
00040  * this name is so entrenched in add-on software that it is likely to be hard to
00041  * achieve.
00042  *
00043  * The criticalInfo class is a very simple class to obtain basic directory
00044  * information in a way that should be resistant to hacking.  There is a slightly
00045  * different version of this class in the user side index.php and this one gives
00046  * more information, including the name of the administrator directory.
00047  *
00048  * __autoload is one of a tiny number of functions outside classes.  It is a special
00049  * PHP5 name and is invoked whenever there is a reference to an unknown class.
00050  * The smart class mapper is used to try to locate the class, in which case it is
00051  * loaded.  There are very few uses of "require" or "include" in the core of Aliro
00052  * and this is one of the few.  It is important that they be resistant to hacker
00053  * attempts to load external code.
00054  *
00055  * The startup function exists so that the amount of code executing in a global
00056  * context is minimal.  It checks for attempts to inject values into global data.
00057  * Then it loads essential classes using robust file paths, and invokes the admin
00058  * side logic of the class aliroRequest.
00059  *
00060  * The code initially executed simply buffers all output so that any diagnostic
00061  * output (deliberate or accidental) during core processing and the running of
00062  * components, modules and mambots is trapped until after headers have been sent.
00063  * Or indefinitely for any component that wishes to send a file to the browser,
00064  * or similar.
00065  *
00066  */
00067 
00068 
00070 define( '_VALID_MOS', 1 );
00071 
00072 class criticalInfo {
00073     private static $instance = __CLASS__;
00074     public $absolute_path;
00075     public $admin_absolute_path;
00076     public $admin_dir;
00077     public $class_base;
00078     public $isAdmin = true;
00079 
00080     private function __construct() {
00081         $this->admin_absolute_path = str_replace('\\', '/', dirname(__FILE__));
00082         define ('_ALIRO_ADMIN_PATH', $this->admin_absolute_path);
00083         define ('_ALIRO_CURRENT_PATH', $this->admin_absolute_path);
00084         $this->absolute_path = dirname($this->admin_absolute_path);
00085         define('_ALIRO_ABSOLUTE_PATH', $this->absolute_path);
00086         $this->admin_dir = substr($this->admin_absolute_path, strlen($this->absolute_path));
00087         define ('_ALIRO_ADMIN_DIR', $this->admin_dir);
00088         if (!defined('_ALIRO_CLASS_BASE')) define ('_ALIRO_CLASS_BASE', $this->absolute_path);
00089         $this->class_base = _ALIRO_CLASS_BASE;
00090         define ('_ALIRO_IS_ADMIN', 1);
00091     }
00092 
00093     public static function getInstance () {
00094         return is_object(self::$instance) ? self::$instance : (self::$instance = new self::$instance);
00095     }
00096 
00097 }
00098 
00099 class aliro {
00100     private static $instance = __CLASS__;
00101     private $timer = null;
00102     public $installed = false;
00103 
00104     public static function getInstance () {
00105         if (!is_object(self::$instance)) {
00106             self::$instance = new self::$instance();
00107             $critical = criticalInfo::getInstance();
00108         }
00109         return self::$instance;
00110     }
00111 
00112     public function classExists ($classname) {
00113         return smartAdminClassMapper::getInstance()->classExists($classname);
00114     }
00115     
00116     public function requireClass ($classname) {
00117         smartAdminClassMapper::getInstance()->requireClass($classname);
00118     }
00119 
00120     public function startup () {
00121 
00122         $protects = array('_REQUEST', '_GET', '_POST', '_COOKIE', '_FILES', '_SERVER', '_ENV', 'GLOBALS', '_SESSION');
00123 
00124         foreach ($protects as $protect) {
00125             if ( in_array($protect , array_keys($_REQUEST)) ||
00126             in_array($protect , array_keys($_GET)) ||
00127             in_array($protect , array_keys($_POST)) ||
00128             in_array($protect , array_keys($_COOKIE)) ||
00129             in_array($protect , array_keys($_FILES))) {
00130                 die('Invalid Request.');
00131             }
00132         }
00133         if (false !== strpos($_SERVER['REQUEST_URI'], 'mosConfig_absolute_path')) die ('Invalid Request.');
00134 
00135         $abovedir = dirname(dirname(__FILE__));
00136         require_once ($abovedir.'/definitions.php');
00137 
00138         $filepath = _ALIRO_CLASS_BASE.'/configs/'.md5(_ALIRO_ABSOLUTE_PATH.'/configuration.php').'.php';
00139         if (file_exists($filepath) AND filesize($filepath) > 10 ) $this->installed = true;
00140 
00141         $thisdir = _ALIRO_CLASS_BASE._ALIRO_ADMIN_DIR;
00142         require_once (_ALIRO_CLASS_BASE.'/objectcache.php');
00143         $this->timer = new aliroProfiler();
00144         // The include path is needed for HTMLpurifier (will possibly serve for other extensions too):
00145         set_include_path(_ALIRO_CLASS_BASE.'/extclasses/'.PATH_SEPARATOR.get_include_path());
00146         require_once (_ALIRO_CLASS_BASE.'/extclasses/HTMLPurifier/Bootstrap.php');
00147         require_once (_ALIRO_CLASS_BASE.'/classloader.php');
00148         require_once ($thisdir.'/classloader.php');
00149         smartAdminClassMapper::getInstance();
00150         if (!$this->installed) {
00151             $newinstall = new aliroInstall();
00152             $newinstall->install();
00153             exit();
00154         }
00155         $controller = aliroRequest::getInstance();
00156         $errorhandler = aliroErrorRecorder::getInstance();
00157         set_error_handler(array($errorhandler, 'PHPerror'));
00158         new aliroJoomla();
00159         $controller->doControl();
00160     }
00161 
00162     public function getElapsed () {
00163         return $this->timer->getElapsed();
00164     }
00165     
00166     public function getTimeMessage () {
00167         return sprintf(T_('Time to generate page %s seconds'), $this->getElapsed());
00168     }
00169 }
00170 
00171 ob_start();
00172 ob_implicit_flush(false);
00173 aliro::getInstance()->startup();

Generated on Wed May 14 13:01:56 2008 for ALIRO by  doxygen 1.5.5