Roundcube Webmail 0.8.5 Login form for virtual hosting

Many of virtual hosting providers are using Roundcube webmail, but it lacks one very useful feature for multiple domains on single server – automatic domain completion in login form. Every user needs to use full e-mail address as login name, and this is very annoying for long domain names… So here is my solution:

1: ) Apache configuration.

I’m assuming you are using alias for every domain to access one single webmail (in case you are not, this patch does not make any use). This is how Apache virtual host should look like:

This means every user can access his webmail on “mail” subdomain.

2: ) Setting up roundcube.

I will not go through the Roundcube webmail setup steps. You can find it here: http://trac.roundcube.net/wiki/Howto_Install

Just make sure, there is only one imap host defined in main.inc.php (can be other than localhost) or else there is a better way to map domain to username:

3: ) Roundcube Modifications.

First we need to add a new field to login form for domain. Edit file ./program/include/rcube_template.php. Add folowing line inside “private function loginform($attrib)” function. I placed it between “$input_user = …” and “$input_pass = … ” to maintain the correct order according to login form.

Next, add folowing lines between ” $table->add(‘input’, $input_user->show(get_input_value(‘_user’, RCUBE_INPUT_GPC)));” and “$table->add(‘title’, html::label(‘rcmloginpwd’, Q(rcube_label(‘password’))));” lines:

Next, add folowing line to your default localization file. In my case its ./program/localization/en_US/labels.inc:

Save file, and check out your new login page it should look like this:

loginscreenWith automatically filled domain field for every domain (http://mail.domain1.com will show “domain1.com”, http://mail.domain2.com will show “domain2.com” etc.).

Ok, one more thing to do – we need to make roundcube to get this variable and add it to username. Edit file “./index.php” – add folowing between ” ‘user’ => trim(get_input_value(‘_user’, RCUBE_INPUT_POST)),” and “‘pass’ => get_input_value(‘_pass’, RCUBE_INPUT_POST, true,” lines:

Next add folowing right before “// Login” line:

Final thing – replace folowing line “$RCMAIL->login($auth[user], $auth[‘pass’], $auth[‘host’], $auth[‘cookiecheck’])” with this one:

4: ) Enjoy!

Now every user should be able to log in with his username only, when accessing webmail on his subdomain. You can also manually modify this field and type in a different domain or even leave it blank and log in using full e-mail address as username!

Please feel free to leave any comments or suggestions, and keep in mind, that I’m not a php programmer, so there could be some other (or better) way to achieve this.

 

Leave a Reply