From 51755209b649aafd1bb993e7f8b58fba9bf50a43 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Fri, 12 Jul 2013 15:37:36 +0200
Subject: [PATCH] Adapt usage of config class

refs #4354
---
 Vagrantfile                                   |  4 +-
 application/controllers/ModulesController.php | 15 ++--
 .../layouts/scripts/parts/navigation.phtml    |  2 +-
 config/{icinga.ini => config.ini}             |  0
 .../modules/monitoring}/backends.ini          |  4 +-
 .../modules/monitoring}/instances.ini         |  0
 .../modules/monitoring}/menu.ini              |  0
 .../Application/ApplicationBootstrap.php      | 26 +++----
 library/Icinga/Application/Config.php         | 39 ++++++-----
 library/Icinga/Application/Modules/Module.php |  4 +-
 library/Icinga/Application/Web.php            |  2 +-
 .../Backend/LdapUserBackend.php               | 26 +++----
 library/Icinga/Authentication/Manager.php     | 68 +++++++++----------
 library/Icinga/Backend.php                    | 10 +--
 library/Icinga/Web/ActionController.php       | 23 ++++++-
 library/Icinga/Web/ModuleActionController.php |  4 +-
 .../monitoring/library/Monitoring/Backend.php |  5 +-
 public/css.php                                |  2 +-
 public/index.php                              |  2 +-
 19 files changed, 129 insertions(+), 107 deletions(-)
 rename config/{icinga.ini => config.ini} (100%)
 rename {modules/monitoring/config => config/modules/monitoring}/backends.ini (59%)
 rename {modules/monitoring/config => config/modules/monitoring}/instances.ini (100%)
 rename {modules/monitoring/config => config/modules/monitoring}/menu.ini (100%)

diff --git a/Vagrantfile b/Vagrantfile
index 5a6eaf508..79419bad3 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -48,6 +48,8 @@ Vagrant::Config.run do |config|
   # an identifier, the second is the path on the guest to mount the
   # folder, and the third is the path on the host to the actual folder.
   # # config.vm.share_folder "v-icinga2-web-pub", "/var/www/html/icinga2-web", "./pub"
+  config.vm.share_folder "v-test", "/vagrant/config", "./config", :owner => 'vagrant', :group => 'apache', :extra => 'dmode=775,fmode=775'
+  config.vm.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-test", "1"]
 
   # Enable provisioning with Puppet stand alone.  Puppet manifests
   # are contained in a directory path relative to this Vagrantfile.
@@ -56,7 +58,7 @@ Vagrant::Config.run do |config|
   config.vm.provision :puppet do |puppet|
     puppet.module_path = ".vagrant-puppet/modules"
     puppet.manifests_path = ".vagrant-puppet/manifests"
-    #puppet.options = "-v -d"
+  # #   puppet.options = "-v -d"
   end
 
   # The npm module jquery won't install via puppet because of an mysterious error
diff --git a/application/controllers/ModulesController.php b/application/controllers/ModulesController.php
index 8e28308ea..1a5dec426 100755
--- a/application/controllers/ModulesController.php
+++ b/application/controllers/ModulesController.php
@@ -4,21 +4,21 @@
 /**
  * Icinga 2 Web - Head for multiple monitoring frontends
  * 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>
  * @author Icinga Development Team <info@icinga.org>
  */
@@ -58,16 +58,15 @@ class ModulesController extends ActionController
     public function overviewAction()
     {
         $this->indexAction();
-        
+
     }
 
     public function enableAction()
     {
         $this->manager->enableModule($this->_getParam('name'));
         $this->manager->loadModule($this->_getParam('name'));
-        $this->getResponse()->setHeader('X-Icinga-Enable-Module', $this->_getParam('name')); 
-        $this->replaceLayout = true; 
-        $this->indexAction();
+        $this->getResponse()->setHeader('X-Icinga-Enable-Module', $this->_getParam('name'));
+        $this->redirectNow('index?_render=body');
 
     }
 
diff --git a/application/layouts/scripts/parts/navigation.phtml b/application/layouts/scripts/parts/navigation.phtml
index bb166d86c..04dbf801e 100755
--- a/application/layouts/scripts/parts/navigation.phtml
+++ b/application/layouts/scripts/parts/navigation.phtml
@@ -3,7 +3,7 @@
     $url = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();
     $currentKey = isset($this->navkey) ? $this->navkey : $url;
 
