home

Screenshot of JappixMini in phpBB3

How to add a jabber-based multi user chat to phpBB3

We will setup the Jabber server ejabberd in a way that it uses the phpBB3 user database for authentication. Then we can setup the PHP/Javascript application Jappix so that we can use or own Jappix Mini chat from within our phpBB3 forum.

I assume that you have already installed a web server with phpBB3 running.

  1. Install the Jabber Server
  2. Create the authentication script
  3. Configure ejabberd
  4. Add the chat room
  5. Install Jappix
  6. Add Jappix Mini to phpBB3
  7. Optional: Add an anonymous chat room for guests
    1. Adapt ejabberd.cfg
    2. Add the chat room
    3. Adapt the phpBB3 template
  8. Thanks...
  9. License

Install the Jabber Server

On Ubuntu, simply do a apt-get install ejabberd. This will install ejabberd with all the necessary modules. On other distributions, you may have to follow the instructions on http://www.ejabberd.im/ejabberd_http_bind to enable the BOSH server. You can also find other alternatives here.

Create the authentication script

ejabberd uses an internal database for authentication by default. We want ejabberd to use the phpBB database, so we use the "external authentication" method.

Based on "Authenticate Against MySQL with PHP" from http://www.ejabberd.im/extauth, I wrote the script phpbb3_extauth.php, which will be called by ejabberd and communicates via standard input/output. Download this script to your server, and adapt the path to the PHP interpreter (first line), the path to phpBB, and the database configuration. Make sure that the ejabberd user has the permission to read and execute the script, but no one else, as it contains the database password.

Configure ejabberd

First, make sure to read the "Basic Configuration" section of the ejabberd guide.

Assuming that your domain is example.org, add these lines to your /etc/ejabberd/ejabberd.cfg:

%% list of virtual hosts 
{hosts, ["example.org"]}.

%% define ACL for phpBB users
{acl, phpbb, {server, "example.org"}}.

%% specify an adminstration user (must be created in phpBB later!)
{acl, phpbb_admin, {user, "ADMIN_USERNAME", "example.org"}}.

%% host-specific options
{host_config, "example.org", [
    {extauth_program, "/path/to/phpbb3_extauth.php"}, % adapt path!
    {auth_method, external},
    {access, phpbb_muc, [{allow, phpbb}]}, % multi user chat only for phpbb users
    {access, phpbb_muc_admin, [{allow, phpbb_admin}]}, % multi user chat administration only for phpbb admin
    {{add, modules}, [
        {mod_http_bind, []}, % provides a BOSH server
        {mod_muc, [ % multi user chat
                  {host, "muc.@HOST@"},
                  {access, phpbb_muc}, % TODO: not working yet!
                  {access_create, phpbb_muc_admin},
                  {access_persistent, phpbb_muc_admin},
                  {access_admin, phpbb_muc_admin},
                  {max_users, 500}
        ]}
    ]}
]}.

Add the chat room

Now, restart ejabberd: /etc/init.d/ejabberd restart

You should be able to login as ADMIN_USERNAME@example.org with a Jabber client. Choose a client which is capable of administering chat rooms (e.g. pidgin) and add a chat room with the persistent flag set.

Install Jappix

Now, install Jappix, which is easy - it does not even need a database. The installation will ask you for a BOSH host, which should be http://example.org:5280/http-bind/. For the group chat host, use muc.example.com.

Add Jappix Mini to phpBB3

As Jappix resumes sessions even if the settings have changed, a rather ugly workaround is needed to get the desired behaviour when a user logs out and then logs in with another username.

So you need to put the following lines to PHPBB_PATH/styles/YOUR_TEMPLATE/template/overall_header.html just before </head>:

<!-- IF not S_IS_BOT and S_USER_LOGGED_IN -->
<script type="text/javascript" src="http://JAPPIX_URL/php/get.php?l=en&amp;t=js&amp;g=mini.xml&amp;f=jquery.js"></script>

