Using the prosody xmpp/chat server

Using the prosody xmpp/chat server

Prosody is a Lua-powered chat-server, which has been around for a few years now. Prosody is very straight-forward to install and configure, and the reliability means that it is a perfect way to provide chat-services to a small office, company, or group of friends. This brief article will cover installing it, both natively and within docker, along with a few pointers to things you can do with it.

Prosody is a XMPP-based chat-server, which allows multiple users to chat to each other, either directly (person-to-person) or via “conference rooms”.

Conference-rooms are similar to IRC-channels, they allow multiple people to join the same space and chat freely to all participants.

Because XMPP is an open standard there are many clients you can choose from, available for a large number of operating systems. Popular clients include Pidgin, PSI, and empathy.

If you’re new to XMPP-based chat there’s nothing too much to learn, except that all logins for chat-servers consist of both a username and a domain-name – so you’ll login to a chat server with what looks very much like an email address.

Installing Prosody

As always prosody can be installed easily using apt-get or aptitude:

root@chat ~ # apt-get install prosody

Once installed the configuration of the server consists of two parts:

  • The main configuration file, /etc/prosody/prosody.cfg.lua.
  • The configuration directory /etc/prosody/conf.d/

The main configuration file controls the servers global options, then includes files from beneath the conf.d/directory – which is where you’ll create configuration for each of your virtual hosts.

As mentioned earlier XMPP servers deal with user-accounts which have two parts: A username, and a domain-name.

To get started we just need to create a configuration file for our domain. Create the file /etc/prosody/conf.d/chat.example.com.cfg.lua with contents:

-- Virtual host for our chat-server

-- Define the host.
VirtualHost "chat.example.com"

-- Allow MUC / conference-rooms
Component "rooms.chat.example.com" "muc"
  name                   = "Chatrooms"
  restrict_room_creation = false

Once you’ve done that you can restart the service:

root@chat ~ # /etc/init.d/prosody restart

Your server should now be ready, and will allow two things:

  • Connection from users with logins “username@chat.example.com“.
  • The creation of arbitrary “rooms”.

If you were creating a chat-server for your own company, or domain, at this point you’d configure the DNS record chat.example.com to point to the IP address of your server.

It isn’t strictly necessary to setup DNS, as most chat-clients allow you to specify both a username (of the form “user@host.com”) along with the actual server-name to connect to (which you would set to the IP of your server).

Firewalling Note

If you’re only concerned with users chatting to each other, via the server, you only need to open port 5222 on your firewall.

Creating Accounts

There are two main ways you can configure account setup on the chat-server:

  • Permissively:
    • You allow anybody who can access the server to register their own account.
  • Strictly:
    • You explicitly create accounts for all the users you desire.

These two options are configured via the main server configuration file /etc/prosody/prosody.cfg.lua via the setting:

-- Disable account creation by default, for security
-- For more information see http://prosody.im/doc/creating_accounts
allow_registration = false;

With this setting, as noted, the default, you must create your user accounts manually – which you can do by running:

root@chat ~ # prosodyctl register LOGIN DOMAIN PASSWORD

For example you might create the account steve@chat.example.com with password “reallys3cr3t” like so:

root@chat ~ # prosodyctl register steve chat.example.com reallys3cr3t

If you prefer to allow users to register themselves then you set the value of allow_registration to be true, and restart the server. If your server is not firewalled away from the world expect you’ll find spam accountss have registered themselves eventually.

NOTE: Most clients allow new accounts to be registered easily, for example on the account setup page of Pidgin there is a checkbox “Create account on server”.

Source: Using the prosody xmpp/chat server