diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php
index a82a432e..5eb63e7e 100644
--- a/application/controllers/ConfigController.php
+++ b/application/controllers/ConfigController.php
@@ -8,13 +8,7 @@ class Director_ConfigController extends ActionController
{
public function showAction()
{
- /** @var IcingaConfig $config */
- $config = IcingaConfig::generate($this->db());
- $this->view->files = array();
-
- foreach ($config->getFiles() as $filename => $config) {
- $this->view->files[$filename] = $config->getContent();
- }
+ $this->view->config = IcingaConfig::fromDb(pack('H*', $this->params->get('checksum')), $this->db());
}
public function storeAction()
diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php
index 82426c71..7ce29afc 100644
--- a/application/controllers/ListController.php
+++ b/application/controllers/ListController.php
@@ -186,4 +186,11 @@ class Director_ListController extends ActionController
$this->view->table = $this->loadTable('activityLog')->setConnection($this->db());
$this->render('table');
}
+
+ public function generatedconfigAction()
+ {
+ $this->view->title = $this->translate('Generated Configs');
+ $this->view->table = $this->loadTable('generatedConfig')->setConnection($this->db());
+ $this->render('table');
+ }
}
diff --git a/application/views/scripts/config/show.phtml b/application/views/scripts/config/show.phtml
index 36614343..1803e515 100644
--- a/application/views/scripts/config/show.phtml
+++ b/application/views/scripts/config/show.phtml
@@ -1,12 +1,28 @@
-files as $file => $content): ?>
-
= $this->escape($file) ?>
+config->getFiles() as $filename => $file): ?>
+
= $this->escape($filename) ?>
-= $this->escape($content) ?>
+= $this->escape($file->getContent()) ?>
diff --git a/configuration.php b/configuration.php
index 25c381ff..8553dfd4 100644
--- a/configuration.php
+++ b/configuration.php
@@ -52,8 +52,8 @@ $section->add($this->translate('Endpoints'))
$section->add($this->translate('Activity Log'))
->setUrl('director/list/activitylog')
->setPriority(900);
-$section->add($this->translate('Show config'))
- ->setUrl('director/config/show')
+$section->add($this->translate('Show configs'))
+ ->setUrl('director/list/generatedconfig')
->setPriority(902);
$section->add($this->translate('Store config'))
->setUrl('director/config/store')
diff --git a/library/Director/IcingaConfig/IcingaConfig.php b/library/Director/IcingaConfig/IcingaConfig.php
index a51c0707..9dc454e5 100644
--- a/library/Director/IcingaConfig/IcingaConfig.php
+++ b/library/Director/IcingaConfig/IcingaConfig.php
@@ -60,6 +60,13 @@ class IcingaConfig
return $files;
}
+ public static function fromDb($checksum, DbConnection $connection)
+ {
+ $config = new static($connection);
+ $config->loadFromDb($checksum);
+ return $config;
+ }
+
public static function generate(DbConnection $connection)
{
$config = new static($connection);
@@ -187,6 +194,36 @@ class IcingaConfig
return $this;
}
+ protected function loadFromDb($checksum)
+ {
+ $query = $this->db->select()->from(
+ self::$table,
+ array('checksum', 'last_activity_checksum')
+ )->where('checksum = ?', $checksum);
+ $result = $this->db->fetchRow($query);
+ $this->checksum = $result->checksum;
+ $this->last_activity_checksum = $result->last_activity_checksum;
+ $query = $this->db->select()->from(
+ array('cf' => 'director_generated_config_file'),
+ array(
+ 'file_path' => 'cf.file_path',
+ 'checksum' => 'f.checksum',
+ 'content' => 'f.content',
+ )
+ )->join(
+ array('f' => 'director_generated_file'),
+ 'cf.file_checksum = f.checksum',
+ array()
+ )->where('cf.config_checksum = ?', $checksum);
+
+ foreach ($this->db->fetchAll($query) as $row) {
+ $file = new IcingaConfigFile();
+ $this->files[$row->file_path] = $file->setContent($row->content);
+ }
+
+ return $this;
+ }
+
protected function createFileFromDb($type)
{
$class = 'Icinga\\Module\\Director\\Objects\\Icinga' . ucfirst($type);
diff --git a/library/Director/IcingaConfig/IcingaConfigFile.php b/library/Director/IcingaConfig/IcingaConfigFile.php
index cb36a572..82549cd0 100644
--- a/library/Director/IcingaConfig/IcingaConfigFile.php
+++ b/library/Director/IcingaConfig/IcingaConfigFile.php
@@ -7,13 +7,17 @@ use Icinga\Module\Director\Objects\IcingaObject;
class IcingaConfigFile
{
public static $table = 'director_generated_file';
+
public static $keyName = 'checksum';
protected $content;
+ protected $checksum;
+
public function prepend($content)
{
$this->content = $content . $this->content;
+ $this->checksum = null;
return $this;
}
@@ -22,14 +26,25 @@ class IcingaConfigFile
return $this->content;
}
+ public function setContent($content)
+ {
+ $this->content = $content;
+ $this->checksum = null;
+ return $this;
+ }
+
public function getHexChecksum()
{
- return sha1($this->content);
+ return current(unpack('H*', $this->getChecksum()));
}
public function getChecksum()
{
- return sha1($this->content, true);
+ if ($this->checksum === null) {
+ $this->checksum = sha1($this->content, true);
+ }
+
+ return $this->checksum;
}
public function addObjects($objects)
@@ -44,5 +59,7 @@ class IcingaConfigFile
public function addObject(IcingaObject $object)
{
$this->content .= $object->toConfigString();
+ $this->checksum = null;
+ return $this;
}
}