diff --git a/conf/config.inc.php b/conf/config.inc.php index 04b7177..e6710f0 100644 --- a/conf/config.inc.php +++ b/conf/config.inc.php @@ -197,6 +197,9 @@ # Smarty debug mode - will popup debug information on web interface $smarty_debug = false; +# The name of an HTTP Header that may hold a reference to an extra config file to include. +#$header_name_extra_config="WP-Extra-Config"; + # Allow to override current settings with local configuration if (file_exists (dirname (__FILE__) . '/config.inc.local.php')) { include dirname (__FILE__) . '/config.inc.local.php'; @@ -207,4 +210,15 @@ define("SMARTY", "/usr/share/php/smarty3/Smarty.class.php"); } +# Allow to override current settings with an extra configuration file, whose reference is passed in HTTP_HEADER $header_name_extra_config +if (isset($header_name_extra_config)) { + $extraConfigKey = "HTTP_".strtoupper(str_replace('-','_',$header_name_extra_config)); + if (array_key_exists($extraConfigKey, $_SERVER)) { + $extraConfig = preg_replace("/[^a-zA-Z0-9-_]+/", "", filter_var($_SERVER[$extraConfigKey], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)); + if (strlen($extraConfig) > 0 && file_exists (__DIR__ . "/config.inc.".$extraConfig.".php")) { + require __DIR__ . "/config.inc.".$extraConfig.".php"; + } + } +} + ?> diff --git a/docs/general-parameters.rst b/docs/general-parameters.rst index f2f6fce..e65f5cb 100644 --- a/docs/general-parameters.rst +++ b/docs/general-parameters.rst @@ -19,6 +19,40 @@ White Pages default configuration file is ``white-pages/conf/config.inc.php``. I Do not copy ``config.inc.php`` into ``config.inc.local.php``, as the first one includes the second. You would then create an infinite loop and crash your application. +Multi tenancy +------------- + +You can load a specific configuration file by passing a HTTP header. +This feature is disabled by default. To enable it: + +.. code-block:: php + + $header_name_extra_config = "WP-Extra-Config"; + +Then if you send the header ``WP-Extra-Config: domain1``, the file +``conf/config.inc.domain1.php`` will be loaded. + +Using Apache, we may set such header using the following: + +.. code-block:: apache + + + ServerName wp.domain1.com + RequestHeader setIfEmpty WP-Extra-Config domain1 + [...] + + +Using Nginx, we could use instead: + +.. code-block:: nginx + + server { + [...] + location ~ \.php { + fastcgi_param WP-Extra-Config domain1; + [...] + } + Language --------