<script type="text/javascript">
jQuery(document).ready(function() {
  current_sessid = "{SESSION_ID}";
  saved_sessid = getDB("jappix-mini", "phpbb_sessid");
  if (saved_sessid != current_sessid) removeDB('jappix-mini', 'dom');
  setDB("jappix-mini", "phpbb_sessid", current_sessid);
});
</script>

<script type="text/javascript">
   jQuery(document).ready(function() {
      MINI_GROUPCHATS = ["ROOM_NAME"];
      MINI_NICKNAME = "{S_USERNAME}";
      launchMini(true, false, "example.org", "{S_USERNAME}", "{SESSION_ID}");
   });
</script>
<!-- ENDIF -->

Adapt JAPPIX_URL, ROOM_NAME and of course example.org. You can also change the l=en if you want another language. The variables in curly braces will be substituted by phpBB.

Don't forget to refresh phpBB's caches after making changes to the template!

More information about configuring Jappix Mini is available here.

Optional: Add an anonymous chat room for guests

Adapt ejabberd.cfg

%% list of virtual hosts 
{hosts, ["example.org", "anonymous.example.org"]}.

%% specify an administration user for anonymous
%% (must be created with `ejabberdctl register ADMIN_USERNAME anonymous.example.org PASSWORD`)
{acl, anonymous_admin, {user, "admin", "anonymous.example.org"}}.

%% host for anonymous users
{host_config, "anonymous.example.org", [
    {auth_method, [internal, anonymous]},
    {access, register, [{deny, all}]},
    {access, anon_muc, [{allow, all}]}, % multi user chat for all users
    {access, anon_muc_admin, [{allow, anonymous_admin}]}, % multi user chat administration only for anonymous admin
    {modules, [
        {mod_muc, [ % multi user chat
                  {host, "muc.@HOST@"},
                  {access, anon_muc},
                  {access_create, anon_muc_admin},
                  {access_persistent, anon_muc_admin},
                  {access_admin, anon_muc_admin},
                  {max_users, 500}
        ]}
    ]}
]}.

Add the chat room

Restart ejabberd again, and add a persistent chat room with your administration user.

Adapt the phpBB3 template

Instead of the code we placed before </head> above, use this:

<!-- IF not S_IS_BOT -->
<script type="text/javascript" src="http://JAPPIX_URL/php/get.php?l=en&t=js&g=mini.xml&f=jquery.js"></script>

<script type="text/javascript">
jQuery(document).ready(function() {
<!-- IF S_USER_LOGGED_IN --> 
  current_sessid = "{SESSION_ID}";
<!-- ENDIF -->
<!-- IF not S_USER_LOGGED_IN -->
  current_sessid = "";
<!-- ENDIF -->
  saved_sessid = getDB("jappix-mini", "phpbb_sessid");
  if (saved_sessid != current_sessid) removeDB('jappix-mini', 'dom');
  setDB("jappix-mini", "phpbb_sessid", current_sessid);
});
</script>
<!-- ENDIF -->

<!-- IF not S_IS_BOT and S_USER_LOGGED_IN -->
<script type="text/javascript">
   jQuery(document).ready(function() {
      MINI_GROUPCHATS = ["ROOM_NAME"];
      MINI_NICKNAME = "{S_USERNAME}";
      launchMini(true, false, "example.org", "{S_USERNAME}", "{SESSION_ID}");
   });
</script>
<!-- ENDIF -->

<!-- IF not S_IS_BOT and not S_USER_LOGGED_IN -->
<script type="text/javascript">
   jQuery(document).ready(function() {
      MINI_GROUPCHATS = ["ANONYMOUS_ROOM_NAME@muc.anonymous.example.org"];
      launchMini(false, true, "anonymous.example.org");
   });
</script>
<!-- ENDIF -->

Thanks...

... to Valérian Saliou and his team for Jappix! These guys are doing really great work!

License

Creative Commons License
How to add a jabber-based multi user chat to phpBB3 by Leberwurscht is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.