ejabberd: Business Card Search

Published on November 08, 2008

ejabberd: Business Card Search

    In an ejabberd note with LDAP authorization, I described the key points for setting up an ejabberd server. In a note, external authentication programs showed how you can use an external program if the functionality of the built-in modules is not enough. Now let's add a search on users' business cards.


    Connecting Modules


    For starters, briefly about connecting modules. In the virtual host configuration (or in the global area), an entry is created that looks like this:
    {modules, [
        {module1, [module_option1]],
        {module2, [module_option2]]
    ]},
    

    In this record, you need to list the necessary modules with parameters.

    A list of modules and parameters can be found all in the same ejabberd Handbook .

    Now in my modules are configured like this:
    {modules, [
      {mod_last, []},
      {mod_offline, []}
    ]}
    

    Mod_disco module


    Support for the XEP-0030 extension : Service Discovery - Service Search. Without this module, customers will not be able to find out what services we offer:
    {modules, [
      {mod_last, []},
      {mod_offline, []},
      {mod_disco, []}
    ]}
    

    Mod_vcard_ldap module


    XEP-0054 Extension Support : vCards - Electronic Business Cards. The module allows receiving from LDAP information about the name, surname, e-mail and other (everything is configured) for each user. Its special charm is that it works even if authorization other than ldap is used. That is, I can authenticate users using my own program, and still extract useful information from LDAP.
    {modules, [
      {mod_last, []},
      {mod_offline, []},
      {mod_disco, []},
      {mod_vcard_ldap, [
      % Here I will write options
      ]}
    ]}
    

    If authentication through LDAP is used, then the following options can be omitted. Their values ​​mod_vcard_ldap will be taken from those indicated earlier. However, if you specify them explicitly, it will not be worse.
        {ldap_servers, ["ldap.company.local"]},
        {ldap_port, 389},
        {ldap_base, "ou = people, dc = company, dc = local"},
        {ldap_filter, "(gidNumber = 100)"},
    
    The description of these options was already in ejabberd with authorization via LDAP .

    Below is a simple example of further configuration. Only the most basic properties are used.
    % Match vCard fields with LDAP attributes
    {ldap_vcard_map, [
      {"NICKNAME", "% u", []},
      {"GIVEN", "% s", ["givenName"]},
      {"FAMILY", "% s", ["sn"]},
      {"FN", "% s% s", ["givenName", "sn"]},
      {"EMAIL", "% s", ["mail"]}
    ]},
    % We set the fields for searching by cards and their correspondence to the attributes of LDAP accounts
    {ldap_search_fields, [
      {"User", "% u"},
      {"Name", "givenName"},
      {"Family Name", "sn"},
      {"Email", "mail"}
    ]},
    % We set what vCard fields should be shown in the search results
    {ldap_search_reported, [
      {"Full Name", "FN"},
      {"Nickname", "NICKNAME"}
    ]}
    

    Restart ejabberd. And here you can check the result. Or use a client, for example Psi:

    Service discovery

    And search by cards:

    image