Roundcube Community Forum

Third Party Contributions => Old Style Plug-Ins => Topic started by: coolant on July 25, 2006, 11:13:01 PM

Title: Multiple Domains Login
Post by: coolant on July 25, 2006, 11:13:01 PM
I just downloaded RoundCube, and I love it so far. I host over 50 domains and people hated typing in their full email addresses to login. This will only work if you have mail.domain.com, mail.domain2.com, etc. I quickly made a solution.

(http://dev.odiym.com/roundcube.jpg)

Before you start, make backups.

index.php

Under if ($_action=='login' && $_task=='mail'){ add :
Code: [Select]
$user = "$_POST[_user]@" . substr($_SERVER[HTTP_HOST], 5) . "";
And then change :
Code: [Select]
else if (isset($_POST['_user']) && isset($_POST['_pass']) && rcmail_login($_POST['_user'], $_POST['_pass'], $host))
to

Code: [Select]
else if (isset($user) && isset($_POST['_pass']) && rcmail_login($user, $_POST['_pass'], $host))
That takes care of the actually logging in part. Now to change the form.

program/include/main.inc

Find function rcmail_login_form($attrib)

Change

Code: [Select]
$input_user = new textfield(array('name' => '_user', 'size' => 30));to
Code: [Select]
$input_user = new textfield(array('name' => '_user', 'size' => 15));
Change

Code: [Select]
$fields['user'] = $input_user->show($_POST['_user']);to
Code: [Select]
$fields['user'] = "" . $input_user->show($_POST['_user']) . " @ " . substr($_SERVER[HTTP_HOST], 5) . "";
I know I could of done it 50 different ways, but this way was easy and quick.

Good luck!
Title: Re: Multiple Domains Login
Post by: bpat1434 on July 26, 2006, 11:47:03 AM
Easier than properly configuring the main.inc.php file?

// the mail host chosen to perform the log-in
// leave blank to show a textbox at login, give a list of hosts
// to display a pulldown menu or set one host as string.
// To use SSL connection, enter ssl://hostname:993
$rcmail_config['default_host'] = array('imap.domain.net' => 'Domain',
'imap.domain2.net' => 'Domain 2'
);

// TCP port used for IMAP connections
$rcmail_config['default_port'] = 143;

// Automatically add this domain to user names for login
// Only for IMAP servers that require full e-mail addresses for login
// Specify an array with 'host' => 'domain' values to support multiple hosts
$rcmail_config['username_domain'] = array('imap.domain.net' => 'domain.net',
'imap.domain2.net' => 'domain2.net'
);

// This domain will be used to form e-mail addresses of new users
// Specify an array with 'host' => 'domain' values to support multiple hosts
$rcmail_config['mail_domain'] = array('imap.domain.net' => 'domain.net',
'imap.domain2.net' => 'domain2.net'
);

Hmm... me thinks not....

Heck... you can take it one step further in ease:

// the mail host chosen to perform the log-in
// leave blank to show a textbox at login, give a list of hosts
// to display a pulldown menu or set one host as string.
// To use SSL connection, enter ssl://hostname:993
$rcmail_config['default_host'] = array('imap.domain.net' => 'Domain',
'imap.domain2.net' => 'Domain 2'
);

// TCP port used for IMAP connections
$rcmail_config['default_port'] = 143;

// Automatically add this domain to user names for login
// Only for IMAP servers that require full e-mail addresses for login
// Specify an array with 'host' => 'domain' values to support multiple hosts
$rcmail_config['username_domain'] = array('imap.domain.net' => 'domain.net',
'imap.domain2.net' => 'domain2.net'
);

// This domain will be used to form e-mail addresses of new users
// Specify an array with 'host' => 'domain' values to support multiple hosts
$rcmail_config['mail_domain'] = $rcmail_config['username_domain'];
Title: Re: Multiple Domains Login
Post by: flosoft on July 28, 2006, 06:25:50 PM
thx for both tutorials :D
Title: Re: Multiple Domains Login
Post by: SKaero on August 04, 2006, 05:01:13 AM
Its good code, But I only have one domain 8)
Title: Re: Multiple Domains Login
Post by: tenaka on August 17, 2006, 06:18:25 AM
ok guys, the second solution sounds great but its not really useful.

all my customers also use: mail.domain1.com mail.domain2.com etc...

that means I do not want them to see a dropdown of all the domains I host (in coolants example it would be a dropdown list of 50 domains) and chose theirs from the list, instead roundcube should be able to detect the domain where the user logged in from, strip mail. from it and append it to the username, at least thats what some plugins for squirrelmail can do...
Title: Re: Multiple Domains Login
Post by: bpat1434 on August 17, 2006, 03:21:17 PM
Hmm..... so you'd want something like:

$user = $_POST['_user'].'@'.substr($_SERVER['HTTP_HOST'], 5);

right?
Title: Re: Multiple Domains Login
Post by: yada on September 28, 2006, 02:51:32 AM
Cool plugin but i was wondering lets say you only have one domain
and i don t want my users to have to type in their domain and or server info think you could make something for that ???
Title: Re: Multiple Domains Login
Post by: Pete on September 28, 2006, 03:54:04 AM
yada, you can use the same example above or if you don't mind them typing in their account name (everything before @yourserver.com) and password you can do this without a plugin by specifying a domain in the config file.
Title: Re: Multiple Domains Login
Post by: yada on September 29, 2006, 12:28:56 AM
wow cool thanx man ;)
Title: Re: Multiple Domains Login
Post by: WebSide on October 11, 2006, 05:52:56 AM
Quote from: Brett
Hmm..... so you'd want something like:

