Ejabberd Jabber Service and JWChat

One of the things I have wanted to do, however, lacked the need for it, was setup a Jabber instant messaging server. That is, until about three months ago, when I was presented with a problem to which I needed a solution for. I needed a Jabber server that would allow clients to connect to it from behind a corporate firewall. The Jabber port for a non-SSL enabled connection is 5222; the Jabber port for a SSL-enabled connection is 5223. The easiest solution, which was not an option, would have been to open the blocked ports on the firewall and allow the users to access a public server.
A buddy of mine referred me to JWChat, a Jabber web client which uses only JavaScript and HTML on the client-side. JWChat needs support for HTTP polling on the backend server. HTTP polling is a protocol that, "enables access to a Jabber server from behind firewalls which do not allow outgoing sockets on port 5222, via HTTP requests." The CVS version of JWChat was tested in combination with ejabberd-0.7.5, an HTTP polling capable server. Reviewing the current Jabber server implementations, ejabberd supports approximately 77% of the expected server features of the Jabber/XMPP protocol and the license is GPL. Another nice feature.
The ejabberd web site has two good tutorials on installing ejabberd and another one on installing JWChat and configuring the server. Once the server is up and running, ejabberd has an embedded webserver to provide a web administration tool. A sample screenshot is shown above.
The ejabberd server is currently running on Apache 1.3.31 and I found the biggest difficulty was getting the web server setup correctly. Through no fault of the documentation, I feel it was simply a lack of understanding on my part to what was going on. The web server needs to be setup so that it redirects requests from the HTTPBASE of config.js of the JWChat configuration to the HTTP polling capable Jabber server component, which in this case, is ejabberd. In my config.js configuration, HTTPBASE was simply set to, "http-poll/". In the Apache configuration file you need to make sure you have the mod_proxy and mod_negotiation modules enabled. Depending on how you built your Apache server, if you see the following lines in your Apache configuration you probably have it already,
# # Dynamic Shared Object (DSO) Support # . . . LoadModule negotiation_module libexec/mod_negotiation.so LoadModule proxy_module libexec/libproxy.so
For the mod_proxy section of the Apache configuration I had the following,
<IfModule mod_proxy.c>
ProxyRequests Off
ProxyPass /jabber/http-poll/ http://private.mycompany.com:5280/http-poll/
<Directory proxy:*>
Order deny,allow
Deny from all
Allow from all
</Directory>
</IfModule>
and in the VirtualHost section I had,
<VirtualHost xxx.xxx.xxx.x:80>
Servername private.mycompany.com
DocumentRoot /usr/local/apache/www/private
AddDefaultCharset UTF-8
RewriteEngine On
RewriteRule ^/http-poll/ http://private.mycompany.com:5280/http-poll/ [P]
<Directory /usr/local/apache/www/private/jabber>
Options +MultiViews
</Directory>
</VirtualHost>
After some searching I found the following startup script which I placed in the /etc/rc.d/init.d directory of the linux server to control the starting and stopping of ejabberd.
#!/bin/sh
#########################################################
#
# ejabberd -- script to start ejabberd.
# Written by Sander Devrieze (s.devrieze at pandora.be)
#
#########################################################
ERL=/usr/local/bin/erl
NAME=ejabberd
#########################################################
case "$1" in
start)
echo "Starting $NAME."
cd /var/lib/ejabberd/ebin/
$ERL -pa /var/lib/ejabberd/ebin \
-name ejabberd \
-s ejabberd \
-ejabberd config \"/etc/ejabberd/ejabberd.cfg\" \
log_path \"/var/log/ejabberd/ejabberd.log\" \
-sasl sasl_error_logger \{file,\"/var/log/ejabberd/sasl.log\"\} \
-mnesia dir \"/var/lib/ejabberd/spool\" \
-heart \
-detached
;;
stop)
echo "Stopping $NAME."
echo "rpc:call('ejabberd@`hostname -f`', init, stop, [])." | $ERL -name ejabberdstop
# should be -s in place of -f with -sname in place of -name for other way of starting
;;
status)
echo "Not implemented yet."
;;
restart|reload)
$0 stop
sleep 3
$0 start
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 1
esac
I have used both the JWChat web client for instant messaging as well as my Gaim client and both work really well with the server.
