Integrating RoundCube (0.2 stable)

I’m not pro at this type of thing and I’ve only had InterWorx for a week or so now, but I love RoundCube so much that I was compelled to figure out how to integrate it into the webmail-chooser and make it accessible server-wide.

I was nearly successful at integrating it right within the /home/interworx/lib area (where horde and squirrelmail are located) but unfortunately the iworx copy of php is too old for the latest stable version of roundcube (which requires php 5.2 or higher).

However, as I did say I was successful, I managed to get it working from within one of my SiteWorx accounts (but that is completely transparent to the user). I am not sure if it’s possible to update iworx php, and I didn’t want to try, so I updated the server-copy of php to allow the latest RoundCube to work.

Anyway here’s to get RoundCube working server wide and integrate it within the webmail chooser. Legend: mysite.com = a domain in one of your SiteWorx accounts where roundcube is installed. anydomain.com = any other domains on the server, within other SiteWorx accounts. I take no responsibility if anything bad comes from this guide! Also, future interworx updates may undo these changes - so keep that in mind.

  • Within a SiteWorx account install a copy of RoundCube (0.2stable in my case). I installed it into a folder called [B]/rc[/B] (public_html/rc). However, it will actually be [B]anydomain.com/roundcube[/B] that is used to access it (see next step). The directory you install it to doesn't need to match the desired URL for your visitors to use - but they can match if you want them to. I chose to have them different.
  • As root, edit [B]/etc/httpd/conf.d/iworx.conf[/B] so that any request to go to [B]anydomain.com/roundcube[/B] will actually refer to the files stored in [B]mysite.com/rc[/B]. The following 2 lines need to be added to iworx.conf (P.S 'dynamics' is my SiteWorx account in which I have roundcube installed):
ProxyPass /roundcube http://127.0.0.1/~dynamics/rc
ProxyPassReverse /roundcube http://127.0.0.1/~dynamics/rc
  • Restart Apache and test to see if [B]anydomain.com/roundcube[/B] works. Any of your domains should allow you to see your RoundCube installation.
Now, the tricky part is getting it integrated into the WebMail chooser (anydomain.com/webmail). Here's how to do that:
  • RoundCube needs a helper/middle-man in order to allow a login from another php page. I found a php class to do just this, here: http://blog.philippheckel.com/2008/05/16/roundcube-login-via-php-script
  • You will need to save a copy of RoundcubeLogin.class.php inside your roundcube installation folder. You can use the rclogin.php file to test the class if you want. Just edit it so that it has an email address and password inside, and the directory variable also needs to match [B]the proxypass [/B]that was made above ([B]/roundcube/[/B] in my case) and not the real install directory (unless they are the same). Open rclogin.php in your browser to test the login class. You can delete it when done testing.
  • Now you need to make a file which will be used to pass the login information from the webmail chooser to RoundCube (as the middle-man). Luckily for us we can just copy and paste the sample code from philippheckel's blog and change the username and password values into some POST variables. I chose to save this file as [B]redirect.php [/B](keeping with the naming conventions used for horde and squirrelmail's login scripts). Just as with the rclogin.php test file, you need to use the directory from your proxypass, and not the actual roundcube directory. Here is the sample code, modified to use my /roundcube/ directory and with some POST variables (rcUser and rcPass):
<?php
    include "RoundcubeLogin.class.php";    

    // Create login object and enable debugging
    $rcl = new RoundcubeLogin("/roundcube/", true);

    try {
        // If we are already logged in, simply redirect
        if ($rcl->isLoggedIn())
            $rcl->redirect();

        // If not, try to login and simply redirect on success
        $rcl->login($_POST['rcUser'], $_POST['rcPass']);

        if ($rcl->isLoggedIn())
            $rcl->redirect();

        // If the login fails, display an error message
        die("ERROR: Login failed due to a wrong user/pass combination. Please go back and try again.");
    }
    catch (RoundcubeLoginException $ex) {
        echo "ERROR: Technical problem, ".$ex->getMessage();
        $rcl->dumpDebugStack(); exit;
    }

?>

Save that in your roundcube directory and you are ready to add RoundCube to the webmail chooser to finish things up.

  • Edit [B]/home/interworx/lib/horde/index.html[/B] (NOT index.[B]php[/B]). Yes, it's a bit odd that the chooser is within horde's directory.. The next few steps aren't going to make much sense if you don't know how the webmail chooser works. I'll explain that at the end of the post. For now.. just go with it.
  • Add this section to the gomail function (notice the 2 references to our POST variables):
     if( document.webmailchooser.webmail[selIndex].value == 'roundcube' ) {
        createCookie( 'webmail-choice', 'roundcube', 150 );
        with( document.rc_login ) {
          rcUser.value = email;
          rcPass.value = passv;
          submit();
        }
      }

The gomail function should look like this all together:

   function gomail() {
      selIndex = document.webmailchooser.webmail.selectedIndex;
      email = document.webmailchooser.email.value;
      passv = document.webmailchooser.pass.value;

      if( document.webmailchooser.webmail[selIndex].value == 'roundcube' ) {
        createCookie( 'webmail-choice', 'roundcube', 150 );
        with( document.rc_login ) {
          rcUser.value = email;
          rcPass.value = passv;
          submit();
        }
      }

      if( document.webmailchooser.webmail[selIndex].value == 'horde' ) {
        createCookie( 'webmail-choice', 'horde', 150 );
          with( document.imp_login ) {
          imapuser.value = email;
          pass.value = passv;
          submit();
        }
      }

      if( document.webmailchooser.webmail[selIndex].value == 'squirrelmail' ) {
        createCookie( 'webmail-choice', 'squirrelmail', 361 );
        with( document.sq_login ) {
          login_username.value = email;
          secretkey.value = passv;
          submit();
        }
      }

      return( false );
    }
  • Now add the RoundCube option to the drop list:
                      <option value="roundcube">RoundCube WebMail

