#!/usr/bin/perl use CGI; use Net::LDAP qw(:all); use CGI::Carp qw(fatalsToBrowser); use strict; my $q = new CGI; print $q->header; if($q->param('looking') eq 'yes'){ my $ldap = Net::LDAP->new('ldap') or die "$@"; $ldap->bind; # an anonymous bind my $base = "c=us"; my @Attrs = (); my $search = "(&"; if($q->param('first') ne ''){ $search = "$search (givenName=" . $q->param('first') . ")"; } if($q->param('last') ne ''){ $search = "$search (sn=" . $q->param('last') . ")"; } if($q->param('dept') ne ''){ $search = "$search (Department=" . $q->param('dept') . ")"; } if($q->param('phone') ne ''){ $search = "$search (telephoneNumber=" . $q->param('phone') . ")"; } if($q->param('fax') ne ''){ $search = "$search (facsimileTelephoneNumber=" . $q->param('fax') . ")"; } $search = $search . ")"; $result = LDAPsearch($ldap, $search,\@Attrs); my @entries = $result->entries; $ldap->unbind; # take down session } print < Directory
\n"; print "\n"; print "\n"; print "\n"; print ""; print "\n"; print "\n"; print "\n"; } print "
Directory
Use this form to find an employee. Enter as much information as you know. Use * for wildcards.
First Name
Last Name
Department Name
Phone
Fax
EODUMP PRINTRESULTS(); print <"; foreach $entr (@entries) { $phone = $entr->get('telephoneNumber'); $user = $entr->get('cn'); $email = $entr->get('mail'); $department = $entr->get('Department'); $address = $entr->get('address'); $address = $address->[0]; $department = $department->[0]; $phone = $phone->[0]; $user = $user->[0]; $email = $email->[0]; $title = $entr->get('title'); $title = $title->[0]; $street = $entr->get('postalAddress'); $street = $street->[0]; $fax = $entr->get('facsimileTelephoneNumber'); $fax = $fax->[0]; (my $lname, my $fname) = split(/\, /, $user); print "
$user$phone
$title\n
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print ""; print "
$department
$street
 
"; } sub LDAPsearch { my ($ldap,$searchString,$attrs) = @_ ; my $result = $ldap->search ( base => "$base", scope => "sub", filter => "$searchString", attrs => $attrs, sizelimit => $size_limit ); } #### #!/usr/bin/perl # vcfcreater.vcf # If you use IIS all you need to do is add a handler for # the .vcf file to be run through perl.exe # On *nix you just need to make it executable and have a # handle for the extention. use CGI; use strict; my $q = new CGI; my $city = "CITY"; my $state = "NO"; my $zip = "44444"; #Example if you are in eastern time zone in the US it is 5 my $Greenwich_mean_time_difference = 5; my $office = "Dot Com Store"; my $fname = $q->param('fname'); my $lname = $q->param('lname'); my $title = $q->param('title'); my $phone = $q->param('phone'); my $fax = $q->param('fax'); my $address = $q->param('address'); my $email = $q->param('email'); my($sec, $min, $hour, $day, $month, $year)=(localtime)[0,1,2,3,4,5]; $hour = $hour + $Greenwich_mean_time_difference; $year += 1900; $month++; if($month < 10){ $month = "0$month"; } if($day < 10) { $day = "0$day"; } print "Content-Type: download/x-vcard\n\n"; print "BEGIN:VCARD\nVERSION:2.1\n"; print "N:$lname;$fname\n"; print "FN:$fname $lname\n"; print "ORG:$office\n"; print "TITLE:$title\n"; print "TEL;WORK;VOICE:(616) $phone\n"; print "TEL;WORK;FAX:(616) $fax\n"; print "ADR;WORK:;;$address, MW;$city;$state;$zip;United States of America\n"; print "LABEL;WORK;ENCODING=QUOTED-PRINTABLE:$address, MW=0D=0A$city, $state $zip=0D=0AUnited States of America\n"; print "EMAIL;PREF;INTERNET:$email\@somewhere.com\n"; print "REV:$year$month$dayT$hour$min$secZ\n"; print "END:VCARD\n"; exit;