Merge pull request #3588 from Icinga/fix/problems-the-world-has-and-ever-will

Fix problems the world has and ever will
This commit is contained in:
Eric Lippmann 2018-11-15 11:25:48 +01:00 committed by GitHub
commit 1268c16a7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 103 additions and 29 deletions

View File

@ -12,6 +12,7 @@ use Icinga\Application\Modules\Module;
use Icinga\Data\ResourceFactory;
use Icinga\Exception\ConfigurationError;
use Icinga\Exception\NotFoundError;
use Icinga\Forms\ActionForm;
use Icinga\Forms\Config\GeneralConfigForm;
use Icinga\Forms\Config\ResourceConfigForm;
use Icinga\Forms\Config\UserBackendConfigForm;
@ -122,7 +123,20 @@ class ConfigController extends Controller
$module = new Module($app, $name, $manager->getModuleDir($name));
}
$toggleForm = new ActionForm();
$toggleForm->setDefaults(['identifier' => $name]);
if (! $this->view->moduleData->enabled) {
$toggleForm->setAction(Url::fromPath('config/moduleenable'));
$toggleForm->setDescription(sprintf($this->translate('Enable the %s module'), $name));
} elseif ($this->view->moduleData->loaded) {
$toggleForm->setAction(Url::fromPath('config/moduledisable'));
$toggleForm->setDescription(sprintf($this->translate('Disable the %s module'), $name));
} else {
$toggleForm = null;
}
$this->view->module = $module;
$this->view->toggleForm = $toggleForm;
$this->view->tabs = $module->getConfigTabs()->activate('info');
$this->view->moduleGitCommitId = Version::getGitHead($module->getBaseDir());
} else {
@ -137,15 +151,20 @@ class ConfigController extends Controller
public function moduleenableAction()
{
$this->assertPermission('config/modules');
$module = $this->getParam('name');
$manager = Icinga::app()->getModuleManager();
try {
$manager->enableModule($module);
$form = new ActionForm();
$form->setOnSuccess(function (ActionForm $form) {
$module = $form->getValue('identifier');
Icinga::app()->getModuleManager()->enableModule($module);
Notification::success(sprintf($this->translate('Module "%s" enabled'), $module));
$this->rerenderLayout()->reloadCss()->redirectNow('config/modules');
});
try {
$form->handleRequest();
} catch (Exception $e) {
$this->view->exceptionMessage = $e->getMessage();
$this->view->moduleName = $module;
$this->view->moduleName = $form->getValue('name');
$this->view->action = 'enable';
$this->render('module-configuration-error');
}
@ -157,15 +176,20 @@ class ConfigController extends Controller
public function moduledisableAction()
{
$this->assertPermission('config/modules');
$module = $this->getParam('name');
$manager = Icinga::app()->getModuleManager();
try {
$manager->disableModule($module);
$form = new ActionForm();
$form->setOnSuccess(function (ActionForm $form) {
$module = $form->getValue('identifier');
Icinga::app()->getModuleManager()->disableModule($module);
Notification::success(sprintf($this->translate('Module "%s" disabled'), $module));
$this->rerenderLayout()->reloadCss()->redirectNow('config/modules');
});
try {
$form->handleRequest();
} catch (Exception $e) {
$this->view->exceptionMessage = $e->getMessage();
$this->view->moduleName = $module;
$this->view->moduleName = $form->getValue('name');
$this->view->action = 'disable';
$this->render('module-configuration-error');
}

View File

@ -0,0 +1,61 @@
<?php
/* Icinga Web 2 | (c) 2018 Icinga Development Team | GPLv2+ */
namespace Icinga\Forms;
use Icinga\Web\Form;
class ActionForm extends Form
{
/**
* The icon shown on the button
*
* @var string
*/
protected $icon = 'arrows-cw';
/**
* Set the icon to show on the button
*
* @param string $name
*
* @return $this
*/
public function setIcon($name)
{
$this->icon = (string) $name;
return $this;
}
public function init()
{
$this->setAttrib('class', 'inline');
$this->setUidDisabled(true);
$this->setDecorators(['FormElements', 'Form']);
}
public function createElements(array $formData)
{
$this->addElement(
'hidden',
'identifier',
[
'required' => true,
'decorators' => ['ViewHelper']
]
);
$this->addElement(
'button',
'btn_submit',
[
'escape' => false,
'type' => 'submit',
'class' => 'link-button spinner',
'value' => 'btn_submit',
'decorators' => ['ViewHelper'],
'label' => $this->getView()->icon($this->icon),
'title' => $this->getDescription()
]
);
}
}

View File

@ -18,22 +18,11 @@
</tr>
<tr>
<th><?= $this->translate('State') ?></th>
<td><?= $state ?><?php if ($state === 'enabled'): ?>
<?= $this->qlink(
$this->translate('disable'),
'config/moduledisable',
array('name' => $module->getName()),
array('title' => sprintf($this->translate('Disable the %s module'), $module->getName()), 'class' => 'action-link')
); ?>
<?php endif ?>
<?php if ($state === 'disabled'): ?>
<?= $this->qlink(
$this->translate('enable'),
'config/moduleenable',
array('name' => $module->getName()),
array('title' => sprintf($this->translate('Enable the %s module'), $module->getName()), 'class' => 'action-link')
); ?>
<?php endif ?>
<td>
<?= $state ?>
<?php if (isset($this->toggleForm)): ?>
<?= $this->toggleForm ?>
<?php endif ?>
</td>
<tr>
<th><?= $this->escape($this->translate('Version')) ?></th>

View File

@ -27,7 +27,7 @@
echo $this->qlink(
$module->name,
'config/module/',
'config/module',
array('name' => $module->name),
array(
'class' => 'rowaction',

View File

@ -262,7 +262,7 @@ class IniParser
}
try {
$configArray = parse_ini_string($content, true);
$configArray = parse_ini_string($content, true, INI_SCANNER_RAW);
} catch (ErrorException $e) {
throw new ConfigurationError('Couldn\'t parse the INI file `%s\'', $path, $e);
}

View File

@ -77,7 +77,7 @@ $this->addHelperFunction('img', function ($url, $params = null, array $propertie
return sprintf(
'<img src="%s"%s />',
$view->url($url, $params),
$view->escape($view->url($url, $params)),
$view->propertiesToString($properties)
);
});