This is what the drop list code looks like, if RoundCube is the first in it:

                    <select name="webmail">
                      <option value="roundcube">RoundCube WebMail
                      <option value="horde">Horde/IMP
                      <option value="squirrelmail">SquirrelMail

Change this code (which checks a cookie to pre-select the last-used webmail option)…

  <script language="javascript">
    cookieval = readCookie( 'webmail-choice' );
    if( cookieval == 'horde' ) {
      document.webmailchooser.webmail.options[0].selected = 1;
      document.webmailchooser.webmail.options[1].selected = 0;
    }
    if( cookieval == 'squirrelmail' ) {
      document.webmailchooser.webmail.options[1].selected = 1;
      document.webmailchooser.webmail.options[0].selected = 0;
    }
    document.webmailchooser.email.focus();
  </script>

Into this code:

  <script language="javascript">
    cookieval = readCookie( 'webmail-choice' );
    if( cookieval == 'roundcube' ) {
      document.webmailchooser.webmail.options[0].selected = 1;
      document.webmailchooser.webmail.options[1].selected = 0;
      document.webmailchooser.webmail.options[2].selected = 0;
    }
    if( cookieval == 'horde' ) {
      document.webmailchooser.webmail.options[0].selected = 0;
      document.webmailchooser.webmail.options[1].selected = 1;
      document.webmailchooser.webmail.options[2].selected = 0;
    }
    if( cookieval == 'squirrelmail' ) {
      document.webmailchooser.webmail.options[0].selected = 0;
      document.webmailchooser.webmail.options[1].selected = 0;
      document.webmailchooser.webmail.options[2].selected = 1;
    }
    document.webmailchooser.email.focus();
  </script>

Now after that last code and before the form (imp_login), add a new form (change the action= directory to match your proxypass, also notice our POST vars again):

<form name="rc_login" action="/roundcube/redirect.php" method="post">
<input type="hidden" name="rcUser" value="" />
<input type="hidden" name="rcPass" />
<!--
<input type="submit" value="Login" />
-->
</form>

That’s it! Save the file and test if you can login to RoundCube from anydomain.com/webmail

How the chooser works: There’s a hidden form for each webmail app (one for horde and one for squirrelmail, plus the one we add for RoundCube) within the chooser page. When you enter your login and password, some javascript code copies that login info into the corresponding hidden form for the chosen webmail app. This preference is also saved into a cookie so that next time you visit the chooser, the webmail app you used las is pre-chosen from the drop list. The hidden form is used to submit your login to the webmail app via the middle-man (the login class and redirect.php).

Hope this helps someone!

Oh I should also mention, this does NOT work from the control panel itself (which points to https://anydomain.com:2443/roundcube). I can’t seem to figure that one out. I will post an update if I get this working.

Wow, very detailed write up! I haven’t looked at roundcube at all, but I’m sure there are a good amount of people that will find this very useful…and hey, maybe this will help get it installed by default :slight_smile:

Thanks.

I sure hope it becomes a default. Even Cpanel comes with it now.

It’s so much simpler and faster than other webmail apps. Drag and drop alone is to die for. Auto saving drafts every few minutes has saved me from losing long emails many times (especially on dial-up at the in-laws). The preview pane is great and it blocks images from unknown senders by default - this helps avoid more spam from sites that listen to see if images in their mail is accessed. Even when you type in an address, it checks your addressbook and gives autofill options. Love it.

People have made plugs to allow it to play with SpamAssassin settings, change password, vacation messages etc. I hope that in the next release of InterWorx those could all be put together :0

I love InterWorx so much… never have I had such a great experience with running a server, or seeking help from tech support. It’s amazing how you see their presence all across the froms.

I used to use Plesk but it always had issues and I was consistently limited in anything I did. It broke all the time. Then they updated to 9.0.0 and so many things went bad that I had to jump ship. They would not even post a single post on their forum to acknowledge the problems. People are freaking out over there, and they won’t do anything about it. It’s a pathetic program and since I’m not a huge Cpanel person, I spent days looking at alternatives. I was a little hesitant when I came across InterWorx.com (it’s a very basic looking site… needs some color and style… I didn’t get a great first impression) - but once I got into the demo and played for a bit I was in love.

Anyway… here’s hoping to see RoundCube in the next release.

I used to use Plesk but it always had issues and I was consistently limited in anything I did. It broke all the time. Then they updated to 9.0.0 and so many things went bad that I had to jump ship. They would not even post a single post on their forum to acknowledge the problems. People are freaking out over there, and they won’t do anything about it. It’s a pathetic program…

They also started acquiring other products like h-sphere, helm, etc probably in the hope to make them die in the near future (stopping development and support gradually) and moving those customers to plesk.

One day interworx will be part of plesk family? :slight_smile:

Let’s hope not, I’m kind of getting found of the small web hosting business :wink:

Seriously…I’d rather not work for Plesk :wink:

So is Plesk the forerunners of the Borg?