2015-06-30 11:19:31 +02:00
|
|
|
<?php
|
|
|
|
|
2015-10-20 22:34:04 +02:00
|
|
|
namespace Icinga\Module\Director\Controllers;
|
2015-06-30 11:19:31 +02:00
|
|
|
|
2020-10-26 18:50:13 +01:00
|
|
|
use gipfl\Web\Widget\Hint;
|
2021-10-05 23:13:40 +02:00
|
|
|
use Icinga\Module\Director\Objects\IcingaCommandArgument;
|
|
|
|
use Icinga\Module\Director\Web\Table\BranchedIcingaCommandArgumentTable;
|
2019-05-02 13:23:06 +02:00
|
|
|
use ipl\Html\Html;
|
2017-07-20 22:29:00 +02:00
|
|
|
use Icinga\Module\Director\Forms\IcingaCommandArgumentForm;
|
|
|
|
use Icinga\Module\Director\Objects\IcingaCommand;
|
2018-05-04 18:02:05 +02:00
|
|
|
use Icinga\Module\Director\Resolver\CommandUsage;
|
2015-10-20 22:34:04 +02:00
|
|
|
use Icinga\Module\Director\Web\Controller\ObjectController;
|
2017-07-20 22:29:00 +02:00
|
|
|
use Icinga\Module\Director\Web\Table\IcingaCommandArgumentTable;
|
2015-08-03 13:42:19 +02:00
|
|
|
|
2015-10-20 22:34:04 +02:00
|
|
|
class CommandController extends ObjectController
|
2015-06-30 11:19:31 +02:00
|
|
|
{
|
2018-05-04 18:02:05 +02:00
|
|
|
/**
|
2018-10-30 16:35:09 +01:00
|
|
|
* @throws \Icinga\Exception\AuthenticationException
|
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
* @throws \Icinga\Security\SecurityException
|
2018-05-04 18:02:05 +02:00
|
|
|
*/
|
2015-08-03 13:42:19 +02:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
parent::init();
|
2017-07-04 21:22:20 +02:00
|
|
|
$o = $this->object;
|
|
|
|
if ($o && ! $o->isExternal()) {
|
2021-10-05 23:13:40 +02:00
|
|
|
if ($this->getBranch()->isBranch()) {
|
|
|
|
$urlParams = ['uuid' => $o->getUniqueId()->toString()];
|
|
|
|
} else {
|
|
|
|
$urlParams = ['name' => $o->getObjectName()];
|
|
|
|
}
|
2017-07-04 21:22:20 +02:00
|
|
|
$this->tabs()->add('arguments', [
|
2015-08-03 13:42:19 +02:00
|
|
|
'url' => 'director/command/arguments',
|
2021-10-05 23:13:40 +02:00
|
|
|
'urlParams' => $urlParams,
|
2015-08-03 13:42:19 +02:00
|
|
|
'label' => 'Arguments'
|
2017-07-04 21:22:20 +02:00
|
|
|
]);
|
2015-08-03 13:42:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-04 18:02:05 +02:00
|
|
|
/**
|
2018-10-30 16:35:09 +01:00
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
* @throws \Zend_Db_Select_Exception
|
2018-05-04 18:02:05 +02:00
|
|
|
*/
|
|
|
|
public function indexAction()
|
|
|
|
{
|
2018-07-27 23:30:42 +02:00
|
|
|
if (! $this->getRequest()->isApiRequest()) {
|
|
|
|
$this->showUsage();
|
|
|
|
}
|
2018-05-04 18:02:05 +02:00
|
|
|
parent::indexAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-30 16:35:09 +01:00
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
* @throws \Icinga\Security\SecurityException
|
|
|
|
* @throws \Zend_Db_Select_Exception
|
2018-05-04 18:02:05 +02:00
|
|
|
*/
|
|
|
|
public function renderAction()
|
|
|
|
{
|
|
|
|
if ($this->object->isExternal()) {
|
|
|
|
$this->showUsage();
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::renderAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-30 16:35:09 +01:00
|
|
|
* @throws \Zend_Db_Select_Exception
|
2018-05-04 18:02:05 +02:00
|
|
|
*/
|
|
|
|
protected function showUsage()
|
|
|
|
{
|
|
|
|
/** @var IcingaCommand $command */
|
|
|
|
$command = $this->object;
|
|
|
|
if ($command->isInUse()) {
|
|
|
|
$usage = new CommandUsage($command);
|
2020-10-26 18:50:13 +01:00
|
|
|
$this->content()->add(Hint::info(Html::sprintf(
|
2018-05-04 18:02:05 +02:00
|
|
|
$this->translate('This Command is currently being used by %s'),
|
|
|
|
Html::tag('span', null, $usage->getLinks())->setSeparator(', ')
|
2020-10-26 18:50:13 +01:00
|
|
|
))->addAttributes([
|
|
|
|
'data-base-target' => '_next'
|
|
|
|
]));
|
2018-05-04 18:02:05 +02:00
|
|
|
} else {
|
2020-10-26 18:50:13 +01:00
|
|
|
$this->content()->add(Hint::warning($this->translate('This Command is currently not in use')));
|
2018-05-04 18:02:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-03 13:42:19 +02:00
|
|
|
public function argumentsAction()
|
|
|
|
{
|
2017-07-04 21:22:20 +02:00
|
|
|
$p = $this->params;
|
2017-07-20 22:29:00 +02:00
|
|
|
/** @var IcingaCommand $o */
|
2017-07-04 21:22:20 +02:00
|
|
|
$o = $this->object;
|
|
|
|
$this->tabs()->activate('arguments');
|
2017-07-20 22:29:00 +02:00
|
|
|
$this->addTitle($this->translate('Command arguments: %s'), $o->getObjectName());
|
2021-10-05 23:13:40 +02:00
|
|
|
$form = (new IcingaCommandArgumentForm)
|
|
|
|
->setBranch($this->getBranch())
|
|
|
|
->setCommandObject($o);
|
|
|
|
if ($argument = $p->shift('argument')) {
|
2017-09-03 09:23:52 +02:00
|
|
|
$this->addBackLink('director/command/arguments', [
|
|
|
|
'name' => $p->get('name')
|
|
|
|
]);
|
2021-10-05 23:13:40 +02:00
|
|
|
if ($this->branch->isBranch()) {
|
|
|
|
$arguments = $o->arguments();
|
|
|
|
$argument = $arguments->get($argument);
|
|
|
|
// IcingaCommandArgument::create((array) $arguments->get($argument)->toFullPlainObject());
|
|
|
|
// $argument->setBeingLoadedFromDb();
|
|
|
|
} else {
|
|
|
|
$argument = IcingaCommandArgument::load([
|
|
|
|
'command_id' => $o->get('id'),
|
|
|
|
'argument_name' => $argument
|
|
|
|
], $this->db());
|
|
|
|
}
|
|
|
|
$form->setObject($argument);
|
2015-08-03 13:42:19 +02:00
|
|
|
}
|
|
|
|
$form->handleRequest();
|
2017-07-21 08:23:52 +02:00
|
|
|
$this->content()->add([$form]);
|
2021-10-05 23:13:40 +02:00
|
|
|
if ($this->branch->isBranch()) {
|
|
|
|
(new BranchedIcingaCommandArgumentTable($o, $this->getBranch()))->renderTo($this);
|
|
|
|
} else {
|
|
|
|
(new IcingaCommandArgumentTable($o, $this->getBranch()))->renderTo($this);
|
|
|
|
}
|
2015-08-03 13:42:19 +02:00
|
|
|
}
|
2018-10-30 16:35:09 +01:00
|
|
|
|
|
|
|
protected function hasBasketSupport()
|
|
|
|
{
|
2019-05-27 17:27:18 +02:00
|
|
|
return true;
|
2018-10-30 16:35:09 +01:00
|
|
|
}
|
2015-06-30 11:19:31 +02:00
|
|
|
}
|