Roundcube Community Forum

News and Announcements => General Discussion => Topic started by: joaquimsa on May 02, 2009, 05:13:43 AM

Title: multiple servers
Post by: joaquimsa on May 02, 2009, 05:13:43 AM
Hi,

We are starting to use roundcube in our hosting cluster , but i need to know if on thing is possible.

We have severall mail servers and i wish to manage all with the same roundcube instalation . Everything is fine and works well specifying the host server.

But what i wish is to avoyd that . Is there a way to auto-detect the host server ?
Our name structure is quite simple and we have 'a' records for every domain that allows to know the host of each domain.
So basically i need something that grabs the domain of the login entered by the client and automatically configure the default_host and smtp as "mail.".
Is this possible?

Thanks,
Joaquim
Title: multiple servers
Post by: rosali on May 03, 2009, 01:11:11 AM
Just parse the domain part from the URL and set host name dynamically. Here is an expample for some dynamic configuration:


function parse_domain(){

  $a_url = array();
  $temp = parse_url($_SERVER['HTTP_HOST']);
  $a_url['path'] = $temp['path'];
  $temp = array();
  $temp = array_reverse(explode(".",$_SERVER['HTTP_HOST']));
  if(!empty($temp[1])){
    $host = $temp[1] . "." . $temp[0];
  }
  else{
    $host = $temp[0];
  }
  if(!empty($temp[3]) && !empty($temp[2])){
    $host = $temp[2] . "." . $temp[1] . "." . $temp[0];
  }

  $a_url['subdomain'] = str_replace(".".$host,"",$_SERVER['HTTP_HOST']);
 
  $a_url['domain'] = $host;
 
  $a_url['script'] = str_replace("index.php","",$_SERVER['SCRIPT_NAME']);

  return $a_url;

}

/* Override here default or plugin configs */
/*
$a_home['path']       => script path
$a_home['subdomain']  => subdomain prefix
$a_home['domain']     => domain

NOTICE: mail.mydomain.co.uk => returns domain mydomain.co.uk
        If your home is me.mydomain.co.uk then "me" is returned as subdomain prefix !!
*/

$a_home = usersettings_parse_domain();

/* override config ::: extend for dynamic config ... print_r($rcmail_config) and exit !!! */
if(strtolower($a_home['domain']) != localhost){
  $rcmail_config['smtp_helo_host']            = $a_home['domain'];
  $rcmail_config['product_name']              = $a_home['domain'];
  $rcmail_config['admin_email']               = "webmaster@" . $a_home['domain'];
  $rcmail_config['default_domain']            = $a_home['domain'];
  $rcmail_config['pw_imap_host']              = "imap." . $a_home['domain'];
  $rcmail_config['pw_smtp_host']              = "smtp." . $a_home['domain'];
  $rcmail_config['pw_pop3_host']              = "pop."  . $a_home['domain'];
  $rcmail_config['pw_webmail']                = "http://" . $a_home['path'] . "";  
  $rcmail_config['pw_footer']                 = $a_home['domain'] . " - Webm@il-Team";
  $rcmail_config['roundcube_url']             = "http://" . $a_home['path'] . $a_home['script'];
  $rcmail_config['checked_identities_footer'] = $a_home['domain'] . " - Webm@il-Team";
  $rcmail_config['localhost_real_name']       = $a_home['domain'];
}
Title: multiple servers
Post by: lacri on May 03, 2009, 02:50:01 AM
i have an other solution on login retriving user data from LDAP and we added a new field for all users in LDAP thats hold the mailhost, on login retrieving the mailhost and setting automaticaly to use the right imap and smtp server for each user.

So can Users login with email, uid alias and alias email by retrieving the User Data setting the uid for loggin on IMAP in RC.
Title: multiple servers
Post by: joaquimsa on May 03, 2009, 02:18:30 PM
Hi,

Thanks for the help, but i have some doubts in both solutions.

Regarding rosali, as far as i understand that script will use the url , but the url where roundcube will work will be the same for all. Basically using that method i just need to cactch the user login ,remove the domain and pass it to the host .  But where will that script be used?


Lacri, i check the table and in deed there is an field with the host, however at least on time it needs to be filled, and after that i will i use it automatically?

I see that the solution could be something simples as getting the domain from the user email address, and pass it to the host variable. But in what file should that be done , i dont realy know the structure of roundcube yet.

Thanks,
Joaquim
Title: multiple servers
Post by: rosali on May 04, 2009, 05:25:26 AM
You could do it in ./config/main.inc.php ... f.e. parse there from $_POST['_user'] ...
Title: multiple servers
Post by: chaw on April 04, 2011, 07:38:54 AM
Hi Lacri,

could you tell us, how you did this other solution?
Is there a plugin?

tanks

chaw
Title: multiple servers
Post by: kseones on April 07, 2011, 10:53:08 AM
Hi,

We use on our server Roundcube with multiple domains and I think I have a good and simple solution.

I redirected the subdomains webmail.domain1.com and webmail.domain2.com on the same Roundcube installation.

Then chanced the line 68 in main.inc.php:

$default_host = str_replace("webmail.","", $_SERVER['HTTP_HOST']);
$rcmail_config['default_host'] = $default_host;

As result for the subdomain 'webmail.domain1.com' the host 'domain1.com' will be used.

Hope this helps
Remzi
Title: multiple servers
Post by: locu on April 07, 2011, 08:14:39 PM
Instead of using hostname from httpd, I use the user's username entry to determine their domain.  Then I rewrite that to make the default_host be mail.domain.com

In main.inc.php I did the following and it worked like a charm.

$_userdomain = explode('@', $_POST['_user']);
$_userdomain = $_userdomain[1];
$rcmail_config['default_host'] = 'mail.' . $_userdomain;
Title: Re: multiple servers
Post by: TrueFriend on July 01, 2012, 04:53:11 PM
Please how i rewrite mail address?

I can input "fname.lname@2" and rewrite and login as [email protected] ?

My solution does not work.

$_userdomain = explode('@', $_POST['_user']);
$_userdomain = $_userdomain[1];
if ($_userdomain==1) {$_userdomain="localhost";}
if ($_userdomain==2) {$_userdomain="srvname.tld";}
$rcmail_config['default_host'] = $_userdomain;

$_userserver = explode('@', $_POST['_user']);
$_userserver_b = $_userserver[1];

if ($_userserver_b==1) {$_POST['_user']=$_userserver[0]."@localhost";}
if ($_userserver_b==2) {$_POST['_user']=$_userserver[0]."@srvname.tld";}