From 459fc77fc7e7cef9e50f9a48fe51559de8e76335 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 13 Nov 2014 14:05:13 +0100 Subject: [PATCH] CLI/Webserver Setup: Allow to define Icinga Web 2's configuration directory refs #6120 --- .../application/clicommands/ConfigCommand.php | 19 ++++++--- modules/setup/library/Setup/Webserver.php | 39 +++++++++++++++++-- .../setup/library/Setup/Webserver/Apache.php | 2 +- .../setup/library/Setup/Webserver/Nginx.php | 1 + 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/modules/setup/application/clicommands/ConfigCommand.php b/modules/setup/application/clicommands/ConfigCommand.php index 04b518b07..660207df1 100644 --- a/modules/setup/application/clicommands/ConfigCommand.php +++ b/modules/setup/application/clicommands/ConfigCommand.php @@ -73,18 +73,20 @@ class ConfigCommand extends Command * * OPTIONS: * - * --path= The URL path to Icinga Web 2 + * --path= The URL path to Icinga Web 2 [/icingaweb] * - * --root/--document-root= The directory from which the webserver will serve files + * --root/--document-root= The directory from which the webserver will serve files [./public] * - * --file= Write configuration to file + * --config= Path to Icinga Web 2's configuration files [/etc/icingaweb] + * + * --file= Write configuration to file [stdout] * * * EXAMPLES: * * icingacli setup config webserver apache * - * icingacli setup config webserver apache --path /icingaweb --document-root /usr/share/icingaweb/public + * icingacli setup config webserver apache --path /icingaweb --document-root /usr/share/icingaweb/public --config=/etc/icingaweb * * icingacli setup config webserver apache --file /etc/apache2/conf.d/icingaweb.conf * @@ -100,7 +102,7 @@ class ConfigCommand extends Command } catch (ProgrammingError $e) { $this->fail($this->translate('Unknown type') . ': ' . $type); } - $path = $this->params->get('path', '/icingaweb'); + $path = $this->params->get('path', $webserver->getWebPath()); if (! is_string($path) || strlen(trim($path)) === 0) { $this->fail($this->translate('The argument --path expects a URL path')); } @@ -110,8 +112,15 @@ class ConfigCommand extends Command 'The argument --root/--document-root expects a directory from which the webserver will serve files' )); } + $configDir = $this->params->get('config', $webserver->getConfigDir()); + if (! is_string($documentRoot) || strlen(trim($documentRoot)) === 0) { + $this->fail($this->translate( + 'The argument --config expects a path to Icinga Web 2\'s configuration files' + )); + } $webserver ->setDocumentRoot($documentRoot) + ->setConfigDir($configDir) ->setWebPath($path); $config = $webserver->generate() . "\n"; if (($file = $this->params->get('file')) !== null) { diff --git a/modules/setup/library/Setup/Webserver.php b/modules/setup/library/Setup/Webserver.php index d8c18161c..40951f6fa 100644 --- a/modules/setup/library/Setup/Webserver.php +++ b/modules/setup/library/Setup/Webserver.php @@ -24,7 +24,14 @@ abstract class Webserver * * @var string */ - protected $webPath; + protected $webPath = '/icingaweb'; + + /** + * Path to Icinga Web 2's configuration files + * + * @var string + */ + protected $configDir; /** * Create instance by type name @@ -56,12 +63,12 @@ abstract class Webserver $searchTokens = array( '{webPath}', '{documentRoot}', - '{configPath}', + '{configDir}', ); $replaceTokens = array( $this->getWebPath(), $this->getDocumentRoot(), - Icinga::app()->getConfigDir() + $this->getConfigDir() ); $template = str_replace($searchTokens, $replaceTokens, $template); return $template; @@ -132,4 +139,30 @@ abstract class Webserver } return $this->documentRoot; } + + /** + * Set the configuration directory + * + * @param string $configDir + * + * @return $this + */ + public function setConfigDir($configDir) + { + $this->configDir = (string) $configDir; + return $this; + } + + /** + * Get the configuration directory + * + * @return string + */ + public function getConfigDir() + { + if ($this->configDir === null) { + return Icinga::app()->getConfigDir(); + } + return $this->configDir; + } } diff --git a/modules/setup/library/Setup/Webserver/Apache.php b/modules/setup/library/Setup/Webserver/Apache.php index e25182fdf..f35c6954f 100644 --- a/modules/setup/library/Setup/Webserver/Apache.php +++ b/modules/setup/library/Setup/Webserver/Apache.php @@ -36,7 +36,7 @@ Alias {webPath} "{documentRoot}" Allow from all - SetEnv ICINGAWEB_CONFIGDIR /etc/icingaweb/ + SetEnv ICINGAWEB_CONFIGDIR "{configDir}" EnableSendfile Off diff --git a/modules/setup/library/Setup/Webserver/Nginx.php b/modules/setup/library/Setup/Webserver/Nginx.php index 4885dc03b..336456142 100644 --- a/modules/setup/library/Setup/Webserver/Nginx.php +++ b/modules/setup/library/Setup/Webserver/Nginx.php @@ -25,6 +25,7 @@ location ~ ^{webPath}/index\.php(.*)$ { fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME {documentRoot}/index.php; + fastcgi_param ICINGAWEB_CONFIGDIR {configDir}; } location ~ ^{webPath}(.+)? {