<?php
/**
* SpotSec Backend
*
* LICENSE
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @category SpotSec_Backend
* @package Backend
* @copyright Copyright (c) 2006 SpotSec Networks
* @license GNU Public License
* @link http://www.spotsec.com
*/
/**
* WARNING: ENTER AT YOUR OWN RISK, SOURCE CODE AHEAD MAY WIELD HACKS
*/
/**
* Development/Debugging external file stuff
*
* This file is not committed to source control, but instead it is
* here to allow developers an extra hook for their development setup.
*/
if (file_exists('../application/configs/Devel.php')) {
include_once('../application/configs/Devel.php');
}
/**
* SpotSec_Error_Handler
*/
require_once('SpotSec/Error/Handler.php');
/**
* SpotSec_Exception_Handler
*/
require_once('SpotSec/Exception/Handler.php');
/**
* SpotSec_Log_Writer_Syslog
*/
require_once('SpotSec/Log/Writer/Syslog.php');
/**
* SpotSec_View
*/
require_once('SpotSec/View.php');
/**
* Zend
*/
require_once('Zend/Loader.php');
/**
* Zend_Log
*/
require_once('Zend/Log.php');
/**
* SpotSec Framework Bootstrap
*/
spl_autoload_register(array('Zend_Loader', 'autoload'));
set_error_handler(array(new SpotSec_Error_Handler(), 'globalErrorHandler'));
set_exception_handler(array(new SpotSec_Exception_Handler(), 'globalExceptionHandler'));
SpotSec_Config_Framework::getInstance()->loadConfig('../application/configs/SpotSec.xml', 'staging');
try {
/**
* Get basic configuration
*/
$basicConfig = new Zend_Config_Xml('../application/configs/config.xml', 'staging');
} catch (Exception $e) {
throw new SpotSec_Exception('Could not get configuration file: ' . $e->getMessage(), SpotSec_Exception::FATAL);
}
$backendConf = Backend_Config_Backend::getInstance();
$backendConf->setConfPath($basicConfig->paths->configData);
/**
* Backup for bug with SoapServer::handle()
*
* @todo remove when deemed safe
*/
if (! isset($HTTP_RAW_POST_DATA)){
$HTTP_RAW_POST_DATA = file_get_contents('php://input');
}
try {
/**
* Generate list of controllers
*/
$controllers = array();
$controllersPath = $basicConfig->paths->controllers;
$controllersSuffix = $basicConfig->controllers->fileSuffix;
$controllersFolder = new SpotSec_Folder($controllersPath);
/**
* Default controller dir
*/
$controllers['default'] = $controllersPath;
/**
* Push controllers into array
*/
foreach ($controllersFolder->getListing() as $controllerFolderItem) {
// Make sure folder item is a folder and does not start with a '.'
if (substr($controllerFolderItem, -14) != $controllersSuffix && $controllerFolderItem{0} != '.') {
$controllers[str_replace($controllersSuffix, '', $controllerFolderItem)] = $controllersPath . '/' . $controllerFolderItem;
}
}
} catch (Exception $e) {
/**
* Note: Exception is thrown later at the front controller
*/
}
/**
* Acls
*/
if ($backendConf->acl instanceof Zend_Acl) {
// Get stored acl object
$acl = $backendConf->acl;
} else {
$acl = new Zend_Acl();
// Default acls
$acl->add(new Zend_Acl_Resource('default_Login'));
$roleGuest = new Zend_Acl_Role('guest');
$acl->addRole($roleGuest);
$acl->allow($roleGuest, 'default_Login');
$backendConf->acl = $acl;
}
$aclPlugin = new Backend_Controller_Plugin_Acl_Adapter_Backend(array(
'module' => null,
'controller' => 'login',
'action' => 'index'
));
/**
* Http Auth
*/
/*
$authPlugin = new Zend_Auth_Adapter_Http(array(
'accept_schemes' => 'digest',
'realm' => '/',
'digest_domains' => '/',
'nonce_timeout' => 3600,
'proxy_auth' => false
));
$authPlugin->setDigestResolver(new Zend_Auth_Adapter_Http_Resolver_File('../application/configs/passwd'));
*/
/**
* Instantiate SpotSec_View object
*/
$view = new SpotSec_View();
$view->setScriptPath($basicConfig->paths->views);
$view->setWidgetPath('/mnt/StorageHD/Projects/spotsecng/trunk/Framework/src/usr/share/php/library/SpotSec/View/Widgets');
/**
* Setup front controller
*/
$frontController = Zend_Controller_Front::getInstance();
$frontController->setControllerDirectory($controllers)
//->registerPlugin(new SpotSec_Controller_Plugin_Auth_Http($authPlugin, null, 'login', 'index'))
->registerPlugin(new SpotSec_Controller_Plugin_Acl($acl, $aclPlugin))
->setParam('SpotSec_View', $view)
->setParam('Backend_Config', $basicConfig);
/**
* Dispatch front controller
*/
$frontController->dispatch();
/**
* Check for uncaught exceptions caught by the response object
*/
$response = $frontController->getResponse();
if ($response->isException()) {
foreach ($response->getException() as $e) {
/**
* Redirect to a pretty error page
*/
throw $e;
}
}