4 our $jabberd = "jabber.domain.com";
5 our $groupname = "Iris";
7 my $vcardtpl = "../ldap/vcard.xml";
9 my $basedn = "dc=nodomain";
10 my $ldapserver = "localhost";
11 my $disname="cn=admin,dc=nodomain";
12 my $ldappass= "secret";
13 my $ldapperson = "irisPerson";
14 my $ldapchatroom = "";
17 my $ldapjidattr = "irisUserPresenceID";
18 my $ldapjidmatch = qr/urn:mace:rediris.es:presence:xmpp:([\w\-_\.]+@.+)/;
20 ##########################
24 Vcard2Ldap - Stuff for convert LDAP entries to Jabberd roster ones.
29 my $ldap = Vcard2Ldap::ldap_open ();
30 my $users = Vcard2Ldap::jabber_get_users ($ldap);
31 my $vcard2ldap = Vcard2Ldap::vcard_get_map ();
34 print $_->{"jid"} . "\n";
35 print $_->{"rostergroup"} . "\n";
38 my $us = $ldap->search(
39 base => "dc=nodomain",
44 foreach ($us->entries) {
45 print Vcard2Ldap::jabber_jid ($_) . "\n";
50 print $vcard2ldap->{"FN"} . "\n";
55 This module isn't intend for general usage, it was made for the sole purpose of
56 working together with vcard2ldap jabberd module.
58 See http://repo.or.cz/w/vcard2ldap.git for details.
64 List of global variables.
68 The jabberd server hostname
72 The name of the roster group where jids will be stored.
76 List of public functions.
80 Open connection. Returns a LDAP handler.
82 =item C<jabber_get_users>
84 Returns a list of records: {jid,group}
88 Returns a jid from an LDAP entry. Empty string if none.
92 Returns the group of the LDAP entry. Empty string if none.
94 =item C<vcard_get_map>
96 Returns the "vCard map". This hash maps XML vCard tags to LDAP attributes.
103 use Net
::LDAP
::Control
;
108 my $ldap = Net
::LDAP
->new ($ldapserver, debug
=> 0) or die "$@";
109 my $mesg = $ldap->bind (
111 password
=> $ldappass,
112 version
=> 3) or die "Cannot bind to ldap server ($!)";
114 die $mesg->error if $mesg->code;
122 my $us = $ldap->search(
125 filter
=> "(&(objectClass=$ldapperson)($ldapgroup=*))"
127 die $us->error if $us->code;
131 add_chatrooms
($ldap) if (length ($ldapchatrooms) > 0);
137 sub jabber_get_users
{
140 ldap_get_users
($ldap) if ($#users == -1);
148 foreach (Vcard2Ldap
::jabber_get_users
()) {
149 return $_ if ($_->{"jid"} eq $ujid);
152 warn $ujid . ": user not in directory or malformed entry!";
158 my $attr = $user->get_value ($ldapjidattr, asref
=> 1);
162 return lc ($_) if (length ($ldapjidmatch) == 0);
163 return lc ($1) if ($_ =~ $ldapjidmatch);
167 warn $user->get_value ("cn") . ": user with no jid!";
173 my $group = $user->get_value ($ldapgroup, asref
=> 1);
175 return lc (@
{$group}[0]) if ($#{$group} == 0);
177 warn $user->get_value ("cn") . ": group is unique and mandatory!";
182 my $xs = new XML
::Simple
(keeproot
=> 0, suppressempty
=> 1);
183 my $vcard = $xs->XMLin($vcardtpl);
186 while (my ($key, $value) = each (%$vcard)) {
187 for (split(/\n/, parse_vcard
($key, $value))) {
188 my @sp = split(/ /, $_);
189 $vcard2ldap->{$sp[0]} = $sp[1];
201 foreach ($us->entries) {
202 my $jid = jabber_jid
($_);
203 my $rgroup = jabber_group
($_);
207 "rostergroup" => $rgroup
208 } if ($jid && $rgroup);
215 my $us = $ldap->search(
218 filter
=> "(&(objectClass=$ldapchatroom)($ldapgroup=*))"
221 die $us->error if $us->code;
231 if (!ref ($value) && !($key eq "xmlns")) {
232 $ret .= $key . " " . $value . "\n";
233 } elsif (ref ($value) eq "HASH" ) {
237 } elsif ($_ eq "content") {
238 $ret .= "$key". parse_vcard
("", $value->{$_});
240 $ret .= "$key/". parse_vcard
($_, $value->{$_});
243 } elsif (ref ($value) eq "ARRAY") {
245 $ret .= "$key" . parse_vcard
("", $_);