Finally, a Near Ideal IRC and Instant Messaging Setup

Instant messaging (IM) and Internet Relay Chat (IRC) are an essential part of how I communicate with friends, family, co-workers, and the Free Software Community. Finally, I got things working in a near ideal way by combining Bip, Bitlbee, SSH, Screen, irssi, and X-Chat Gnome.

Feature Requirements

In no particular order:

  • Always connected so I don't miss important messages and can follow long-running conversation threads
  • Ability to detach without logging off so I can concentrate on other things
  • Non-intrusive notifications when I receive messages
  • Logging of all conversations
  • Ability to connect from a variety of places and environments (my Treo 650, my Linux machines at work and home, my fiancee's Win XP machine)
  • Ability to be connected simultaneously with multiple clients without using different nicks
  • Be secure and ensure my privacy as much as is possible with these public networks

Sever setup

Since I use Debian on my server and Ubuntu or Debian on my desktops, all it took for installation was an apt-get. Follow the above links or visit your distribution's website for more information. I assume that openssh is already installed.

% sudo apt-get install screen bitlbee bip irssi

bitlbee

Debconf asked me what port I wanted bitlbee to listen on. I chose 16667.

In order to meet my criteria of being secure, I didn't want bitlbee to listen on an outside port. It uses inetd by default, so I didn't know how to turn that off. I had to use tcpwrappers. I added the following line to /etc/hosts.deny:

bitlbee:ALL

And to /etc/hosts.allow:

bitlbee:127.0.0.1

bitlbee will now only accept connections from localhost.

Check out the one of the many getting started guides for help on getting started with using bitlbee.

bip

I edited the ~/.bip/bip.conf, with my particular setup. Check out my password santized version. I have configuration for the 3 IRC networks I connect to and a connection to my bitlbee server on the localhost. Also, in particular, I made sure bip more was secure by only listening on localhost:

ip = "127.0.0.1";

And now, to only allow connections via clients that support SSL:

client_side_ssl = true;

This is possibly redundant because I use an ssh tunnel to connect from remote machines.

You need to create a SSL certificate for this to work, so:

% cd ~/.bip; openssl req -new -x509 -days 365 -nodes -out bip.pem -keyout bip.pem

Now, you need to create a password for your bip user:

% bipmkpw

It will output a string like this (in this case, the password is simply 'bip'): 18ec9bd2afc62b10cc4abffcdba3693db9288575.

Put this in your ~/.bip/bip.conf file, in the password line for your user:

password = "18ec9bd2afc62b10cc4abffcdba3693db9288575";

Since I want logging, I also need to create a directory to log things in:

% mkdir ~/logs/chat

And indicate this in bip.conf:

log_root = "/home/nafai/logs/chat";

Finally, tell bip to "replay" backlogs when I reconnect:

backlog = true;                 # enable backlog
backlog_lines = 0;             # number of lines in backlog, 0 means no limit
always_backlog = true;         # backlog even lines already backlogged

irssi

I now run irssi under screen on the server. This way, I can connect from anywhere I can run an ssh client. irssi took some special set up. Each network you connect bip to requires a different connection. You specify which connection to use by the server password. For example, say I wanted to connect to my freenode connection, the password would be this: nafai:mypasswordsetinbip:freenode. irssi doesn't allow you to define multiple servers with the same address. The helpful people on #bip on freenode, gave me this useful hint. Set up a fake proxy within irssi like this:

settings = {
    core = {
        real_name = "Travis B. Hartwell";
        user_name = "nafai";
        nick = "Nafai";
        proxy_address = "localhost";
        proxy_port = "7778";
        proxy_string = "";
        use_proxy = "yes";
    };
};

Then, you define the server using a "fake" address, such as this:

servers = (
{
    address = "fn";
    chatnet = "fn";
    port = "7778";
    password = "nafai:password:freenode";
    use_ssl = "yes";
    ssl_verify = "no";
    autoconnect = "yes";
},

Take a look at my password sanitized irssi config.

Starting it up on the server

Now I need to start up everything under screen. Refer to the screen documentation for more information:

% screen

First, start up bip:

% bip

It will daemonize itself and connect to your various networks. Now, start irssi:

% irssi

It will proceed to connect to bip. You can now detach from the client with screen via C-a C-d if you use the default screen keybindings.

On subsequent log-ins, re attach to your screen session like this:

% screen -r

Linux Desktop Client Setup

I use xchat-gnome on my Ubuntu desktop machine. First, install it:

% sudo apt-get install xchat-gnome

ssh tunnel

Next, in order to connect to bip, you'll need to have an ssh tunnel to your remote server:

% ssh -NfL 7778:localhost:7778 myserver.com

If you don't have ssh key authentication set up, it will prompt for a password.

XChat-Gnome

Now you can connect via XChat. Start XChat and then configure a new network for each connection defined in bip.

Edit -> Preferences -> Networks -> Add

Name the network something appropriate. "BipFreenode" or something like that.

Check "Automatically connect to network, Use secure session, and Accept invalid SSL certificate.

Under the server password, input the password as appropriate (for example, nafai:password:freenode).

Switch to the Servers tab. Click Add. Input localhost/7778 as the server address and port.

Do this for each of your connections.

I had to make a couple modifications to the xchat config so the replay of the backlogs wouldn't mess xchat up. I couldn't find the settings in the Preferences dialog, so I edited the ~/.xchat/xchat.conf file, with these lines:

flood_ctcp_num = 5000
flood_ctcp_time = 300
flood_msg_num = 5000
flood_msg_time = 500

Those numbers might be too high, but at least it works.

Also, so I can be notified when someone messages me, I enabled the following plugins from Edit -> Preferences -> Scripts and Plugins:

  • Sound Notification
  • Notifcation
  • On-screen display

And there you have it, my set up in a very large nutshell.

I have a few more ideas of what I want to do:

  • Make my logs searchable by Beagle and, by extension, The Gnome Deskbar Applet
  • Create a plugin for Galago to provide presence information from XChat for bitlbee users
  • Set up irssi to make sure that channel and query windows for a given server connection are always sequential
  • Set up irssi and xchat to better integrate with bitlbee, for example, displaying the typing status, etc
  • Write NafAI to respond when I am away.
  • ....Profit

Hope this is helpful.