Install ejabberd, and jwchat



I used to have Openfire as chat server serving my few friends on my virtual server, but as on one side I wasn't able to connect using a lot of clients and on the other side it was using a lot of RAM (~86MB) I decided to replace it with ejabberd which users only ~13MB and seems to be accepted by more clients.

As I wanted to access the chat as well from my mobile I installed as well jwchat.

I first tried to link my Apache server to the ejabberd server, but unluckily even after many attempts it just didn't work.
Therefore I decided to use ejabberd's built-in http-server and just proxy all inbound requests through Apache to ejabberd's http-server. Ejabberd's default port 5280 is closed by my firewall.

ejabberd:

Install "ejabberd". Under Gentoo I am using the USE-flags "ssl mod_irc mod_muc pam web zlib".

Now that you have ejabberd installed have a look at "/etc/jabber/ejabberd.cfg". In there set the hosts variable to be "localhost". It should look like this:

{hosts, ["localhost"]}.

After a few lines you'll see somethig which starts with a...

{5222, ejabberd_c2s, [

...where you will have to set the port to which the "serious" chat clients like pidgin (so, the "standalone" ones - not the web-client) will connect to. Don't forget to open that port on your firewall if you didn't already do it.

Now, if you require it, request an SSL certificate, better a wildcard one, e.g. from cacert.org. Once you have your signed certificate, put everything into a ".pem" file with...

cat signed_cacert_server_cert_wildcard_<mydomain>.cert private_4cacert.key > /etc/jabber/ejabberd_cacert.pem

...and uncomment & set the line...

{certfile, "/etc/jabber/ssl.pem"}, starttls,

...to...

{certfile, "/etc/jabber/ejabberd_cacert.pem"}, starttls,

One more thing: I wanted to have full control of who was using the chat, therefore I changed...

{access, register, [{allow, all}]}.

...to....

{access, register, [{deny, all}]}.

...so that users cannot register on their own - (I hope I changed the right setting)

Ok, now try to start it up (Gentoo: "/etc/init.d/ejabberd start") and register the first user:

ejabberdctl register <youruser> localhost <userspassword>

After configuring the server like this you will have to specify in the client (e.g. Pidgin) as domain "localhost". Other clients might want it in the format "<username>@localhost".

jwchat:

Have again a look at "/etc/jabber/ejabberd.cfg".
Just a few lines after where you set the "localhost" variable you'll see a section which starts with "{listen" and in there, at the end of that section where you see something like

{5280, ejabberd_http, [
                         http_poll,
                         web_admin
                        ]}

you'll have to replace it with this:

{5280, ejabberd_http, [
                         {request_handlers, [
                                             {["web"], mod_http_fileserver}
                         ]},
                         http_bind,
                         http_poll,
                         web_admin
                        ]}
 ]}.

Check that you don't have the final "]}." twice.

Create under "/var/lib/ejabberd/" a brand new directory called "www":

mkdir /var/lib/ejabberd/www


Download "jwchat" and put it into the www-directory you just created. In my case all files are under "/var/lib/ejabberd/www/jwchat/".
Now do as described here: rename all "*.en"-files with...

for a in $(ls *.en); do b=${a%.en}; cp $a $b; done

...and delete the other languages:

rm *.html.* *.js.*

You should now have a "config.js"-file containing "localhost" for the SITENAME and at least the following entries:

var BACKENDS =
       [
                {
                        name:"Native Binding",
                        description:"Ejabberd's native HTTP Binding backend",
                        httpbase:"/http-bind/",
                        type:"binding",
                        servers_allowed:[SITENAME]
                },
                {
                        name:"Native Polling",
                        description:"Ejabberd's native HTTP Polling backend",
                        httpbase:"/http-poll/",
                        type:"polling",
                        servers_allowed:[SITENAME]
                },
       ];

So, now ejabberd & jwchat should be ok and you should be able to access the chat from the host on which you installed it - give it a try before continuing:

  • open somehow a browser on the host where ejabberd & jwchat are running (you have it right there, or through a ssh-tunnel) and type in the URL which should be "http://localhost:5280/web/jwchat/index.html". Don't forget the "index.html" otherwise it won't work.
  • Choose "native binding" and enter the userid & pwd that you previously registered with e.g. "ejabberdctl register mytestuser localhost mypassword".
  • To know that it worked after logging in you 1) should not get any error messages from jwchat and 2) executing the command "ejabberdctl connected-users" should show the user you just logged in.

Ok, now all that is missing is the apache configuration, so that you'll be able to connect to the chat with e.g. "https://my.server.com/index.html".

Make sure first of all that you have the "mod_proxy_html" module for Apache installed and enabled. This module is NOT INCLUDED IN THE APACHE PACKAGE!!! (took me a week to realize this :o|).
Therefore in Gentoo do "emerge mod_proxy_html" to install it and add "-D PROXY_HTML" to "/etc/conf.d/apache2" to enable it.
All in all my "/etc/conf.d/apache2" looks like this:

"APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D LANGUAGE -D PROXY -D PROXY_HTML -D SSL -D SSL_DEFAULT_VHOST -D PHP5""


Now have a look at your Apache vhost config file and add...

ProxyRequests Off
        RewriteEngine On
        ProxyPass / http://localhost:5280/web/jwchat/
        ProxyPassReverse / http://localhost:5280/web/jwchat/
        RewriteRule ^/http-poll/ http://localhost:5280/http-poll/ [P]
        RewriteRule ^/http-bind/ http://localhost:5280/http-bind/ [P]

...and that's it. Restart Apache and you should be able to connect to your webchat with "https://my.server.com/index.html" :o).

Ok, now you can delete the "poll"-part from jwchat's config file as you'll only be using http-bind.