From 88e451402f3c369ef19e84603021e33f2888fcc1 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 13 May 2014 14:27:30 +0200 Subject: [PATCH] Redirect to /install when the setup.token exists but no config.ini refs #6136 --- application/controllers/InstallController.php | 9 +++ .../Web/Controller/ActionController.php | 64 ++++++++++++++----- 2 files changed, 58 insertions(+), 15 deletions(-) diff --git a/application/controllers/InstallController.php b/application/controllers/InstallController.php index f2b0398e2..f476a568e 100644 --- a/application/controllers/InstallController.php +++ b/application/controllers/InstallController.php @@ -19,6 +19,15 @@ class InstallController extends ActionController */ protected $requiresAuthentication = false; + /** + * Whether the controller requires configuration + * + * The install wizard does not require any configuration. + * + * @var bool + */ + protected $requiresConfiguration = false; + /** * Show the wizard and run the installation once its finished */ diff --git a/library/Icinga/Web/Controller/ActionController.php b/library/Icinga/Web/Controller/ActionController.php index 5b42f8730..5893a3c3f 100644 --- a/library/Icinga/Web/Controller/ActionController.php +++ b/library/Icinga/Web/Controller/ActionController.php @@ -46,6 +46,7 @@ use Icinga\File\Pdf; use Icinga\Exception\ProgrammingError; use Icinga\Web\Session; use Icinga\Session\SessionNamespace; +use Icinga\Exception\NotReadableError; /** * Base class for all core action controllers @@ -61,6 +62,13 @@ class ActionController extends Zend_Controller_Action */ protected $requiresAuthentication = true; + /** + * Whether the controller requires configuration + * + * @var bool + */ + protected $requiresConfiguration = true; + private $config; private $configs = array(); @@ -114,26 +122,24 @@ class ActionController extends Zend_Controller_Action $this->_helper = new Zend_Controller_Action_HelperBroker($this); $this->_helper->addPath('../application/controllers/helpers'); - // when noInit is set (e.g. for testing), authentication and init is skipped - if (isset($invokeArgs['noInit'])) { - // TODO: Find out whether this still makes sense? - return; - } - if ($this->_request->isXmlHttpRequest()) { $this->windowId = $this->_request->getHeader('X-Icinga-WindowId', null); } - if ($this->requiresLogin() === false) { - $this->view->tabs = new Tabs(); - $this->init(); - } else { - $url = $this->getRequestUrl(); - if ($url === 'default/index/index') { - // TODO: We need our own router :p - $url = 'dashboard'; + if ($this->requiresConfig() === false) { + if ($this->requiresLogin() === false) { + $this->view->tabs = new Tabs(); + $this->init(); + } else { + $url = $this->getRequestUrl(); + if ($url === 'default/index/index') { + // TODO: We need our own router :p + $url = 'dashboard'; + } + $this->redirectToLogin($url); } - $this->redirectToLogin($url); + } else { + $this->redirectNow(Url::fromPath('install')); } } @@ -224,11 +230,39 @@ class ActionController extends Zend_Controller_Action } } + /** + * Check whether the controller requires configuration. That is when no configuration + * is available and when it is possible to setup the configuration + * + * @return bool + * + * @see requiresConfiguration + */ + protected function requiresConfig() + { + if (!$this->requiresConfiguration) { + return false; + } + + if (file_exists(Config::$configDir . '/setup.token')) { + try { + $config = Config::app()->toArray(); + } catch (NotReadableError $e) { + return true; + } + + return empty($config); + } else { + return false; + } + } + /** * Check whether the controller requires a login. That is when the controller requires authentication and the * user is currently not authenticated * * @return bool + * * @see requiresAuthentication */ protected function requiresLogin()