$user = $_POST['_user'].'@'.substr($_SERVER['HTTP_HOST'], 5);

right?

This looks great. In which file i must wrote this?
Title: Re: Multiple Domains Login
Post by: bpat1434 on October 11, 2006, 07:31:53 AM
It would need to go into index.php either replacing or AFTER you see the default $user = line.
Title: Re: Multiple Domains Login
Post by: bigpaw on January 12, 2007, 08:04:40 AM
Quote from: coolant

I know I could of done it 50 different ways, but this way was easy and quick.



i downloaded roundcube version 0.1Beta2 about two months back...testing it with one domain first before i moved it over to the 100+ domains i host....a friend/workmate of mine (Luke Kyohere) did a quick hack on the index.php page and voila.....all the virtual domains i had were logging in with just the user id, without appending @domain.tld.... here is the modification (one of those 50 other ways ;) )

NOTE: all the domains i host are in the form mail.domain.tld

Code: [Select]

diff index.php.orig index.php
165,166c165,170
< if ($_action=='login' && $_task=='mail')
<  {
---
> // try to log in
>  if(isset($_POST['_user']) && $_action == 'login' && $_task == 'mail')
>   {
>    if($_SERVER['SERVER_NAME'] and !preg_match('/(.*)\@(.*)/',$_POST['_user'])){
>        $domain = preg_replace('/^(\w*)\./','',$_SERVER['SERVER_NAME']);
>        $_POST['_user'] = $_POST['_user'].&quot;@&quot;.$domain;
>    }

Title: Re: Multiple Domains Login
Post by: Jonn3 on January 19, 2007, 02:32:58 AM
Wouldn't this cause trouble if for some reason there are two equal usernames with different domains?
For example john@domain1.com, john@domain2.com

As it most likely is to cause trouble, there would be no way to get around this without entering @domain.com right?
Title: Re: Multiple Domains Login
Post by: bpat1434 on January 20, 2007, 12:05:19 PM
It could cause trouble; however, if you have webmail.domain.com point to an IP of where RC is, and webmail.domain2.com point to the same IP of where RC is, then you could conceivably use $_SERVER['HTTP_HOST'], wipe out the 'webmail.' portion, and tack that on. Now, that's not to say it's full-proof. The only full-proof plan is to use the array that's set up in the main.inc.php file, or use multiple installations that could use the same database.
Title: Re: Multiple Domains Login
Post by: Insanity5902 on January 21, 2007, 05:47:36 PM
Here is what I do, and it seems to have worked so far.

In my main.inc.php, I set the default_host to use localhost:993, then set username_domain as follows

Code: (config/main.inc.php) [Select]
$tempDomain = array_reverse(explode(".",$_SERVER['HTTP_HOST']));
$rcmail_config['username_domain'] = $tempDomain[1].".".$tempDomain[0];

This creates an array in tempDomain with each portion of the domain used to get there has a node, and by reversing it, it puts the TLD in position 0, so postions 1 is the root domain. As long as you don't use log domain e-mail addresses (e.g. user@mail.cs.utexas.edu), then you shouldn't have a problem.

Now if the user logs in with their full e-mail address then roundcube ignores the default domain, and if they don't then it grabs it from the address they used to get there. So you could have http://www.webmail.domain.com, and it would append domain.com to the user name if they don't put one on there.

The other beauty of this setup is that the default Roundcube install does all the work, we are just using what was given to us by the Developers.

The last thing I do, just to make things obvious to the user is to add a small section during the login screen. This is in program/include/main.inc

Code: (program/include/main.inc) [Select]

$fields[user]




@$CONFIG[username_domain]



$fields[pass]

This just adds the detected username_domain under the username field.

You can see what this looks like at http://mail.routedtechnologies.com/roundcube/. You can see the change of domain name by going to http://mail.rsatechnology.net/roundcube/

I think this setup is pretty much fool proof, if someone sees a flaw it please let me know.
Title: Re: Multiple Domains Login
Post by: OJM on January 28, 2007, 07:57:47 AM
Quote from: Brett
Hmm..... so you'd want something like:

$user = $_POST['_user'].'@'.substr($_SERVER['HTTP_HOST'], 5);

right?

Quote from: Brett
It would need to go into index.php either replacing or AFTER you see the default $user = line.

Sorry Brett, I can't see where this needs to go. I'm running version 0.1-beta2

I sell hosting, and have 6 email servers. However I'd like to have one location for my webmail, and for RoundCube to work out which mail server to logon to, from the email address the person is using. I assume the example you gave will do this, but I'm not sure where your code needs to be placed, to remove the dropdown box.

Cheers.
Title: Re: Multiple Domains Login
Post by: bpat1434 on January 28, 2007, 08:49:39 PM
Sorry, my bad. Look in /program/includes/main.inc for the function rcmail_login. Inside there you need to find this:
 // exit if IMAP login failed
 if (!($imap_login = $IMAP->connect($host, $user, $pass, $imap_port, $imap_ssl)))
  return FALSE;


And add just before it the line $user= $_POST['_user'].'@'.substr($_SERVER['HTTP_HOST'], 5);

So you come out with:
$user = $_POST['_user'].'@'.substr($_SERVER['HTTP_HOST'], 5);

 // exit if IMAP login failed
 if (!($imap_login = $IMAP->connect($host, $user, $pass, $imap_port, $imap_ssl)))
  return FALSE;
Title: Re: Multiple Domains Login
Post by: dgec on February 05, 2007, 06:22:05 PM
I'm confused about how exactly this is set up and the capabilities.

Here's my fairly standard setup - will any of the above work for me?

- 1 main, purchased account with my own email account.
- I have websites I manage, which have domains pointing to subdirectories in my public_html directory (eg cust1.com is pointed to my.com/cust1). no big deal.

I want my customers to be able to use their user1@cust1.com and user2@cust2.com off of my RC install. (Actually I'd like to be able to use user1@cust1.com AND user1@cust2.com for that matter.)

At this point, I'm not as concerned about automatically picking up their domain (I'm guessing the user selects a link to "cust1.com/mail" which redirects to my.com/email) as I am about having to install multiple RCs and databases.

Title: Re: Multiple Domains Login
Post by: bpat1434 on February 05, 2007, 07:38:01 PM
You don't need to install multiple databases. One database will support 1 SMTP server, and mutiple IMAP servers. So all email addresses will work. Now, since I'm guessing that you only have 1 SMTP server, only one installation is needed. You'll just have to make them insert their entire email address (user1@cust1.com) as the username, and their password. If you want, you can have a drop-down list of IMAP servers available to them.
Title: Re: Multiple Domains Login
Post by: dgec on February 06, 2007, 11:07:41 AM
Great! That was my guess, but one thread sounded like multiple code instances were needed.
Thanks!
Title: Re: Multiple Domains Login
Post by: dgec on February 06, 2007, 02:09:19 PM
Quote from: Insanity5902
In my main.inc.php, I set the default_host to use localhost:993, then set username_domain as follows

Code: (config/main.inc.php) [Select]
$tempDomain = array_reverse(explode(".",$_SERVER['HTTP_HOST']));
$rcmail_config['username_domain'] = $tempDomain[1].".".$tempDomain[0];

I added the two blocks of code Insanity mentions and it works fine for my primary "domain1.com", exactly as I would hope.

However, I tried both a php redirect from "domain2.com/mail.php" and an actual href link directly to the actual RC directory (and the index.php) and they show up as domain1.com still, which is not desired behaviour.

To the above quoted code block, I tried changing to REFERER, but I couldn't get anything out of that to work either.

Any ideas?
Title: Re: Multiple Domains Login
Post by: bpat1434 on February 06, 2007, 04:32:31 PM
Hmm.... let me stew on this a bit... it can be done with sessions. It'd be a dirty hack but the basics would be like this:

1.) User goes to domain2.com/mail (or webmail.domain2.com)
2.) That index.php redirects to another index.php page with a url like: webmail.domain1.com/domain.myHostname
3.) .htaccess mod_rewrite takes the domain.myHostname and splits it, and sends that to Index.php

