aboutsummaryrefslogtreecommitdiffstats
path: root/lib/DJabberd/Plugin/VCard
diff options
context:
space:
mode:
authorGravatar Edward Rudd 2010-02-15 12:34:37 -0500
committerGravatar Edward Rudd 2010-02-15 12:34:37 -0500
commitd245a790ab7ffffedf825573cc64c7503db6b3ba (patch)
tree8b1c8e1ee00a3af8f92d912d020f969377db0163 /lib/DJabberd/Plugin/VCard
import release 0.010.01
Diffstat (limited to 'lib/DJabberd/Plugin/VCard')
-rw-r--r--lib/DJabberd/Plugin/VCard/LDAP.pm159
1 files changed, 159 insertions, 0 deletions
diff --git a/lib/DJabberd/Plugin/VCard/LDAP.pm b/lib/DJabberd/Plugin/VCard/LDAP.pm
new file mode 100644
index 0000000..4606ea4
--- /dev/null
+++ b/lib/DJabberd/Plugin/VCard/LDAP.pm
@@ -0,0 +1,159 @@
1package DJabberd::Plugin::VCard::LDAP;
2
3use warnings;
4use strict;
5
6use base 'DJabberd::Plugin::VCard';
7
8use Net::LDAP;
9
10our $logger = DJabberd::Log->get_logger();
11
12=head1 NAME
13
14DJabberd::VCard::LDAP - LDAP VCard Provider for DJabberd
15
16=head1 VERSION
17
18Version 0.01
19
20=cut
21
22our $VERSION = '0.01';
23
24=head1 SYNOPSIS
25
26Provides an LDAP VCard backend for DJabberd
27
28 <Vhost mydomain.com>
29 <Plugin DJabberd::Plugin::VCard::LDAP>
30 LDAPURI ldap://localhost/
31 LDAPBindDN cn=reader
32 LDAPBindPW pass
33 LDAPBaseDN ou=people
34 LDAPFilter (uid=%u)
35 </Plugin>
36 </VHost>
37
38LDAPURI , LDAPBaseDN, and LDAPFilter are required
39Everything else is optional.
40
41LDAPFilter is an LDAP filter with a %u that will be substituted with the incoming userid (w/o the domain)
42
43=cut
44
45sub set_config_ldapuri {
46 my ($self, $ldapuri) = @_;
47 if ( $ldapuri =~ /((?:ldap[si]?\:\/\/)?[\w\.%\d]+\/?)/ ) {
48 $self->{'ldap_uri'} = $ldapuri;
49 }
50}
51
52sub set_config_ldapbinddn {
53 my ($self, $ldapbinddn) = @_;
54 $self->{'ldap_binddn'} = $ldapbinddn;
55}
56
57sub set_config_ldapbindpw {
58 my ($self, $ldapbindpw) = @_;
59 $self->{'ldap_bindpw'} = $ldapbindpw;
60}
61
62sub set_config_ldapbasedn {
63 my ($self, $ldapbasedn) = @_;
64 $self->{'ldap_basedn'} = $ldapbasedn;
65}
66
67sub set_config_ldapfilter {
68 my ($self, $ldapfilter) = @_;
69 $self->{'ldap_filter'} = $ldapfilter;
70}
71
72sub finalize {
73 my $self = shift;
74 $logger->error_die("Invalid LDAP URI") unless $self->{ldap_uri};
75 $logger->error_die("No LDAP BaseDN Specified") unless $self->{ldap_basedn};
76 $logger->error_die("Must specify filter with userid as %u") unless $self->{ldap_filter};
77
78 # Initialize ldap connection
79 $self->{'ldap_conn'} = Net::LDAP->new($self->{ldap_uri})
80 or $logger->error_die("Could not connect to LDAP Server ".$self->{ldap_uri});
81
82 if (defined $self->{'ldap_binddn'}) {
83 if (not $self->{'ldap_conn'}->bind($self->{'ldap_binddn'},
84 password=>$self->{'ldap_bindpw'})) {
85 $logger->error_die("Could not bind to ldap server");
86 }
87 }
88
89 $self->SUPER::finalize;
90}
91
92sub _isdef {
93 my $arg = shift;
94 return $arg if defined $arg;
95 return '';
96}
97
98sub load_vcard {
99 my ($self, $user) = @_;
100
101 my $suser = $user;
102 $suser =~ s/^(.*)\@.*$/$1/;
103
104 my $filter = $self->{'ldap_filter'};
105 $filter =~ s/%u/$suser/;
106 $logger->info("Searching $filter on ".$self->{'ldap_basedn'});
107 my $srch = $self->{'ldap_conn'}->search(
108 base=>$self->{'ldap_basedn'},
109 filter=>$filter,
110 attrs=>['dn','sn','cn','givenName','mail','telephoneNumber','title','description','displayName']);
111 if ($srch->code || $srch->count < 1) {
112 $logger->info("Account $user not found.");
113 return;
114 } else {
115 my $entry = $srch->entry(0);
116 my $vCard = '<vCard xmlns="vcard-temp" version="3.0">'
117 .'<FN>'._isdef($entry->get_value('cn')).'</FN>'
118 .'<N>'
119 .'<FAMILY>'._isdef($entry->get_value('sn')).'</FAMILY>'
120 .'<GIVEN>'._isdef($entry->get_value('givenName')).'</GIVEN>'
121 .'</N>'
122 .'<TITLE>'._isdef($entry->get_value('title')).'</TITLE>'
123 .'<NICKNAME>'._isdef($entry->get_value('displayName')).'</NICKNAME>'
124 .'<TEL><HOME/><VOICE/><NUMBER>'._isdef($entry->get_value('telephoneNumber')).'</NUMBER></TEL>'
125 .'<EMAIL><INTERNET/><PREF/><USERID>'._isdef($entry->get_value('mail')).'</USERID></EMAIL>'
126 .'<JABBERID>'.$user.'</JABBERID>'
127 .'<DESC>'._isdef($entry->get_value('description')).'</DESC>'
128 .'</vCard>';
129 undef($entry);
130 undef($srch);
131 return $vCard;
132 }
133}
134
135
136sub store_vcard { 0 }
137
138=head1 AUTHOR
139
140Edward Rudd, C<< <urkle at outoforder.cc> >>
141
142=head1 SUPPORT
143
144You can find documentation for this module with the perldoc command.
145
146 perldoc DJabberd::Plugin::VCard::LDAP
147
148=head1 ACKNOWLEDGEMENTS
149
150=head1 COPYRIGHT & LICENSE
151
152Copyright 2007 Edward Rudd, all rights reserved.
153
154This program is free software; you can redistribute it and/or modify it
155under the same terms as Perl itself.
156
157=cut
158
1591; # End of DJabberd::Plugin::VCard::LDAP