Skip to content

Commit

Permalink
Merge pull request #130 from ltb-project/multi-tenant
Browse files Browse the repository at this point in the history
Multi tenancy
  • Loading branch information
coudot authored Jun 30, 2023
2 parents 8e70959 + 1702087 commit 8156f98
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
14 changes: 14 additions & 0 deletions conf/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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";
}
}
}

?>
34 changes: 34 additions & 0 deletions docs/general-parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<VirtualHost *:80>
ServerName wp.domain1.com
RequestHeader setIfEmpty WP-Extra-Config domain1
[...]
</VirtualHost>
Using Nginx, we could use instead:

.. code-block:: nginx
server {
[...]
location ~ \.php {
fastcgi_param WP-Extra-Config domain1;
[...]
}
Language
--------

Expand Down

0 comments on commit 8156f98

Please sign in to comment.