Single RoundCube setup for multiple ISPConfig3 servers

Discussion in 'Tips/Tricks/Mods' started by Hans, Mar 11, 2010.

  1. Hans

    Hans Moderator Moderator

    Since í'm using ISPConfig3, i'm interested in a single installation of the RoundCube webmail client, for all my ISPConfig3 servers.
    For maintenance reasons, i prefer one single setup instead of one RoundCube webmail client on every ISPConfig3 server.

    Within the RoundCube configuration file main.inc.php i can change the line $rcmail_config['default_host'] = 'localhost'; into $rcmail_config['default_host'] = '';
    By doing this an extra field on the login screen appears, so the hostname of the imap-server can be filled in there.
    However this is not what i want.
    Another possibility is to give one ISPConfig 3 server the task of mailserver and nothing else.
    By doing this, RoundCube needs only one host, so that's a possibility, but it's not what i prefer.

    So my question is: does anybody know how to configure RoundCube, so that it can access multiple hosts?
     
  2. JeGr

    JeGr Member

    Hi Hans,

    if that's not what you wanted, what result do you intend to achieve? A dropdown with hosts listed? Can you describe your setup a bit, too? Perhaps than I may be able to help.
     
  3. Hans

    Hans Moderator Moderator

    @Grey,
    Thanks for your help, I wanted no dropdownlist, but that's a little complicated with more then one mailserver, i guess.
    (I'm not a programmer). After all. i decided to work with a dropdownlist, which works fine.
    So, now i use one single RoundCube installation (for maintenance), from which i can access every ISPConfig3-server in my network. My RoundCube installation can be visited form every website when the suffix /webmail has been added or by clicking the Webmail icon in the ISPConfig3 controlpanel.
     
    Last edited: May 19, 2010
  4. nachbar

    nachbar New Member

    Hi Hans,

    i search such the same setup you have or you want. How have you configured ispconfig3 or / and roundcube to solve the problem?

    Lets take an example:
    We have seperate hosts e.g. 1 to 3. And a seperate ispconfig3 server

    So the roundcube single installation will be on ispconfig3 server too. So how to tell roundcube to choose the correct server? E.g. [email protected] is hostet on host 2. How knows roundcube to take host 2 as login server?
     
  5. Hans

    Hans Moderator Moderator

    What i explain above is functioning fine already.
    Here is my RC login screen. As you can see, i have a dropdown list. As you can see i have 6 mailservers (each ISPConfig3). What the client has to do is: login with its username and password and choose the mailserver (1-6). If you need an example of the RoundCube main.inc.configuration file i can post it here for you.
     
  6. JeGr

    JeGr Member

    I think I know what you meant. You have 6 different mail servers, all running ISPConfig 3 and configured via a central ISPConfig instance, right? So what you would need for RC to work would be to automatically select the according server to the given user.

    E.g:
    User xyz_abc logs in - his account is on server 5, so mailserver 5 would be selected.
    User abc_123 logs in - her account is on server 2.

    Am I suspecting that right?
     
  7. nachbar

    nachbar New Member

    @Grey

    Yeah. That is what i mean. I dont want that the customers have to select the correct server. I want that the correct server will be selected automatic.

    So for this i search a solution. How could it be managed?
     
  8. Hans

    Hans Moderator Moderator

    Yes, you understand me completely.

    On an ISPConfig 3 server, the username for the mailbox is the same as the e-mailaddress.
    To logon succesfully, we need 3 things:

    - user name ([email protected])
    - password
    - server name

    Until now, i use the default dropdown menu to select the right server name, as i do not know how tweak RoundCube, so that the right server is selected automaticly.

    If you are able to do that, it would be great!
     
    Last edited: May 20, 2010
  9. JeGr

    JeGr Member

    As we are in progress of evaluating to switch from ISPConfig 2 to V3 it sure will be a thing I will look into, as we are happy users of your last RoundCube Package for v2 for a long time, Hans. Thanks for that again. So if I can help you this time, it would be a great "payback" ;)

    So as I see things, it would be necessary for Roundcube to be able to select the server according to the username given automagically. I don't have a DB dump of a v3 database at hand, but I think there has to be a connection between the mail user account and it's corresponding mailserver somewhere (has to, as ISPConfig has to know which server to make changes to mailpasswords or sth).

    So I suppose the trick would be for roundcube to not only connect to the server, but make an additional SQL query and select the corresponding mailserver and then connect with it. My guess is, one would add a patch or an addon for roundcube for that. I have to look into the roundcube plugins, if that is doable via plugins or if it requires some codebase hack. Would the second be a problem? If I would do it via hacking the code I would supply some .patch file or sth alike.

    Greets

    Edit:
    I had a quick look on the Roundcube site and found: http://www.needful.de/en/opensource/roundcube.html
    That is a plugin for the authentication process to rewrite user names (email-address) to Confixx users names. So as RC allows plugins to hook into the authentication process, I think that shouldn't be a big problem to write one, that makes a SQL call to the ISPConfig DB and selects the correct server.
     
    Last edited: May 20, 2010
  10. till

    till Super Moderator Staff Member ISPConfig Developer

    The ispconfig mail_user table has a field server_id which holds the ID of the server this address belongs to. Yoou can lookup the server hostname then with tis ID in the server table.
     
  11. nachbar

    nachbar New Member

    Perhaps no databse connection is necessary. What is if roundcube is doing a dig ns-request to locate the server and so take the correct server? This is just an idea.

    If you think the database is the better solution just do it. Sorry about but i can't help a lot because iam not a programmer. :(
     
  12. till

    till Super Moderator Staff Member ISPConfig Developer

    One possible problem that I see with using a dns query is that someone else might be able to use the webmail for emails that are not hosted on servers of your company. You might prevent that by e.g. providing a list of allowed mailserver IP's or mailserver hostnames, but then the complexity gets to to a similar level then doing a sql query.
     
  13. Hans

    Hans Moderator Moderator

    Thanks to you all,
    If Grey will succeed it will be wonderful !!

    @Grey:
    Thanks for your words and You'll have no regret when you're migrated to ISPConfig3!

    @Till:
    I think that information is very useful indeed.
     
  14. JeGr

    JeGr Member

    That's exactly what I was thinking when I wrote my answer. I wouldn't like to do a dig or NS-lookup via PHP, as that's something that can be abused "relative easily". Also a simple (even a nested) query should not decrease performance of the login that much, so I would rather rely on the ISPConfig DB than other data :)

    I'm currently looking into setting up a VM for testing a few ideas.
     
  15. austingecko

    austingecko New Member

    This thread caught my attention...while I don't yet run in a multiserver environment I liked the idea and concept to do so with a centralized Roundcube install location. A query based approach would seem doable as Hans indicated the server_id is in the "mail_user" table which could be queried with a join to the "server" table in the "dbispconfig" database to retrieve the "server_name" value.

    I poked around and found in the Roundcube directory:

    index.php

    Code:
     $auth = $RCMAIL->plugins->exec_hook('authenticate', array(
        'host' => $RCMAIL->[B]autoselect_host()[/B],
        'user' => trim(get_input_value('_user', RCUBE_INPUT_POST)),
        'cookiecheck' => true,
      )) + array('pass' => get_input_value('_pass', RCUBE_INPUT_POST, true, 'ISO-88$
    program/include/rcmail.php


    Code:
      [B]public function autoselect_host()[/B]
      {
        $default_host = $this->config->get('default_host');
        $host = null;
    
        if (is_array($default_host)) {
          $post_host = get_input_value('_host', RCUBE_INPUT_POST);
    
          // direct match in default_host array
          if ($default_host[$post_host] || in_array($post_host, array_values($defau$
            $host = $post_host;
          }
    
          // try to select host by mail domain
          list($user, $domain) = explode('@', get_input_value('_user', RCUBE_INPUT_$
          if (!empty($domain)) {
            foreach ($default_host as $imap_host => $mail_domains) {
              if (is_array($mail_domains) && in_array($domain, $mail_domains)) {
                $host = $imap_host;
                break;
              }
            }
          }
    
          // take the first entry if $host is still an array
          if (empty($host)) {
            $host = array_shift($default_host);
          }
        }
        else if (empty($default_host)) {
          $host = get_input_value('_host', RCUBE_INPUT_POST);
        }
        else
          $host = $default_host;
    
        return $host;
      }
    Seems like one should be able to modify the autoselect_host function to include a SQL query and return the right host/server needed.

    Hopefully someone with PHP/MySQL programming experience will come along and contribute and knock this out for you.
     
  16. JeGr

    JeGr Member

    Thank you for looking into. If the plugin approach fails this is surely a good starting point to look into. But I'll try to hook into the login first.
     
  17. JeGr

    JeGr Member

    After quite a good time messing around with RC code, I found a solution. One problem remains, though, that is a bit unpleasant:

    I got it working to "auto-select" the mailhost according to the username given (aka email-adress). That was possible doing with a simple plugin and api hooks. Nice. BUT:

    It seems RC gets a bit angry if you write "anything" into it's "default_host" configuration field. I tried setting it to 'none' or 'ispc-controlled' to symbolize, that no hostname will be given but instead the plugin will do the work. Problem is, that RC takes this value above all others (as it seems) and even ignores the values my plugin was setting while logging in. If you change it to '' (empty string) it works! But instead now it shows the server-input field, that I tried to avoid.

    So my solution isn't that shiny as I thought it would be. It merely consists of two parts:

    1) Small & simple plugin that does the dirty-work in background, selecting the server with a double SELECT sql statement like Till suggested.

    2) I simply hacked around in RCs intestines ;) By modifying "./program/include/rcube_template.php" at about line 1046-1048, I set the server fields to hidden so they won't show up in the login screen.

    1) is - I think - upgradeable without big problems to new RC versions.
    2) has to be done again if you install a new version of RC.


    If that is acceptable, would someone (probably Hans as it was his request originally and he has the required setup) be able to test that thing with me? I don't have a real multi-server-environment, so I have to guess it works as I'm now able to login without a server set anywhere (so it must be read out of the database).

    Greets
    Jens
     
  18. Hans

    Hans Moderator Moderator

    Thanks Grey,
    I think option 1 is probably the best as we need to avoid problems with new releases of RoundCube.

    I will test your files and let you know how i'm doing.
    Thanks for your work so far!
     
  19. JeGr

    JeGr Member

    Those were no options but parts of the same solution. The server field can not be stripped out without modifications on the source, I suppose. But I hope that will change.
     
  20. Hans

    Hans Moderator Moderator

    Simple solution

    I think i found a possible but simple solution.

    If you replace the line
    Code:
    $rcmail_config['default_host'] = 'ssl://localhost';
    in the RoundCube configuration file with:
    Code:
    $rcmail_config['default_host'] = str_replace("www.","",$_SERVER['SERVER_NAME']);
    Then in your browser, go to http://www.yourdomain.tld/webmail.
    As you can see the server field at the RoundCube login screen is hidden and yourdomain.tld will be used as the server name. The result is a succesful login from every ISPConfig server in my network. :)

    The problem is that it only works when you type http://www.yourdomain.tld/webmail in your browser. It does not work with names other the "www". Maybe i'm on the right track and someone can make it better then this.
     
    Last edited: May 21, 2010

Share This Page