roundcube/roundcubemail — pull request #73 by blacklion (2013-05-22 14:51:32+00:00)
Title: Add support for using single Roundcube installation from multiple httpd servers on one host.

I have shared hosting server with such config:

Each user has its own copy of Apache, running from this user's account (and serving on localhost:40${userid}). Single nginx used to multiplex all requests according to hostnames to multiple Apache servers. So, no scripts or PHP code are running from "root" or "www" account.

Some users want to use Roundcube on their hosts, and want ability to configure it without my help (and without editing system configs, which they could not do anyway).

I, as host admin, want to have only one copy of Roundcube sources on my system, under control of package manager, as it allows me to upgrade software and track vulnerabilities. I don't want to monitor each user server for installed Roundcube and force them to upgrade.

Here is problem with current Roundcube: it allows to have per-host configuration files with 'include_host_config', but all of them should live in on directory, which should not be writable by users. Also, users could add server aliases, and when new server alias is added, it should be added to main Roundcube config too (to load appropriate host config). Or every server alias should have its own host config, in non-user-writable directory. It is ugly.

With this commit I've added new configuration parameter: 'use_document_root'

If this parameter is set, it is used as suffix to $_SERVER['DOCUMENT_ROOT'], and resulting path is used as new root for configuration, temporary and log directories. main.inc.php is reloaded from new config directory, and db.inc.php and host-dependent config is looked up in this new path, too. mimetypes.php, plugins and themes are still looked up in install path (maybe, it is good idea, to add ability to use per-user plugins and themes, too, but it is not included in this commit, as Roundcube should be able to find plugins and themes in TWO places, both system-wide and user-confgured, and it is much more intrusive changes).

This patch works well on my own server like this:

(1) Roundcube installed with packet manager to /usr/local/www/roundcube. No server uses/serves this path directly.
(2) "/usr/local/www/roundcube/config/main.inc.php" contains ONLY 'use_document_root' parameter, set to '../rcube'.
(3) Each user, who wants to use Roundcube on its host(s) has:
(a)
Alias /mail/ /usr/local/www/roundcube/
in its httpd.conf
(b) "rcube" directory created in home directory
(c) "~/rcube/config/main.inc.php" and "~/rcube/config/db.inc.php" files with settings, usually pointing to "~/rcube/rcube.sqlite" as database, and with default 'log_dir' and 'temp_dir' settings, which gives "~/rcube/logs" and "~/rcube/temp", nice and clean.

It works great!

I'm sure, this commit is not perfect, it could break tests and using Roundcube library in other applications, as I don;t understand this part of Roundcube completely. Feel free to use ideas from this commit for proper implementation of this feature.