-= $this->escape($file->getContent()) ?> ++highlight): ?> += highlight(linkObjects($this->escape($file->getContent()), $linkObject), $highlight, $highlightSeverity) ?> + += linkObjects($this->escape($file->getContent()), $linkObject) ?> +
diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 9499f20a..428eb587 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -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'); diff --git a/application/views/scripts/config/file.phtml b/application/views/scripts/config/file.phtml index 586ba879..8d215301 100644 --- a/application/views/scripts/config/file.phtml +++ b/application/views/scripts/config/file.phtml @@ -5,9 +5,59 @@ = $this->addLink ?> += 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] = '' . $lines[$line - 1] . ''; + return implode("\n", $lines); +} + +?>
-= $this->escape($file->getContent()) ?> ++highlight): ?> += highlight(linkObjects($this->escape($file->getContent()), $linkObject), $highlight, $highlightSeverity) ?> + += linkObjects($this->escape($file->getContent()), $linkObject) ?> +