Lots of little steps. Or, you can send the HTTP header with the location redirection in PHP like:
header("Referer: [url]http://www.domain2.com"[/url]);
header("Location: [url]http://www.domain1.com/mail"[/url]);

Something like that might work as well. Then again, this is what virtual user tables are for ;)
Title: Re: Multiple Domains Login
Post by: dgec on February 06, 2007, 09:15:15 PM
I did 1) & 2) . 3) I don't know enough about yet.

I might try your header trick, which I prefer, 'cause I can put it in a page and program it to pick up its own url (I think) and I want to make this as generic as possible.

Virutal user tables? hmm..... M4? urk. I know just enough about linux mailers not to want to touch that.
Title: Re: Multiple Domains Login
Post by: bpat1434 on February 06, 2007, 10:46:47 PM
virtual user tables aren't just linux ;) They're essentially flat-file databases.... not sure how to work with them, but I know it can be done.
Title: Re: Multiple Domains Login
Post by: bigpaw on February 08, 2007, 12:24:25 AM
Quote from: Jonn3
Wouldn't this cause trouble if for some reason there are two equal usernames with different domains?
For example john@domain1.com, john@domain2.com

As it most likely is to cause trouble, there would be no way to get around this without entering @domain.com right?

not really, i tested this on more than one domain, with same username and it works well for me, whether you have RC installed on the mail server itself or have it installed on a web server and have RC talk to the IMAP server, it still works fine.

