105
my ($directory,$list) = @_;
107
&Log::do_log('debug2',' Ldap::export_list(%s,%s)', $directory,$list->{'name'});
109
my (@owner_emails,@editor_emails,@editor_names,@owner_names);
111
##To record owner's and editor's email and gecos
112
## !! STRUCTURE LDAP A REVOIR
113
my $owners = $list->get_owners();
114
foreach my $element (@{$owners}) {
115
next unless (defined $element->{'email'});
116
if (ref($element->{'email'})) {
117
push(@owner_emails, @{$element->{'email'}});
119
push(@owner_emails,$element->{'email'});
121
push(@owner_names,$element->{'gecos'});
124
foreach my $element (@{$list->{'admin'}{'editor'}}){
125
push(@editor_emails,$element->{'email'}) if(defined $element->{'email'}) ;
126
push(@editor_names,$element->{'gecos'}) if(defined $element->{'gecos'});
129
unless (eval "require Net::LDAP") {
130
&Log::do_log ('err',"Unable to use LDAP library, Net::LDAP required, install perl-ldap (CPAN) first");
136
my $ldap = Net::LDAP->new($Conf{'ldap_export'}{$directory}{'host'});
139
&Log::do_log('err',"Ldap::export_list:Unable to bind to the directory %s", $dir);
143
##Bind:To verify the password
144
my $cnx = $ldap->bind(dn => "$Conf{'ldap_export'}{$directory}{'DnManager'}" , password => "$Conf{'ldap_export'}{$directory}{'password'}");
146
unless(defined($cnx) && ($cnx->code == 0)){
147
&Log::do_log('notice', 'Ldap::export_list:Incorrect password for binding with dn: %s',$Conf{'ldap_export'}{$directory}{'DnManager'});
152
##If the entry already exists delete it
155
unless &delete_list($directory, $list, $ldap);
157
my $list_email = $list->get_list_address();
158
my $dn = "cn=$list_email,$Conf{'ldap_export'}{$directory}{'suffix'}";
160
my $total = $list->get_total() || 0;
161
my $result_add = $ldap->add(
164
'cn' => "$list_email",
165
'listName' => "$list->{'name'}",
166
'listEmailAddress' => "$list_email",
167
'listSubject' => "$list->{'admin'}{'subject'}" || 'unknown',
168
'listLang' => $list->{'admin'}{'lang'},
169
'listCreateDate' => $list->{'admin'}{'creation'}{'date'} || 'unknown',
170
'listCreateDateepoch' => $list->{'admin'}{'creation'}{'date_epoch'} || 0,
171
'listDescription' =>$list->get_info() || 'unknown',
172
'listSubscribersNumber' => "$total",
173
'robotEmail' => "$list->{'admin'}{'host'}",
174
'robotType' => 'sympa',
175
'listUrlHomePage' =>'http://'."$list->{'admin'}{'host'}".'/'.'wws',
176
'listUrlArc' => 'http://'."$list->{'admin'}{'host'}".'/wws/arc/'."$list->{'name'}",
177
'listUrlInfo' =>'http://'."$list->{'admin'}{'host'}".'/wws/info/'."$list->{'name'}",
178
'listTheme' => [@{$list->{'admin'}{'topics'}}],
179
#'listOwnerName' => [@owner_names]|| 'none' ,
180
#'listOwnerEmail' => [@owner_emails],
181
#'listEditorName' => [@editor_names],
182
#'listEditorEmail' => [@editor_emails],
183
'objectclass' => ['top','MailingList']
187
#&Log::do_log('notice',"xxxadd ok") if($result_add->code == 0);
189
unless (defined($result_add) && ($result_add->code == 0)){
190
#my $error = $result_add->error;
191
&Log::do_log('err'," Ldap::export_list: Adding Error ");
192
# my $server_error = $result_add->server_error;
193
# &Log::do_log('err'," Ldap::export_list: Server error=$server_error ");
194
# &Log::do_log('err','Ldap::export_list:Unable to add the entry %s, in the directory %s ',$dn,$Conf{'ldap_export'}{$directory}{'host'});
205
my($directory,$list,$ldap) = @_;
206
&Log::do_log('debug3', 'Ldap::delete_list(%s,%s)', $directory,$list->{'name'});
208
my $already_binded = 1;
210
unless (eval "require Net::LDAP") {
211
&Log::do_log ('err',"Unable to use LDAP library, Net::LDAP required, install perl-ldap (CPAN) first");
216
## We may used delete_list independently OR from export_list()
217
unless (defined $ldap) {
220
$ldap = Net::LDAP->new($Conf{'ldap_export'}{$directory}{'host'});
223
&Log::do_log('err',"Ldap::delete_list:unable to bind to the directory %s", $dir);
227
##To verify the password
228
my $cnx = $ldap->bind(dn => "$Conf{'ldap_export'}{$directory}{'DnManager'}" , password => "$Conf{'ldap_export'}{$directory}{'password'}");
230
unless(defined($cnx) && ($cnx->code == 0)){
231
&Log::do_log('notice', 'Ldap::delete_list:Incorrect dn %s for binding',$Conf{'ldap_export'}{$directory}{'DnManager'});
237
##To create the dn and delete this entry
238
my $list_email = $list->get_list_address();
239
my $dn = "cn=$list_email,$Conf{'ldap_export'}{$directory}{'suffix'}";
240
my $filter = "(listEmailAddress = $list_email)";
242
my $result_search = $ldap->search (
243
base => "$Conf{'ldap_export'}{$directory}{'suffix'}",
248
if($result_search->count > 0){
249
my $result_delete = $ldap->delete("$dn");
251
unless(defined($result_delete) && ($result_delete->code == 0)){
252
my $error = $result_delete->error;
253
&Log::do_log('err',"Ldap::export_list: Delete Error=$error");
258
&Log::do_log('info',"Ldap::delete_list: Deleting the entry $dn");
261
unless $already_binded;
264
sub get_exported_lists{
266
my $directory = shift;
268
&Log::do_log('debug3','Ldap::get_exported_lists(%s)',$directory);
272
unless (eval "require Net::LDAP") {
273
&Log::do_log ('err',"Unable to use LDAP library, Net::LDAP required, install perl-ldap (CPAN) first");
278
my $ldap = Net::LDAP->new($Conf{'ldap_export'}{$directory}{'host'}, timeout => $Conf{'ldap_export'}{$directory}{'connection_timeout'});
280
&Log::do_log('err',"unable to bind to '%s' directory", $directory);
284
my $cnx = $ldap->bind();
286
unless(defined($cnx) && ($cnx->code == 0)){
287
&Log::do_log('err', 'Ldap::exported_lists: Bind failed on %s',$Conf{'ldap_export'}{$directory}{'host'});
292
my $search_filter = "(|(listEmailAddress=*$filter*)(listSubject=*$filter*))";
293
my $result_search = $ldap->search (
294
base => "$Conf{'ldap_export'}{$directory}{'suffix'}",
295
filter => "$search_filter",
299
unless (defined($result_search) && ($result_search->code == 0)){
300
&Log::do_log('notice',"No result for directory '%s' : %s",$directory, $result_search->error );
302
foreach my $entry ($result_search->all_entries){
303
$list_name = $entry->get_value('listName');
304
$list_address = $entry->get_value('listEmailAddress');
305
$subject = $entry->get_value('listSubject');
306
$urlinfo = $entry->get_value('listUrlInfo');
307
$host = $entry->get_value('robotEmail');
309
%lists = ("$list_name" => {'list_address' => "$list_address",
310
'subject' => "$subject",
311
'urlinfo' => "$urlinfo",
322
##Subroutine not used yet but may be useful later
323
sub get_dn_anonymous{
326
$datas->{'timeout'} = 20 unless($datas->{'timeout'});
327
$datas->{'scope'} = 'sub' unless($datas->{'scope'});
329
unless (eval "require Net::LDAP") {
330
&Log::do_log ('err',"Unable to use LDAP library, Net::LDAP required, install perl-ldap (CPAN) first");
336
my $ldap = Net::LDAP->new($datas->{'host'},timeout => $datas->{'timeout'});
338
&Log::do_log('err','Ldap::get_dn_anonymous :Unable to bind to the directory %s',$datas->{'host'});
343
my $cnx = $ldap->bind();
345
unless(defined($cnx) && ($cnx->code == 0)){
346
&Log::do_log('err', 'Ldap::exported_lists: Bind failed on %s',$datas->{'host'});
353
my $result_search = $ldap->search (
354
base => $datas->{'base'},
355
filter => $datas->{'filter'},
356
scope => $datas->{'scope'},
357
timeout => $datas->{'timeout'},
359
unless (defined($result_search) && ($result_search->code == 0)){
360
&Log::do_log('notice',"Ldap::get_dn_anonymous :No result for directory %s",$directory );
364
if (defined($result_search) && ($result_search->count() == 0)) {
365
do_log('notice','Ldap::get_dn_anonymous : No entry in the Ldap Directory of %s',$datas->{'host'});
369
my $refhash = $result_search->as_struct();
370
my (@DN) = keys(%$refhash);
378
116
## Packages must return true.