mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-09-26 03:09:11 +02:00
config/file: link to generated objects
This commit is contained in:
parent
2bf5bdddb5
commit
c46f9d52e6
@ -135,17 +135,27 @@ class ConfigController extends ActionController
|
|||||||
// Show a single file
|
// Show a single file
|
||||||
public function fileAction()
|
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(
|
$tabs = $this->configTabs()->add('file', array(
|
||||||
'label' => $this->translate('Rendered file'),
|
'label' => $this->translate('Rendered file'),
|
||||||
'url' => $this->getRequest()->getUrl(),
|
'url' => $this->getRequest()->getUrl(),
|
||||||
))->activate('file');
|
))->activate('file');
|
||||||
|
|
||||||
$this->view->addLink = $this->view->qlink(
|
if ($fileOnly) {
|
||||||
$this->translate('back'),
|
$tabs->remove('config');
|
||||||
'director/config/files',
|
if ($tabs->has('deployment')) {
|
||||||
$this->getConfigTabParams(),
|
$tabs->remove('deployment');
|
||||||
array('class' => 'icon-left-big')
|
}
|
||||||
);
|
} 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());
|
$this->view->config = IcingaConfig::load(Util::hex2binary($this->params->get('config_checksum')), $this->db());
|
||||||
$filename = $this->view->filename = $this->params->get('file_path');
|
$filename = $this->view->filename = $this->params->get('file_path');
|
||||||
|
@ -5,9 +5,59 @@
|
|||||||
<?= $this->addLink ?>
|
<?= $this->addLink ?>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</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 "%s" {',
|
||||||
|
$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"(.+?)"\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">
|
<div class="content">
|
||||||
<pre>
|
<pre class="generated-config">
|
||||||
<?= $this->escape($file->getContent()) ?>
|
<?php if ($this->highlight): ?>
|
||||||
|
<?= highlight(linkObjects($this->escape($file->getContent()), $linkObject), $highlight, $highlightSeverity) ?>
|
||||||
|
<?php else: ?>
|
||||||
|
<?= linkObjects($this->escape($file->getContent()), $linkObject) ?>
|
||||||
|
<?php endif ?>
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
@ -65,6 +65,10 @@ pre.logfile {
|
|||||||
overflow: auto;
|
overflow: auto;
|
||||||
white-space: pre;
|
white-space: pre;
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
.loglevel, .application {
|
.loglevel, .application {
|
||||||
font-weight: bold;
|
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 {
|
table.avp th {
|
||||||
font-size: inherit;
|
font-size: inherit;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user