Quote from: bigpaw
Code: [Select]
>    if($_SERVER['SERVER_NAME'] and !preg_match('/(.*)\@(.*)/',$_POST['_user'])){
>        $domain = preg_replace('/^(\w*)\./','',$_SERVER['SERVER_NAME']);
>        $_POST['_user'] = $_POST['_user'].&quot;@&quot;.$domain;
>    }


the variable $domain will end up with a value domain.tld. it doesn't matter if the SERVER_NAME or HTTP_HOST is webmail.domain.tld or mail.domain.tld


Quote from: Brett
Hmm..... so you'd want something like:

$user = $_POST['_user'].'@'.substr($_SERVER['HTTP_HOST'], 5);

right?

Bret, this is may cause some trouble.....using substr() the way you have chops off the first five characters of HTTP_HOST, if someone has a domain name that is not of the form mail.domain.tld then he is in trouble e.g if i had webmail.domain.tld, i would get il.domain.tld instead of the desired domain.tld. using explode and reversing the array as Insanity said would also work...

if you use HTTP_HOST, you will get the contents of 'host' from the current request. using SERVER_NAME will return the name of the server host under which RC is being run, if you use vhosts like i do, this value will be the value defined for that vhost.
Title: Re: Multiple Domains Login
Post by: dgec on February 09, 2007, 04:46:37 PM
Quote from: Brett
Lots of little steps. Or, you can send the HTTP header with the location redirection in PHP like:
header("Referer: [url]http://www.domain2.com"[/url]);
header("Location: [url]http://www.domain1.com/mail"[/url]);

Rats. Doesn't work. Actually, I realized that was pretty much what I was trying, and then tried to pick up Referer too, but didn't set it explicitly. Apparently doesn't matter, I still get no value on the receiving page.

I wonder, could it be something about because there's already a domain redirect, which sends
 domain2.com to domain1.com/domain2?

The domain2.com is also defined as domain2.domain1.com (cpanel).
Does the server know the url for domain2.com/mail is really
 domain1.com/domain2/mail or even domain2.domain1.com/mail
... if that makes sense?
Title: Re: Multiple Domains Login
Post by: bpat1434 on February 10, 2007, 12:30:09 AM
Quote from: bigpaw
Bret, this is may cause some trouble.....using substr() the way you have chops off the first five characters of HTTP_HOST, if someone has a domain name that is not of the form mail.domain.tld then he is in trouble e.g if i had webmail.domain.tld, i would get il.domain.tld instead of the desired domain.tld. using explode and reversing the array as Insanity said would also work...

if you use HTTP_HOST, you will get the contents of 'host' from the current request. using SERVER_NAME will return the name of the server host under which RC is being run, if you use vhosts like i do, this value will be the value defined for that vhost.
Well, that was a solution to the issue of one person, not meant as an overall solution.

Quote
Rats. Doesn't work. Actually, I realized that was pretty much what I was trying, and then tried to pick up Referer too, but didn't set it explicitly. Apparently doesn't matter, I still get no value on the receiving page.

I wonder, could it be something about because there's already a domain redirect, which sends
 domain2.com to domain1.com/domain2?

The domain2.com is also defined as domain2.domain1.com (cpanel).
Does the server know the url for domain2.com/mail is really
 domain1.com/domain2/mail or even domain2.domain1.com/mail
... if that makes sense?
If there's a domain redirect, no scripts / pages will be executed. The redirect happens before anything else. I guess if you needed to you could always just copy the contents of the roundcube folder X times (X = number of sites / domains) and use the same database.
Title: Re: Multiple Domains Login
Post by: leroy on February 11, 2007, 04:02:02 AM
I added this snippet to index.php that allows users to login without entering their domain name. I have 30+ accounts on the server and I have no idea what server they are logging in from so SERVER variables don't help. This way they only have to use their full name once, then after that they can login with just the short name. I'm making some presumptions about the users table, and it may not work if the shortname appears more than once in the table (though a selectbox could be easily hacked out for that possibility), But it degrades gracefully.

