building a messaging server part five

Jabber

What would be cooler than to have all the users hosted on the server also automatically have Jabber accounts and be able to send each other instant messages? That's the topic of this part.

Setting up Jabber is the most complicated part of this series. I had to hack a bit of the code in order to get this to work, but I've also created patches.

Installing Jabber

Jabber 1.4 will be used. It's an older version and has less features than the newer Jabber 2, but it's stable and more simple.

To install, simply do:

apt-get install jabber

Support for XML will also need to be installed for some perl code later on.

apt-get install libxml-simple-perl libxml-parser-perl libxml-perl

Finally, the Jabber::Connection perl module will also need installed. Unfortunately, the CPAN version (0.3) is incompatible, so we need the 0.4. When I checked, the homepage hosting this version was down, but I was able to find a mirror. You'll need make install in order to compile it:

apt-get install make

To install it, simply untar it and do:

perl Makefile.PL
make
make install

This takes care of all the requirements for Jabber.

A Note About Jabber Servers

Jabber works by routing messages based on domain name. For example, when someone sends a message to joe@server1.local, the message will arrive at the server "server1.local".

This works fine if the Jabber installation resides on the same server where the A record for server1.local is. However, if this is not the case -- if Jabber is installed on a separate server -- then you must configure Jabber differently. So the Jabber ID will be joe@jabber.server1.local instead of joe@server1.local. Continue to follow along with the instructions, but append jabber. to all the hostnames. Please make sure your A records are configured accordingly.

Configuring Jabber

The Jabber configuration file, jabber.xml is located in the /etc/jabber/ directory. The first step is to open it up and replace all occurances of localhost with the server name (in this case, I've created a new A record called jabber.server1.local that I'll be using).

Next, find the line that defines the jabber hosts. This should be around like 54. You need to define a <host> entry for each server you are hosting. The comments say that this all needs to be on one line, but I've found that it doesn't.

<host>server1.local</host>
<host>server2.local</host>

Then change the admin information on line 182.

SSL should definitely be enabled. This is done around line 419.

<ssl port='5223'>192.168.1.10</ssl>

Also define the certificate to use around line 644

<key ip='192.168.1.10'>/etc/ssl/certs/mail.certkey.pem</key>

Configuring Jabber Authentication

Jabber needs some way of looking up the passwords for the virtual accounts that are stored in the separate password file (/etc/postfix/virtual/passwd). There's a Jabber plugin that will allow Jabber to authenticate off of different network services -- including IMAP. I think this is the easiest solution and it'll be the one used here.

The plugin is called xdb_auth_cpile. There is a great README file included on the webpage and also in the plugin package. I hate copying instructions, so please jump over to that document and follow along.

When you're finished setting it up, copy the xdb_auth_cpile.pm.imap file to xdb_auth_cpile.pm. Also, edit the file to include the IMAP server (localhost) on line 37.

Jabber user accounts are in an email-like format:username@jabberserver.local. My test email account is joe@server1.local and my Jabber ID are the same thing. But if Jabber resides on a different server, it could be something like joe@jabber.server1.local.

When logging in to Jabber, the xdb_auth_cpile plugin will only pass the joe parameter to the IMAP server. To fix this, I've modified the code and wrote two different patches: one patch for if the Jabber server is on the same server as the server1.local A record and another patch for if the installation is on a different server (like jabber.server1.local).

Apply the patch to the xdb_auth_cpile.pl file.

Both patches also make the xdb_auth_cpile.pl file expect all the files it requires (including itself) to be in the /etc/jabber directory. Please place all files concerning this plugin there.

The patch for the single server installation simply sends the full Jabber ID (such as joe@server1.local) to the IMAP server. The multi-server patch expects a Jabber ID of joe@jabber.server1.local. It will strip the jabber part out so the ID matches the email address.

In order for this plugin to work, the xdb_auth_cpile.pl program needs to be running constantly. To simplify things, I've edited the Jabber init script to include this program. Here's the patch for that (Debian only).

Running Jabber

After all of this is set up, start Jabber. If it's successfully running, go ahead and set up an Instant Messaging client to work with it. I've found that iChat just flat out does not work with this. However, both Adium and Gaim do.

Make sure you specify your Jabber ID correctly.

If you're using Gaim with a single-server setup, you'll need to specify your username as just the first portion (joe), the server as the domain portion (server1.local) and in extra options, use jabber.server1.local as the connecting server.

Talking to Other Jabber Users

If all of your A records are configured correctly, you'll be able to talk to any other Jabber and GTalk user.

Once you have everything set up, you can test it out by sending me a message at joe@terrarum.net!