icingaweb2-module-director/application/controllers/ConfigController.php

123 lines
4.0 KiB
PHP
Raw Normal View History

<?php
2015-10-20 22:34:04 +02:00
namespace Icinga\Module\Director\Controllers;
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
2015-06-23 14:37:23 +02:00
use Icinga\Module\Director\Util;
use Icinga\Module\Director\Web\Controller\ActionController;
2015-09-30 08:40:09 +02:00
use Icinga\Web\Notification;
use Icinga\Web\Url;
2015-10-20 22:34:04 +02:00
class ConfigController extends ActionController
{
protected $isApified = true;
2015-09-30 08:40:09 +02:00
public function deployAction()
{
$isApiRequest = $this->getRequest()->isApiRequest();
2015-09-30 08:40:09 +02:00
$checksum = $this->params->get('checksum');
if ($checksum) {
$config = IcingaConfig::load(Util::hex2binary($checksum), $this->db());
} else {
$config = IcingaConfig::generate($this->db());
$checksum = $config->getHexChecksum();
}
2015-09-30 08:40:09 +02:00
if ($this->api()->dumpConfig($config, $this->db())) {
if ($isApiRequest) {
return $this->sendJson((object) array('checksum' => $checksum));
} else {
$url = Url::fromPath('director/list/deploymentlog?checkforchanges');
Notification::success(
$this->translate('Config has been submitted, validation is going on')
);
$this->redirectNow($url);
}
2015-09-30 08:40:09 +02:00
} else {
if ($isApiRequest) {
return $this->sendJsonError('Config deployment failed');
} else {
$url = Url::fromPath('director/config/show', array('checksum' => $checksum));
Notification::success(
$this->translate('Config deployment failed')
);
$this->redirectNow($url);
}
2015-09-30 08:40:09 +02:00
}
}
// Show all files for a given config
public function filesAction()
{
$tabs = $this->getTabs();
if ($deploymentId = $this->params->get('deployment_id')) {
$tabs->add('deployment', array(
'label' => $this->translate('Deployment'),
'url' => 'director/deployment',
'urlParams' => array(
'id' => $deploymentId
)
));
}
$tabs->add('config', array(
'label' => $this->translate('Config'),
'url' => $this->getRequest()->getUrl(),
))->activate('config');
$checksum = $this->params->get('checksum');
$this->view->table = $this
->loadTable('GeneratedConfigFile')
->setConnection($this->db())
->setConfigChecksum($checksum);
$this->render('objects/table', null, true);
}
2015-12-17 10:54:38 +01:00
// Show a single file
public function fileAction()
{
$this->view->config = IcingaConfig::load(Util::hex2binary($this->params->get('config_checksum')), $this->db());
$filename = $this->view->filename = $this->params->get('file_path');
$this->view->title = sprintf(
$this->translate('Config file "%s"'),
$filename
);
$this->view->file = $this->view->config->getFile($filename);
}
public function showAction()
{
$tabs = $this->getTabs();
if ($deploymentId = $this->params->get('deployment_id')) {
$tabs->add('deployment', array(
'label' => $this->translate('Deployment'),
'url' => 'director/deployment/show',
'urlParams' => array(
'id' => $deploymentId
)
));
}
$tabs->add('config', array(
'label' => $this->translate('Config'),
'url' => $this->getRequest()->getUrl(),
))->activate('config');
2015-12-15 16:46:19 +01:00
$this->view->config = IcingaConfig::load(Util::hex2binary($this->params->get('checksum')), $this->db());
}
2015-06-17 18:57:51 +02:00
2015-12-15 16:46:19 +01:00
// TODO: Check if this can be removed
2015-06-17 18:57:51 +02:00
public function storeAction()
{
$config = IcingaConfig::generate($this->db());
2015-06-29 10:13:39 +02:00
$this->redirectNow(
Url::fromPath('director/config/show',
array('checksum' => $config->getHexChecksum()))
);
2015-06-17 18:57:51 +02:00
}
}