AddressBook

 view release on metacpan or  search on metacpan

lib/AddressBook.pm  view on Meta::CPAN

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
the key_fields of each.
 
=over 6
 
=item Z<>
 
If no match is found, the entry is added to the master.
 
=item Z<>
 
If multiple matches are found, an error occurrs.
 
=item Z<>
 
If one match is found, then:
 
=over 8
 
=item Z<>
 
If the records match, nothing is done.

lib/AddressBook/DB/HTML.pm  view on Meta::CPAN

106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
      $attributes{$key} = join ($self->{intra_attr_sep},
                              map {a({-href=>"mailto:$_"},$_)} @{$attr->{$key}->{value}});
    }
  }
  $format = $self->{write_format};
  foreach (values %{$self->{config}->{db2generic}->{$self->{db_name}}}) {
    $format =~ s/\$($_)/\$attributes{$1}/g;
  }
  my @attributes = (sort {$attr->{$a}->{meta}->{order} <=> $attr->{$b}->{meta}->{order}} (keys %attributes));
  $format =~ s'keys %attributes'@attributes'g;
  eval qq{\$ret = $format}; warn "Syntax error in HTML backend \"write_format\": $@" if $@;
  return $ret;
}
 
sub entry_form {
  my $self = shift;
  my $class = ref $self || croak "Not a method call";
  my $entry = shift;
  my $formname = shift;
  my ($format,$ret,$key,$option,@options,%selected,$i,%result,$default);
  #$entry->calculate;

lib/AddressBook/DB/HTML.pm  view on Meta::CPAN

204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
      $result{$key} .= "<input type=hidden name=\"_${key}_count\" value=$#options>";
    }
  }
  %attributes = %result;
  $format = $self->{form_format};
  foreach (values %{$self->{config}->{db2generic}->{$self->{db_name}}}) {
    $format =~ s/\$($_)/\$attributes{$1}/g;
  }
  my @attributes = (sort {$attr->{$a}->{meta}->{order} <=> $attr->{$b}->{meta}->{order}} (keys %attributes));
  $format =~ s'keys %attributes'@attributes'g;
  eval qq{\$ret = $format}; warn "Syntax error in HTML backend \"form_format\": $@" if $@;
  return $ret;
}
 
sub read_from_args {
  my $self = shift;
  my $class = ref $self || croak "Not a method call";
  my $query = shift;
  my ($key,$canon_field_name,@value,$i,$key_count);
  my $entry = AddressBook::Entry->new(config=>$self->{config});
  foreach $key (keys %{$self->{config}->{db2generic}->{$self->{db_name}}}) {

lib/AddressBook/DB/LDAP.pm  view on Meta::CPAN

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  dn_calculate="'cn=' . $cn . ',mail=' . $mail"
 
=back
 
Any of these options may be specified in the constructor, or in the configuration file.
 
=cut
 
use strict;
use Net::LDAP::Util qw(ldap_error_text);
use Carp;
use vars qw(@ISA $VERSION);
 
$VERSION = '0.13';
 
@ISA = qw(AddressBook);
 
=head2 new

lib/AddressBook/DB/LDAP.pm  view on Meta::CPAN

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
    ($hostname,$base) = split "/", $self->{dsn};
  }
  $self->{hostname} = $hostname || $self->{hostname};
  $self->{base} = $base || $self->{base};
  $self->{ldap} = Net::LDAP->new($self->{hostname}, async => 1 || croak $@);
  unless ($self->{anonymous}) {
    $mesg = $self->{ldap}->bind($self->{username}, password => $self->{password});
  } else {
    $mesg = $self->{ldap}->bind;
  }
  if ($mesg->is_error) {
    croak "could not bind to LDAP server: " . $mesg->error;
  }
  return $self;
}
 
sub search {
  my $self = shift;
  my $class = ref $self || croak "Not a method call.";
  my @ret;
  my %arg = @_;
  my $max_size = $arg{entries} || 0;

lib/AddressBook/DB/LDAP.pm  view on Meta::CPAN

150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
    }
    $filter = "(| $filter)";
    $self->{so} = $self->{ldap}->search(base => $self->{base} || '',
                                      async => 1,
                                      sizelimit => $max_size,
                                      timelimit => $max_time,
                                      filter => "(&(objectclass=" .
                                      $self->{objectclass} .')' .
                                      $filter . ')');
    if ($self->{so}->code) {
      $self->{code} = ldap_error_text($self->{so}->code);
      return 0;
    }
  } else {
    # We need to return everything;
    $self->{so} = $self->{ldap}->search(base => $self->{base} || '',
                                      async => 1,
                                      filter => "objectclass=" . $self->{objectclass});
    if ($self->{so}->code) {
      $self->{code} = ldap_error_text($self->{so}->code) ;
      return 0;
    }
  }
  undef $self->{code};
  return $self->{so}->count;
}
 
sub read {
  my $self = shift;
  my $class = ref $self || croak "Not a method call";

lib/AddressBook/DB/LDAP.pm  view on Meta::CPAN

185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
    my $ret = AddressBook::Entry->new(config=>$self->{config});
    foreach $attr ($entry->attributes) {
      if (exists $self->{config}->{db2generic}->{$self->{db_name}}->{$attr}) {
        $ret->add(db=>$self->{db_name},attr=>{$attr=>[$entry->get_value($attr)]});
      }
    }
    $ret->{timestamp} = _get_timestamp($entry);
    undef $self->{code};
    return $ret;
  } else {
    $self->{code} = ldap_error_text($self->{so}->code) ;
    return undef;
  }
}
 
