diff --git a/application/controllers/AuthenticationController.php b/application/controllers/AuthenticationController.php index 4ea5043d0..bf9d0a655 100644 --- a/application/controllers/AuthenticationController.php +++ b/application/controllers/AuthenticationController.php @@ -6,6 +6,7 @@ namespace Icinga\Controllers; use Icinga\Application\Icinga; use Icinga\Forms\Authentication\LoginForm; use Icinga\Web\Controller; +use Icinga\Web\Helper\CookieHelper; use Icinga\Web\Url; /** @@ -37,13 +38,14 @@ class AuthenticationController extends Controller $this->redirectNow($form->getRedirectUrl()); } if (! $requiresSetup) { - if (! $this->getRequest()->hasCookieSupport()) { + $cookies = new CookieHelper($this->getRequest()); + if (! $cookies->isSupported()) { $this ->getResponse() ->setBody("Cookies must be enabled to run this application.\n") ->setHttpResponseCode(403) ->sendResponse(); - exit(); + exit; } $form->handleRequest(); } diff --git a/application/controllers/ErrorController.php b/application/controllers/ErrorController.php index ed35c3162..c7c998101 100644 --- a/application/controllers/ErrorController.php +++ b/application/controllers/ErrorController.php @@ -36,7 +36,7 @@ class ErrorController extends ActionController Logger::error('Stacktrace: %s', $exception->getTraceAsString()); if (! ($isAuthenticated = $this->Auth()->isAuthenticated())) { - $this->innerLayout = 'error'; + $this->innerLayout = 'guest-error'; } switch ($error->type) { @@ -89,6 +89,7 @@ class ErrorController extends ActionController if ($this->getInvokeArg('displayExceptions')) { $this->view->stackTrace = $exception->getTraceAsString(); } + break; } diff --git a/application/controllers/StaticController.php b/application/controllers/StaticController.php index 7c284d567..79632e1d8 100644 --- a/application/controllers/StaticController.php +++ b/application/controllers/StaticController.php @@ -7,7 +7,6 @@ use Icinga\Web\Controller; use Icinga\Application\Icinga; use Icinga\Application\Logger; use Icinga\Web\FileCache; -use Icinga\Web\LessCompiler; /** * Delivery static content to clients @@ -87,94 +86,4 @@ class StaticController extends Controller readfile($filePath); } - - /** - * Return a javascript file from the application's or the module's public folder - */ - public function javascriptAction() - { - $module = $this->_getParam('module_name'); - $file = $this->_getParam('file'); - - if ($module == 'app') { - $basedir = Icinga::app()->getApplicationDir('../public/js/icinga/components/'); - $filePath = $basedir . $file; - } else { - if (! Icinga::app()->getModuleManager()->hasEnabled($module)) { - Logger::error( - 'Non-existing frontend component "' . $module . '/' . $file - . '" was requested. The module "' . $module . '" does not exist or is not active.' - ); - echo "/** Module not enabled **/"; - return; - } - $basedir = Icinga::app()->getModuleManager()->getModule($module)->getBaseDir(); - $filePath = $basedir . '/public/js/' . $file; - } - - if (! file_exists($filePath)) { - Logger::error( - 'Non-existing frontend component "' . $module . '/' . $file - . '" was requested, which would resolve to the the path: ' . $filePath - ); - echo '/** Module has no js files **/'; - return; - } - $response = $this->getResponse(); - $response->setHeader('Content-Type', 'text/javascript'); - $this->setCacheHeader(); - - $response->setHeader( - 'Last-Modified', - gmdate('D, d M Y H:i:s', filemtime($filePath)) . ' GMT' - ); - - readfile($filePath); - } - - /** - * Set cache header for the response - * - * @param int $maxAge The maximum age to set - */ - private function setCacheHeader($maxAge = 3600) - { - $maxAge = (int) $maxAge; - $this - ->getResponse() - ->setHeader('Cache-Control', sprintf('max-age=%d', $maxAge), true) - ->setHeader('Pragma', 'cache', true) - ->setHeader( - 'Expires', - gmdate('D, d M Y H:i:s', time() + $maxAge) . ' GMT', - true - ); - } - - /** - * Send application's and modules' CSS - */ - public function stylesheetAction() - { - $lessCompiler = new LessCompiler(); - $moduleManager = Icinga::app()->getModuleManager(); - - $publicDir = realpath(dirname($_SERVER['SCRIPT_FILENAME'])); - - $lessCompiler->addItem($publicDir . '/css/vendor'); - $lessCompiler->addItem($publicDir . '/css/icinga'); - - foreach ($moduleManager->getLoadedModules() as $moduleName) { - $cssDir = $moduleName->getCssDir(); - - if (is_dir($cssDir)) { - $lessCompiler->addItem($cssDir); - } - } - - $this->getResponse()->setHeader('Content-Type', 'text/css'); - $this->setCacheHeader(3600); - - $lessCompiler->printStack(); - } } diff --git a/application/forms/Config/General/ApplicationConfigForm.php b/application/forms/Config/General/ApplicationConfigForm.php index 4e431aab2..da0b4e451 100644 --- a/application/forms/Config/General/ApplicationConfigForm.php +++ b/application/forms/Config/General/ApplicationConfigForm.php @@ -8,12 +8,14 @@ use Icinga\Data\ResourceFactory; use Icinga\Web\Form; /** - * Form class to modify the general application configuration + * Configuration form for general application options + * + * This form is not used directly but as subform to the {@link GeneralConfigForm}. */ class ApplicationConfigForm extends Form { /** - * Initialize this form + * {@inheritdoc} */ public function init() { @@ -21,7 +23,9 @@ class ApplicationConfigForm extends Form } /** - * @see Form::createElements() + * {@inheritdoc} + * + * @return $this */ public function createElements(array $formData) { @@ -68,6 +72,7 @@ class ApplicationConfigForm extends Form ) ) ); + if (isset($formData['global_config_backend']) && $formData['global_config_backend'] === 'db') { $backends = array(); foreach (ResourceFactory::getResourceConfigs()->toArray() as $name => $resource) { diff --git a/application/forms/Config/General/LoggingConfigForm.php b/application/forms/Config/General/LoggingConfigForm.php index 3690b8060..89aec7538 100644 --- a/application/forms/Config/General/LoggingConfigForm.php +++ b/application/forms/Config/General/LoggingConfigForm.php @@ -6,10 +6,15 @@ namespace Icinga\Forms\Config\General; use Icinga\Application\Logger; use Icinga\Web\Form; +/** + * Configuration form for logging options + * + * This form is not used directly but as subform for the {@link GeneralConfigForm}. + */ class LoggingConfigForm extends Form { /** - * Initialize this form + * {@inheritdoc} */ public function init() { @@ -17,8 +22,9 @@ class LoggingConfigForm extends Form } /** - * (non-PHPDoc) - * @see Form::createElements() For the method documentation. + * {@inheritdoc} + * + * @return $this */ public function createElements(array $formData) { diff --git a/application/forms/Config/General/ThemingConfigForm.php b/application/forms/Config/General/ThemingConfigForm.php new file mode 100644 index 000000000..be35a2fb2 --- /dev/null +++ b/application/forms/Config/General/ThemingConfigForm.php @@ -0,0 +1,72 @@ +setName('form_config_general_theming'); + } + + /** + * {@inheritdoc} + * + * @return $this + */ + public function createElements(array $formData) + { + $this->addElement( + 'select', + 'themes_default', + array( + 'description' => $this->translate('The default theme', 'Form element description'), + 'label' => $this->translate('Default Theme', 'Form element label'), + 'multiOptions' => Icinga::app()->getThemes() + ) + ); + + $this->addElement( + 'checkbox', + 'themes_disabled', + array( + 'description' => $this->translate( + 'Check this box for disallowing users to change the theme. If a default theme is set, it will be' + . ' used nonetheless', + 'Form element description' + ), + 'label' => $this->translate('Disable Themes', 'Form element label') + ) + ); + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getValues($suppressArrayNotation = false) + { + $values = parent::getValues($suppressArrayNotation); + if ($values['themes_default'] === 'Icinga') { + $values['themes_default'] = null; + } + if (! $values['themes_disabled']) { + $values['themes_disabled'] = null; + } + return $values; + } +} diff --git a/application/forms/Config/GeneralConfigForm.php b/application/forms/Config/GeneralConfigForm.php index 5b00d06f4..5df09a140 100644 --- a/application/forms/Config/GeneralConfigForm.php +++ b/application/forms/Config/GeneralConfigForm.php @@ -5,15 +5,16 @@ namespace Icinga\Forms\Config; use Icinga\Forms\Config\General\ApplicationConfigForm; use Icinga\Forms\Config\General\LoggingConfigForm; +use Icinga\Forms\Config\General\ThemingConfigForm; use Icinga\Forms\ConfigForm; /** - * Form class for application-wide and logging specific settings + * Configuration form for application-wide options */ class GeneralConfigForm extends ConfigForm { /** - * Initialize this configuration form + * {@inheritdoc} */ public function init() { @@ -22,13 +23,15 @@ class GeneralConfigForm extends ConfigForm } /** - * @see Form::createElements() + * {@inheritdoc} */ public function createElements(array $formData) { $appConfigForm = new ApplicationConfigForm(); $loggingConfigForm = new LoggingConfigForm(); - $this->addElements($appConfigForm->createElements($formData)->getElements()); - $this->addElements($loggingConfigForm->createElements($formData)->getElements()); + $themingConfigForm = new ThemingConfigForm(); + $this->addSubForm($appConfigForm->create($formData)); + $this->addSubForm($loggingConfigForm->create($formData)); + $this->addSubForm($themingConfigForm->create($formData)); } } diff --git a/application/forms/Config/UserBackendConfigForm.php b/application/forms/Config/UserBackendConfigForm.php index 55ec88833..524facfb8 100644 --- a/application/forms/Config/UserBackendConfigForm.php +++ b/application/forms/Config/UserBackendConfigForm.php @@ -321,21 +321,6 @@ class UserBackendConfigForm extends ConfigForm } } - /** - * Retrieve all form element values - * - * @param bool $suppressArrayNotation Ignored - * - * @return array - */ - public function getValues($suppressArrayNotation = false) - { - $values = parent::getValues(); - $values = array_merge($values, $values['backend_form']); - unset($values['backend_form']); - return $values; - } - /** * Return whether the given values are valid * diff --git a/application/forms/Config/UserGroup/UserGroupBackendForm.php b/application/forms/Config/UserGroup/UserGroupBackendForm.php index 7f57408c7..da0337dba 100644 --- a/application/forms/Config/UserGroup/UserGroupBackendForm.php +++ b/application/forms/Config/UserGroup/UserGroupBackendForm.php @@ -198,19 +198,4 @@ class UserGroupBackendForm extends ConfigForm $this->populate($data); } } - - /** - * Retrieve all form element values - * - * @param bool $suppressArrayNotation Ignored - * - * @return array - */ - public function getValues($suppressArrayNotation = false) - { - $values = parent::getValues(); - $values = array_merge($values, $values['backend_form']); - unset($values['backend_form']); - return $values; - } } diff --git a/application/forms/ConfigForm.php b/application/forms/ConfigForm.php index 3d6d85dc7..70399c970 100644 --- a/application/forms/ConfigForm.php +++ b/application/forms/ConfigForm.php @@ -5,9 +5,9 @@ namespace Icinga\Forms; use Exception; use Zend_Form_Decorator_Abstract; +use Icinga\Application\Config; use Icinga\Web\Form; use Icinga\Web\Notification; -use Icinga\Application\Config; /** * Form base-class providing standard functionality for configuration forms @@ -21,6 +21,23 @@ class ConfigForm extends Form */ protected $config; + /** + * {@inheritdoc} + * + * Values from subforms are directly added to the returned values array instead of being grouped by the subforms' + * names. + */ + public function getValues($suppressArrayNotation = false) + { + $values = parent::getValues($suppressArrayNotation); + foreach (array_keys($this->_subForms) as $name) { + // Zend returns values from subforms grouped by their names, but we want them flat + $values = array_merge($values, $values[$name]); + unset($values[$name]); + } + return $values; + } + /** * Set the configuration to use when populating the form or when saving the user's input * diff --git a/application/forms/Navigation/NavigationConfigForm.php b/application/forms/Navigation/NavigationConfigForm.php index c06c75aab..d6c7d7de1 100644 --- a/application/forms/Navigation/NavigationConfigForm.php +++ b/application/forms/Navigation/NavigationConfigForm.php @@ -761,17 +761,6 @@ class NavigationConfigForm extends ConfigForm return $valid; } - /** - * {@inheritdoc} - */ - public function getValues($suppressArrayNotation = false) - { - $values = parent::getValues(); - $values = array_merge($values, $values['item_form']); - unset($values['item_form']); - return $values; - } - /** * {@inheritdoc} */ diff --git a/application/forms/PreferenceForm.php b/application/forms/PreferenceForm.php index d8ab9f2b1..f0d50b466 100644 --- a/application/forms/PreferenceForm.php +++ b/application/forms/PreferenceForm.php @@ -6,12 +6,14 @@ namespace Icinga\Forms; use Exception; use DateTimeZone; use Icinga\Application\Config; +use Icinga\Application\Icinga; use Icinga\Application\Logger; use Icinga\Authentication\Auth; use Icinga\User\Preferences; use Icinga\User\Preferences\PreferencesStore; use Icinga\Util\TimezoneDetect; use Icinga\Util\Translator; +use Icinga\Web\Cookie; use Icinga\Web\Form; use Icinga\Web\Notification; use Icinga\Web\Session; @@ -103,6 +105,14 @@ class PreferenceForm extends Form Session::getSession()->user->setPreferences($this->preferences); + if (($theme = $this->getElement('theme')) !== null + && ($theme = $theme->getValue()) !== $this->getRequest()->getCookie('theme') + ) { + $this->getResponse() + ->setCookie(new Cookie('theme', $theme)) + ->setReloadCss(true); + } + try { if ($this->store && $this->getElement('btn_submit_preferences')->isChecked()) { $this->save(); @@ -142,6 +152,20 @@ class PreferenceForm extends Form */ public function createElements(array $formData) { + if (! (bool) Config::app()->get('themes', 'disabled', false)) { + $themes = Icinga::app()->getThemes(); + if (count($themes) > 1) { + $this->addElement( + 'select', + 'theme', + array( + 'label' => $this->translate('Theme', 'Form element label'), + 'multiOptions' => $themes + ) + ); + } + } + $languages = array(); $languages['autodetect'] = sprintf($this->translate('Browser (%s)', 'preferences.form'), $this->getLocale()); foreach (Translator::getAvailableLocaleCodes() as $language) { diff --git a/application/forms/Security/RoleForm.php b/application/forms/Security/RoleForm.php index 9ebfc2c91..96560726b 100644 --- a/application/forms/Security/RoleForm.php +++ b/application/forms/Security/RoleForm.php @@ -42,33 +42,7 @@ class RoleForm extends ConfigForm 'application/stacktraces' => $this->translate( 'Allow to adjust in the preferences whether to show stacktraces' ) . ' (application/stacktraces)', - 'config/*' => $this->translate('Allow config access') . ' (config/*)', -/* - // [tg] seems excessive for me, hidden for rc1, tbd - 'config/application/*' => 'config/application/*', - 'config/application/general' => 'config/application/general', - 'config/application/resources' => 'config/application/resources', - 'config/application/userbackend' => 'config/application/userbackend', - 'config/application/usergroupbackend' => 'config/application/usergroupbackend', - 'config/application/navigation' => 'config/application/navigation', - 'config/authentication/*' => 'config/authentication/*', - 'config/authentication/users/*' => 'config/authentication/users/*', - 'config/authentication/users/show' => 'config/authentication/users/show', - 'config/authentication/users/add' => 'config/authentication/users/add', - 'config/authentication/users/edit' => 'config/authentication/users/edit', - 'config/authentication/users/remove' => 'config/authentication/users/remove', - 'config/authentication/groups/*' => 'config/authentication/groups/*', - 'config/authentication/groups/show' => 'config/authentication/groups/show', - 'config/authentication/groups/add' => 'config/authentication/groups/add', - 'config/authentication/groups/edit' => 'config/authentication/groups/edit', - 'config/authentication/groups/remove' => 'config/authentication/groups/remove', - 'config/authentication/roles/*' => 'config/authentication/roles/*', - 'config/authentication/roles/show' => 'config/authentication/roles/show', - 'config/authentication/roles/add' => 'config/authentication/roles/add', - 'config/authentication/roles/edit' => 'config/authentication/roles/edit', - 'config/authentication/roles/remove' => 'config/authentication/roles/remove', - 'config/modules' => 'config/modules' -*/ + 'config/*' => $this->translate('Allow config access') . ' (config/*)' ); $helper = new Zend_Form_Element('bogus'); diff --git a/application/layouts/scripts/body.phtml b/application/layouts/scripts/body.phtml index a492f8676..936c5eb1d 100644 --- a/application/layouts/scripts/body.phtml +++ b/application/layouts/scripts/body.phtml @@ -18,22 +18,18 @@ if ($this->layout()->autorefreshInterval) { ?>