config/file: link to generated objects

This commit is contained in:
Thomas Gelf 2016-07-28 07:11:09 +00:00
parent 2bf5bdddb5
commit c46f9d52e6
3 changed files with 95 additions and 8 deletions

View File

@ -135,17 +135,27 @@ class ConfigController extends ActionController
// Show a single file
public function fileAction()
{
$fileOnly = $this->params->get('fileOnly');
$this->view->highlight = $this->params->get('highlight');
$this->view->highlightSeverity = $this->params->get('highlightSeverity');
$tabs = $this->configTabs()->add('file', array(
'label' => $this->translate('Rendered file'),
'url' => $this->getRequest()->getUrl(),
))->activate('file');
$this->view->addLink = $this->view->qlink(
$this->translate('back'),
'director/config/files',
$this->getConfigTabParams(),
array('class' => 'icon-left-big')
);
if ($fileOnly) {
$tabs->remove('config');
if ($tabs->has('deployment')) {
$tabs->remove('deployment');
}
} else {
$this->view->addLink = $this->view->qlink(
$this->translate('back'),
'director/config/files',
$this->getConfigTabParams(),
array('class' => 'icon-left-big')
);
}
$this->view->config = IcingaConfig::load(Util::hex2binary($this->params->get('config_checksum')), $this->db());
$filename = $this->view->filename = $this->params->get('file_path');

View File

@ -5,9 +5,59 @@
<?= $this->addLink ?>
</span>
</div>
<?php
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
$decode = function($str) { return htmlspecialchars_decode($str, ENT_COMPAT | ENT_SUBSTITUTE | ENT_HTML5); };
} else {
$decode = function($str) { return htmlspecialchars_decode($str, ENT_COMPAT | ENT_IGNORE); };
}
$view = $this;
$linkObject = function ($match) use ($view, $decode) {
if ($match[2] === 'Service') {
return $match[0];
}
$name = $decode($match[3]);
return sprintf(
'%s %s &quot;%s&quot; {',
$match[1],
$match[2],
$view->qlink(
$name,
'director/' . $match[2],
array('name' => $name),
array('data-base-target' => '_next')
)
);
};
function linkObjects($config, $linkCallback) {
$pattern = '/^(object|template)\s([A-Z][A-Za-z]*?)\s&quot;(.+?)&quot;\s{/m';
return preg_replace_callback(
$pattern,
$linkCallback,
$config
);
}
function highlight($what, $line, $severity) {
$lines = explode("\n", $what);
$lines[$line - 1] = '<span class="highlight ' . $severity . '">' . $lines[$line - 1] . '</span>';
return implode("\n", $lines);
}
?>
<div class="content">
<pre>
<?= $this->escape($file->getContent()) ?>
<pre class="generated-config">
<?php if ($this->highlight): ?>
<?= highlight(linkObjects($this->escape($file->getContent()), $linkObject), $highlight, $highlightSeverity) ?>
<?php else: ?>
<?= linkObjects($this->escape($file->getContent()), $linkObject) ?>
<?php endif ?>
</pre>
</div>

View File

@ -65,6 +65,10 @@ pre.logfile {
overflow: auto;
white-space: pre;
a {
color: #fff;
}
.loglevel, .application {
font-weight: bold;
}
@ -95,6 +99,29 @@ pre.logfile {
}
}
pre.generated-config {
.highlight {
padding-left: 0.5em;
a {
color: inherit;
}
&.critical {
border-left: 0.5em solid @color-critical;
}
&.warning {
border-left: 0.5em solid @color-warning;
}
&.information {
border-left: 0.5em solid @color-ok;
}
}
}
table.avp th {
font-size: inherit;
}