Merge branch 'feature/user-preference-api-4066'

resolves #4066
This commit is contained in:
Eric Lippmann 2013-07-30 14:09:35 +02:00
commit 14a30ccaf5
21 changed files with 792 additions and 320 deletions

View File

@ -36,7 +36,7 @@ class ModulesController extends ActionController
public function init()
{
$this->manager = Icinga::app()->moduleManager();
$this->manager = Icinga::app()->getModuleManager();
}
public function indexAction()

View File

@ -17,7 +17,7 @@ class StaticController extends ActionController
private function getModuleList()
{
$modules = Icinga::app()->moduleManager()->getLoadedModules();
$modules = Icinga::app()->getModuleManager()->getLoadedModules();
// preliminary static definition
$result = array();

View File

@ -30,7 +30,8 @@ namespace Icinga\Application;
use Icinga\Application\Modules\Manager as ModuleManager;
use Icinga\Application\Platform;
use Zend_Loader_Autoloader as ZendLoader;
use Icinga\Exception\ProgrammingError;
use Zend_Loader_Autoloader;
use Icinga\Exception\ConfigurationError;
/**
@ -54,21 +55,63 @@ use Icinga\Exception\ConfigurationError;
* use Icinga\Application\LegacyWeb;
* LegacyWeb::start()->setIcingaWebBasedir(ICINGAWEB_BASEDIR)->dispatch();
* </code>
*
* @copyright Copyright (c) 2013 Icinga-Web Team <info@icinga.org>
* @author Icinga-Web Team <info@icinga.org>
* @package Icinga\Application
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
*/
abstract class ApplicationBootstrap
{
protected $loader;
protected $libdir;
protected $config;
protected $configDir;
protected $appdir;
protected $moduleManager;
/**
* Icinga auto loader
*
* @var Loader
*/
private $loader;
/**
* Library directory
*
* @var string
*/
private $libDir;
/**
* Config object
*
* @var Config
*/
private $config;
/**
* Configuration directory
*
* @var string
*/
private $configDir;
/**
* Application directory
*
* @var string
*/
private $appDir;
/**
* Module manager
*
* @var ModuleManager
*/
private $moduleManager;
/**
* Flag indicates we're on cli environment
*
* @var bool
*/
protected $isCli = false;
/**
* Flag indicates we're on web environment
*
* @var bool
*/
protected $isWeb = false;
/**
@ -78,52 +121,50 @@ abstract class ApplicationBootstrap
*/
protected function __construct($configDir)
{
$this->checkPrerequisites();
$this->libDir = realpath(__DIR__. '/../..');
$this->libdir = realpath(__DIR__. '/../..');
if (! defined('ICINGA_LIBDIR')) {
define('ICINGA_LIBDIR', $this->libdir);
if (!defined('ICINGA_LIBDIR')) {
define('ICINGA_LIBDIR', $this->libDir);
}
// TODO: Make appdir configurable for packagers
$this->appdir = realpath($this->libdir. '/../application');
$this->appDir = realpath($this->libDir. '/../application');
if (! defined('ICINGA_APPDIR')) {
define('ICINGA_APPDIR', $this->appdir);
if (!defined('ICINGA_APPDIR')) {
define('ICINGA_APPDIR', $this->appDir);
}
$this->registerAutoloader();
$this->registerZendAutoloader();
$this->setupAutoloader();
$this->setupZendAutoloader();
Benchmark::measure('Bootstrap, autoloader registered');
Icinga::setApp($this);
// Unfortunately this is needed to get the Zend Plugin loader working:
set_include_path(
implode(
PATH_SEPARATOR,
array($this->libdir, get_include_path())
)
);
$this->configDir = $configDir;
require_once dirname(__FILE__) . '/functions.php';
}
/**
* Bootstrap interface method for concrete bootstrap objects
*
* @return mixed
*/
abstract protected function bootstrap();
public function moduleManager()
/**
* Getter for module manager
*
* @return ModuleManager
*/
public function getModuleManager()
{
if ($this->moduleManager === null) {
$this->moduleManager = new ModuleManager($this, $this->configDir . '/enabledModules');
}
return $this->moduleManager;
}
/**
* Getter for class loader
*
* @return Loader
*/
public function getLoader()
@ -131,68 +172,84 @@ abstract class ApplicationBootstrap
return $this->loader;
}
protected function loadEnabledModules()
/**
* Getter for configuration object
*
* @return Config
*/
public function getConfig()
{
$this->moduleManager()->loadEnabledModules();
return $this;
return $this->config;
}
/**
* Flag indicates we're on cli environment
*
* @return bool
*/
public function isCli()
{
return $this->isCli;
}
/**
* Flag indicates we're on web environment
*
* @return bool
*/
public function isWeb()
{
return $this->isWeb;
}
/**
* Getter for application dir
*
* Optional append sub directory
*
* @param null|string $subdir optional subdir
* @return string
*/
public function getApplicationDir($subdir = null)
{
$dir = $this->appdir;
$dir = $this->appDir;
if ($subdir !== null) {
$dir .= '/' . ltrim($subdir, '/');
}
return $dir;
}
public function hasModule($name)
{
return $this->moduleManager()->hasLoaded($name);
}
public function getModule($name)
{
return $this->moduleManager()->getModule($name);
}
public function loadModule($name)
{
return $this->moduleManager()->loadModule($name);
}
public function getConfig()
{
return $this->config;
}
/**
* Starting concrete bootstrap classes
*
* @param string $configDir
* @return ApplicationBootstrap
*/
public static function start($configDir)
{
$class = get_called_class();
/** @var ApplicationBootstrap $obj */
$obj = new $class($configDir);
$obj->bootstrap();
return $obj;
}
public function registerAutoloader()
/**
* Setup icinga auto loader
*
* @return self
*/
public function setupAutoloader()
{
require $this->libdir. '/Icinga/Exception/ProgrammingError.php';
require $this->libdir. '/Icinga/Application/Loader.php';
require $this->libDir. '/Icinga/Exception/ProgrammingError.php';
require $this->libDir. '/Icinga/Application/Loader.php';
$this->loader = new Loader();
$this->loader->registerNamespace('Icinga', $this->libdir. '/Icinga');
$this->loader->registerNamespace('Icinga\\Form', $this->appdir. '/forms');
$this->loader->registerNamespace('Icinga', $this->libDir. '/Icinga');
$this->loader->registerNamespace('Icinga\\Form', $this->appDir. '/forms');
$this->loader->register();
return $this;
}
/**
@ -200,46 +257,35 @@ abstract class ApplicationBootstrap
*
* @return self
*/
protected function registerZendAutoloader()
protected function setupZendAutoloader()
{
require_once 'Zend/Loader/Autoloader.php';
ZendLoader::getInstance();
\Zend_Loader_Autoloader::getInstance();
// Unfortunately this is needed to get the Zend Plugin loader working:
set_include_path(
implode(
PATH_SEPARATOR,
array($this->libDir, get_include_path())
)
);
return $this;
}
/**
* Check whether we have all we need
*
* Pretty useless right now as a namespaces class would not work
* with PHP 5.3
* Setup module loader and all enabled modules
*
* @return self
*/
protected function checkPrerequisites()
protected function setupModules()
{
if (version_compare(phpversion(), '5.3.0', '<') === true) {
die('PHP > 5.3.0 required');
}
return $this;
}
$this->moduleManager = new ModuleManager($this, $this->configDir . '/enabledModules');
/**
* Check whether a given PHP extension is available
*
* @return boolean
*/
protected function hasExtension($name)
{
if (!extension_loaded($name)) {
if (! @ dl($name)) {
throw new ConfigurationError(
sprintf(
'The PHP extension %s is not available',
$name
)
);
}
}
$this->moduleManager->loadEnabledModules();
return $this;
}
/**
@ -247,34 +293,19 @@ abstract class ApplicationBootstrap
*
* @return self
*/
protected function loadConfig()
protected function setupConfig()
{
Config::$configDir = $this->configDir;
$this->config = Config::app();
return $this;
}
/**
* Configure cache settings
*
* TODO: Right now APC is hardcoded, make this configurable
*
* @return self
*/
protected function configureCache()
{
// TODO: Provide Zend_Cache_Frontend_File for statusdat
//$this->cache = \Zend_Cache::factory('Core', 'Apc');
return $this;
}
/**
* Error handling configuration
*
* @return self
*/
protected function configureErrorHandling()
protected function setupErrorHandling()
{
if ($this->config->get('global', 'environment') == 'development') {
error_reporting(E_ALL | E_NOTICE);
@ -286,15 +317,16 @@ abstract class ApplicationBootstrap
}
/**
* Set timezone settings
* Setup default timezone
*
* @return self
*/
protected function setTimezone()
protected function setupTimezone()
{
date_default_timezone_set(
$this->config->global->get('timezone', 'UTC')
);
return $this;
}
}

View File

@ -1,9 +1,43 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Application;
require_once dirname(__FILE__) . '/ApplicationBootstrap.php';
// @codingStandardsIgnoreStart
require_once dirname(__FILE__). '/ApplicationBootstrap.php';
require_once dirname(__FILE__). '/../Exception/ProgrammingError.php';
// @codingStandardsIgnoreStop
use Icinga\Exception\ProgrammingError;
/**
* Bootstrapping on cli environment
*/
class Cli extends ApplicationBootstrap
{
protected $isCli = true;
@ -11,22 +45,23 @@ class Cli extends ApplicationBootstrap
protected function bootstrap()
{
$this->assertRunningOnCli();
return $this->loadConfig()
->configureErrorHandling()
->setTimezone();
return $this->setupConfig()
->setupErrorHandling()
->setupTimezone();
}
/**
* Fail if Icinga has not been called on CLI
*
* @throws Exception
* @return void
* @throws \Exception
*/
private static function assertRunningOnCli()
private function assertRunningOnCli()
{
if (Platform::isCli()) {
return;
}
throw new Exception('Icinga is not running on CLI');
throw new ProgrammingError('Icinga is not running on CLI');
}
}

View File

@ -1,13 +1,37 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* Run embedded in other web applications
* This file is part of Icinga 2 Web.
*
* @package Icinga\Application
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Application;
// @codingStandardsIgnoreStart
require_once dirname(__FILE__) . '/ApplicationBootstrap.php';
// @codingStandardsIgnoreStop
use Icinga\Exception\ProgrammingError;
/**
@ -18,19 +42,20 @@ use Icinga\Exception\ProgrammingError;
* use Icinga\Application\EmbeddedWeb;
* EmbeddedWeb::start();
* </code>
*
* @copyright Copyright (c) 2013 Icinga-Web Team <info@icinga.org>
* @author Icinga-Web Team <info@icinga.org>
* @package Icinga\Application
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
*/
class EmbeddedWeb extends ApplicationBootstrap
{
/**
* Embedded bootstrap parts
*
* @see ApplicationBootstrap::bootstrap
* @return self
*/
protected function bootstrap()
{
return $this->loadConfig()
->configureErrorHandling()
->setTimezone()
->loadEnabledModules();
return $this->setupConfig()
->setupErrorHandling()
->setupTimezone()
->setupModules();
}
}

View File

@ -1,26 +1,72 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Application;
use Icinga\Exception\ProgrammingError;
/**
* Icinga application container
*/
class Icinga
{
protected static $app;
/**
* @var ApplicationBootstrap
*/
private static $app;
/**
* Getter for an application environment
*
* @return ApplicationBootstrap|Web
* @throws ProgrammingError
*/
public static function app()
{
if (null === self::$app) {
if (self::$app == null) {
throw new ProgrammingError('Icinga has never been started');
}
return self::$app;
}
public static function setApp($app)
/**
* Setter for an application environment
*
* @param ApplicationBootstrap $app
* @throws ProgrammingError
*/
public static function setApp(ApplicationBootstrap $app)
{
if (null !== self::$app) {
if (self::$app !== null) {
throw new ProgrammingError('Cannot start Icinga twice');
}
self::$app = $app;
}
}

View File

@ -30,6 +30,7 @@ namespace Icinga\Application\Modules;
use Icinga\Application\ApplicationBootstrap;
use Icinga\Application\Config;
use Icinga\Application\Icinga;
use Icinga\Web\Hook;
use Zend_Controller_Router_Route as Route;
@ -42,58 +43,74 @@ class Module
{
/**
* Module name
*
* @var string
*/
private $name;
/**
* Base directory of module
*
* @var string
*/
private $basedir;
/**
* Directory for styles
*
* @var string
*/
private $cssdir;
/**
* Library directory
*
* @var string
*/
private $libdir;
/**
* Directory containing translations
*
* @var string
*/
private $localedir;
/**
* Directory where controllers reside
*
* @var string
*/
private $controllerdir;
/**
* Directory containing form implementations
*
* @var string
*/
private $formdir;
/**
* Module bootstrapping script
*
* @var string
*/
private $registerscript;
/**
* Icinga application
* @var \Icinga\Application\ApplicationBootstrap
*
* @var \Icinga\Application\Web
*/
private $app;
/**
* Create a new module object
*
* @param ApplicationBootstrap $app
* @param string $name
* @param strinb $basedir
*/
public function __construct(ApplicationBootstrap $app, $name, $basedir)
{
$this->app = $app;
@ -110,6 +127,7 @@ class Module
/**
* Register module
*
* @return bool
*/
public function register()
@ -122,18 +140,26 @@ class Module
/**
* Test for an enabled module by name
*
* @param string $name
* @return boolean
*/
public static function exists($name)
{
return Icinga::app()->moduleManager()->hasEnabled($name);
return Icinga::app()->getModuleManager()->hasEnabled($name);
}
/**
* Get module by name
*
* @param string $name
* @param bool $autoload
* @return mixed
*/
public static function get($name, $autoload = false)
{
$manager = Icinga::app()->moduleManager();
if (! $manager->hasLoaded($name)) {
$manager = Icinga::app()->getModuleManager();
if (!$manager->hasLoaded($name)) {
if ($autoload === true && $manager->hasEnabled($name)) {
$manager->loadModule($name);
}
@ -144,6 +170,7 @@ class Module
/**
* Test if module provide css
*
* @return bool
*/
public function hasCss()
@ -153,6 +180,8 @@ class Module
/**
* Getter for module name
*
* @return string
*/
public function getName()
{
@ -161,6 +190,7 @@ class Module
/**
* Getter for css file name
*
* @return string
*/
public function getCssFilename()
@ -179,6 +209,7 @@ class Module
/**
* Getter for library directory
*
* @return string
*/
public function getLibDir()
@ -188,6 +219,7 @@ class Module
/**
* Getter for configuration directory
*
* @return string
*/
public function getConfigDir()
@ -197,6 +229,7 @@ class Module
/**
* Getter for form directory
*
* @return string
*/
public function getFormDir()
@ -206,7 +239,8 @@ class Module
/**
* Getter for module config object
* @param null|string $file
*
* @param null|string $file
* @return Config
*/
public function getConfig($file = null)
@ -218,7 +252,8 @@ class Module
/**
* Register new namespaces on the autoloader
* @return Module
*
* @return self
*/
protected function registerAutoloader()
{
@ -237,7 +272,8 @@ class Module
/**
* Bind text domain for i18n
* @return Module
*
* @return self
*/
protected function registerLocales()
{
@ -252,7 +288,7 @@ class Module
*
* Add controller directory to mvc
*
* @return Module
* @return self
*/
protected function registerWebIntegration()
{
@ -261,7 +297,7 @@ class Module
}
if (file_exists($this->controllerdir) && is_dir($this->controllerdir)) {
$this->app->frontController()->addControllerDirectory(
$this->app->getfrontController()->addControllerDirectory(
$this->controllerdir,
$this->name
);
@ -275,14 +311,15 @@ class Module
/**
* Register menu entries
* @return Module
*
* @return self
*/
protected function registerMenuEntries()
{
$cfg = $this->app
->getConfig()
->module($this->name, 'menu');
$view = $this->app->getView();
$view = $this->app->getViewRenderer();
if ($cfg) {
$view->view->navigation = $cfg->merge($view->view->navigation);
}
@ -291,11 +328,12 @@ class Module
/**
* Register routes for web access
* @return Module
*
* @return self
*/
protected function registerRoutes()
{
$this->app->frontController()->getRouter()->addRoute(
$this->app->getFrontController()->getRouter()->addRoute(
$this->name . '_jsprovider',
new Route(
'js/' . $this->name . '/:file',
@ -306,7 +344,7 @@ class Module
)
)
);
$this->app->frontController()->getRouter()->addRoute(
$this->app->getFrontController()->getRouter()->addRoute(
$this->name . '_img',
new Route(
'img/' . $this->name . '/:file',
@ -322,7 +360,8 @@ class Module
/**
* Run module bootstrap script
* @return Module
*
* @return self
*/
protected function runRegisterScript()
{
@ -335,10 +374,11 @@ class Module
/**
* Register hook
*
* @param string $name
* @param string $class
* @param string $key
* @return Module
* @return self
*/
protected function registerHook($name, $key, $class)
{

View File

@ -2,24 +2,24 @@
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
@ -28,14 +28,17 @@
namespace Icinga\Application;
use Icinga\Authentication\Manager;
use Zend_Controller_Front as FrontController;
use Zend_Layout as Layout;
use Zend_Paginator as Paginator;
use Zend_View_Helper_PaginationControl as PaginationControl;
use Zend_Controller_Action_HelperBroker as ActionHelper;
use Zend_Controller_Router_Route as Route;
use Icinga\Web\View as IcingaView;
use Icinga\Authentication\Manager as AuthenticationManager;
use Icinga\User\Preferences;
use Icinga\Web\Request;
use Zend_Controller_Front;
use Zend_Layout;
use Zend_Paginator;
use Zend_View_Helper_PaginationControl;
use Zend_Controller_Action_HelperBroker;
use Zend_Controller_Router_Route;
use Zend_Controller_Action_Helper_ViewRenderer;
use Icinga\Web\View;
/**
* Use this if you want to make use of Icinga funtionality in other web projects
@ -45,77 +48,114 @@ use Icinga\Web\View as IcingaView;
* use Icinga\Application\EmbeddedWeb;
* EmbeddedWeb::start();
* </code>
*
* @copyright Copyright (c) 2013 Icinga-Web Team <info@icinga.org>
* @author Icinga-Web Team <info@icinga.org>
* @package Icinga\Application
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
*/
class Web extends ApplicationBootstrap
{
protected $view;
protected $frontController;
/**
* View object
*
* @var View
*/
private $viewRenderer;
/**
* Zend front controller instance
*
* @var Zend_Controller_Front
*/
private $frontController;
/**
* Request object
*
* @var Request
*/
private $request;
/**
* Identify web bootstrap
*
* @var bool
*/
protected $isWeb = true;
/**
* Initialize all together
*
* @return self
*/
protected function bootstrap()
{
return $this->loadConfig()
->configureErrorHandling()
->setTimezone()
->configureCache()
->prepareZendMvc()
->loadTranslations()
->loadEnabledModules()
->setupSpecialRoutes()
->configurePagination();
return $this->setupConfig()
->setupErrorHandling()
->setupTimezone()
->setupRequest()
->setupZendMvc()
->setupTranslation()
->setupModules()
->setupRoute()
->setupPagination();
}
protected function setupSpecialRoutes()
/**
* Prepare routing
*
* @return self
*/
private function setupRoute()
{
// TODO: Find a better solution
$this->frontController->getRouter()->addRoute(
'module_overview',
new Route(
new Zend_Controller_Router_Route(
'js/modules/list.js',
array(
'controller' => 'static',
'action' => 'modulelist',
'action' => 'modulelist',
)
)
);
$this->frontController->getRouter()->addRoute(
'module_javascript',
new Route(
new Zend_Controller_Router_Route(
'js/modules/:module_name/:file',
array(
'controller' => 'static',
'action' => 'javascript'
'action' => 'javascript'
)
)
);
return $this;
}
public function frontController()
/**
* Getter for frontController
*
* @return Zend_Controller_Front
*/
public function getFrontController()
{
// TODO: ProgrammingError if null
return $this->frontController;
}
public function getView()
/**
* Getter for view
*
* @return View
*/
public function getViewRenderer()
{
// TODO: ProgrammingError if null
return $this->view;
return $this->viewRenderer;
}
public function dispatch()
{
$this->dispatchFrontController();
}
protected function loadTranslations()
/**
* Load translations
*
* @return self
*/
private function setupTranslation()
{
// AuthManager::getInstance()->getSession()->language;
$locale = null;
@ -124,16 +164,17 @@ class Web extends ApplicationBootstrap
}
putenv('LC_ALL=' . $locale . '.UTF-8');
setlocale(LC_ALL, $locale . '.UTF-8');
bindtextdomain('icinga', ICINGA_APPDIR . '/locale');
bindtextdomain('icinga', $this->getApplicationDir() . '/locale');
textdomain('icinga');
return $this;
}
protected function dispatchFrontController()
/**
* Dispatch public interface
*/
public function dispatch()
{
// AuthManager::getInstance()->getSession();
$this->frontController->dispatch();
return $this;
}
/**
@ -141,25 +182,62 @@ class Web extends ApplicationBootstrap
*
* @return self
*/
protected function prepareZendMvc()
private function setupZendMvc()
{
// TODO: Replace Zend_Application:
Layout::startMvc(
Zend_Layout::startMvc(
array(
'layout' => 'layout',
'layoutPath' => $this->appdir . '/layouts/scripts'
'layout' => 'layout',
'layoutPath' => $this->getApplicationDir('/layouts/scripts')
)
);
return $this->prepareFrontController()
->prepareView();
$this->setupFrontController();
$this->setupViewRenderer();
return $this;
}
protected function prepareFrontController()
/**
* Inject dependencies into request
*
* @return self
*/
private function setupRequest()
{
$this->frontController = FrontController::getInstance();
$this->request = new Request();
$this->frontController->setControllerDirectory($this->appdir . '/controllers');
$authenticationManager = AuthenticationManager::getInstance(
null,
array(
'writeSession' => true
)
);
if ($authenticationManager->isAuthenticated() === true) {
$user = $authenticationManager->getUser();
$preferences = new Preferences();
$user->setPreferences($preferences);
$this->request->setUser($user);
}
return $this;
}
/**
* Instantiate front controller
*
* @return self
*/
private function setupFrontController()
{
$this->frontController = Zend_Controller_Front::getInstance();
$this->frontController->setRequest($this->request);
$this->frontController->setControllerDirectory($this->getApplicationDir('/controllers'));
$this->frontController->setParams(
array(
@ -170,43 +248,52 @@ class Web extends ApplicationBootstrap
return $this;
}
protected function prepareView()
/**
* Register helper paths and views for renderer
*
* @return self
*/
private function setupViewRenderer()
{
$view = ActionHelper::getStaticHelper('viewRenderer');
$view->setView(new IcingaView());
/** @var \Zend_Controller_Action_Helper_ViewRenderer $view */
$view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$view->setView(new View());
$view->view->addHelperPath($this->appdir . '/views/helpers');
$view->view->addHelperPath($this->getApplicationDir('/views/helpers'));
// TODO: find out how to avoid this additional helper path:
$view->view->addHelperPath($this->appdir . '/views/helpers/layout');
$view->view->addHelperPath($this->getApplicationDir('/views/helpers/layout'));
$view->view->setEncoding('UTF-8');
$view->view->headTitle()->prepend(
$this->config->{'global'}->get('project', 'Icinga')
$this->getConfig()->{'global'}->get('project', 'Icinga')
);
$view->view->headTitle()->setSeparator(' :: ');
$view->view->navigation = $this->config->app('menu');
$this->view = $view;
$view->view->headTitle()->setSeparator(' :: ');
$view->view->navigation = $this->getConfig()->app('menu');
$this->viewRenderer = $view;
return $this;
}
/**
* Configure pagination settings
*
* @return self
*/
protected function configurePagination()
private function setupPagination()
{
Paginator::addScrollingStylePrefixPath(
Zend_Paginator::addScrollingStylePrefixPath(
'Icinga_Web_Paginator_ScrollingStyle',
'Icinga/Web/Paginator/ScrollingStyle'
);
Paginator::setDefaultScrollingStyle('SlidingWithBorder');
PaginationControl::setDefaultViewPartial(
Zend_Paginator::setDefaultScrollingStyle('SlidingWithBorder');
Zend_View_Helper_PaginationControl::setDefaultViewPartial(
array('mixedPagination.phtml', 'default')
);
return $this;
}
}

View File

@ -29,7 +29,7 @@
namespace Icinga\Authentication\Backend;
use Icinga\Authentication\User as User;
use Icinga\User;
use Icinga\Authentication\UserBackend;
use Icinga\Authentication\Credentials;
use Icinga\Authentication;

View File

@ -28,7 +28,7 @@
namespace Icinga\Authentication\Backend;
use Icinga\Authentication\User as User;
use Icinga\User;
use Icinga\Authentication\UserBackend;
use Icinga\Authentication\Credentials;
use Icinga\Protocol\Ldap;
@ -94,10 +94,16 @@ class LdapUserBackend implements UserBackend
protected function selectUsername($username)
{
return $this->connection->select()
->from(IcingaConfig::app('authentication')->users->user_class,
array(IcingaConfig::app('authentication')->users->user_name_attribute))
->where(IcingaConfig::app('authentication')->users->user_name_attribute,
$this->stripAsterisks($username));
->from(
IcingaConfig::app('authentication')->users->user_class,
array(
IcingaConfig::app('authentication')->users->user_name_attribute
)
)
->where(
IcingaConfig::app('authentication')->users->user_name_attribute,
$this->stripAsterisks($username)
);
}
/**

View File

@ -2,58 +2,115 @@
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Authentication;
namespace Icinga;
use Icinga\User\Preferences;
use InvalidArgumentException;
/**
* This class represents an authorized user and can be used
* to retrieve authorization information (@TODO: Not implemented yet) or
* to retrieve user information
* This class represents an authorized user
*
* You can retrieve authorization information (@TODO: Not implemented yet) or
* to retrieve user information
*
*/
class User
{
public $username = "";
public $firstname = "";
public $lastname = "";
public $email = "";
public $domain = "";
public $additionalInformation = array();
public $permissions = array();
public $groups = array();
/**
* Creates a user object given the provided information
*
* @param String $username
* @param String $firstname
* @param String $lastname
* @param String $email
**/
* Username
*
* @var string
*/
private $username;
/**
* Firstname
*
* @var string
*/
private $firstname;
/**
* Lastname
*
* @var string
*/
private $lastname;
/**
* Users email address
*
* @var string
*/
private $email;
/**
* Domain
*
* @var string
*/
private $domain;
/**
* More information about user
*
* @var array
*/
private $additionalInformation = array();
/**
* Set of permissions
*
* @var array
*/
private $permissions = array();
/**
* Groups for this user
*
* @var array
*/
private $groups = array();
/**
* Preferences object
*
* @var Preferences
*/
private $preferences;
/**
* Creates a user object given the provided information
*
* @param string $username
* @param string $firstname
* @param string $lastname
* @param string $email
*/
public function __construct($username, $firstname = null, $lastname = null, $email = null)
{
$this->setUsername($username);
@ -72,143 +129,186 @@ class User
}
/**
* Returns all groups this user belongs to
*
* @return Array
**/
* Setter for preferences
*
* @param Preferences $preferences
*/
public function setPreferences(Preferences $preferences)
{
$this->preferences = $preferences;
}
/**
* Getter for preferences
*
* @return Preferences
*/
public function getPreferences()
{
return $this->preferences;
}
/**
* Return all groups this user belongs to
*
* @return array
*/
public function getGroups()
{
return $this->groups;
}
/**
* Sets the groups this user belongs to
*
* @return Array
**/
* Set the groups this user belongs to
*/
public function setGroups(array $groups)
{
$this->groups = $groups;
}
/**
* Returns true if the user is a member of this group
*
* @return Boolean
**/
public function isMemberOf(Group $group)
* Return true if the user is a member of this group
*
* @param string $group
* @return boolean
*/
public function isMemberOf($group)
{
return in_array($group, $this->groups);
}
/**
* Returns permission information for this user
*
* @return Array
**/
* Return permission information for this user
*
* @return Array
*/
public function getPermissions()
{
return $this->permissions;
}
/**
* @return String
**/
* Getter for username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* @param String $name
**/
* Setter for username
*
* @param string $name
*/
public function setUsername($name)
{
$this->username = $name;
}
/**
* @return String
**/
* Getter for firstname
*
* @return string
*/
public function getFirstname()
{
return $this->firstname;
}
/*+
* @param String $name
**/
/**
* Setter for firstname
*
* @param string $name
*/
public function setFirstname($name)
{
$this->firstname = $name;
}
/**
* @return String
**/
* Getter for lastname
*
* @return string
*/
public function getLastname()
{
return $this->lastname;
}
/**
* @param String $name
**/
* Setter for lastname
*
* @param string $name
*/
public function setLastname($name)
{
$this->lastname = $name;
}
/**
* @return String
**/
* Getter for email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* @param String $mail
*
* @throws \InvalidArgumentException When an invalid mail is provided
**/
* Setter for mail
*
* @param string $mail
* @throws InvalidArgumentException When an invalid mail is provided
*/
public function setEmail($mail)
{
if (filter_var($mail, FILTER_VALIDATE_EMAIL)) {
$this->mail = $mail;
} else {
throw new \InvalidArgumentException("Invalid mail given for user $this->username: $mail");
throw new InvalidArgumentException("Invalid mail given for user $this->username: $mail");
}
}
/**
* @param String $domain
**/
* Setter for domain
*
* @param string $domain
*/
public function setDomain($domain)
{
$this->domain = $domain;
}
/**
* @return String
**/
* Getter for domain
*
* @return string
*/
public function getDomain()
{
return $this->domain;
}
/**
* @param String $key
* @param String $value
**/
* Set additional information about user
*
* @param string $key
* @param string $value
*/
public function setAdditional($key, $value)
{
$this->additionalInformation[$key] = $value;
}
/**
* @return mixed
**/
* Getter for additional information
*
* @param string $key
* @return mixed|null
*/
public function getAdditional($key)
{
if (isset($this->additionalInformation[$key])) {

View File

@ -0,0 +1,36 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\User;
/**
* Handling retrieve and persist of user preferences
*/
class Preferences
{
}

View File

@ -299,7 +299,7 @@ class ActionController extends ZfController
$css = $less->compileFile($cssdir . '/pdfprint.less');
/*
foreach (\Icinga\Application\Icinga::app()->moduleManager()->getLoadedModules() as $name => $module) {
foreach (\Icinga\Application\Icinga::app()->getModuleManager()->getLoadedModules() as $name => $module) {
if ($module->hasCss()) {
$css .= $less->compile(
'.icinga-module.module-'

View File

@ -0,0 +1,66 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Web;
use Icinga\Exception\ProgrammingError;
use Zend_Controller_Request_Http;
use Icinga\User;
/**
* Request to handle special attributes
*/
class Request extends Zend_Controller_Request_Http
{
/**
* User object
*
* @var User
*/
private $user;
/**
* Setter for user
*
* @param User $user
*/
public function setUser(User $user)
{
$this->user = $user;
}
/**
* Getter for user
*
* @return User
*/
public function getUser()
{
return $this->user;
}
}

View File

@ -15,7 +15,7 @@ class Url
public function __construct($url, $params = null, $request = null)
{
if ($request === null) {
$this->request = Icinga::app()->frontController()->getRequest();
$this->request = Icinga::app()->getFrontController()->getRequest();
} else {
// Tests only
$this->request = $request;
@ -158,4 +158,3 @@ class Url
return $base . $url;
}
}

View File

@ -46,7 +46,7 @@ class Form extends AbstractWidget
$module_name = null;
}
if ($module_name !== null) {
$fname = $app->moduleManager()->getModule($module_name)->getBaseDir()
$fname = $app->getModuleManager()->getModule($module_name)->getBaseDir()
. '/application/forms/'
. implode('/', $fparts)
. 'Form.php';

View File

@ -25,7 +25,7 @@
namespace Monitoring\Command;
use Icinga\Authentication\User;
use Icinga\User;
use Icinga\Exception\ProgrammingError;
/**

View File

View File

@ -4,13 +4,13 @@
namespace Tests\Icinga\Authentication;
require_once("../../library/Icinga/Authentication/Credentials.php");
require_once("../../library/Icinga/Authentication/UserBackend.php");
require_once("../../library/Icinga/Authentication/User.php");
require_once __DIR__. '/../../../../../library/Icinga/Authentication/Credentials.php';
require_once __DIR__. '/../../../../../library/Icinga/Authentication/UserBackend.php';
require_once __DIR__. '/../../../../../library/Icinga/User.php';
use Icinga\Authentication\Credentials as Credentials;
use Icinga\Authentication\UserBackend as UserBackend;
use Icinga\Authentication\User as User;
use Icinga\User;
/**
* Simple backend mock that takes an config object

View File

@ -39,12 +39,12 @@ require_once('../../library/Icinga/Protocol/Ldap/Exception.php');
require_once('../../library/Icinga/Application/Config.php');
require_once('../../library/Icinga/Authentication/Credentials.php');
require_once('../../library/Icinga/Authentication/Backend/DbUserBackend.php');
require_once('../../library/Icinga/Authentication/User.php');
require_once('../../library/Icinga/User.php');
use Icinga\Authentication\Backend\DbUserBackend;
use Icinga\Util\Crypto;
use Icinga\Authentication\Credentials;
use Icinga\Authentication\User;
use Icinga\User;
use Icinga\Application\Config;
/**

View File

@ -1,6 +1,6 @@
<?php
namespace Tests\Icinga\Authentication;
namespace Tests\Icinga;
/**
*
* Test class for User