Merge branch 'master' into feature/deduplicate-puppet-code-6842
This commit is contained in:
commit
003567fae8
|
@ -32,6 +32,9 @@ class ConfigController extends ActionController
|
|||
))->add('resources', array(
|
||||
'title' => $this->translate('Resources'),
|
||||
'url' => 'config/resource'
|
||||
))->add('roles', array(
|
||||
'title' => $this->translate('Roles'),
|
||||
'url' => 'roles'
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Forms\ConfirmRemovalForm;
|
||||
use Icinga\Forms\Security\RoleForm;
|
||||
use Icinga\Web\Controller\ActionController;
|
||||
use Icinga\Web\Notification;
|
||||
use Icinga\Web\Widget;
|
||||
|
||||
class RolesController extends ActionController
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$this->view->tabs = Widget::create('tabs')->add('index', array(
|
||||
'title' => $this->translate('Application'),
|
||||
'url' => 'config'
|
||||
))->add('authentication', array(
|
||||
'title' => $this->translate('Authentication'),
|
||||
'url' => 'config/authentication'
|
||||
))->add('resources', array(
|
||||
'title' => $this->translate('Resources'),
|
||||
'url' => 'config/resource'
|
||||
))->add('roles', array(
|
||||
'title' => $this->translate('Roles'),
|
||||
'url' => 'roles'
|
||||
));
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$this->view->tabs->activate('roles');
|
||||
$this->view->roles = Config::app('roles', true);
|
||||
}
|
||||
|
||||
public function newAction()
|
||||
{
|
||||
$role = new RoleForm(array(
|
||||
'onSuccess' => function (RoleForm $role) {
|
||||
$name = $role->getElement('name')->getValue();
|
||||
$values = $role->getValues();
|
||||
try {
|
||||
$role->add($name, $values);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$role->addError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
if ($role->save()) {
|
||||
Notification::success(t('Role created'));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
));
|
||||
$role
|
||||
->setSubmitLabel($this->translate('Create Role'))
|
||||
->setIniConfig(Config::app('roles', true))
|
||||
->setRedirectUrl('roles')
|
||||
->handleRequest();
|
||||
$this->view->form = $role;
|
||||
}
|
||||
|
||||
public function updateAction()
|
||||
{
|
||||
$name = $this->_request->getParam('role');
|
||||
if (empty($name)) {
|
||||
throw new Zend_Controller_Action_Exception(
|
||||
sprintf($this->translate('Required parameter \'%s\' missing'), 'role'),
|
||||
400
|
||||
);
|
||||
}
|
||||
$role = new RoleForm();
|
||||
$role->setSubmitLabel($this->translate('Update Role'));
|
||||
try {
|
||||
$role
|
||||
->setIniConfig(Config::app('roles', true))
|
||||
->load($name);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
throw new Zend_Controller_Action_Exception(
|
||||
$e->getMessage(),
|
||||
400
|
||||
);
|
||||
}
|
||||
$role
|
||||
->setOnSuccess(function (RoleForm $role) use ($name) {
|
||||
$oldName = $name;
|
||||
$name = $role->getElement('name')->getValue();
|
||||
$values = $role->getValues();
|
||||
try {
|
||||
$role->update($name, $values, $oldName);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$role->addError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
if ($role->save()) {
|
||||
Notification::success(t('Role updated'));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
})
|
||||
->setRedirectUrl('roles')
|
||||
->handleRequest();
|
||||
$this->view->name = $name;
|
||||
$this->view->form = $role;
|
||||
}
|
||||
|
||||
public function removeAction()
|
||||
{
|
||||
$name = $this->_request->getParam('role');
|
||||
if (empty($name)) {
|
||||
throw new Zend_Controller_Action_Exception(
|
||||
sprintf($this->translate('Required parameter \'%s\' missing'), 'role'),
|
||||
400
|
||||
);
|
||||
}
|
||||
$role = new RoleForm();
|
||||
try {
|
||||
$role
|
||||
->setIniConfig(Config::app('roles', true))
|
||||
->load($name);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
throw new Zend_Controller_Action_Exception(
|
||||
$e->getMessage(),
|
||||
400
|
||||
);
|
||||
}
|
||||
$confirmation = new ConfirmRemovalForm(array(
|
||||
'onSuccess' => function (ConfirmRemovalForm $confirmation) use ($name, $role) {
|
||||
try {
|
||||
$role->remove($name);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
Notification::error($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
if ($role->save()) {
|
||||
Notification::success(t('Role removed'));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
));
|
||||
$confirmation
|
||||
->setSubmitLabel($this->translate('Remove Role'))
|
||||
->setRedirectUrl('roles')
|
||||
->handleRequest();
|
||||
$this->view->name = $name;
|
||||
$this->view->form = $confirmation;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,235 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Forms\Security;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use LogicException;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Forms\ConfigForm;
|
||||
use Icinga\Util\String;
|
||||
|
||||
/**
|
||||
* Form for managing roles
|
||||
*/
|
||||
class RoleForm extends ConfigForm
|
||||
{
|
||||
/**
|
||||
* Provided permissions by currently loaded modules
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $providedPermissions = array();
|
||||
|
||||
/**
|
||||
* Provided restrictions by currently loaded modules
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $providedRestrictions = array();
|
||||
|
||||
/**
|
||||
* (non-PHPDoc)
|
||||
* @see \Icinga\Web\Form::init() For the method documentation.
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
foreach (Icinga::app()->getModuleManager()->getLoadedModules() as $module) {
|
||||
foreach ($module->getProvidedPermissions() as $permission) {
|
||||
/** @var object $permission */
|
||||
$this->providedPermissions[$permission->name] = $permission->name . ': ' . $permission->description;
|
||||
}
|
||||
foreach ($module->getProvidedRestrictions() as $restriction) {
|
||||
/** @var object $restriction */
|
||||
$this->providedRestrictions[$restriction->name] = $restriction->description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPDoc)
|
||||
* @see \Icinga\Web\Form::createElements() For the method documentation.
|
||||
*/
|
||||
public function createElements(array $formData = array())
|
||||
{
|
||||
$this->addElements(array(
|
||||
array(
|
||||
'text',
|
||||
'name',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Role Name'),
|
||||
'description' => t('The name of the role'),
|
||||
'ignore' => true
|
||||
),
|
||||
),
|
||||
array(
|
||||
'textarea',
|
||||
'users',
|
||||
array(
|
||||
'label' => t('Users'),
|
||||
'description' => t('Comma-separated list of users that are assigned to the role')
|
||||
),
|
||||
),
|
||||
array(
|
||||
'textarea',
|
||||
'groups',
|
||||
array(
|
||||
'label' => t('Groups'),
|
||||
'description' => t('Comma-separated list of groups that are assigned to the role')
|
||||
),
|
||||
),
|
||||
array(
|
||||
'multiselect',
|
||||
'permissions',
|
||||
array(
|
||||
'label' => t('Permissions Set'),
|
||||
'description' => t('The permissions to grant. You may select more than one permission'),
|
||||
'multiOptions' => $this->providedPermissions
|
||||
)
|
||||
)
|
||||
));
|
||||
foreach ($this->providedRestrictions as $name => $description) {
|
||||
$this->addElement(
|
||||
'text',
|
||||
$name,
|
||||
array(
|
||||
'label' => $name,
|
||||
'description' => $description
|
||||
)
|
||||
);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a role
|
||||
*
|
||||
* @param string $name The name of the role
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws LogicException If the config is not set
|
||||
* @see ConfigForm::setConfig() For setting the config.
|
||||
*/
|
||||
public function load($name)
|
||||
{
|
||||
if (! isset($this->config)) {
|
||||
throw new LogicException(sprintf('Can\'t load role \'%s\'. Config is not set', $name));
|
||||
}
|
||||
if (! $this->config->hasSection($name)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
t('Can\'t load role \'%s\'. Role does not exist'),
|
||||
$name
|
||||
));
|
||||
}
|
||||
$role = $this->config->getSection($name)->toArray();
|
||||
$role['permissions'] = ! empty($role['permissions'])
|
||||
? String::trimSplit($role['permissions'])
|
||||
: null;
|
||||
$role['name'] = $name;
|
||||
$this->populate($role);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a role
|
||||
*
|
||||
* @param string $name The name of the role
|
||||
* @param array $values
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws LogicException If the config is not set
|
||||
* @throws InvalidArgumentException If the role to add already exists
|
||||
* @see ConfigForm::setConfig() For setting the config.
|
||||
*/
|
||||
public function add($name, array $values)
|
||||
{
|
||||
if (! isset($this->config)) {
|
||||
throw new LogicException(sprintf('Can\'t add role \'%s\'. Config is not set', $name));
|
||||
}
|
||||
if ($this->config->hasSection($name)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
t('Can\'t add role \'%s\'. Role already exists'),
|
||||
$name
|
||||
));
|
||||
}
|
||||
$this->config->setSection($name, $values);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a role
|
||||
*
|
||||
* @param string $name The name of the role
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws LogicException If the config is not set
|
||||
* @throws InvalidArgumentException If the role does not exist
|
||||
* @see ConfigForm::setConfig() For setting the config.
|
||||
*/
|
||||
public function remove($name)
|
||||
{
|
||||
if (! isset($this->config)) {
|
||||
throw new LogicException(sprintf('Can\'t remove role \'%s\'. Config is not set', $name));
|
||||
}
|
||||
if (! $this->config->hasSection($name)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
t('Can\'t remove role \'%s\'. Role does not exist'),
|
||||
$name
|
||||
));
|
||||
}
|
||||
$this->config->removeSection($name);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a role
|
||||
*
|
||||
* @param string $name The possibly new name of the role
|
||||
* @param array $values
|
||||
* @param string $oldName The name of the role to update
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws LogicException If the config is not set
|
||||
* @throws InvalidArgumentException If the role to update does not exist
|
||||
* @see ConfigForm::setConfig() For setting the config.
|
||||
*/
|
||||
public function update($name, array $values, $oldName)
|
||||
{
|
||||
if (! isset($this->config)) {
|
||||
throw new LogicException(sprintf('Can\'t update role \'%s\'. Config is not set', $name));
|
||||
}
|
||||
if ($name !== $oldName) {
|
||||
// The permission got a new name
|
||||
$this->remove($oldName);
|
||||
$this->add($name, $values);
|
||||
} else {
|
||||
if (! $this->config->hasSection($name)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
t('Can\'t update role \'%s\'. Role does not exist'),
|
||||
$name
|
||||
));
|
||||
}
|
||||
$this->config->setSection($name, $values);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPDoc)
|
||||
* @see \Zend_Form::getValues() For the method documentation.
|
||||
*/
|
||||
public function getValues($suppressArrayNotation = false)
|
||||
{
|
||||
$values = array_filter(parent::getValues($suppressArrayNotation));
|
||||
if (isset($values['permissions'])) {
|
||||
$values['permissions'] = implode(', ', $values['permissions']);
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
<div class="controls">
|
||||
<?= $tabs ?>
|
||||
<h1><?= $this->translate('Roles') ?></h1>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div>
|
||||
<?php /** @var \Icinga\Application\Config $roles */ if ($roles->isEmpty()): ?>
|
||||
<?= $this->translate('No roles found.') ?>
|
||||
<?php else: ?>
|
||||
<table class="avp action" data-base-target="_next">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?= $this->translate('Name') ?></th>
|
||||
<th><?= $this->translate('Permissions') ?></th>
|
||||
<th><?= $this->translate('Restrictions') ?></th>
|
||||
<th><?= $this->translate('Users') ?></th>
|
||||
<th><?= $this->translate('Groups') ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($roles as $name => $role): /** @var object $role */ ?>
|
||||
<tr>
|
||||
<td>
|
||||
<?= $this->escape($name) ?>
|
||||
<div class="hidden">
|
||||
<a href="<?= $this->url('roles/update', array('role' => $name)) ?>"></a>
|
||||
</div>
|
||||
</td>
|
||||
<td><?= $this->escape($role->permissions, 0, 50) ?></td>
|
||||
<td>
|
||||
<?php
|
||||
// TODO(el): $role->without(...) or $role->shift(...) would be nice!
|
||||
$restrictions = $role;
|
||||
unset($restrictions['users']);
|
||||
unset($restrictions['groups']);
|
||||
unset($restrictions['permissions']);
|
||||
?>
|
||||
<?php if (! empty($restrictions)): ?>
|
||||
<table>
|
||||
<tbody>
|
||||
<?php foreach ($restrictions as $restrictionName => $restriction): ?>
|
||||
<tr>
|
||||
<th><?= $this->escape($restrictionName) ?></th>
|
||||
<td><?= $this->escape($restriction) ?></td>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php endif ?>
|
||||
</td>
|
||||
<td><?= $this->escape($role->users) ?></td>
|
||||
<td><?= $this->escape($role->groups) ?></td>
|
||||
<td>
|
||||
<a href="<?= $this->url('roles/remove', array('role' => $name)) ?>"
|
||||
title="<?= $this->translate('Remove role') ?>">
|
||||
<?= $this->icon('cancel') ?>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php endif ?>
|
||||
<a data-base-target="_next" href="<?= $this->href('roles/new') ?>">
|
||||
<?= $this->translate('New Role') ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,6 @@
|
|||
<div class="controls">
|
||||
<h1><?= $this->translate('New Role') ?></h1>
|
||||
</div>
|
||||
<div class="content">
|
||||
<?= $form ?>
|
||||
</div>
|
|
@ -0,0 +1,6 @@
|
|||
<div class="controls">
|
||||
<h1><?= sprintf($this->translate('Remove Role %s'), $name) ?></h1>
|
||||
</div>
|
||||
<div class="content">
|
||||
<?= $form ?>
|
||||
</div>
|
|
@ -0,0 +1,6 @@
|
|||
<div class="controls">
|
||||
<h1><?= sprintf($this->translate('Update Role %s'), $name) ?></h1>
|
||||
</div>
|
||||
<div class="content">
|
||||
<?= $form ?>
|
||||
</div>
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env php
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/python
|
||||
|
||||
# {{{ICINGA_LICENSE_HEADER}}}
|
||||
# {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
|
|
@ -4,16 +4,15 @@
|
|||
|
||||
namespace Icinga\Web;
|
||||
|
||||
use Icinga\Authentication\Manager;
|
||||
use Icinga\Web\Menu\MenuItemRenderer;
|
||||
use RecursiveIterator;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Authentication\Manager;
|
||||
use Icinga\Data\ConfigObject;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Web\Menu\MenuItemRenderer;
|
||||
|
||||
class Menu implements RecursiveIterator
|
||||
{
|
||||
|
|
|
@ -82,6 +82,7 @@ class Monitoring_ShowController extends Controller
|
|||
|
||||
public function servicesAction()
|
||||
{
|
||||
$this->setAutorefreshInterval(15);
|
||||
$this->getTabs()->activate('services');
|
||||
$this->_setParam('service', '');
|
||||
// TODO: This used to be a hack and still is. Modifying query string here.
|
||||
|
|
|
@ -22,7 +22,7 @@ $requirements = $form->getRequirements();
|
|||
<td></td>
|
||||
<td class="btn-update">
|
||||
<div class="buttons">
|
||||
<a href="<?= $this->href(); ?>" class="button-like"><?= mt('setup', 'Refresh'); ?></a>
|
||||
<a title="<?= $this->translate('You may also need to restart the web-server for the changes to take effect!'); ?>" href="<?= $this->href(); ?>" class="button-like"><?= mt('setup', 'Refresh'); ?></a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -5,7 +5,8 @@ use Icinga\Application\Config;
|
|||
use Icinga\Application\Platform;
|
||||
use Icinga\Web\Wizard;
|
||||
|
||||
$setupTokenPath = rtrim(Icinga::app()->getConfigDir(), '/') . '/setup.token';
|
||||
$configDir = Icinga::app()->getConfigDir();
|
||||
$setupTokenPath = rtrim($configDir, '/') . '/setup.token';
|
||||
$cliPath = realpath(Icinga::app()->getApplicationDir() . '/../bin/icingacli');
|
||||
|
||||
?>
|
||||
|
@ -20,7 +21,8 @@ $cliPath = realpath(Icinga::app()->getApplicationDir() . '/../bin/icingacli');
|
|||
<?php else: ?>
|
||||
<p><?= mt(
|
||||
'setup',
|
||||
''
|
||||
'This wizard will guide you through the configuration of Icinga Web 2. Once completed and successfully'
|
||||
. ' finished you are able to log in and to explore all the new and stunning features!'
|
||||
); ?></p>
|
||||
<?php endif ?>
|
||||
<form id="<?= $form->getName(); ?>" name="<?= $form->getName(); ?>" enctype="<?= $form->getEncType(); ?>" method="<?= $form->getMethod(); ?>" action="<?= $form->getAction(); ?>">
|
||||
|
@ -44,7 +46,7 @@ $cliPath = realpath(Icinga::app()->getApplicationDir() . '/../bin/icingacli');
|
|||
); ?></p>
|
||||
<p><?= mt('setup', 'If you\'ve got the IcingaCLI installed you can do the following:'); ?></p>
|
||||
<div class="code">
|
||||
<span><?= $cliPath ? $cliPath : 'icingacli'; ?> setup config createDirectory <?= ($user = Platform::getPhpUser()) !== null ? $user : 'your_webserver_group'; ?>;</span>
|
||||
<span><?= $cliPath ? $cliPath : 'icingacli'; ?> setup config createDirectory <?= ($user = Platform::getPhpUser()) !== null ? $user : 'your_webserver_group'; ?><?= $configDir !== '/etc/icingaweb' ? ' --path ' . $configDir : ''; ?>;</span>
|
||||
<span><?= $cliPath ? $cliPath : 'icingacli'; ?> setup token create;</span>
|
||||
</div>
|
||||
<p><?= mt('setup', 'In case the IcingaCLI is missing you can create the token manually:'); ?></p>
|
||||
|
|
|
@ -246,6 +246,8 @@ class DbTool
|
|||
|
||||
$config = array(
|
||||
'dbname' => $dbname,
|
||||
'host' => $this->config['host'],
|
||||
'port' => $this->config['port'],
|
||||
'username' => $this->config['username'],
|
||||
'password' => $this->config['password']
|
||||
);
|
||||
|
|
|
@ -386,7 +386,10 @@ class WebWizard extends Wizard implements SetupWizard
|
|||
$defaultTimezone = Platform::getPhpConfig('date.timezone');
|
||||
$requirements->addMandatory(
|
||||
mt('setup', 'Default Timezone'),
|
||||
mt('setup', 'It is required that a default timezone has been set using date.timezone in php.ini.'),
|
||||
sprintf(
|
||||
mt('setup', 'It is required that a default timezone has been set using date.timezone in %s.'),
|
||||
php_ini_loaded_file() ?: 'php.ini'
|
||||
),
|
||||
$defaultTimezone,
|
||||
$defaultTimezone ? sprintf(mt('setup', 'Your default timezone is: %s'), $defaultTimezone) : (
|
||||
mt('setup', 'You did not define a default timezone.')
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env php
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
require_once '/usr/share/php/Icinga/Application/Cli.php';
|
||||
|
|
|
@ -20,7 +20,6 @@ if (!defined('ICINGA_LIBDIR')) {
|
|||
set_include_path(implode(PATH_SEPARATOR, array($libraryPath, get_include_path())));
|
||||
|
||||
require_once 'Mockery/Loader.php';
|
||||
require_once 'Hamcrest/Hamcrest.php';
|
||||
$mockeryLoader = new \Mockery\Loader;
|
||||
$mockeryLoader->register();
|
||||
|
||||
|
|
Loading…
Reference in New Issue