diff options
| author | 2010-02-15 12:34:37 -0500 | |
|---|---|---|
| committer | 2010-02-15 12:34:37 -0500 | |
| commit | d245a790ab7ffffedf825573cc64c7503db6b3ba (patch) | |
| tree | 8b1c8e1ee00a3af8f92d912d020f969377db0163 | |
import release 0.010.01
| -rw-r--r-- | .gitignore | 4 | ||||
| -rw-r--r-- | Changes | 5 | ||||
| -rw-r--r-- | MANIFEST | 8 | ||||
| -rw-r--r-- | Makefile.PL | 19 | ||||
| -rw-r--r-- | README | 26 | ||||
| -rw-r--r-- | lib/DJabberd/Plugin/VCard/LDAP.pm | 159 | ||||
| -rw-r--r-- | t/00-load.t | 9 | ||||
| -rw-r--r-- | t/boilerplate.t | 48 | ||||
| -rw-r--r-- | t/pod.t | 6 |
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 @@ | |||
| 1 | META.yml | ||
| 2 | Makefile | ||
| 3 | /blib | ||
| 4 | /pm_to_blib | ||
| @@ -0,0 +1,5 @@ | |||
| 1 | Revision history for DJabberd-VCard-LDAP | ||
| 2 | |||
| 3 | 0.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 @@ | |||
| 1 | Changes | ||
| 2 | MANIFEST | ||
| 3 | Makefile.PL | ||
| 4 | README | ||
| 5 | lib/DJabberd/Plugin/VCard/LDAP.pm | ||
| 6 | t/00-load.t | ||
| 7 | t/boilerplate.t | ||
| 8 | t/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 @@ | |||
| 1 | use strict; | ||
| 2 | use warnings; | ||
| 3 | use ExtUtils::MakeMaker; | ||
| 4 | |||
| 5 | WriteMakefile( | ||
| 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 | ); | ||
| @@ -0,0 +1,26 @@ | |||
| 1 | DJabberd-VCard-LDAP | ||
| 2 | |||
| 3 | Provides an LDAP VCard backend. | ||
| 4 | |||
| 5 | INSTALLATION | ||
| 6 | |||
| 7 | To install this module, run the following commands: | ||
| 8 | |||
| 9 | perl Makefile.PL | ||
| 10 | make | ||
| 11 | make test | ||
| 12 | make install | ||
| 13 | |||
| 14 | |||
| 15 | SUPPORT AND DOCUMENTATION | ||
| 16 | |||
| 17 | After installing, you can find documentation for this module with the perldoc command. | ||
| 18 | |||
| 19 | perldoc DJabberd::Plugin::VCard::LDAP | ||
| 20 | |||
| 21 | COPYRIGHT AND LICENCE | ||
| 22 | |||
| 23 | Copyright (C) 2007 Edward Rudd | ||
| 24 | |||
| 25 | This program is free software; you can redistribute it and/or modify it | ||
| 26 | under 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 @@ | |||
| 1 | package DJabberd::Plugin::VCard::LDAP; | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | |||
| 6 | use base 'DJabberd::Plugin::VCard'; | ||
| 7 | |||
| 8 | use Net::LDAP; | ||
| 9 | |||
| 10 | our $logger = DJabberd::Log->get_logger(); | ||
| 11 | |||
| 12 | =head1 NAME | ||
| 13 | |||
| 14 | DJabberd::VCard::LDAP - LDAP VCard Provider for DJabberd | ||
| 15 | |||
| 16 | =head1 VERSION | ||
| 17 | |||
| 18 | Version 0.01 | ||
| 19 | |||
| 20 | =cut | ||
| 21 | |||
| 22 | our $VERSION = '0.01'; | ||
| 23 | |||
| 24 | =head1 SYNOPSIS | ||
| 25 | |||
| 26 | Provides 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 | |||
| 38 | LDAPURI , LDAPBaseDN, and LDAPFilter are required | ||
| 39 | Everything else is optional. | ||
| 40 | |||
| 41 | LDAPFilter is an LDAP filter with a %u that will be substituted with the incoming userid (w/o the domain) | ||
| 42 | |||
| 43 | =cut | ||
| 44 | |||
| 45 | sub set_config_ldapuri { | ||
| 46 | my ($self, $ldapuri) = @_; | ||
| 47 | if ( $ldapuri =~ /((?:ldap[si]?\:\/\/)?[\w\.%\d]+\/?)/ ) { | ||
| 48 | $self->{'ldap_uri'} = $ldapuri; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | sub set_config_ldapbinddn { | ||
| 53 | my ($self, $ldapbinddn) = @_; | ||
| 54 | $self->{'ldap_binddn'} = $ldapbinddn; | ||
| 55 | } | ||
| 56 | |||
| 57 | sub set_config_ldapbindpw { | ||
| 58 | my ($self, $ldapbindpw) = @_; | ||
| 59 | $self->{'ldap_bindpw'} = $ldapbindpw; | ||
| 60 | } | ||
| 61 | |||
| 62 | sub set_config_ldapbasedn { | ||
| 63 | my ($self, $ldapbasedn) = @_; | ||
| 64 | $self->{'ldap_basedn'} = $ldapbasedn; | ||
| 65 | } | ||
| 66 | |||
| 67 | sub set_config_ldapfilter { | ||
| 68 | my ($self, $ldapfilter) = @_; | ||
| 69 | $self->{'ldap_filter'} = $ldapfilter; | ||
| 70 | } | ||
| 71 | |||
| 72 | sub 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 | |||
| 92 | sub _isdef { | ||
| 93 | my $arg = shift; | ||
| 94 | return $arg if defined $arg; | ||
| 95 | return ''; | ||
| 96 | } | ||
| 97 | |||
| 98 | sub 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 | |||
| 136 | sub store_vcard { 0 } | ||
| 137 | |||
| 138 | =head1 AUTHOR | ||
| 139 | |||
| 140 | Edward Rudd, C<< <urkle at outoforder.cc> >> | ||
| 141 | |||
| 142 | =head1 SUPPORT | ||
| 143 | |||
| 144 | You 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 | |||
| 152 | Copyright 2007 Edward Rudd, all rights reserved. | ||
| 153 | |||
| 154 | This program is free software; you can redistribute it and/or modify it | ||
| 155 | under the same terms as Perl itself. | ||
| 156 | |||
| 157 | =cut | ||
| 158 | |||
| 159 | 1; # 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 | |||
| 3 | use Test::More tests => 1; | ||
| 4 | |||
| 5 | BEGIN { | ||
| 6 | use_ok( 'DJabberd::Plugin::VCard::LDAP' ); | ||
| 7 | } | ||
| 8 | |||
| 9 | diag( "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 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use Test::More tests => 3; | ||
| 6 | |||
| 7 | sub 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 | |||
| 30 | not_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 | |||
| 35 | not_in_file_ok(Changes => | ||
| 36 | "placeholder date/time" => qr(Date/time) | ||
| 37 | ); | ||
| 38 | |||
| 39 | sub 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 | |||
| 48 | module_boilerplate_ok('lib/DJabberd/Plugin/VCard/LDAP.pm'); | ||
| @@ -0,0 +1,6 @@ | |||
| 1 | #!perl -T | ||
| 2 | |||
| 3 | use Test::More; | ||
| 4 | eval "use Test::Pod 1.14"; | ||
| 5 | plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; | ||
| 6 | all_pod_files_ok(); | ||
