2015-06-30 11:19:31 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Web\Controller;
|
|
|
|
|
2017-10-20 10:23:23 +02:00
|
|
|
use Icinga\Exception\IcingaException;
|
2016-03-06 14:20:49 +01:00
|
|
|
use Icinga\Exception\InvalidPropertyException;
|
2016-02-17 19:22:36 +01:00
|
|
|
use Icinga\Exception\NotFoundError;
|
2017-07-20 08:31:53 +02:00
|
|
|
use Icinga\Module\Director\Deployment\DeploymentInfo;
|
|
|
|
use Icinga\Module\Director\Forms\DeploymentLinkForm;
|
2017-07-25 10:16:15 +02:00
|
|
|
use Icinga\Module\Director\Forms\IcingaCloneObjectForm;
|
2017-07-06 09:04:32 +02:00
|
|
|
use Icinga\Module\Director\Forms\IcingaObjectFieldForm;
|
2015-08-02 15:01:07 +02:00
|
|
|
use Icinga\Module\Director\Objects\IcingaObject;
|
2017-07-20 08:31:53 +02:00
|
|
|
use Icinga\Module\Director\Objects\IcingaObjectGroup;
|
2017-08-16 23:53:37 +02:00
|
|
|
use Icinga\Module\Director\RestApi\IcingaObjectHandler;
|
2017-06-22 00:44:31 +02:00
|
|
|
use Icinga\Module\Director\Web\Controller\Extension\ObjectRestrictions;
|
2016-11-16 16:02:28 +01:00
|
|
|
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
2017-08-16 23:53:37 +02:00
|
|
|
use Icinga\Module\Director\Web\ObjectPreview;
|
2017-07-20 08:31:53 +02:00
|
|
|
use Icinga\Module\Director\Web\Table\ActivityLogTable;
|
2017-07-11 08:33:03 +02:00
|
|
|
use Icinga\Module\Director\Web\Table\GroupMemberTable;
|
2017-08-16 23:53:37 +02:00
|
|
|
use Icinga\Module\Director\Web\Table\IcingaObjectDatafieldTable;
|
2017-07-03 07:04:31 +02:00
|
|
|
use Icinga\Module\Director\Web\Tabs\ObjectTabs;
|
2017-10-09 15:23:27 +02:00
|
|
|
use dipl\Html\Link;
|
2015-06-30 11:19:31 +02:00
|
|
|
|
|
|
|
abstract class ObjectController extends ActionController
|
|
|
|
{
|
2017-06-22 00:44:31 +02:00
|
|
|
use ObjectRestrictions;
|
|
|
|
|
2017-02-08 12:38:14 +01:00
|
|
|
/** @var IcingaObject */
|
2015-06-30 11:19:31 +02:00
|
|
|
protected $object;
|
|
|
|
|
2017-08-16 08:08:08 +02:00
|
|
|
/** @var bool This controller handles REST API requests */
|
2015-12-10 13:11:21 +01:00
|
|
|
protected $isApified = true;
|
|
|
|
|
2017-08-16 08:08:08 +02:00
|
|
|
/** @var array Allowed object types we are allowed to edit anyways */
|
2016-03-22 18:19:13 +01:00
|
|
|
protected $allowedExternals = array(
|
|
|
|
'apiuser',
|
|
|
|
'endpoint'
|
|
|
|
);
|
|
|
|
|
2017-08-16 23:53:37 +02:00
|
|
|
protected $type;
|
|
|
|
|
2015-06-30 11:19:31 +02:00
|
|
|
public function init()
|
|
|
|
{
|
2015-12-10 13:11:21 +01:00
|
|
|
parent::init();
|
|
|
|
|
2016-12-16 12:07:01 +01:00
|
|
|
if ($this->getRequest()->isApiRequest()) {
|
2017-08-16 08:08:08 +02:00
|
|
|
$handler = new IcingaObjectHandler($this->getRequest(), $this->getResponse(), $this->db());
|
2017-08-22 16:47:57 +02:00
|
|
|
try {
|
|
|
|
$this->eventuallyLoadObject();
|
|
|
|
} catch (NotFoundError $e) {
|
|
|
|
// Silently ignore the error, the handler will complain
|
|
|
|
$handler->sendJsonError($e, 404);
|
|
|
|
// TODO: nice shutdown
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2017-08-16 08:08:08 +02:00
|
|
|
$handler->setApi($this->api());
|
|
|
|
if ($this->object) {
|
|
|
|
$handler->setObject($this->object);
|
2016-12-16 12:07:01 +01:00
|
|
|
}
|
2017-08-16 08:08:08 +02:00
|
|
|
$handler->dispatch();
|
2018-09-05 22:27:07 +02:00
|
|
|
// Hint: also here, hard exit. There is too much magic going on.
|
|
|
|
// Letting this bubble up smoothly would be "correct", but proved
|
|
|
|
// to be too fragile. Web 2, all kinds of pre/postDispatch magic,
|
|
|
|
// different view renderers - hard exit is the only safe bet right
|
|
|
|
// now.
|
|
|
|
exit;
|
2017-08-16 08:08:08 +02:00
|
|
|
} else {
|
2017-08-22 16:47:57 +02:00
|
|
|
$this->eventuallyLoadObject();
|
2017-08-21 13:20:47 +02:00
|
|
|
if ($this->getRequest()->getActionName() === 'add') {
|
|
|
|
$this->addSingleTab(
|
|
|
|
sprintf($this->translate('Add %s'), ucfirst($this->getType())),
|
|
|
|
null,
|
|
|
|
'add'
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$this->tabs(new ObjectTabs($this->getType(), $this->getAuth(), $this->object));
|
|
|
|
}
|
2016-12-16 12:07:01 +01:00
|
|
|
}
|
2015-06-30 11:19:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function indexAction()
|
2015-07-30 10:04:12 +02:00
|
|
|
{
|
2017-08-16 08:08:08 +02:00
|
|
|
if (! $this->getRequest()->isApiRequest()) {
|
|
|
|
$this->redirectToPreviewForExternals()
|
|
|
|
->editAction();
|
2016-03-18 14:58:46 +01:00
|
|
|
}
|
2015-06-30 11:19:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function addAction()
|
|
|
|
{
|
2017-07-03 07:04:31 +02:00
|
|
|
$this->tabs()->activate('add');
|
2017-08-16 23:53:37 +02:00
|
|
|
$url = sprintf('director/%ss', $this->getPluralType());
|
2015-06-30 11:19:31 +02:00
|
|
|
|
2017-08-21 09:07:20 +02:00
|
|
|
$imports = $this->params->get('imports');
|
2017-08-16 23:53:37 +02:00
|
|
|
$form = $this->loadObjectForm()
|
2017-07-28 18:46:11 +02:00
|
|
|
->presetImports($imports)
|
2015-06-30 11:19:31 +02:00
|
|
|
->setSuccessUrl($url);
|
|
|
|
|
2017-08-21 09:07:20 +02:00
|
|
|
if ($oType = $this->params->get('type', 'object')) {
|
2017-07-03 07:04:31 +02:00
|
|
|
$form->setPreferredObjectType($oType);
|
2016-10-13 13:53:01 +02:00
|
|
|
}
|
|
|
|
|
2017-07-03 07:04:31 +02:00
|
|
|
if ($oType === 'template') {
|
2017-08-16 23:53:37 +02:00
|
|
|
$this->addTemplate();
|
2016-10-13 13:53:01 +02:00
|
|
|
} else {
|
2017-08-16 23:53:37 +02:00
|
|
|
$this->addObject();
|
2016-10-13 13:53:01 +02:00
|
|
|
}
|
2015-07-30 09:26:02 +02:00
|
|
|
|
|
|
|
$form->handleRequest();
|
2017-07-03 07:04:31 +02:00
|
|
|
$this->content()->add($form);
|
2015-12-10 13:19:16 +01:00
|
|
|
}
|
|
|
|
|
2017-08-16 23:53:37 +02:00
|
|
|
public function editAction()
|
2016-03-29 19:32:50 +02:00
|
|
|
{
|
2017-08-16 23:53:37 +02:00
|
|
|
$object = $this->requireObject();
|
|
|
|
$this->tabs()->activate('modify');
|
|
|
|
$this->addObjectTitle()
|
|
|
|
->addObjectForm($object)
|
|
|
|
->addActionClone()
|
|
|
|
->addActionUsage();
|
2016-03-29 19:32:50 +02:00
|
|
|
}
|
|
|
|
|
2017-08-16 23:53:37 +02:00
|
|
|
public function renderAction()
|
2017-07-25 10:18:07 +02:00
|
|
|
{
|
2017-10-12 16:26:50 +02:00
|
|
|
$this->assertTypePermission()
|
|
|
|
->assertPermission('director/showconfig');
|
2017-08-16 23:53:37 +02:00
|
|
|
$this->tabs()->activate('render');
|
|
|
|
$preview = new ObjectPreview($this->requireObject(), $this->getRequest());
|
2017-08-18 16:13:09 +02:00
|
|
|
if ($this->object->isExternal()) {
|
|
|
|
$this->addActionClone();
|
|
|
|
}
|
2017-08-16 23:53:37 +02:00
|
|
|
$preview->renderTo($this);
|
2017-07-25 10:18:07 +02:00
|
|
|
}
|
|
|
|
|
2015-12-10 13:19:16 +01:00
|
|
|
public function cloneAction()
|
|
|
|
{
|
2017-10-12 16:26:50 +02:00
|
|
|
$this->assertTypePermission();
|
2017-08-16 23:53:37 +02:00
|
|
|
$object = $this->requireObject();
|
2017-07-25 10:16:15 +02:00
|
|
|
$form = IcingaCloneObjectForm::load()
|
2017-08-16 23:53:37 +02:00
|
|
|
->setObject($object)
|
2017-07-25 10:16:15 +02:00
|
|
|
->handleRequest();
|
2017-08-16 23:53:37 +02:00
|
|
|
|
2017-08-18 16:13:09 +02:00
|
|
|
if ($object->isExternal()) {
|
|
|
|
$this->tabs()->activate('render');
|
|
|
|
} else {
|
|
|
|
$this->tabs()->activate('modify');
|
|
|
|
}
|
2017-08-16 23:53:37 +02:00
|
|
|
$this->addTitle($this->translate('Clone: %s'), $object->getObjectName())
|
|
|
|
->addBackToObjectLink()
|
|
|
|
->content()->add($form);
|
2015-06-30 11:19:31 +02:00
|
|
|
}
|
|
|
|
|
2015-08-02 15:01:47 +02:00
|
|
|
public function fieldsAction()
|
|
|
|
{
|
2017-07-11 08:33:03 +02:00
|
|
|
$this->assertPermission('director/admin');
|
2017-07-29 00:12:34 +02:00
|
|
|
$object = $this->requireObject();
|
2015-08-02 15:01:47 +02:00
|
|
|
$type = $this->getType();
|
|
|
|
|
2017-07-06 09:04:32 +02:00
|
|
|
$this->addTitle(
|
2016-05-03 09:09:01 +02:00
|
|
|
$this->translate('Custom fields: %s'),
|
2017-07-29 00:12:34 +02:00
|
|
|
$object->getObjectName()
|
2015-08-02 15:01:47 +02:00
|
|
|
);
|
2017-07-29 00:12:34 +02:00
|
|
|
$this->tabs()->activate('fields');
|
2015-08-02 15:01:47 +02:00
|
|
|
|
2017-07-06 09:04:32 +02:00
|
|
|
$form = IcingaObjectFieldForm::load()
|
2017-06-22 00:44:31 +02:00
|
|
|
->setDb($this->db())
|
2015-09-14 16:54:43 +02:00
|
|
|
->setIcingaObject($object);
|
|
|
|
|
|
|
|
if ($id = $this->params->get('field_id')) {
|
2017-08-16 23:53:37 +02:00
|
|
|
$form->loadObject([
|
|
|
|
"${type}_id" => $object->id,
|
2015-10-13 17:58:50 +02:00
|
|
|
'datafield_id' => $id
|
2017-08-16 23:53:37 +02:00
|
|
|
]);
|
2016-02-28 10:58:42 +01:00
|
|
|
|
2017-07-06 09:04:32 +02:00
|
|
|
$this->actions()->add(Link::create(
|
2016-02-28 10:58:42 +01:00
|
|
|
$this->translate('back'),
|
2017-07-06 09:04:32 +02:00
|
|
|
$this->url()->without('field_id'),
|
2016-02-28 10:58:42 +01:00
|
|
|
null,
|
2017-07-06 09:04:32 +02:00
|
|
|
['class' => 'icon-left-big']
|
|
|
|
));
|
2015-09-14 16:54:43 +02:00
|
|
|
}
|
|
|
|
$form->handleRequest();
|
2017-08-16 23:53:37 +02:00
|
|
|
$this->content()->add($form);
|
|
|
|
$table = new IcingaObjectDatafieldTable($object);
|
2018-05-05 00:24:49 +02:00
|
|
|
$table->getAttributes()->set('data-base-target', '_self');
|
2017-08-16 23:53:37 +02:00
|
|
|
$table->renderTo($this);
|
2015-08-02 15:01:47 +02:00
|
|
|
}
|
|
|
|
|
2015-06-30 11:19:31 +02:00
|
|
|
public function historyAction()
|
|
|
|
{
|
2017-10-12 16:26:50 +02:00
|
|
|
$this
|
|
|
|
->assertTypePermission()
|
|
|
|
->assertPermission('director/audit')
|
2017-07-29 00:12:34 +02:00
|
|
|
->setAutorefreshInterval(10)
|
|
|
|
->tabs()->activate('history');
|
|
|
|
|
|
|
|
$name = $this->requireObject()->getObjectName();
|
|
|
|
$this->addTitle($this->translate('Activity Log: %s'), $name);
|
|
|
|
|
2016-03-16 22:50:35 +01:00
|
|
|
$db = $this->db();
|
2015-06-30 11:19:31 +02:00
|
|
|
$type = $this->getType();
|
2017-07-20 08:31:53 +02:00
|
|
|
(new ActivityLogTable($db))
|
2017-07-29 00:12:34 +02:00
|
|
|
->setLastDeployedId($db->getLastDeploymentActivityLogId())
|
|
|
|
->filterObject('icinga_' . $type, $name)
|
2017-07-20 08:31:53 +02:00
|
|
|
->renderTo($this);
|
2015-06-30 11:19:31 +02:00
|
|
|
}
|
|
|
|
|
2017-07-11 08:33:03 +02:00
|
|
|
public function membershipAction()
|
|
|
|
{
|
2017-07-29 00:12:34 +02:00
|
|
|
$object = $this->requireObject();
|
|
|
|
if (! $object instanceof IcingaObjectGroup) {
|
2017-07-11 08:33:03 +02:00
|
|
|
throw new NotFoundError('Not Found');
|
|
|
|
}
|
|
|
|
|
2017-07-29 00:12:34 +02:00
|
|
|
$this
|
|
|
|
->addTitle($this->translate('Group membership: %s'), $object->getObjectName())
|
|
|
|
->setAutorefreshInterval(15)
|
|
|
|
->tabs()->activate('membership');
|
2017-07-11 08:33:03 +02:00
|
|
|
|
2017-07-29 00:12:34 +02:00
|
|
|
$type = substr($this->getType(), 0, -5);
|
|
|
|
GroupMemberTable::create($type, $this->db())
|
|
|
|
->setGroup($object)
|
|
|
|
->renderTo($this);
|
2017-07-11 08:33:03 +02:00
|
|
|
}
|
|
|
|
|
2017-08-16 23:53:37 +02:00
|
|
|
protected function addObjectTitle()
|
|
|
|
{
|
|
|
|
$object = $this->requireObject();
|
|
|
|
$name = $object->getObjectName();
|
|
|
|
if ($object->isTemplate()) {
|
|
|
|
$this->addTitle($this->translate('Template: %s'), $name);
|
|
|
|
} else {
|
|
|
|
$this->addTitle($name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function addActionUsage()
|
|
|
|
{
|
|
|
|
$type = $this->getType();
|
|
|
|
$object = $this->requireObject();
|
|
|
|
if ($object->isTemplate() && ! $type === 'serviceSet') {
|
|
|
|
$this->actions()->add([
|
|
|
|
Link::create(
|
|
|
|
$this->translate('Usage'),
|
|
|
|
"director/${type}template/usage",
|
|
|
|
['name' => $object->getObjectName()],
|
|
|
|
['class' => 'icon-sitemap']
|
|
|
|
)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function addActionClone()
|
|
|
|
{
|
|
|
|
$this->actions()->add(Link::create(
|
|
|
|
$this->translate('Clone'),
|
|
|
|
'director/' . $this->getType() .'/clone',
|
|
|
|
$this->object->getUrlParams(),
|
|
|
|
array('class' => 'icon-paste')
|
|
|
|
));
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function addTemplate()
|
2015-06-30 11:19:31 +02:00
|
|
|
{
|
2017-08-16 23:53:37 +02:00
|
|
|
$this->assertPermission('director/admin');
|
|
|
|
$this->addTitle(
|
|
|
|
$this->translate('Add new Icinga %s template'),
|
|
|
|
$this->getTranslatedType()
|
2015-06-30 11:19:31 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-08-16 23:53:37 +02:00
|
|
|
protected function addObject()
|
|
|
|
{
|
2017-10-12 16:26:50 +02:00
|
|
|
$this->assertTypePermission();
|
2017-08-16 23:53:37 +02:00
|
|
|
$imports = $this->params->get('imports');
|
|
|
|
if (is_string($imports) && strlen($imports)) {
|
|
|
|
$this->addTitle(
|
|
|
|
$this->translate('Add %s: %s'),
|
|
|
|
$this->getTranslatedType(),
|
|
|
|
$imports
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$this->addTitle(
|
|
|
|
$this->translate('Add new Icinga %s'),
|
|
|
|
$this->getTranslatedType()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function redirectToPreviewForExternals()
|
|
|
|
{
|
|
|
|
if ($this->object
|
|
|
|
&& $this->object->isExternal()
|
|
|
|
&& ! in_array($this->object->getShortTableName(), $this->allowedExternals)
|
|
|
|
) {
|
|
|
|
$this->redirectNow(
|
|
|
|
$this->getRequest()->getUrl()->setPath(sprintf('director/%s/render', $this->getType()))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getType()
|
|
|
|
{
|
|
|
|
if ($this->type === null) {
|
|
|
|
// Strip final 's' and upcase an eventual 'group'
|
|
|
|
$this->type = preg_replace(
|
|
|
|
array('/group$/', '/period$/', '/argument$/', '/apiuser$/', '/set$/'),
|
|
|
|
array('Group', 'Period', 'Argument', 'ApiUser', 'Set'),
|
|
|
|
$this->getRequest()->getControllerName()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getPluralType()
|
|
|
|
{
|
|
|
|
return $this->getType() . 's';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getTranslatedType()
|
|
|
|
{
|
|
|
|
return $this->translate(ucfirst($this->getType()));
|
|
|
|
}
|
|
|
|
|
2017-10-12 16:26:50 +02:00
|
|
|
protected function assertTypePermission()
|
|
|
|
{
|
|
|
|
return $this->assertPermission(
|
|
|
|
'director/' . strtolower($this->getPluralType())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-08-16 08:08:08 +02:00
|
|
|
protected function eventuallyLoadObject()
|
|
|
|
{
|
|
|
|
if (null !== $this->params->get('name') || $this->params->get('id')) {
|
|
|
|
$this->loadObject();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-02 15:01:07 +02:00
|
|
|
protected function loadObject()
|
2015-06-30 11:19:31 +02:00
|
|
|
{
|
2016-03-06 14:20:49 +01:00
|
|
|
if ($this->object === null) {
|
2017-08-16 08:08:08 +02:00
|
|
|
if ($id = $this->params->get('id')) {
|
|
|
|
$this->object = IcingaObject::loadByType(
|
|
|
|
$this->getType(),
|
|
|
|
(int) $id,
|
|
|
|
$this->db()
|
|
|
|
);
|
|
|
|
} elseif (null !== ($name = $this->params->get('name'))) {
|
2016-03-06 14:20:49 +01:00
|
|
|
$this->object = IcingaObject::loadByType(
|
|
|
|
$this->getType(),
|
|
|
|
$name,
|
|
|
|
$this->db()
|
|
|
|
);
|
2017-03-06 21:46:22 +01:00
|
|
|
|
|
|
|
if (! $this->allowsObject($this->object)) {
|
|
|
|
$this->object = null;
|
|
|
|
throw new NotFoundError('No such object available');
|
|
|
|
}
|
2016-03-06 20:24:47 +01:00
|
|
|
} elseif ($this->getRequest()->isApiRequest()) {
|
2016-03-12 01:36:58 +01:00
|
|
|
if ($this->getRequest()->isGet()) {
|
|
|
|
$this->getResponse()->setHttpResponseCode(422);
|
2016-03-06 20:24:47 +01:00
|
|
|
|
2016-03-12 01:36:58 +01:00
|
|
|
throw new InvalidPropertyException(
|
|
|
|
'Cannot load object, missing parameters'
|
|
|
|
);
|
|
|
|
}
|
2016-03-06 14:20:49 +01:00
|
|
|
}
|
2016-02-27 12:23:00 +01:00
|
|
|
|
2017-07-31 10:34:57 +02:00
|
|
|
if ($this->object !== null) {
|
2017-08-16 23:53:37 +02:00
|
|
|
$this->addDeploymentLink();
|
2017-07-31 10:34:57 +02:00
|
|
|
}
|
2015-06-30 11:19:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->object;
|
|
|
|
}
|
2016-02-03 00:54:00 +01:00
|
|
|
|
2017-08-16 23:53:37 +02:00
|
|
|
protected function addDeploymentLink()
|
2017-07-31 10:34:57 +02:00
|
|
|
{
|
2017-10-20 10:23:23 +02:00
|
|
|
try {
|
|
|
|
$info = new DeploymentInfo($this->db());
|
|
|
|
$info->setObject($this->object);
|
|
|
|
|
|
|
|
if (! $this->getRequest()->isApiRequest()) {
|
|
|
|
$this->actions()->add(
|
|
|
|
DeploymentLinkForm::create(
|
|
|
|
$this->db(),
|
|
|
|
$info,
|
|
|
|
$this->Auth(),
|
|
|
|
$this->api()
|
|
|
|
)->handleRequest()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch (IcingaException $e) {
|
|
|
|
// pass (deployment may not be set up yet)
|
2017-07-31 10:34:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 23:53:37 +02:00
|
|
|
protected function addBackToObjectLink()
|
2016-02-03 00:54:00 +01:00
|
|
|
{
|
2017-08-16 23:53:37 +02:00
|
|
|
$this->actions()->add(Link::create(
|
|
|
|
$this->translate('back'),
|
|
|
|
'director/' . strtolower($this->getType()),
|
|
|
|
['name' => $this->object->getObjectName()],
|
|
|
|
['class' => 'icon-left-big']
|
|
|
|
));
|
2016-02-03 00:54:00 +01:00
|
|
|
|
2017-08-16 23:53:37 +02:00
|
|
|
return $this;
|
|
|
|
}
|
2016-02-03 00:54:00 +01:00
|
|
|
|
2017-08-16 23:53:37 +02:00
|
|
|
protected function addObjectForm(IcingaObject $object = null)
|
|
|
|
{
|
|
|
|
$form = $this->loadObjectForm($object);
|
|
|
|
$this->content()->add($form);
|
|
|
|
$form->handleRequest();
|
|
|
|
return $this;
|
|
|
|
}
|
2016-02-03 00:54:00 +01:00
|
|
|
|
2017-08-16 23:53:37 +02:00
|
|
|
protected function loadObjectForm(IcingaObject $object = null)
|
|
|
|
{
|
|
|
|
/** @var DirectorObjectForm $class */
|
|
|
|
$class = sprintf(
|
|
|
|
'Icinga\\Module\\Director\\Forms\\Icinga%sForm',
|
|
|
|
ucfirst($this->getType())
|
|
|
|
);
|
|
|
|
|
|
|
|
$form = $class::load()
|
|
|
|
->setDb($this->db())
|
|
|
|
->setAuth($this->Auth());
|
2016-02-03 00:54:00 +01:00
|
|
|
|
2017-08-16 23:53:37 +02:00
|
|
|
if ($object !== null) {
|
|
|
|
$form->setObject($object);
|
2016-02-03 00:54:00 +01:00
|
|
|
}
|
2017-08-16 23:53:37 +02:00
|
|
|
|
|
|
|
$this->onObjectFormLoaded($form);
|
|
|
|
|
|
|
|
return $form;
|
2016-02-03 00:54:00 +01:00
|
|
|
}
|
2016-02-17 19:22:36 +01:00
|
|
|
|
2017-08-16 23:53:37 +02:00
|
|
|
protected function onObjectFormLoaded(DirectorObjectForm $form)
|
2016-02-27 12:23:00 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-02-17 19:22:36 +01:00
|
|
|
protected function requireObject()
|
|
|
|
{
|
|
|
|
if (! $this->object) {
|
|
|
|
$this->getResponse()->setHttpResponseCode(404);
|
2017-07-31 10:34:57 +02:00
|
|
|
if (null === $this->params->get('name')) {
|
2016-02-17 19:22:36 +01:00
|
|
|
throw new NotFoundError('You need to pass a "name" parameter to access a specific object');
|
|
|
|
} else {
|
|
|
|
throw new NotFoundError('No such object available');
|
|
|
|
}
|
|
|
|
}
|
2016-05-25 08:11:53 +02:00
|
|
|
|
2017-07-29 00:12:34 +02:00
|
|
|
return $this->object;
|
2016-03-18 11:44:48 +01:00
|
|
|
}
|
2015-06-30 11:19:31 +02:00
|
|
|
}
|