diff options
-rw-r--r-- | Changes | 3 | ||||
-rw-r--r-- | lib/DJabberd/Plugin/VCard/LDAP.pm | 48 |
2 files changed, 42 insertions, 9 deletions
@@ -1,5 +1,8 @@ | |||
1 | Revision history for DJabberd-VCard-LDAP | 1 | Revision history for DJabberd-VCard-LDAP |
2 | 2 | ||
3 | 0.02 2007-08-23 | ||
4 | More complete vCard. Support substituting domain as well as userid in filter | ||
5 | |||
3 | 0.01 2007-08-23 | 6 | 0.01 2007-08-23 |
4 | First version, released on an unsuspecting world. | 7 | First version, released on an unsuspecting world. |
5 | 8 | ||
diff --git a/lib/DJabberd/Plugin/VCard/LDAP.pm b/lib/DJabberd/Plugin/VCard/LDAP.pm index 4606ea4..63a2a6a 100644 --- a/lib/DJabberd/Plugin/VCard/LDAP.pm +++ b/lib/DJabberd/Plugin/VCard/LDAP.pm | |||
@@ -15,11 +15,11 @@ DJabberd::VCard::LDAP - LDAP VCard Provider for DJabberd | |||
15 | 15 | ||
16 | =head1 VERSION | 16 | =head1 VERSION |
17 | 17 | ||
18 | Version 0.01 | 18 | Version 0.02 |
19 | 19 | ||
20 | =cut | 20 | =cut |
21 | 21 | ||
22 | our $VERSION = '0.01'; | 22 | our $VERSION = '0.02'; |
23 | 23 | ||
24 | =head1 SYNOPSIS | 24 | =head1 SYNOPSIS |
25 | 25 | ||
@@ -38,7 +38,9 @@ Provides an LDAP VCard backend for DJabberd | |||
38 | LDAPURI , LDAPBaseDN, and LDAPFilter are required | 38 | LDAPURI , LDAPBaseDN, and LDAPFilter are required |
39 | Everything else is optional. | 39 | Everything else is optional. |
40 | 40 | ||
41 | LDAPFilter is an LDAP filter with a %u that will be substituted with the incoming userid (w/o the domain) | 41 | LDAPFilter is an LDAP filter substutions |
42 | - %u will be substituted with the incoming userid (w/o the domain) (ie. myuser) | ||
43 | - %d will be substituted with the incoming userid's domain (ie. mydoman.com) | ||
42 | 44 | ||
43 | =cut | 45 | =cut |
44 | 46 | ||
@@ -98,34 +100,62 @@ sub _isdef { | |||
98 | sub load_vcard { | 100 | sub load_vcard { |
99 | my ($self, $user) = @_; | 101 | my ($self, $user) = @_; |
100 | 102 | ||
101 | my $suser = $user; | 103 | $user =~ /^(.+)\@(.+)$/; |
102 | $suser =~ s/^(.*)\@.*$/$1/; | 104 | my ($userid,$domain) = ($1, $2); |
103 | 105 | ||
104 | my $filter = $self->{'ldap_filter'}; | 106 | my $filter = $self->{'ldap_filter'}; |
105 | $filter =~ s/%u/$suser/; | 107 | $filter =~ s/%u/$userid/; |
108 | $filter =~ s/%d/$domain/; | ||
106 | $logger->info("Searching $filter on ".$self->{'ldap_basedn'}); | 109 | $logger->info("Searching $filter on ".$self->{'ldap_basedn'}); |
107 | my $srch = $self->{'ldap_conn'}->search( | 110 | my $srch = $self->{'ldap_conn'}->search( |
108 | base=>$self->{'ldap_basedn'}, | 111 | base=>$self->{'ldap_basedn'}, |
109 | filter=>$filter, | 112 | filter=>$filter, |
110 | attrs=>['dn','sn','cn','givenName','mail','telephoneNumber','title','description','displayName']); | 113 | attrs=>['dn','sn','cn','givenName','mail','telephoneNumber','title','description','displayName', |
114 | 'mobile','company','department','wWWHomePage','homePhone','facsimileTelephoneNumber','pager', | ||
115 | 'streetAddress','co','postalCode','postOfficeBox','st','l','jpegPhoto']); | ||
111 | if ($srch->code || $srch->count < 1) { | 116 | if ($srch->code || $srch->count < 1) { |
112 | $logger->info("Account $user not found."); | 117 | $logger->info("Account $user not found."); |
113 | return; | 118 | return; |
114 | } else { | 119 | } else { |
115 | my $entry = $srch->entry(0); | 120 | my $entry = $srch->entry(0); |
121 | my $photo = $entry->get_value('jpegPhoto'); | ||
122 | if (defined $photo) { | ||
123 | $photo = '<PHOTO><BINVAL>'.$photo.'</BINVAL></PHOTO>'; | ||
124 | } else { | ||
125 | $photo = ''; | ||
126 | } | ||
116 | my $vCard = '<vCard xmlns="vcard-temp" version="3.0">' | 127 | my $vCard = '<vCard xmlns="vcard-temp" version="3.0">' |
117 | .'<FN>'._isdef($entry->get_value('cn')).'</FN>' | 128 | .'<FN>'._isdef($entry->get_value('cn')).'</FN>' |
118 | .'<N>' | 129 | .'<N>' |
119 | .'<FAMILY>'._isdef($entry->get_value('sn')).'</FAMILY>' | 130 | .'<FAMILY>'._isdef($entry->get_value('sn')).'</FAMILY>' |
120 | .'<GIVEN>'._isdef($entry->get_value('givenName')).'</GIVEN>' | 131 | .'<GIVEN>'._isdef($entry->get_value('givenName')).'</GIVEN>' |
121 | .'</N>' | 132 | .'</N>' |
122 | .'<TITLE>'._isdef($entry->get_value('title')).'</TITLE>' | ||
123 | .'<NICKNAME>'._isdef($entry->get_value('displayName')).'</NICKNAME>' | 133 | .'<NICKNAME>'._isdef($entry->get_value('displayName')).'</NICKNAME>' |
124 | .'<TEL><HOME/><VOICE/><NUMBER>'._isdef($entry->get_value('telephoneNumber')).'</NUMBER></TEL>' | 134 | .'<ORG>' |
135 | .'<ORGNAME>'._isdef($entry->get_value('company')).'</ORGNAME>' | ||
136 | .'<ORGUNIT>'._isdef($entry->get_value('department')).'</ORGUNIT>' | ||
137 | .'</ORG>' | ||
138 | .'<TITLE>'._isdef($entry->get_value('title')).'</TITLE>' | ||
139 | .'<TEL><HOME/><VOICE/><NUMBER>'._isdef($entry->get_value('homePhone')).'</NUMBER></TEL>' | ||
140 | .'<TEL><WORK/><VOICE/><NUMBER>'._isdef($entry->get_value('telephoneNumber')).'</NUMBER></TEL>' | ||
141 | .'<TEL><WORK/><FAX/><NUMBER>'._isdef($entry->get_value('facsimileTelephoneNumber')).'</NUMBER></TEL>' | ||
142 | .'<TEL><WORK/><MSG/><NUMBER>'._isdef($entry->get_value('pager')).'</NUMBER></TEL>' | ||
143 | .'<TEL><HOME/><CELL/><NUMBER>'._isdef($entry->get_value('mobile')).'</NUMBER></TEL>' | ||
125 | .'<EMAIL><INTERNET/><PREF/><USERID>'._isdef($entry->get_value('mail')).'</USERID></EMAIL>' | 144 | .'<EMAIL><INTERNET/><PREF/><USERID>'._isdef($entry->get_value('mail')).'</USERID></EMAIL>' |
145 | .'<ADR>' | ||
146 | .'<HOME/>' | ||
147 | .'<EXTADDR/>' | ||
148 | .'<STREET>'._isdef($entry->get_value('streetAddress')).'</STREET>' | ||
149 | .'<LOCALITY>'._isdef($entry->get_value('l')).'</LOCALITY>' | ||
150 | .'<REGION>'._isdef($entry->get_value('st')).'</REGION>' | ||
151 | .'<PCODE>'._isdef($entry->get_value('postalCode')).'</PCODE>' | ||
152 | .'<CTRY>'._isdef($entry->get_value('co')).'</CTRY>' | ||
153 | .'</ADR>' | ||
126 | .'<JABBERID>'.$user.'</JABBERID>' | 154 | .'<JABBERID>'.$user.'</JABBERID>' |
155 | .$photo | ||
127 | .'<DESC>'._isdef($entry->get_value('description')).'</DESC>' | 156 | .'<DESC>'._isdef($entry->get_value('description')).'</DESC>' |
128 | .'</vCard>'; | 157 | .'</vCard>'; |
158 | $logger->info($vCard); | ||
129 | undef($entry); | 159 | undef($entry); |
130 | undef($srch); | 160 | undef($srch); |
131 | return $vCard; | 161 | return $vCard; |