-    $item = $this->navigation->listAll("menu");
+    $item = $this->navigation->keys("menu");
 ?>
 <?php if ($this->auth()->isAuthenticated()): ?>
 <ul class="nav nav-tabs icinga-navigation" >
diff --git a/config/icinga.ini b/config/config.ini
similarity index 100%
rename from config/icinga.ini
rename to config/config.ini
diff --git a/modules/monitoring/config/backends.ini b/config/modules/monitoring/backends.ini
similarity index 59%
rename from modules/monitoring/config/backends.ini
rename to config/modules/monitoring/backends.ini
index 5c8d7f4e6..3fabbbf5d 100644
--- a/modules/monitoring/config/backends.ini
+++ b/config/modules/monitoring/backends.ini
@@ -2,8 +2,8 @@
 [localdb]
 type = ido
 host = localhost
-user = "icinga"
-pass = "icinga"
+user = "icinga-idoutils"
+pass = "***"
 db = "icinga"
 
 
diff --git a/modules/monitoring/config/instances.ini b/config/modules/monitoring/instances.ini
similarity index 100%
rename from modules/monitoring/config/instances.ini
rename to config/modules/monitoring/instances.ini
diff --git a/modules/monitoring/config/menu.ini b/config/modules/monitoring/menu.ini
similarity index 100%
rename from modules/monitoring/config/menu.ini
rename to config/modules/monitoring/menu.ini
diff --git a/library/Icinga/Application/ApplicationBootstrap.php b/library/Icinga/Application/ApplicationBootstrap.php
index 4675a1e4c..c3d5534ed 100755
--- a/library/Icinga/Application/ApplicationBootstrap.php
+++ b/library/Icinga/Application/ApplicationBootstrap.php
@@ -44,7 +44,7 @@ abstract class ApplicationBootstrap
     protected $loader;
     protected $libdir;
     protected $config;
-    protected $configFile;
+    protected $configDir;
     protected $appdir;
     protected $moduleManager;
     protected $isCli = false;
@@ -57,7 +57,7 @@ abstract class ApplicationBootstrap
      *
      * @return void
      */
-    protected function __construct($configFile = null)
+    protected function __construct($configDir)
     {
         $this->checkPrerequisites();
         $this->libdir = realpath(dirname(dirname(dirname(__FILE__))));
@@ -88,10 +88,7 @@ abstract class ApplicationBootstrap
             )
         );
 
-        if ($configFile === null) {
-            $configFile = dirname($this->libdir) . '/config/icinga.ini';
-        }
-        $this->configFile = $configFile;
+        $this->configDir = $configDir;
         require_once dirname(__FILE__) . '/functions.php';
     }
 
@@ -100,7 +97,7 @@ abstract class ApplicationBootstrap
     public function moduleManager()
     {
         if ($this->moduleManager === null) {
-            $this->moduleManager = new ModuleManager($this, $this->config->global->moduleFolder);
+            $this->moduleManager = new ModuleManager($this, $this->configDir . '/enabledModules');
         }
         return $this->moduleManager;
     }
@@ -155,10 +152,10 @@ abstract class ApplicationBootstrap
         return $this->config;
     }
 
-    public static function start($config = null)
+    public static function start($configDir)
     {
         $class = get_called_class();
-        $obj = new $class();
+        $obj = new $class($configDir);
         $obj->bootstrap();
         return $obj;
     }
@@ -217,11 +214,8 @@ abstract class ApplicationBootstrap
      */
     protected function loadConfig()
     {
-        // TODO: add an absolutely failsafe config loader
-        if (! @is_readable($this->configFile)) {
-            throw new \Exception('Cannot read config file: ' . $this->configFile);
-        }
-        $this->config = Config::getInstance($this->configFile);
+        Config::$configDir = $this->configDir;
+        $this->config = Config::app();
         return $this;
     }
 