sub _get_timestamp {
  my $entry=shift;
  my $timestamp;
  if ($entry->exists("modifytimestamp")) {
    ($timestamp) = $entry->get_value("modifytimestamp");
  } elsif ($entry->exists("createtimestamp")) {

lib/AddressBook/DB/LDAP.pm  view on Meta::CPAN

230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
  }
  my $entry = $args{entry};
  $entry->calculate;
  my $old_entry=$self->read;
  my $rdn = $self->_rdn_from_entry($entry);
  my $old_rdn = $self->_rdn_from_entry($old_entry);
  my $result;
  if ($rdn ne $old_rdn) {
    $result=$self->{ldap}->moddn("$old_rdn," . $self->{base},deleteoldrdn=>1,newrdn=>$rdn);
    if ($result->code) {
      $self->{code} =  ldap_error_text($result->code) ;
      return 0;
    }
  }
  my %attr = %{$entry->get(db=>$self->{db_name},values_only=>'1')};
  $result=$self->{ldap}->modify("$rdn," . $self->{base},replace=>[%attr]);
  if ($result->code) {
    $self->{code} =  ldap_error_text($result->code) ;
    return 0;
  }
  undef $self->{code};
  return 1;
}
 
sub add {
  my $self = shift;
  my $class = ref $self || croak "Not a method call";
  my $entry = shift;
  $entry->calculate;
  my $dn = $self->_rdn_from_entry($entry) . "," . $self->{base};
  my %attr = %{$entry->get(db=>$self->{db_name},values_only=>'1')};
  $attr{objectclass} = [$self->{objectclass}];
  my $result = $self->{ldap}->add($dn, attrs => [%attr]);
  if ($result->code) {
    $self->{code} =  ldap_error_text($result->code) ;
    return 0;
  }
  undef $self->{code};
  return 1;
}
 
sub write {
  my $self = shift;
  my $class = ref $self || croak "Not a method call";
  return $self->add(@_);
}
 
sub delete {
  my $self = shift;
  my $class = ref $self || croak "Not a method call.";
  my $entry=shift;
  $entry->calculate;
  my $dn = $self->_rdn_from_entry($entry) . "," . $self->{base};
  my $result = $self->{ldap}->delete($dn);
  if ($result->code) {
    $self->{code} = ldap_error_text($result->code) ;
    return 0;
  }
  undef $self->{code};
  return 1;
}
 
sub code {
  my $self = shift;
  my $class = ref $self || croak "Not a method call.";
  return $self->{code};
}
 
sub _rdn_from_entry {
  my $self = shift;
  my $class = ref $self || croak "Not a method call";
  my $entry = shift || croak "Need an entry";
  my ($dn,$dn_calculate);
  my %attr = %{$entry->get(db=>$self->{db_name},values_only=>'1')};
  ($dn_calculate=$self->{dn_calculate}) =~ s/\$(\w*)/\$attr{$1}->[0]/g;
  eval qq{\$dn = $dn_calculate}; warn "Syntax error in dn_calculate: $@" if $@;
  return $dn;
}
 
1;
__END__
 
=head2 Timestamps
 
For syncronization purposes, all records are timestamped using the "modifytimestamp"
LDAP attribute.  If the record has no "modifytimestamp", "createtimestamp" is used.

lib/AddressBook/DB/LDIF.pm  view on Meta::CPAN

141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
  $self->{ldif}->write($ldap_entry);
}
 
sub _dn_from_entry {
  my $self = shift;
  my $class = ref $self || croak "Not a method call";
  my $entry = shift || croak "Need an entry";
  my ($dn,$dn_calculate);
  my %attr = %{$entry->get(db=>$self->{db_name},values_only=>'1')};
  ($dn_calculate=$self->{dn_calculate}) =~ s/\$(\w*)/\$attr{$1}->[0]/g;
  eval qq{\$dn = $dn_calculate}; warn "Syntax error in dn_calculate: $@" if $@;
  $dn .= "," . $self->{base};
  return $dn;
}
 
sub _get_timestamp {
  my $self = shift;
  my $class = ref $self || croak "Not a method call";
  my @stat = stat($self->{filename});
  return ParseDateString("epoch $stat[9]");
}

lib/AddressBook/DB/PDB.pm  view on Meta::CPAN

200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
   $value = join $self->{intra_attr_sep_char}, @{$attrs->{$field}->{value}};
   $record->{phoneLabel}->[$phone_index] = $self->{phone_labels}->{$field};
   $record->{entry}->[$phone_index+3] = $value;
   $phone_index++;
   if ($phone_index == 5) {last# there is only room for 5 "phone" fields
 }
 for ($i=0;$i<=keys %labels;$i++) {
   unless ($record->{entry}->[$i]) {$record->{entry}->[$i] = undef}
 }
 ($phone_display_calc = $self->{phone_display}) =~ s/\$([\w-]+)/\$attrs->{$1}->{value}->[0]/g;
 eval qq{ \$phone_display = $phone_display_calc }; warn "Syntax error in phone_display_calc: $@" if $@;
 @phone_display = split ",",$phone_display;
find_phone: for ($i=0;$i<=$#phone_display;$i++) {
  if ($attrs->{$phone_display[$i]}->{value}->[0]) {
    $phone_target = $self->{phone_labels}->{$phone_display[$i]};
    for ($j=0;$j<=$#{$record->{phoneLabel}};$j++) {
      if ($record->{phoneLabel}->[$j] == $phone_target) {
        $record->{showPhone} = $j;
        last find_phone;
      }
     }



( run in 0.504 second using v1.01-cache-2.11-cpan-e5176c747c2 )