Author Topic: Multiple Domains Login  (Read 61246 times)

Offline coolant

  • Newbie
  • *
  • Posts: 2
Multiple Domains Login
« 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.



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!

Offline bpat1434

  • Administrator
  • Hero Member
  • *****
  • Posts: 673
Re: Multiple Domains Login
« Reply #1 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'];
 
  

Offline flosoft

  • Administrator
  • Sr. Member
  • *****
  • Posts: 349
    • http://flosoft.biz
Re: Multiple Domains Login
« Reply #2 on: July 28, 2006, 06:25:50 PM »
thx for both tutorials :D

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,491
    • http://SKaero.com/
Re: Multiple Domains Login
« Reply #3 on: August 04, 2006, 05:01:13 AM »
Its good code, But I only have one domain 8)

Offline tenaka

  • Newbie
  • *
  • Posts: 2
Re: Multiple Domains Login
« Reply #4 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...

Offline bpat1434

  • Administrator
  • Hero Member
  • *****
  • Posts: 673
Re: Multiple Domains Login
« Reply #5 on: August 17, 2006, 03:21:17 PM »
Hmm..... so you'd want something like:

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

right?
 
  

Offline yada

  • Newbie
  • *
  • Posts: 6
Re: Multiple Domains Login
« Reply #6 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 ???

Offline Pete

  • Jr. Member
  • **
  • Posts: 15
Re: Multiple Domains Login
« Reply #7 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.

Offline yada

  • Newbie
  • *
  • Posts: 6
Re: Multiple Domains Login
« Reply #8 on: September 29, 2006, 12:28:56 AM »
wow cool thanx man ;)

Offline WebSide

  • Newbie
  • *
  • Posts: 4
Re: Multiple Domains Login
« Reply #9 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?

Offline bpat1434

  • Administrator
  • Hero Member
  • *****
  • Posts: 673
Re: Multiple Domains Login
« Reply #10 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.
 
  

Offline bigpaw

  • Newbie
  • *
  • Posts: 2
Re: Multiple Domains Login
« Reply #11 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;
>    }


Offline Jonn3

  • Jr. Member
  • **
  • Posts: 23
Re: Multiple Domains Login
« Reply #12 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?

Offline bpat1434

  • Administrator
  • Hero Member
  • *****
  • Posts: 673
Re: Multiple Domains Login
« Reply #13 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.
 
  

Offline Insanity5902

  • Newbie
  • *
  • Posts: 3
Re: Multiple Domains Login
« Reply #14 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.