5 our $jabberd = "jabber.domain.com";
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 $ldapgroupmatch = "";
18 my $ldapjid = "irisUserPresenceID";
19 my $ldapjidmatch = qr/urn:mace:rediris.es:presence:xmpp:([\w\-_\.]+@.+)/;
21 ##########################
25 Vcard2Ldap - Stuff for convert LDAP entries to Jabberd roster ones.
30 my $ldap = Vcard2Ldap::ldap_open ();
31 my $users = Vcard2Ldap::jabber_get_users ($ldap);
32 my $vcard2ldap = Vcard2Ldap::vcard_get_map ();
35 print $_->{"jid"} . "\n";
36 print $_->{"rostergroup"} . "\n";
39 my $us = $ldap->search (
40 base => "dc=nodomain",
45 foreach ($us->entries) {
46 print Vcard2Ldap::jabber_jid ($_) . "\n";
51 print $vcard2ldap->{"FN"} . "\n";
56 This module isn't intend for general usage, it was made for the sole purpose of
57 working together with vcard2ldap jabberd module.
59 See http://repo.or.cz/w/vcard2ldap.git for details.
65 List of global variables.
69 The jabberd server hostname
73 The name of the roster group where jids will be stored.
77 List of public functions.
81 Open connection. Returns a LDAP handler.
83 =item C<jabber_get_users>
85 Returns a list of records: {jid,group}
89 Returns a jid from an LDAP entry. Empty string if none.
93 Returns the list of groups of the LDAP entry. Empty array if none.
95 =item C<vcard_get_map>
97 Returns the "vCard map". This hash maps XML vCard tags to LDAP attributes.
104 use Net
::LDAP
::Control
;
109 my $ldap = Net
::LDAP
->new ($ldapserver, debug
=> 0) or die "$@";
110 my $mesg = $ldap->bind (
112 password
=> $ldappass,
113 version
=> 3) or die "Cannot bind to ldap server ($!)";
115 die $mesg->error if $mesg->code;
123 my $us = $ldap->search (
126 filter
=> "(&(objectClass=$ldapperson)($ldapgroup=*))"
128 die $us->error if $us->code;
132 add_chatrooms
($ldap) if (length ($ldapchatroom) > 0);
138 sub jabber_get_users
{
141 ldap_get_users
($ldap) if ($#users == -1);
149 foreach (Vcard2Ldap
::jabber_get_users
()) {
150 return $_ if ($_->{"jid"} eq $ujid);
153 warn $ujid . ": user not in directory or malformed entry!";
159 my $attr = $user->get_value ($ldapjid, asref
=> 1);
164 if (length ($ldapjidmatch) == 0) {
166 } elsif ($_ =~ $ldapjidmatch) {
171 if (index ($jid, "@") == -1) {
172 $jid .= "\@$jabberd";
179 warn $user->get_value ("cn") . ": user with no jid!" if (!$jid);
185 my $attr = $user->get_value ($ldapgroup, asref
=> 1);
192 if (length ($ldapgroupmatch) == 0) {
194 } elsif ($_ =~ $ldapgroupmatch) {
198 (push @group, $tmp) if ($tmp);
203 warn $user->get_value ("cn") . ": group is mandatory!";
210 my $xs = new XML
::Simple
(keeproot
=> 0, suppressempty
=> 1);
211 my $vcard = $xs->XMLin ($vcardtpl);
214 while (my ($key, $value) = each (%$vcard)) {
215 for (split (/\n/, parse_vcard
($key, $value))) {
216 my @sp = split (/ /, $_);
217 $vcard2ldap->{$sp[0]} = $sp[1];
229 foreach ($us->entries) {
230 my $jid = jabber_jid
($_);
231 my @rgroup = jabber_group
($_);
247 my $us = $ldap->search (
250 filter
=> "(&(objectClass=$ldapchatroom)($ldapgroup=*))"
253 die $us->error if $us->code;
263 if (!ref ($value) && !($key eq "xmlns")) {
264 $ret .= $key . " " . $value . "\n";
265 } elsif (ref ($value) eq "HASH" ) {
269 } elsif ($_ eq "content") {
270 $ret .= "$key". parse_vcard
("", $value->{$_});
272 $ret .= "$key/". parse_vcard
($_, $value->{$_});
275 } elsif (ref ($value) eq "ARRAY") {
277 $ret .= "$key" . parse_vcard
("", $_);