// try to log in
if ($_action=='login' && $_task=='mail')
 {

   
   $sql = "Select username from users";
   $result = mysql_query($sql);
   while($row = mysql_fetch_assoc($result)) {
      $buf = explode("@",$row['username']);
      if($_POST['_user'] == $buf[0]) {
         $_POST['_user'] .= "@".$buf[1];
         break;
      }
   }

 
 $host = $_POST['_host'] ? $_POST['_host'] : $CONFIG['default_host'];
Title: Re: Multiple Domains Login
Post by: lizzie on February 24, 2007, 12:15:58 PM
Quote from: Brett
Sorry, my bad. Look in /program/includes/main.inc for the function rcmail_login. Inside there you need to find this:
 // exit if IMAP login failed
 if (!($imap_login = $IMAP->connect($host, $user, $pass, $imap_port, $imap_ssl)))
  return FALSE;


And add just before it the line $user= $_POST['_user'].'@'.substr($_SERVER['HTTP_HOST'], 5);

So you come out with:
$user = $_POST['_user'].'@'.substr($_SERVER['HTTP_HOST'], 5);

 // exit if IMAP login failed
 if (!($imap_login = $IMAP->connect($host, $user, $pass, $imap_port, $imap_ssl)))
  return FALSE;

Just started up on this thing and it is AMAZING.

I have implemented this hack and it works almost perfectly apart from one thing:

For some reason no user is recognised as an existing user and a new entry is created for them in the users table in the database. This means that all the settings of each individual user (timezone, identities, etc...) are lost.

Have I missed something, or is anyone else having this problem? I am using the release version, not SVN ones, but it was fine before I implemented this hack.

Thanks in advance.
Title: Re: Multiple Domains Login
Post by: lizzie on February 24, 2007, 01:01:25 PM
Having just posted that, I had a brainwave...

In program/include/main.inc, the $user variable was changed to the POST variable again.

$user = $_POST['_user'].'@'.substr($_SERVER['HTTP_HOST'], 5);


If you put this:

// domain name hack
$user .= '@'.substr($_SERVER['HTTP_HOST'], 5);


above this:

 // query if user already registered
 $sql_result = $DB->query("SELECT user_id, username, language, preferences
              FROM ".get_table_name('users')."
              WHERE mail_host=? AND (username=? OR alias=?)",
              $host,
              $user,
              $user);


instead, it works a treat. It merely adds the relevant domain to the end of the $user string, then checks to see if the user is new or not.

I tied this in with Insanity5902's hack slightly modified shown below to put the "@domain.tld" on the login screen to avoid confusion:

$domain_lizzie = substr($_SERVER['HTTP_HOST'], 5);

$out = <<$form_start
$SESS_HIDDEN_FIELD
$fields[action]











$form_host
$fields[user]@$domain_lizzie
$fields[pass]

$form_end
EOF;


The bits you need to add are line 1 of the above and lines 12 + 13.

Also,

[quote="bigpaw ]
Quote from: Brett
Hmm..... so you'd want something like:

$user = $_POST['_user'].'@'.substr($_SERVER['HTTP_HOST'], 5);


right?

Bret, this is may cause some trouble.....using substr() the way you have chops off the first five characters of HTTP_HOST, if someone has a domain name that is not of the form mail.domain.tld then he is in trouble e.g if i had webmail.domain.tld, i would get il.domain.tld instead of the desired domain.tld. using explode and reversing the array as Insanity said would also work...
[/quote]

Regarding this, if you change the highlighted number to 8 for webmail.domain.tld - the number of characters leading up to the bit you want. You can use the .htaccess file to ensure that the www. is omitted so as to avoid user input errors.

The $_SERVER['HTTP_HOST'] string is more reliable than some of the explode() methods which don't work for mail.domain.co.uk for example... I have both on my server.

Hope this helps someone.
Title: Re: Multiple Domains Login
Post by: jingo on May 17, 2007, 05:26:28 AM
In my setup I have multiple domains

mail.domain1.com
mail.domain2.com
mail.domain3.com

which are all redirected through apache mod_rewrite to

"https://ssl.mysslenableddomain.com/mail.domain1.com/roundcube/" etc.

Added these lines to main.inc.php:
Code: [Select]
$tempDomain = explode( &quot;/&quot;, $_SERVER['REQUEST_URI'], 3);  # &quot;3&quot; is a limit of the array, never need more.
$tempDomain = array_reverse( explode( &quot;.&quot;, $tempDomain[1] ) );
$rcmail_config['username_domain'] = $tempDomain[1].&quot;.&quot;.$tempDomain[0];

$_SERVER['REQUEST_URI'] returns "/mail.domain1.com/roundcube/"
explode by "/" then returns an array :
[ 0] => ""
[1] => "mail.domain1.com"
[2] => the rest... because of the limit of 3

then explode [1] by "." returns
[ 0] => "mail"
[1] => "domain1"
[2] => "com"

array is reversed to support other configs like "http://www.mail.domain1.com" which is common.
Title: Re: Multiple Domains Login
Post by: renevdb on June 29, 2007, 09:05:26 PM
I have a setup with a dropdown for a few domains, now I want to change to the smtp server instead of PHP. If I put in a snmp server it works okay, but as I use multiple domains I created a array. This however does not work.

$rcmail_config['default_host'] = array(
 'mail.domain1.com' => 'domain1.com',
 'mail.domain2.com' => 'domain2.com'
 );

$rcmail_config['username_domain'] = array(
 'mail.domain1.com' => 'domain1.com',
 'mail.domain2.com' => 'domain2.com'
 );

$rcmail_config['mail_domain'] = $rcmail_config['username_domain'];

$rcmail_config['smtp_server'] = 'mail.domain1.com';

==============================================

If I chance this it will not let me sent.

$rcmail_config['smtp_server'] = array(
 'mail.domain1.com' => 'domain1.com',
 'mail.domain2.com' => 'domain2.com'
 );

What do I need to change?
Title: Re: Multiple Domains Login
Post by: bpat1434 on July 08, 2007, 05:22:22 PM
I contributed a patch to the devs for multiple SMTP servers. If you grab the latest trunk (although currently the SVN server is down :() you should be able to do exactly as you have done. But if you downloaded the 0.1-rc1 it is not included.
Title: Re: Multiple Domains Login
Post by: TommyER on July 16, 2007, 01:56:26 PM
I have seen that in the user-entry in the data is a field called "mail_host".

Is it possible to create a login only with username (or alias) and password and the script lookup for the "mail_host" and continue with RC?

So it would be easy to login with multiple mail servers.

Tom
Title: Re: Multiple Domains Login
Post by: bpat1434 on July 16, 2007, 02:35:56 PM
You mean like a VirtUser file? Roundcube supports those already. I don't know how to use them, but it seems like what you want.
Title: Re: Multiple Domains Login
Post by: TommyER on July 16, 2007, 04:36:25 PM
No. I don' want to use a edited file on the server. I'd like to use the main functions and tables of RC.

Example:

Username: email-adress -> stored in alias in the database, instead of the username (could also the username if someone likes it)
Password: Password
Server: leave blank or hidden field

On the login process the RC-script should lookup in table users for the entry "mail_host" and set the variable to the value of the database entry and connect to the mail-server. So there is no extra file necessary. RC have the information but didn't use it.
Title: Re: Multiple Domains Login
Post by: bpat1434 on July 17, 2007, 09:56:29 AM
If the server is blank or hidden, then it can only be one server (as per RC main.inc.php file). Otherwise a drop-down is shown for multiple servers, or a blank input box for user-defined servers.

So in that case, you can just have them use their username (without the "@domain.tld" portion) and define the domain to append to the username in the main.inc.php file and they can log in that way.
Title: Re: Multiple Domains Login
Post by: TommyER on July 17, 2007, 01:35:42 PM
Hi Brett,

i know those two options. But I suggest an idea of an third option if you re-read my posting. I can't programming this in cgi, but maybe can someone program it.
Title: Re: Multiple Domains Login
Post by: Mickey on August 04, 2007, 09:55:37 AM
I'll just add my 2 cents here. This works fine for us with multiple domains:
we have mail.***.com domains pointing to one rc install. This hack works
like: if the domain has a prefix "mail" then it get's rid of the server part and
@domain part in login. if no "mail" prefix found it displays the standard login
form where you have to type in everything:

in config/main.inc.php add this:
Code: [Select]
function getDomain() {
$host=$_SERVER['HTTP_HOST'];
$prefix='mail';
$arr=explode('.',$host);
if ($arr[0]==$prefix) { unset($arr[0]); $host=implode('.',$arr); }
else { $host=''; }
return $host;
}

and modify the following 2 config lines:
Code: [Select]
$rcmail_config['default_host'] = getDomain();
Code: [Select]
$rcmail_config['username_domain'] = getDomain();
Hope this is helps for someone,
Mickey


Title: Re: Multiple Domains Login
Post by: bpat1434 on August 04, 2007, 03:48:50 PM
TommyER: You might look at the source-code to Roundcube. A virtual user query is what you need. I'm not 100% sure how to do it, but I know it can be done (as others on here have done before).
Title: Re: Multiple Domains Login
Post by: rsw686 on October 31, 2007, 02:13:41 PM
I'm slightly confused on how to configure the options for my setup. I am using postfix with virtual domains and roundcube is on the same server. The server is behind NAT so I currently have the following set

$rcmail_config['default_host'] = 'localhost';

When logging in the user has to type the full email@domain.com. I want a dropdown of domains available, but no matter the domain choice it needs to use localhost for the default_host. Otherwise unless I hard code each domain with the public IP into my hosts file the request will go out to the router through NAT and back, which ties up CPU cycles on the router.

Seems simple but I have a feeling this isn't possible. As the host is used to link the username_domain to default_host to append the correct domain name.
Title: Re: Multiple Domains Login
Post by: bpat1434 on October 31, 2007, 08:28:10 PM
Not possible right now as each array key for the domains has to be different, and since they'll all be "localhost" you can only have one.

What you could do is manually add in the template a drop-down box and set all the values to localhost.....
Title: Re: Multiple Domains Login
Post by: dave1978 on January 04, 2008, 04:08:01 PM
Is it possible to strip the domain from the user and use that as the server to save the user having to enter the domain twice for example:

User info@domain1.com
Server domain1.com (automatically taken from the address that user entered)

User info@domain2.com
Server domain2.com (automatically taken from the address that user entered)
Title: Re: Multiple Domains Login
Post by: bpat1434 on January 04, 2008, 06:04:37 PM
Yes it's possible, but you'd have to modify the source in the login functions to do so.
Title: Re: Multiple Domains Login
Post by: dave1978 on January 04, 2008, 08:59:18 PM
I should have had a better look anyway I've now replaced line 500 of main.inc

Code: [Select]
$host = isset($_POST['_host']) ? get_input_value('_host', RCUBE_INPUT_POST) : $CONFIG['default_host'];

with

Code: [Select]
$usersplit = explode('@', get_input_value('_user', RCUBE_INPUT_POST));
 $host = $usersplit[1];

and it now seems to work a treat does exactly what I needed
Title: Re: Multiple Domains Login
Post by: bpat1434 on January 05, 2008, 12:13:48 PM
Fantastic!! Glad to hear you got it working as you wanted ;)
Title: Re: Multiple Domains Login
Post by: dano on January 11, 2008, 12:10:29 PM
Hello,

I use part of a hack that was originally posted as a Cpanel password change hack. I will try to post the pertinent information here. I am using this on a Cpanel 11 server with multiple virtual hosts and multiple users per domain.

I have my httpd.conf configure so that Roundcube loads when a user browses to http://www.domain.com/rcmail.

The user MUST put 'www' in the url or else it will not work. An error returns and Roundcube puts the user name in the log in box but you can see that it's incorrect.

In index.php locate the login section (find // try to log in). Replace it with
Code: [Select]
// try to log in
if(isset($_POST['_user']) && $_action == 'login' && $_task == 'mail')
 {
 if($_SERVER['SERVER_NAME'] and !preg_match('/(.*)\@(.*)/',$_POST['_user'])){
    $domain = preg_replace('/^(\w*)\./','',$_SERVER['SERVER_NAME']);
    $_POST['_user'] = $_POST['_user'].&quot;@&quot;.$domain;
 }

In main.inc.php:

Set default_host to localhost
Code: [Select]
$rcmail_config['default_host'] = 'localhost';

Set smtp_server to localhost
Code: [Select]
$rcmail_config['smtp_server'] = 'localhost';

Set smtp_user to %u
Code: [Select]
$rcmail_config['smtp_user'] = '%u';

Set smtp_pass to %p
Code: [Select]
$rcmail_config['smtp_pass'] = '%p';

And I believe that that is everything. Hope that's able to help someone!
Title: Re: Multiple Domains Login
Post by: yenemy on March 27, 2008, 11:49:09 AM
Edit: Haha, sorry about the post resurrection; didn't notice this was from way back in January

Hi all, just installed Roundcube a few days ago and I'm liking it quite a lot. I too got tired of typing in my full email address when logging in, so I put the following in main.inc.php:

Code: [Select]
// Automatically add this domain to user names for login
// Only for IMAP servers that require full e-mail addresses for login
// Specify an array with 'host' => 'domain' values to support multiple host
$hostStr = $_SERVER['HTTP_HOST'];
$wPos = strPos($hostStr, '.')+1;
$rcmail_config['username_domain'] = substr($hostStr,$wPos);

Basically just grabs the browser domain and strips the first element. So as long as the user's logging in at the right domain, they should be fine. Works a treat for me, thought I'd share in case anyone else wants it. I saw some stuff with database calls, etc. earlier in this thread, but that's way beyond me at this point... I'm no programmer, and certainly not a PHP one.
Title: Re: Multiple Domains Login
Post by: cornbread on March 27, 2008, 12:33:03 PM
Hope you don't mind I added this to the trac as a feature request.

http://trac.roundcube.net/ticket/1484930
Title: Re: Multiple Domains Login
Post by: yenemy on March 27, 2008, 03:48:17 PM
cornbread, I don't mind at all!
Although, a more foolproof way would be to grab the last two elements instead of stripping the first one since some subdomains come in differently: e.g., four elements like some subdomains ("http://www.email.domain.com")

---------------------------------

So after my last post, I figured I should just go ahead and do it.

And here it is:

Code: [Select]
// Automatically add this domain to user names for login
// Only for IMAP servers that require full e-mail addresses for login
// Specify an array with 'host' => 'domain' values to support multiple host

$hostArr = explode('.',$_SERVER['HTTP_HOST']);
$hostDomain = join('.',array_reverse(array(array_pop($hostArr),array_pop($hostArr))));
$rcmail_config['username_domain'] = $hostDomain;

--------------

Haha, which looks a lot like a dupe of jingo's (http://roundcubeforum.net/forum/index.php?topic=212.msg6628#msg6628).
Title: Roundcube and multiple domains
Post by: wheaties82 on December 10, 2008, 09:29:25 PM
First off I am a noob to this so go gentle on me . . . I am experiencing a strange issue with Roundcube 0.2-beta.

I have an email server that has two virtual domains and Postfix is configured to accept mail for either domainA or domainB. so johndoe@domainA can also be johndoe@domainB -- same email (aka johndoe can log into domainA or domainB and see the same Maildir files) just different mail servers are used for sending / receiving.

I have installed RC for domainA already with its own independent database and user. It is functioning properly.

In a separate folder with a new installation (independent directory from domainA) I have another installation referencing a (new) seperate database and user. The installation summary ends without an issue -- everything says it is ok, I can even send a test email. The strange issue is when I attempt to do a test login (or normal login) I get a timeout error. Below are examples:

[08-Dec-2008 23:02:50] PHP Fatal error: Maximum execution time of 120 seconds exceeded in /var/www/domainB/webmail/program/lib/imap.inc on line 317
[08-Dec-2008 23:08:23] PHP Fatal error: Maximum execution time of 120 seconds exceeded in /var/www/domainB/webmail/program/lib/imap.inc on line 208

I have verified that domainB is working with IMAP as I can login to the account via thunderbird and send and receive without any problems.  I have verified that all my MX and DNS records are correct -- as I can send and receive email no problem

I have tried sharing the same database as domainA but I get the same results -- a timeout and error referrencing imap.inc

I have read the posts included in this thread but they all seem to point to solutions where the user has to enter '@domainA' after the username -- and my server is not configured to do that -- it only needs the username.

Am I incorrect in assuming that Roundcube is capable of having two independent installations referencing different domains on the same server?

:confused::confused::confused:
Title: Multiple Domains Login
Post by: zhylninc on April 25, 2010, 02:31:09 AM
and nginx config
 location / {
            proxy_pass http://192.168.1.2/;
            proxy_set_header Host $host;
                       }


proxy_set_header Host $host;
;)
Title: Multiple Domains
Post by: egrogg on June 04, 2011, 07:28:38 PM
Quote from: Mickey;7794
I'll just add my 2 cents here. This works fine for us with multiple domains:
we have mail.***.com domains pointing to one rc install. This hack works
like: if the domain has a prefix "mail" then it get's rid of the server part and
@domain part in login. if no "mail" prefix found it displays the standard login
form where you have to type in everything:

in config/main.inc.php add this:
Code: [Select]
function getDomain() {
$host=$_SERVER['HTTP_HOST'];
$prefix='mail';
$arr=explode('.',$host);
if ($arr[0]==$prefix) { unset($arr[0]); $host=implode('.',$arr); }
else { $host=''; }
return $host;
}


and modify the following 2 config lines:
Code: [Select]
$rcmail_config['default_host'] = getDomain();
Code: [Select]
$rcmail_config['username_domain'] = getDomain();

Hope this is helps for someone,
Mickey



This solution works great!  Perfect instructions!

is there a way to change the logo and the "Welcome to *** webmail"  per domain?

I have them going to wmail.domain1.com and wmail.domain2.com
Title: Multiple Domains Login
Post by: SKaero on June 04, 2011, 11:34:08 PM
Do the same thing for $rcmail_config['product_name'].
Title: Multiple Domains
Post by: egrogg on June 05, 2011, 08:19:07 AM
Ahh..I C...

I am guessing here but maybe for the logo there would need to be some kind of "if" statement?  I am not a programmer so, maybe if someone would know how to do that, it would be great...
Title: Multiple Domains Login
Post by: egyreal on June 12, 2011, 08:15:50 AM
thanks dano
Title: Re: Multiple Domains Login
Post by: saulos on August 16, 2016, 01:11:10 PM
Hi, sorry to reopen an old post.
But I will like to know if the solution exposed here are still valid or now we have a different solution ?
Just to be clear I have 2 domain and I will like to have the domain added to the username like :
jim --> jim@domain1.com

if jum chose the 'domain1.com' from the dropdown-

Thanks