Fix messages in ConfigController

Store messages in the current user session to be able to fetch messages from
other controllers, so that the use can be redirected back to the index, instead
of staying in the original action

refs #5100
This commit is contained in:
Matthias Jentsch 2013-11-20 19:10:38 +01:00
parent 941ce6d68e
commit 2a0add3ec3
30 changed files with 432 additions and 191 deletions

View File

@ -30,13 +30,15 @@
use \Icinga\Web\Controller\BaseConfigController;
use \Icinga\Web\Widget\Tab;
use \Icinga\Web\Widget\AlertMessageBox;
use \Icinga\Web\Url;
use \Icinga\Web\Widget\Tabs;
use \Icinga\Web\Hook\Configuration\ConfigurationTabBuilder;
use \Icinga\User\Message;
use \Icinga\Application\Icinga;
use \Icinga\Application\Config as IcingaConfig;
use \Icinga\Data\ResourceFactory;
use \Icinga\Form\Config\GeneralForm;
use \Icinga\Authentication\Manager as AuthenticationManager;
use \Icinga\Form\Config\Authentication\ReorderForm;
use \Icinga\Form\Config\Authentication\LdapBackendForm;
use \Icinga\Form\Config\Authentication\DbBackendForm;
@ -57,6 +59,7 @@ class ConfigController extends BaseConfigController
*/
private $resourceTypes = array('livestatus', 'ido', 'statusdat', 'ldap');
/**
* Create tabs for this configuration controller
*
@ -110,17 +113,18 @@ class ConfigController extends BaseConfigController
*/
public function indexAction()
{
$form = new GeneralForm();
$this->view->messageBox = new AlertMessageBox($this->getAndClearMessages());
$form = new GeneralForm();
$form->setConfiguration(IcingaConfig::app());
$form->setRequest($this->_request);
if ($form->isSubmittedAndValid()) {
if (!$this->writeConfigFile($form->getConfig(), 'config')) {
return;
}
$this->view->successMessage = "Config Sucessfully Updated";
$this->addSuccessMessage("Configuration Sucessfully Updated");
$form->setConfiguration(IcingaConfig::app(), true);
$this->redirectNow('config/index');
}
$this->view->form = $form;
}
@ -130,6 +134,8 @@ class ConfigController extends BaseConfigController
*/
public function loggingAction()
{
$this->view->messageBox = new AlertMessageBox($this->getAndClearMessages());
$form = new LoggingForm();
$form->setConfiguration(IcingaConfig::app());
$form->setRequest($this->_request);
@ -137,8 +143,9 @@ class ConfigController extends BaseConfigController
if (!$this->writeConfigFile($form->getConfig(), 'config')) {
return;
}
$this->view->successMessage = "Config Sucessfully Updated";
$this->addSuccessMessage("Configuration Sucessfully Updated");
$form->setConfiguration(IcingaConfig::app(), true);
$this->redirectNow('config/logging');
}
$this->view->form = $form;
}
@ -148,6 +155,9 @@ class ConfigController extends BaseConfigController
*/
public function moduleoverviewAction()
{
$this->view->messageBox = new AlertMessageBox($this->getAndClearMessages());
$this->view->messages = $this->getAndClearMessages();
$this->view->modules = Icinga::app()->getModuleManager()->select()
->from('modules')
->order('name');
@ -164,10 +174,11 @@ class ConfigController extends BaseConfigController
try {
$manager->enableModule($module);
$manager->loadModule($module);
$this->view->successMessage = 'Module "' . $module . '" enabled';
$this->moduleoverviewAction();
$this->addSuccessMessage('Module "' . $module . '" enabled');
$this->redirectNow('config/moduleoverview');
return;
} catch (Exception $e) {
$this->view->exceptionMessage = $e->getMessage();
$this->view->exceptionMesssage = $e->getMessage();
$this->view->moduleName = $module;
$this->view->action = 'enable';
$this->render('module-configuration-error');
@ -183,8 +194,9 @@ class ConfigController extends BaseConfigController
$manager = Icinga::app()->getModuleManager();
try {
$manager->disableModule($module);
$this->view->successMessage = 'Module "' . $module . '" disabled';
$this->moduleoverviewAction();
$this->addSuccessMessage('Module "' . $module . '" disabled');
$this->redirectNow('config/moduleoverview');
return;
} catch (Exception $e) {
$this->view->exceptionMessage = $e->getMessage();
$this->view->moduleName = $module;
@ -201,6 +213,7 @@ class ConfigController extends BaseConfigController
$config = IcingaConfig::app('authentication', true);
$order = array_keys($config->toArray());
$this->view->backends = array();
$this->view->messageBox = new AlertMessageBox($this->getAndClearMessages());
foreach ($config as $backend=>$backendConfig) {
$form = new ReorderForm();
@ -211,8 +224,8 @@ class ConfigController extends BaseConfigController
if (!$showOnly && $form->isSubmittedAndValid()) {
if ($this->writeAuthenticationFile($form->getReorderedConfig($config))) {
$this->view->successMessage = 'Authentication Order Updated';
$this->authenticationAction(true);
$this->addSuccessMessage('Authentication Order Updated');
$this->redirectNow('config/authentication');
}
return;
}
@ -230,6 +243,8 @@ class ConfigController extends BaseConfigController
*/
public function createauthenticationbackendAction()
{
$this->view->messageBox = new AlertMessageBox();
if ($this->getRequest()->getParam('type') === 'ldap') {
$form = new LdapBackendForm();
} else {
@ -248,7 +263,7 @@ class ConfigController extends BaseConfigController
foreach ($form->getConfig() as $backendName => $settings) {
unset($settings->{'name'});
if (isset($backendCfg[$backendName])) {
$this->view->errorMessage = 'Backend name already exists';
$this->view->messageBox->addError('Backend name already exists');
$this->view->form = $form;
$this->render('authentication/create');
return;
@ -257,11 +272,13 @@ class ConfigController extends BaseConfigController
}
if ($this->writeAuthenticationFile($backendCfg)) {
// redirect to overview with success message
$this->view->successMessage = 'Backend Modification Written';
$this->authenticationAction(true);
$this->addSuccessMessage('Backend Modification Written.');
$this->redirectNow("config/authentication");
}
return;
}
$this->view->messageBox->addForm($form);
$this->view->form = $form;
$this->render('authentication/create');
}
@ -278,13 +295,13 @@ class ConfigController extends BaseConfigController
$configArray = IcingaConfig::app('authentication', true)->toArray();
$authBackend = $this->getParam('auth_backend');
if (!isset($configArray[$authBackend])) {
$this->view->errorMessage = 'Can\'t edit: Unknown Authentication Backend Provided';
$this->authenticationAction(true);
$this->addErrorMessage('Can\'t edit: Unknown Authentication Backend Provided');
$this->configurationerrorAction();
return;
}
if (!array_key_exists('resource', $configArray[$authBackend])) {
$this->view->errorMessage = 'Configuration error: Backend "' . $authBackend . '" has no Resource';
$this->authenticationAction(true);
$this->addErrorMessage('Configuration error: Backend "' . $authBackend . '" has no Resource');
$this->configurationerrorAction();
return;
}
@ -297,8 +314,8 @@ class ConfigController extends BaseConfigController
$form = new DbBackendForm();
break;
default:
$this->view->errorMessage = 'Can\'t edit: backend type "' . $type . '" of given resource not supported.';
$this->authenticationAction(true);
$this->addErrorMessage('Can\'t edit: backend type "' . $type . '" of given resource not supported.');
$this->configurationerrorAction();
return;
}
@ -318,12 +335,13 @@ class ConfigController extends BaseConfigController
}
if ($this->writeAuthenticationFile($backendCfg)) {
// redirect to overview with success message
$this->view->successMessage = 'Backend "' . $authBackend . '" created';
$this->authenticationAction(true);
$this->addSuccessMessage('Backend "' . $authBackend . '" created');
$this->redirectNow("config/authentication");
}
return;
}
$this->view->messageBox->addForm($form);
$this->view->name = $authBackend;
$this->view->form = $form;
$this->render('authentication/modify');
@ -336,16 +354,22 @@ class ConfigController extends BaseConfigController
*/
public function removeauthenticationbackendAction()
{
$this->view->messageBox = new AlertMessageBox();
$configArray = IcingaConfig::app('authentication', true)->toArray();
$authBackend = $this->getParam('auth_backend');
if (!isset($configArray[$authBackend])) {
$this->view->errorMessage = 'Can\'t perform removal: Unknown Authentication Backend Provided';
$this->authenticationAction(true);
$this->view->messageBox->addMessage(
new Message('Can\'t perform removal: Unknown Authentication Backend Provided', Zend_Log::ERR)
);
$this->render('authentication/remove');
return;
}
if (!array_key_exists('resource', $configArray[$authBackend])) {
$this->view->errorMessage = 'Configuration error: Backend "' . $authBackend . '" has no Resource';
$this->authenticationAction(true);
$this->view->messageBox->addMessage(
new Message('Configuration error: Backend "' . $authBackend . '" has no Resource', Zend_Log::ERR)
);
$this->render('authentication/remove');
return;
}
@ -356,8 +380,8 @@ class ConfigController extends BaseConfigController
if ($form->isSubmittedAndValid()) {
unset($configArray[$authBackend]);
if ($this->writeAuthenticationFile($configArray)) {
$this->view->successMessage = 'Authentication Backend "' . $authBackend . '" Removed';
$this->authenticationAction(true);
$this->addSuccessMessage('Authentication Backend "' . $authBackend . '" Removed');
$this->redirectNow("config/authentication");
}
return;
}
@ -369,6 +393,7 @@ class ConfigController extends BaseConfigController
public function resourceAction($showOnly = false)
{
$this->view->messageBox = new AlertMessageBox($this->getAndClearMessages());
$this->view->resources = IcingaConfig::app('resources', true)->toArray();
$this->render('resource');
@ -383,29 +408,33 @@ class ConfigController extends BaseConfigController
if ($form->isSubmittedAndValid()) {
$name = $form->getName();
if (isset($resources->{$name})) {
$this->view->errorMessage = 'Resource name "' . $name .'" already in use.';
$this->view->form = $form;
$this->render('resource/create');
return;
$this->addErrorMessage('Resource name "' . $name .'" already in use.');
} else {
$resources->{$name} = $form->getConfig();
if ($this->writeConfigFile($resources, 'resources')) {
$this->addSuccessMessage('Resource "' . $name . '" created.');
$this->redirectNow("config/resource");
}
}
$resources->{$name} = $form->getConfig();
if ($this->writeConfigFile($resources, 'resources')) {
$this->view->successMessage = 'Resource "' . $name . '" created.';
$this->resourceAction(true);
}
return;
}
$this->view->messageBox = new AlertMessageBox($this->getAndClearMessages());
$this->view->messageBox->addForm($form);
$this->view->form = $form;
$this->render('resource/create');
}
public function editresourceAction()
{
$this->view->messageBox = new AlertMessageBox();
$resources = ResourceFactory::getResourceConfigs();
$name = $this->getParam('resource');
if ($resources->get($name) === null) {
$this->view->errorMessage = 'Can\'t edit: Unknown Resource Provided';
$this->resourceAction(true);
$this->view->messageBox->addMessage(
new Message('Can\'t edit: Unknown Resource Provided', Zend_Log::ERR)
);
$this->render('resource/modify');
return;
}
$form = new EditResourceForm();
@ -423,11 +452,13 @@ class ConfigController extends BaseConfigController
}
$resources->{$name} = $form->getConfig();
if ($this->writeConfigFile($resources, 'resources')) {
$this->view->successMessage = 'Resource "' . $name . '" created.';
$this->resourceAction(true);
$this->addSuccessMessage('Resource "' . $name . '" edited.');
$this->redirectNow("config/resource");
}
return;
}
$this->view->messageBox->addForm($form);
$this->view->form = $form;
$this->view->name = $name;
$this->render('resource/modify');
@ -435,11 +466,15 @@ class ConfigController extends BaseConfigController
public function removeresourceAction()
{
$this->view->messageBox = new AlertMessageBox();
$resources = ResourceFactory::getResourceConfigs()->toArray();
$name = $this->getParam('resource');
if (!isset($resources[$name])) {
$this->view->errorMessage = 'Can\'t remove: Unknown resource provided';
$this->resourceAction(true);
$this->view->messageBox->addMessage(
new Message('Can\'t remove: Unknown resource provided', Zend_Log::ERR)
);
$this->render('resource/remove');
return;
}
@ -449,8 +484,8 @@ class ConfigController extends BaseConfigController
if ($form->isSubmittedAndValid()) {
unset($resources[$name]);
if ($this->writeConfigFile($resources, 'resources')) {
$this->view->successMessage = 'Resource "' . $name . '" removed';
$this->resourceAction(true);
$this->addSuccessMessage('Resource "' . $name . '" removed.');
$this->redirectNow('config/resource');
}
return;
}
@ -460,6 +495,19 @@ class ConfigController extends BaseConfigController
$this->render('resource/remove');
}
/**
* Redirect target only for error-states
*
* When an error is opened in the side-pane, redirecting this request to the index or the overview will look
* weird. This action returns a clear page containing only an AlertMessageBox.
*/
public function configurationerrorAction()
{
$this->view->messageBox = new AlertMessageBox($this->getAndClearMessages());
$this->render('error/error');
}
/**
* Write changes to an authentication file
*

View File

@ -390,6 +390,9 @@ class EditResourceForm extends Form
!file_exists($config->object_file) ||
!file_exists($config->status_file)
) {
$this->addErrorMessage(
'Connectivity validation failed, the provided file or socket does not exist.'
);
return false;
}
break;
@ -402,6 +405,7 @@ class EditResourceForm extends Form
break;
}
} catch (\Exception $exc) {
$this->addErrorMessage('Connectivity validation failed, connection to the given resource not possible.');
return false;
}
return true;

View File

@ -6,20 +6,9 @@ $createDbBackend = $this->href('/config/createAuthenticationBackend', array('typ
<?= $this->tabs->render($this); ?>
<?php if ($this->errorMessage): ?>
<div class="alert alert-danger">
<i class="icinga-icon-error"></i>
<strong><?= $this->escape($this->errorMessage); ?></strong>
</div>
<?php endif; ?>
<?php if ($this->successMessage): ?>
<div class="alert alert-success">
<i class="icinga-icon-success"></i>
<strong><?= $this->escape($this->successMessage); ?></strong>
</div>
<?php endif; ?>
<?php if (isset($this->messageBox)): ?>
<?= $this->messageBox->render() ?>
<?php endif ?>
<div class="panel panel-default">
<div class="panel-heading panel-title">

View File

@ -3,11 +3,10 @@
Create New Authentication Backend
</h4>
<?php if ($this->errorMessage): ?>
<div class="alert alert-danger">
<?= $this->escape($this->errorMessage); ?>
</div>
<?php endif; ?>
<?php if (isset($this->messageBox)): ?>
<?= $this->messageBox->render() ?>
<?php endif ?>
<p>
Create a new backend for authenticating your users. This backend will be added at the end of your authentication order.

View File

@ -3,11 +3,14 @@
Edit Backend "<?= $this->escape($this->name); ?>"
</h4>
<?php if ($this->errorMessage || $this->form->getErrorMessages()): ?>
<?php if (isset($this->messageBox)): ?>
<?= $this->messageBox->render() ?>
<?php endif ?>
<?php if ($this->form->getErrorMessages()): ?>
<div class="alert alert-danger">
<?= $this->escape($this->errorMessage); ?>
<?php foreach ($this->form->getErrorMessages() as $error): ?>
<?= $this->escape($error); ?><br/>
<?= $this->escape($error); ?><br/>
<?php endforeach; ?>
</div>
<?php endif; ?>

View File

@ -2,4 +2,9 @@
<i class="icinga-icon-remove"></i>
Remove Backend "<?= $this->escape($this->name); ?>"
</h4>
<?php if (isset($this->messageBox)): ?>
<?= $this->messageBox->render() ?>
<?php endif ?>
<?= $this->form ?>

View File

@ -1,10 +1,7 @@
<?= $this->tabs->render($this); ?>
<?php if ($this->successMessage): ?>
<div class="alert alert-success">
<i class="icinga-icon-success"></i>
<strong><?= $this->escape($this->successMessage); ?></strong>
</div>
<?php endif; ?>
<?php if (isset($this->messageBox)): ?>
<?= $this->messageBox->render() ?>
<?php endif ?>
<?= $this->form ?>

View File

@ -2,6 +2,10 @@
<?php $errors = $this->form->getErrorMessages(); ?>
<?php if (isset($this->messageBox)): ?>
<?= $this->messageBox->render() ?>
<?php endif ?>
<?php if ($this->successMessage): ?>
<div class="alert alert-success">
<i class="icinga-icon-success"></i>

View File

@ -9,12 +9,9 @@ $modules = $this->modules->paginate();
<h3>Installed Modules</h3>
<?php if ($this->successMessage): ?>
<div class="alert alert-success">
<i class="icinga-icon-success"></i>
<strong><?= $this->escape($this->successMessage); ?></strong>
</div>
<?php endif; ?>
<?php if (isset($this->messageBox)): ?>
<?= $this->messageBox->render() ?>
<?php endif ?>
<?= $this->paginationControl($modules, null, null, array(
'preserve' => $this->preserve

View File

@ -2,28 +2,11 @@
use Icinga\Web\Url;
$createResource = $this->href('/config/createresource');
?>
<?= $this->tabs->render($this); ?>
<?php if ($this->errorMessage): ?>
<div class="alert alert-danger">
<i class="icinga-icon-error"></i>
<strong><?= $this->escape($this->errorMessage); ?></strong>
</div>
<?php endif; ?>
<?php if ($this->successMessage): ?>
<div class="alert alert-success">
<i class="icinga-icon-success"></i>
<strong><?= $this->escape($this->successMessage); ?></strong>
</div>
<?php elseif ($this->flashMessages): ?>
<div class="alert alert-success">
<i class="icinga-icon-success"></i>
<strong><?= $this->escape($this->flashMessages); ?></strong>
</div>
<?php endif; ?>
<?php if (isset($this->messageBox)): ?>
<?= $this->messageBox->render() ?>
<?php endif ?>
<div class="panel panel-default">
<div class="panel-heading panel-title">

View File

@ -3,14 +3,12 @@
Create New Resource
</h4>
<?php if ($this->errorMessage): ?>
<div class="alert alert-danger">
<?= $this->escape($this->errorMessage); ?>
</div>
<?php endif; ?>
<?php if (isset($this->messageBox)): ?>
<?= $this->messageBox->render() ?>
<?php endif ?>
<p>
Create a new resource to describes a data sourc
Resources are entities that provide data to Icingaweb.
</p>
<?= $this->form ?>

View File

@ -3,13 +3,16 @@
Edit Resource "<?= $this->escape($this->name); ?>"
</h4>
<?php if ($this->errorMessage || $this->form->getErrorMessages()): ?>
<?php if (isset($this->messageBox)): ?>
<?= $this->messageBox->render() ?>
<?php endif ?>
<?php if ($this->form->getErrorMessages()): ?>
<div class="alert alert-danger">
<?= $this->escape($this->errorMessage); ?>
<?php foreach ($this->form->getErrorMessages() as $error): ?>
<?= $this->escape($error); ?><br/>
<?= $this->escape($error); ?><br/>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php endif ?>
<?= $this->form ?>

View File

@ -2,4 +2,9 @@
<i class="icinga-icon-remove"></i>
Remove Resource "<?= $this->escape($this->name); ?>"
</h4>
<?= $this->form ?>
<?php if (isset($this->messageBox)): ?>
<?= $this->messageBox->render() ?>
<?php endif ?>
<?= $this->form ?>

View File

@ -1,4 +1,6 @@
<?= $this->tabs->render($this); ?>
<br/>
<div class="alert alert-error">
<h4><i>WARNING ICON</i>Saving "<?= $this->escape($this->file); ?>.ini" Failed</h4>

View File

@ -1,26 +1,9 @@
<?= $this->tabs->render($this); ?>
<div class="alert alert-error">
<h1>An error occurred</h1>
<p>
<?php echo $this->message ?>
</p>
<?php if (isset($this->exception)): ?>
<div style="text-align:left;">
<h3>Exception information:</h3>
<p>
<b>Message:</b>
<?= $this->exception->getMessage(); ?>
</p>
<h3>Stack trace:</h3>
<pre>
<?= $this->exception->getTraceAsString(); ?>
</pre>
<h3>Request Parameters:</h3>
<pre><?= var_export(\Zend_Controller_Front::getInstance()->getParams(), true); ?>
</pre>
</div>
<?php endif; ?>
<?php if (isset($this->messageBox)) : ?>
<?= $this->messageBox->render() ?>
<? endif ?>
</div>

View File

@ -347,7 +347,6 @@ class Manager
return false;
}
$this->user->sendMessage("Hallo ich bin nachricht.");
if ($persist == true) {
$this->persistCurrentUser();
$this->session->write();
@ -399,9 +398,9 @@ class Manager
}
/**
* Returns the current user or null if no user is authenticated
* Returns the current user or null if no user is authenticated
*
* @return User
* @return User
**/
public function getUser()
{

View File

@ -64,10 +64,13 @@ abstract class Session
* @see self::persist
* @param string $key Name of value
* @param mixed $value Value
*
* @returns PhpSession this
*/
public function set($key, $value)
{
$this->sessionValues[$key] = $value;
return $this;
}
/**

View File

@ -32,14 +32,15 @@ namespace Icinga;
use \DateTimeZone;
use \InvalidArgumentException;
use \Icinga\User\Preferences;
use \Icinga\User\Message;
use \Icinga\Authentication\PhpSession;
/**
* This class represents an authorized user
*
* You can retrieve authorization information (@TODO: Not implemented yet) or
* to retrieve user information
*
*/
class User
{
@ -344,17 +345,34 @@ class User
}
/**
* Send a message to this user that can be accessed in other requests.
* Add a message that can be accessed from future requests, to this user.
*
* @param $msg
* This function does NOT automatically write to the session, messages will not be persisted until you do.
*
* @param Message $msg The message
*/
public function sendMessage($msg)
public function addMessage(Message $msg)
{
$this->messages[] = $msg;
}
/**
* Get all currently pending messages
*
* @return array the messages
*/
public function getMessages()
{
return $this->messages;
return isset($this->messages) ? $this->messages : array();
}
/**
* Remove all messages from this user
*
* This function does NOT automatically write the session, messages will not be persisted until you do.
*/
public function clearMessages()
{
$this->messages = null;
}
}

View File

@ -0,0 +1,57 @@
<?php
namespace Icinga\User;
use \Zend_Log;
use \DateTime;
/**
* Class Message
*
* A Message with an additional logging level to indicate the type.
*
* @package Icinga\User
*/
class Message {
/**
* The content of this message
*
* @var string
*/
private $message;
/**
* The logging-level of this message
*/
private $level;
/**
* Create a new Message
*
* @param string $message The message content
* @param $level The status of the message
* * Zend_Log::INFO
* * Zend_Log::ERR
*/
public function __construct($message, $level = Zend_Log::INFO) {
$this->message = $message;
$this->level = $level;
}
/**
* @return string
*/
public function getMessage()
{
return $this->message;
}
/**
* @return The
*/
public function getLevel()
{
return $this->level;
}
}

View File

@ -30,6 +30,9 @@
namespace Icinga\Web\Controller;
use \Icinga\Application\Icinga;
use \Icinga\Authentication\Manager as AuthenticationManager;
use \Zend_Log;
use \Icinga\User\Message;
/**
* Base class for Configuration Controllers
@ -38,7 +41,6 @@ use \Icinga\Application\Icinga;
* added to the application's configuration dialog. If you create a subclass of
* BasePreferenceController and overwrite @see init(), make sure you call
* parent::init(), otherwise you won't have the $tabs property in your view.
*
*/
class BaseConfigController extends ActionController
{
@ -47,6 +49,50 @@ class BaseConfigController extends ActionController
*/
protected $flashManager;
/**
* Remove all messages from the current user, return them and commit
* changes to the underlying session.
*
* @return array The messages
*/
protected function getAndClearMessages()
{
// empty all messages
$user = AuthenticationManager::getInstance()->getUser();
$messages = $user->getMessages();
$user->clearMessages();
AuthenticationManager::getInstance()->getSession()->write();
return $messages;
}
/**
* Send a message with the logging level Zend_Log::INFO to the current user and
* commit the changes to the underlying session.
*
* @param $msg The message content
*/
protected function addSuccessMessage($msg)
{
AuthenticationManager::getInstance()->getUser()->addMessage(
new Message($msg, Zend_Log::INFO)
);
AuthenticationManager::getInstance()->getSession()->write();
}
/**
* Send a message with the logging level Zend_Log::ERR to the current user and
* commit the changes to the underlying session.
*
* @param $msg The message content
*/
protected function addErrorMessage($msg)
{
AuthenticationManager::getInstance()->getUser()->addMessage(
new Message($msg, Zend_Log::ERR)
);
AuthenticationManager::getInstance()->getSession()->write();
}
/*
* Return an array of tabs provided by this configuration controller.
*
@ -68,6 +114,5 @@ class BaseConfigController extends ActionController
{
parent::init();
$this->view->tabs = ControllerTabCollector::collectControllerTabs('ConfigController');
$this->view->flashMessages = $this->_request->getParam('flash_message');
}
}

View File

@ -0,0 +1,113 @@
<?php
namespace Icinga\Web\Widget;
use \Zend_Log;
use \Zend_Form;
use \Icinga\User\Message;
use \Zend_View_Abstract;
/**
* Class AlertMessageBox
*
* Displays a set of alert messages to the user.
*
* @package Icinga\Web\Widget
*/
class AlertMessageBox implements \Icinga\Web\Widget\Widget {
/**
* The displayed alert messages
*
* @var array
*/
private $messages = array();
/**
* The available states.
*
* @var array
*/
private $states = array(
Zend_Log::INFO => array(
'state' => 'alert-success',
'icon' => 'icinga-icon-success'
),
Zend_Log::NOTICE => array(
'state' => 'alert-info',
'icon' => 'icinga-icon-info'
),
Zend_Log::WARN => array(
'state' => 'alert-warning',
'icon' => 'icinga-icon-warning'
),
Zend_Log::ERR => array(
'state' => 'alert-danger',
'icon' => 'icinga-icon-danger'
)
);
/**
* Create a new AlertBox
*
* @param Message|array $messages The message(s) to display
*/
public function __construct($messages = array()) {
if (!is_array($messages)) {
$this->messages = array($messages);
} else {
$this->messages = $messages;
}
}
/**
* Add a new message.
*
* @param Message $message
*/
public function addMessage(Message $message)
{
$this->messages[] = $message;
}
/**
* Add a new error
*
* @param $error
*/
public function addError($error)
{
$this->messages[] = new Message($error, Zend_Log::ERR);
}
/**
* Add the error messages of the given Zend_Form
*/
public function addForm(Zend_Form $form)
{
foreach ($form->getErrorMessages() as $error) {
$this->addError($error);
}
}
/**
* Output the HTML of the AlertBox
*
* @return string
*/
public function render(Zend_View_Abstract $view = null) {
$html = '';
foreach ($this->messages as $message) {
$level = $message->getLevel();
if (!array_key_exists($level, $this->states)) {
continue;
}
$alert = $this->states[$level];
$html .= '<div class="alert ' . $alert['state']. '">' .
'<i class="' . $alert['icon'] . '"></i>' .
'<strong>' . htmlspecialchars($message->getMessage()) . '</strong>' .
'</div>';
}
return $html;
}
}

View File

@ -34,6 +34,7 @@ use \Icinga\Application\Config as IcingaConfig;
use \Icinga\Config\PreservingIniWriter;
use \Icinga\Web\Controller\BaseConfigController;
use \Icinga\Web\Widget\Tab;
use \Icinga\Web\Widget\AlertMessageBox;
use \Icinga\Web\Url;
use Icinga\Module\Monitoring\Form\Config\ConfirmRemovalForm;
@ -69,6 +70,7 @@ class Monitoring_ConfigController extends BaseConfigController {
*/
public function indexAction()
{
$this->view->messageBox = new AlertMessageBox($this->getAndClearMessages());
$this->view->backends = IcingaConfig::module('monitoring', 'backends')->toArray();
$this->view->instances = IcingaConfig::module('monitoring', 'instances')->toArray();
$this->render('index');
@ -89,11 +91,11 @@ class Monitoring_ConfigController extends BaseConfigController {
$backendForm->setBackendConfiguration(IcingaConfig::module('monitoring', 'backends')->get($backend));
if ($backendForm->isSubmittedAndValid()) {
$newConfig = $backendForm->getConfig();
$config = IcingaConfig::module('monitoring', 'backends');
$config->$backend = $newConfig;
if ($this->writeConfiguration($config, 'backends')) {
$this->addSuccessMessage('Backend ' . $backend . ' Modified.');
$this->redirectNow('monitoring/config');
} else {
$this->render('show-configuration');
@ -116,8 +118,8 @@ class Monitoring_ConfigController extends BaseConfigController {
$configArray[$form->getBackendName()] = $form->getConfig();
if ($this->writeConfiguration(new Zend_Config($configArray), 'backends')) {
$this->view->successMessage = 'Backend Creation Succeeded';
$this->indexAction();
$this->addSuccessMessage('Backend Creation Succeeded');
$this->redirectNow('monitoring/config');
} else {
$this->render('show-configuration');
}
@ -146,8 +148,8 @@ class Monitoring_ConfigController extends BaseConfigController {
unset($configArray[$backend]);
if ($this->writeConfiguration(new Zend_Config($configArray), 'backends')) {
$this->view->successMessage = 'Backend "' . $backend . '" Removed';
$this->indexAction();
$this->addSuccessMessage('Backend "' . $backend . '" Removed');
$this->redirectNow('monitoring/config');
} else {
$this->render('show-configuration');
}
@ -178,8 +180,8 @@ class Monitoring_ConfigController extends BaseConfigController {
unset($configArray[$instance]);
if ($this->writeConfiguration(new Zend_Config($configArray), 'instances')) {
$this->view->successMessage = 'Instance "' . $instance . '" Removed';
$this->indexAction();
$this->addSuccessMessage('Instance "' . $instance . '" Removed');
$this->redirectNow('monitoring/config');
} else {
$this->render('show-configuration');
}
@ -207,8 +209,8 @@ class Monitoring_ConfigController extends BaseConfigController {
$instanceConfig = IcingaConfig::module('monitoring', 'instances')->toArray();
$instanceConfig[$instance] = $form->getConfig();
if ($this->writeConfiguration(new Zend_Config($instanceConfig), 'instances')) {
$this->view->successMessage = 'Instance Modified';
$this->indexAction();
$this->addSuccessMessage('Instance Modified');
$this->redirectNow('monitoring/config');
} else {
$this->render('show-configuration');
return;
@ -228,8 +230,8 @@ class Monitoring_ConfigController extends BaseConfigController {
$instanceConfig = IcingaConfig::module('monitoring', 'instances')->toArray();
$instanceConfig[$form->getInstanceName()] = $form->getConfig()->toArray();
if ($this->writeConfiguration(new Zend_Config($instanceConfig), 'instances')) {
$this->view->successMessage = 'Instance Creation Succeeded';
$this->indexAction();
$this->addSuccessMessage('Instance Creation Succeeded');
$this->redirectNow('monitoring/config');
} else {
$this->render('show-configuration');
}

View File

@ -56,7 +56,6 @@ class Monitoring_ShowController extends MonitoringController
*/
public function init()
{
if ($this->getRequest()->getActionName() === 'host') {
$this->view->object = new Host($this->getRequest());
} elseif ($this->getRequest()->getActionName() === 'service'

View File

@ -1,8 +1,8 @@
<?= $this->tabs->render($this); ?>
<?php if ($this->name): ?>
<h4><i>{{EDIT_ICON}} Edit Backend "<?= $this->escape($this->name) ?>"</h4>
<h4><i> <i class="icinga-icon-edit"></i> Edit Backend "<?= $this->escape($this->name) ?>"</h4>
<?php else: ?>
<h4>{{CREATE_ICON}} Create New Backend</h4>
<h4> <i class="icinga-icon-create"></i> Create New Backend</h4>
<?php endif; ?>
<?php if ($this->error): ?>

View File

@ -1,9 +1,8 @@
<?= $this->tabs->render($this); ?>
<?php if (isset($this->name)): ?>
<h4>{{EDIT_ICON}} Edit Instance Configuration for "<?= $this->escape($this->name) ?>"</h4>
<h4><i class="icinga-icon-edit"></i> } Edit Instance Configuration for "<?= $this->escape($this->name) ?>"</h4>
<?php else: ?>
<h4>{{CREATE_ICON}} Configure New Icinga Instance</h4>
<h4><i class="icinga-icon-create"></i> Configure New Icinga Instance</h4>
<?php endif; ?>
<?php if ($this->error): ?>

View File

@ -3,16 +3,13 @@
<h3>Monitoring Backends</h3>
<?php if ($this->successMessage): ?>
<div class="alert alert-success">
<i>{{OK_ICON}}</i>
<strong><?= $this->escape($this->successMessage); ?></strong>
</div>
<?php endif; ?>
<?php if (isset($this->messageBox)): ?>
<?= $this->messageBox->render() ?>
<?php endif ?>
<div>
<a href="<?= Url::fromPath('/monitoring/config/createbackend')->getAbsoluteUrl();?>">
{{CREATE_ICON}} Create New Monitoring Backend
<i class="icinga-icon-create"></i> Create New Monitoring Backend
</a>
</div>
<br/>
@ -24,8 +21,8 @@
<b><?= $this->escape($backendName); ?></b>
<small>(Type: <?= $this->escape($config['type'] === 'ido' ? 'IDO' : ucfirst($config['type'])); ?>)</small>
<div>
<a href="<?= $removeUrl; ?>">{{REMOVE_ICON}} Remove This Backend</a><br/>
<a href="<?= $editUrl; ?>">{{EDIT_ICON}} Edit This Backend</a>
<a href="<?= $removeUrl; ?>"><i class="icinga-icon-remove"></i> Remove This Backend</a><br/>
<a href="<?= $editUrl; ?>"><i class="icinga-icon-edit"></i> Edit This Backend</a>
</div>
</div>
<br/>
@ -37,7 +34,7 @@
<div>
<a href="<?= Url::fromPath('/monitoring/config/createinstance')->getAbsoluteUrl();?>">
{{CREATE_ICON}} Create New Instance
<i class="icinga-icon-create"></i> Create New Instance
</a>
</div>
@ -50,8 +47,8 @@
<small>(Type: <?= isset($config['host']) ? 'Remote' : 'Local'; ?>)</small>
<div>
<a href="<?= $removeUrl; ?>">{{REMOVE_ICON}} Remove This Instance</a><br/>
<a href="<?= $editUrl; ?>">{{EDIT_ICON}} Edit This Instance</a>
<a href="<?= $removeUrl; ?>"><i class="icinga-icon-remove"></i> Remove This Instance</a><br/>
<a href="<?= $editUrl; ?>"><i class="icinga-icon-edit"></i> Edit This Instance</a>
</div>
</div>
<br/>

View File

@ -1,5 +1,5 @@
<?= $this->tabs->render($this); ?>
<h4>{{REMOVE_ICON}} Remove Backend "<?= $this->escape($this->name) ?>"</h4>
<h4><i class="icinga-icon-remove"></i> Remove Backend "<?= $this->escape($this->name) ?>"</h4>
<p>
Are you sure you want to remove the backend <?= $this->escape($this->name) ?>?

View File

@ -1,12 +1,12 @@
<?= $this->tabs->render($this); ?>
<h4>{{REMOVE_ICON}} Remove Instance "<?= $this->escape($this->name) ?>"</h4>
<h4><i class="icinga-icon-remove"></i> Remove Instance "<?= $this->escape($this->name) ?>"</h4>
<p>
Are you sure you want to remove the instance <?= $this->escape($this->name) ?>?
</p>
<p>
{{WARNING_ICON}} If you have still any environments or views refering to this instance, you won't be able to send commands anymore
<i class="icinga-icon-warning"></i> If you have still any environments or views refering to this instance, you won't be able to send commands anymore
after deletion.
</p>

View File

@ -1,7 +1,7 @@
<?= $this->tabs->render($this); ?>
<br/>
<div class="alert alert-error">
<h4><i>{{ERROR_ICON}}</i> Saving <?= $this->escape($this->file); ?>failed</h4>
<h4><i><i class="icinga-icon-error"></i> </i> Saving <?= $this->escape($this->file); ?>failed</h4>
<br/>
<p>
Your <?= $this->escape($this->file); ?> configuration couldn't be stored (error: "<?= $this->exceptionMessage; ?>").<br/>

View File

@ -179,17 +179,6 @@ class ManagerTest extends BaseTestCase
$this->assertTrue($auth->isAuthenticated());
}
/**
* @expectedException Exception
* @expectedExceptionMessage Session write after close
*/
public function testWriteSessionTwice()
{
$auth = $this->getManagerInstance($session, false);
$this->assertFalse($auth->isAuthenticated(true));
$auth->authenticate(new Credential("jdoe", "passjdoe"));
}
/**
* @expectedException Icinga\Exception\ConfigurationError
* @expectedExceptionMessage No authentication backend set