@@ -247,7 +241,7 @@ abstract class ApplicationBootstrap
      */
     protected function configureErrorHandling()
     {
-        if ($this->config->global->environment == 'development') {
+        if ($this->config->get('global', 'environment') == 'development') {
             error_reporting(E_ALL | E_NOTICE);
             ini_set('display_startup_errors', 1);
             ini_set('display_errors', 1);
@@ -264,7 +258,7 @@ abstract class ApplicationBootstrap
     protected function setTimezone()
     {
         date_default_timezone_set(
-            $this->config->{'global'}->get('timezone', 'UTC')
+            $this->config->global->get('timezone', 'UTC')
         );
         return $this;
     }
diff --git a/library/Icinga/Application/Config.php b/library/Icinga/Application/Config.php
index b77861310..a4f672517 100755
--- a/library/Icinga/Application/Config.php
+++ b/library/Icinga/Application/Config.php
@@ -4,6 +4,7 @@
 
 namespace Icinga\Application;
 
+use Icinga\Protocol\Ldap\Exception;
 use Zend_Config_Ini;
 
 /**
@@ -12,52 +13,52 @@ use Zend_Config_Ini;
 class Config extends Zend_Config_Ini
 {
     /**
-     * Configuration directory where ALL (application and module) configuration is located.
-     *
+     * Configuration directory where ALL (application and module) configuration is located
      * @var string
      */
     public static $configDir;
 
     /**
-     * The INI file this configuration has been loaded from.
-     *
+     * The INI file this configuration has been loaded from
      * @var string
      */
     protected $configFile;
 
     /**
-     * Application config instances per file.
-     *
+     * Application config instances per file
      * @var array
      */
     protected static $app = array();
 
     /**
-     * Module config instances per file.
-     *
+     * Module config instances per file
      * @var array
      */
     protected static $modules = array();
 
     /**
-     * Load configuration from the config file $filename.
+     * Load configuration from the config file $filename
      *
      * @see     Zend_Config_Ini::__construct
      *
      * @param   string      $filename
-     * @throws  \Exception
+     * @throws  Exception
      */
     public function __construct($filename)
     {
         if (!@is_readable($filename)) {
-            throw new \Exception('Cannot read config file: ' . $filename);
+            throw new Exception('Cannot read config file: ' . $filename);
         };
         $this->configFile = $filename;
-        parent::__construct($filename);
+        $section = null;
+        $options = array(
+            'allowModifications' => true
+        );
+        parent::__construct($filename, $section, $options);
     }
 
     /**
-     * Retrieve a application config instance.
+     * Retrieve a application config instance
      *
      * @param   string  $configname
      * @return  mixed
@@ -66,13 +67,13 @@ class Config extends Zend_Config_Ini
     {
         if (!isset(self::$app[$configname])) {
             $filename = self::$configDir . '/' . $configname . '.ini';
-            self::$app[$configname] = new Config($filename);
+            self::$app[$configname] = new Config(realpath($filename));
         }
         return self::$app[$configname];
     }
 
     /**
-     * Retrieve a module config instance.
+     * Retrieve a module config instance
      *
      * @param   string  $modulename
      * @param   string  $configname
@@ -86,13 +87,17 @@ class Config extends Zend_Config_Ini
         $moduleConfigs = self::$modules[$modulename];
         if (!isset($moduleConfigs[$configname])) {
             $filename = self::$configDir . '/modules/' . $modulename . '/' . $configname . '.ini';
-            $moduleConfigs[$configname] = new Config($filename);
+            if (file_exists($filename)) {
+                $moduleConfigs[$configname] = new Config(realpath($filename));
+            } else {
+                $moduleConfigs[$configname] = null;
+            }
         }
         return $moduleConfigs[$configname];
     }
 
     /**
-     * Retrieve names of accessible sections or properties.
+     * Retrieve names of accessible sections or properties
      *
      * @param   $name
      * @return  array
diff --git a/library/Icinga/Application/Modules/Module.php b/library/Icinga/Application/Modules/Module.php
index 482804655..8638cdbef 100644
--- a/library/Icinga/Application/Modules/Module.php
+++ b/library/Icinga/Application/Modules/Module.php
@@ -120,7 +120,9 @@ class Module
 
     protected function registerMenuEntries()
     {
-        $cfg = $this->getConfig('menu.ini');
+        $cfg = $this->app
+            ->getConfig()
+            ->module($this->name, 'menu');
         $view = $this->app->getView();
         if ($cfg) {
             $view->view->navigation = $cfg->merge($view->view->navigation);
diff --git a/library/Icinga/Application/Web.php b/library/Icinga/Application/Web.php
index 4da8839aa..b8e17b100 100644
--- a/library/Icinga/Application/Web.php
+++ b/library/Icinga/Application/Web.php
@@ -181,7 +181,7 @@ class Web extends ApplicationBootstrap
             $this->config->{'global'}->get('project', 'Icinga')
         );
         $view->view->headTitle()->setSeparator(' :: ');
-        $view->view->navigation = $this->config->menu;
+        $view->view->navigation = $this->config->app('menu');
 
         $this->view = $view;
         return $this;
diff --git a/library/Icinga/Authentication/Backend/LdapUserBackend.php b/library/Icinga/Authentication/Backend/LdapUserBackend.php
index 93b56b14b..486e729d3 100644
--- a/library/Icinga/Authentication/Backend/LdapUserBackend.php
+++ b/library/Icinga/Authentication/Backend/LdapUserBackend.php
@@ -3,21 +3,21 @@
 /**
  * Icinga 2 Web - Head for multiple monitoring frontends
  * 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>
  * @author Icinga Development Team <info@icinga.org>
  */
@@ -33,7 +33,7 @@ use Icinga\Application\Config as IcingaConfig;
 
 /**
 *   User authentication backend (@see Icinga\Authentication\UserBackend) for
-*   authentication of users via LDAP. The attributes and location of the 
+*   authentication of users via LDAP. The attributes and location of the
 *   user is configurable via the application.ini
 *
 *   See the UserBackend class (@see Icinga\Authentication\UserBackend) for
@@ -45,9 +45,9 @@ class LdapUserBackend implements UserBackend
     *   @var Ldap\Connection
     **/
     protected $connection;
-   
+
     /**
-    *   Creates a new Authentication backend using the 
+    *   Creates a new Authentication backend using the
     *   connection information provided in $config
     *
     *   @param object $config   The ldap connection information
@@ -69,7 +69,7 @@ class LdapUserBackend implements UserBackend
 
     /**
     *   Removes the '*' characted from $string
-    *   
+    *
     *   @param String $string
     *
     *   @return String
@@ -81,19 +81,19 @@ class LdapUserBackend implements UserBackend
 
     /**
     *   Tries to fetch the username given in $username from
-    *   the ldap connection, using the configuration parameters 
+    *   the ldap connection, using the configuration parameters
     *   given in the Authentication configuration
     *
     *   @param  String  $username       The username to select
     *
-    *   @return object  $result 
+    *   @return object  $result
     **/
     protected function selectUsername($username)
     {
         return $this->connection->select()
-            ->from(IcingaConfig::getInstance()->authentication->users->user_class,
-                array(IcingaConfig::getInstance()->authentication->users->user_name_attribute))
-            ->where(IcingaConfig::getInstance()->authentication->users->user_name_attribute,
+            ->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));
     }
 
diff --git a/library/Icinga/Authentication/Manager.php b/library/Icinga/Authentication/Manager.php
index 306cb4993..0417bf453 100644
--- a/library/Icinga/Authentication/Manager.php
+++ b/library/Icinga/Authentication/Manager.php
@@ -3,21 +3,21 @@
 /**
  * Icinga 2 Web - Head for multiple monitoring frontends
  * 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>
  * @author Icinga Development Team <info@icinga.org>
  */
@@ -25,31 +25,31 @@
 
 namespace Icinga\Authentication;
 
-use Icinga\Application\Logger as Logger;
-use Icinga\Application\Config as Config;
+use Icinga\Application\Logger;
+use Icinga\Application\Config as IcingaConfig;
 use Icinga\Exception\ConfigurationError as ConfigError;
 
 /**
 *   The authentication manager allows to identify users and
 *   to persist authentication information in a session.
-*   
+*
 *   Direct instanciation is not permitted, the Authencation manager
-*   must be created using the getInstance method. Subsequent getInstance 
+*   must be created using the getInstance method. Subsequent getInstance
 *   calls return the same object and ignore any additional configuration
 *
 *   When creating the Authentication manager with standard PHP Sessions,
 *   you have to decide whether you want to modify the session on the first
-*   initialization and provide the 'writeSession' option if so, otherwise 
+*   initialization and provide the 'writeSession' option if so, otherwise
 *   session changes won't be written to disk. This is done to prevent PHP
 *   from blockung concurrent requests
 *
-*   @TODO: Group support is not implemented yet 
+*   @TODO: Group support is not implemented yet
 **/
 class Manager
 {
     const BACKEND_TYPE_USER = "User";
     const BACKEND_TYPE_GROUP = "Group";
-    
+
     /**
     *   @var Manager
     **/
@@ -60,7 +60,7 @@ class Manager
     **/
     private $user = null;
     private $groups = array();
-    
+
     /**
     *   @var UserBackend
     **/
@@ -70,32 +70,32 @@ class Manager
     *   @var GroupBackend
     **/
     private $groupBackend = null;
-    
+
     /**
     *   @var Session
     **/
     private $session = null;
-   
+
     /**
     *   Creates a new authentication manager using the provided config (or the
     *   configuration provided in the authentication.ini if no config is given)
-    *   and with the given options. 
+    *   and with the given options.
     *
-    *   @param  Icinga\Config   $config     The configuration to use for authentication
+    *   @param  IcingaConfig    $config     The configuration to use for authentication
     *                                       instead of the authentication.ini
     *   @param  Array           $options    Additional options that affect the managers behaviour.
     *                                       Supported values:
-    *                                       * writeSession : Whether the session should be writable 
-    *                                       * userBackendClass : Allows to provide an own user backend class 
+    *                                       * writeSession : Whether the session should be writable
+    *                                       * userBackendClass : Allows to provide an own user backend class
     *                                         (used for testing)
-    *                                       * groupBackendClass : Allows to provide an own group backend class 
+    *                                       * groupBackendClass : Allows to provide an own group backend class
     *                                         (used for testing)
     *                                       * sessionClass : Allows to provide a different session implementation)
     **/
     private function __construct($config = null, array $options = array())
     {
         if ($config === null) {
-            $config = Config::getInstance()->authentication;
+            $config = IcingaConfig::app('authentication');
         }
         if (isset($options["userBackendClass"])) {
             $this->userBackend = $options["userBackendClass"];
@@ -141,14 +141,14 @@ class Manager
     }
 
     /**
-    *   Creates a backend for the the given authenticationTarget (User or Group) and the 
-    *   Authenticaiton source. 
+    *   Creates a backend for the the given authenticationTarget (User or Group) and the
+    *   Authenticaiton source.
+    *
+    *   initBackend("User", "Ldap") would create a UserLdapBackend,
+    *   initBackend("Group", "MySource") would create a GroupMySourceBackend,
     *
-    *   initBackend("User", "Ldap") would create a UserLdapBackend, 
-    *   initBackend("Group", "MySource") would create a GroupMySourceBackend, 
-    *   
     *   Supported backends can be found in the Authentication\Backend folder
-    *   
+    *
     *   @param  String  $authenticationTarget   "User" or "Group", depending on what
     *                                           authentication information the backend should
     *                                           provide
@@ -169,9 +169,9 @@ class Manager
     }
 
     /**
-    *   Tries to authenticate the current user with the Credentials (@see Credentials). 
+    *   Tries to authenticate the current user with the Credentials (@see Credentials).
     *
-    *   @param Credentials  $credentials        The credentials to use for authentication   
+    *   @param Credentials  $credentials        The credentials to use for authentication
     *   @param Boolean      $persist            Whether to persist the authentication result
     *                                           in the current session
     *
@@ -214,9 +214,9 @@ class Manager
     {
         $this->session->set("user", $this->user);
     }
-    
+
     /**
-    *   Tries to authenticate the user with the current session 
+    *   Tries to authenticate the user with the current session
     **/
     public function authenticateFromSession()
     {
@@ -225,10 +225,10 @@ class Manager
 
     /**
     *   Returns true when the user is currently authenticated
-    *   
+    *
     *   @param  Boolean $ignoreSession      Set to true to prevent authentication by session
     *
-    *   @param  Boolean 
+    *   @param  Boolean
     **/
     public function isAuthenticated($ignoreSession = false)
     {
@@ -240,7 +240,7 @@ class Manager
 
     /**
     *   Purges the current authorisation information and deletes the session
-    *   
+    *
     **/
     public function removeAuthorization()
     {
@@ -250,7 +250,7 @@ class Manager
 
     /**
     *   Returns the current user or null if no user is authenticated
-    *   
+    *
     *   @return User
     **/
     public function getUser()
diff --git a/library/Icinga/Backend.php b/library/Icinga/Backend.php
index 8f7c602b2..5694e0157 100755
--- a/library/Icinga/Backend.php
+++ b/library/Icinga/Backend.php
@@ -2,7 +2,7 @@
 
 namespace Icinga;
 
-use Icinga\Application\Config;
+use Icinga\Application\Config as IcingaConfig;
 use Icinga\Authentication\Manager as AuthManager;
 
 class Backend
@@ -14,15 +14,15 @@ class Backend
     public static function getInstance($name = null)
     {
         if (! array_key_exists($name, self::$instances)) {
-            $config = Config::getInstance()->backends;
+            $backends = IcingaConfig::app('backends');
             if ($name === null) {
                 $name = AuthManager::getInstance()->getSession()->get('backend');
             }
             if ($name === null) {
-                $name = array_shift(array_keys($config->toArray()));
+                $name = array_shift(array_keys($backends->toArray()));
             }
-            if (isset($config->backends->$name)) {
-                $config = $config->backends->$name;
+            if (isset($backends->$name)) {
+                $config = $backends->$name;
                 $type = $config->type;
                 $type[0] = strtoupper($type[0]);
                 $class = '\\Icinga\\Backend\\' . $type;
diff --git a/library/Icinga/Web/ActionController.php b/library/Icinga/Web/ActionController.php
index e4dcb2c4e..407269d57 100755
--- a/library/Icinga/Web/ActionController.php
+++ b/library/Icinga/Web/ActionController.php
@@ -1,5 +1,26 @@
 <?php
 // {{{ICINGA_LICENSE_HEADER}}}
+/**
+ * Icinga 2 Web - Head for multiple monitoring frontends
+ * 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>
+ * @author Icinga Development Team <info@icinga.org>
+ */
 // {{{ICINGA_LICENSE_HEADER}}}
 
 namespace Icinga\Web;
@@ -114,7 +135,7 @@ class ActionController extends ZfController
      */
     protected function loadConfig()
     {
-        $this->config = Config::getInstance();
+        $this->config = Config::app();
     }
 
     /**
diff --git a/library/Icinga/Web/ModuleActionController.php b/library/Icinga/Web/ModuleActionController.php
index d6fec0ba5..4a32bd729 100644
--- a/library/Icinga/Web/ModuleActionController.php
+++ b/library/Icinga/Web/ModuleActionController.php
@@ -5,7 +5,7 @@
  */
 namespace Icinga\Web;
 
-use Icinga\Application\Config;
+use Icinga\Application\Config as IcingaConfig;
 use Icinga\Application\Icinga;
 
 /**
@@ -64,7 +64,7 @@ class ModuleActionController extends ActionController
      */
     protected function loadConfig()
     {
-        $this->config = Config::module($this->module_name);
+        $this->config = IcingaConfig::module($this->module_name);
     }
 
     /**
diff --git a/modules/monitoring/library/Monitoring/Backend.php b/modules/monitoring/library/Monitoring/Backend.php
index e16b7cff1..92f03b323 100644
--- a/modules/monitoring/library/Monitoring/Backend.php
+++ b/modules/monitoring/library/Monitoring/Backend.php
@@ -2,7 +2,7 @@
 
 namespace Icinga\Monitoring;
 
-use Icinga\Application\Config;
+use Icinga\Application\Config as IcingaConfig;
 use Icinga\Authentication\Manager as AuthManager;
 use Exception;
 
@@ -36,8 +36,7 @@ class Backend
     public function getBackendConfigs()
     {
         if (self::$backendConfigs === null) {
-            $config = Config::getInstance()->backends;
-            $backends = $config->backends;
+            $backends = IcingaConfig::app('backends');
             foreach ($backends as $name => $config) {
                 // TODO: Check if access to this backend is allowed
                 self::$backendConfigs[$name] = $config;
diff --git a/public/css.php b/public/css.php
index fb7e690af..d8d85e6e8 100644
--- a/public/css.php
+++ b/public/css.php
@@ -3,7 +3,7 @@
 use Icinga\Application\EmbeddedWeb;
 
 require_once dirname(__FILE__) . '/../library/Icinga/Application/EmbeddedWeb.php';
-$app = EmbeddedWeb::start();
+$app = EmbeddedWeb::start(dirname(__FILE__) . '/../config/');
 require_once 'vendor/lessphp/lessc.inc.php';
 header('Content-type: text/css');
 $less = new lessc;
diff --git a/public/index.php b/public/index.php
index 2b1fb610d..6525abe3a 100755
--- a/public/index.php
+++ b/public/index.php
@@ -7,4 +7,4 @@ require_once dirname(__FILE__). '/../library/Icinga/Application/Web.php';
 
 use Icinga\Application\Web;
 
-Web::start()->dispatch();
+Web::start(dirname(__FILE__) . '/../config/')->dispatch();