aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--Changes5
-rw-r--r--MANIFEST8
-rw-r--r--Makefile.PL19
-rw-r--r--README26
-rw-r--r--lib/DJabberd/Plugin/VCard/LDAP.pm159
-rw-r--r--t/00-load.t9
-rw-r--r--t/boilerplate.t48
-rw-r--r--t/pod.t6
9 files changed, 284 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..10b5458
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
1META.yml
2Makefile
3/blib
4/pm_to_blib
diff --git a/Changes b/Changes
new file mode 100644
index 0000000..c7abf7a
--- /dev/null
+++ b/Changes
@@ -0,0 +1,5 @@
1Revision history for DJabberd-VCard-LDAP
2
30.01 2007-08-23
4 First version, released on an unsuspecting world.
5
diff --git a/MANIFEST b/MANIFEST
new file mode 100644
index 0000000..a00de9e
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,8 @@
1Changes
2MANIFEST
3Makefile.PL
4README
5lib/DJabberd/Plugin/VCard/LDAP.pm
6t/00-load.t
7t/boilerplate.t
8t/pod.t
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644
index 0000000..38343ae
--- /dev/null
+++ b/Makefile.PL
@@ -0,0 +1,19 @@
1use strict;
2use warnings;
3use ExtUtils::MakeMaker;
4
5WriteMakefile(
6 NAME => 'DJabberd::Plugin::VCard::LDAP',
7 AUTHOR => 'Edward Rudd <urkle@outoforder.cc>',
8 VERSION_FROM => 'lib/DJabberd/Plugin/VCard/LDAP.pm',
9 ABSTRACT_FROM => 'lib/DJabberd/Plugin/VCard/LDAP.pm',
10 PL_FILES => {},
11 PREREQ_PM => {
12 'Test::More' => 0,
13 'DJabberd' => '0.83',
14 'DJabberd::Plugin::VCard' => 0,
15 'Net::LDAP' => 0,
16 },
17 DISTNAME => 'DJabberd-VCard-LDAP',
18 dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
19);
diff --git a/README b/README
new file mode 100644
index 0000000..0c7aa40
--- /dev/null
+++ b/README
@@ -0,0 +1,26 @@
1DJabberd-VCard-LDAP
2
3Provides an LDAP VCard backend.
4
5INSTALLATION
6
7To install this module, run the following commands:
8
9 perl Makefile.PL
10 make
11 make test
12 make install
13
14
15SUPPORT AND DOCUMENTATION
16
17After installing, you can find documentation for this module with the perldoc command.
18
19 perldoc DJabberd::Plugin::VCard::LDAP
20
21COPYRIGHT AND LICENCE
22
23Copyright (C) 2007 Edward Rudd
24
25This program is free software; you can redistribute it and/or modify it
26under the same terms as Perl itself.
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
diff --git a/t/00-load.t b/t/00-load.t
new file mode 100644
index 0000000..e9cbf2c
--- /dev/null
+++ b/t/00-load.t
@@ -0,0 +1,9 @@
1#!perl -T
2
3use Test::More tests => 1;
4
5BEGIN {
6 use_ok( 'DJabberd::Plugin::VCard::LDAP' );
7}
8
9diag( "Testing DJabberd::Plugin::VCard::LDAP $DJabberd::Plugin::VCard::LDAP::VERSION, Perl $], $^X" );
diff --git a/t/boilerplate.t b/t/boilerplate.t
new file mode 100644
index 0000000..4db7dda
--- /dev/null
+++ b/t/boilerplate.t
@@ -0,0 +1,48 @@
1#!perl -T
2
3use strict;
4use warnings;
5use Test::More tests => 3;
6
7sub not_in_file_ok {
8 my ($filename, %regex) = @_;
9 open my $fh, "<", $filename
10 or die "couldn't open $filename for reading: $!";
11
12 my %violated;
13
14 while (my $line = <$fh>) {
15 while (my ($desc, $regex) = each %regex) {
16 if ($line =~ $regex) {
17 push @{$violated{$desc}||=[]}, $.;
18 }
19 }
20 }
21
22 if (%violated) {
23 fail("$filename contains boilerplate text");
24 diag "$_ appears on lines @{$violated{$_}}" for keys %violated;
25 } else {
26 pass("$filename contains no boilerplate text");
27 }
28}
29
30not_in_file_ok(README =>
31 "The README is used..." => qr/The README is used/,
32 "'version information here'" => qr/to provide version information/,
33);
34
35not_in_file_ok(Changes =>
36 "placeholder date/time" => qr(Date/time)
37);
38
39sub module_boilerplate_ok {
40 my ($module) = @_;
41 not_in_file_ok($module =>
42 'the great new $MODULENAME' => qr/ - The great new /,
43 'boilerplate description' => qr/Quick summary of what the module/,
44 'stub function definition' => qr/function[12]/,
45 );
46}
47
48module_boilerplate_ok('lib/DJabberd/Plugin/VCard/LDAP.pm');
diff --git a/t/pod.t b/t/pod.t
new file mode 100644
index 0000000..976d7cd
--- /dev/null
+++ b/t/pod.t
@@ -0,0 +1,6 @@
1#!perl -T
2
3use Test::More;
4eval "use Test::Pod 1.14";
5plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
6all_pod_files_ok();