#!/usr/bin/perl #---------------------------------------------------------------------- # foto 20011004-01 - RedIRIS # # script que devuelve una foto del directorio basado en LDAP # #---------------------------------------------------------------------- use Net::LDAP; use Net::LDAP::Search; use URI::Escape; %datos = &ReadParse; $search = $datos{'search'}; if (!defined $datos{'h'}) { $wServer = "ldap.rediris.es"; $wPort = "1389"; } else { ($wServer,$wPort) = split(/:/,$datos{'h'}); $cPort = "389"; $cPort = $wPort if ($wPort ne ""); $wPort = $cPort; } $wBase = (!defined $datos{'b'}) ? "dc=es" : $datos{'b'}; &Cabecera; $pLDAP = Net::LDAP->new ( $wServer, port => $wPort, timeout => 10, async => 1, ); if (defined $pLDAP) { $pLDAP->bind ( anonymous => 1, version => 3 ); $rdo = $pLDAP->search ( base => $wBase, scope => "base", filter => "(c=tv)", ); #-- Comprobamos si hay algun error como: que el servidor tenga version 2 my $err = $rdo->error; if ($err ne "Success") { $pLDAP->unbind; if ($err eq "Protocol Error") { $pLDAP->bind ( anonymous => 1, version => 2 ); } else { print "No podemos contactar con el servidor $wServer."; exit; } } #-- Ini - Pintamos la foto $rdo = $pLDAP->search ( base => $wBase, scope => "base", filter => "(objectclass=*)", attrs => [ 'jpegPhoto' ], ); pintaFoto ($rdo->entry(0)); #-- Fin - Pintamos la foto $pLDAP->unbind; } else { print "El servidor $wServer tiene un problema. No podemos contarctar con él."; } #---------------------------------------------------------------------- # Funcion: ReadParse #---------------------------------------------------------------------- sub ReadParse { if ($ENV{'REQUEST_METHOD'} eq "GET") { $in = $ENV{'QUERY_STRING'}; } elsif ($ENV{'REQUEST_METHOD'} eq "POST") { for ($i = 0; $i < $ENV{'CONTENT_LENGTH'}; $i++) { $in .= getc; } } @in = split (/&/, $in); foreach $i (0 .. $#in) { $in[$i] =~ s/\+/ /g; $in[$i] =~ s/%(..)/pack("c", hex ($1))/ge; $loc = index ($in[$i], "="); $key = substr ($in[$i], 0, $loc); $val = substr ($in[$i], $loc + 1); $in{$key} .= '\0' if (defined ($in{$key})); $in{$key} .= $val; } return %in; } #----------------------------------------------------------------------- # Funcion: Cabecera # Descrip: #----------------------------------------------------------------------- sub Cabecera { print "Content-type: image/jpeg\n\n"; } #----------------------------------------------------------------------- # Funcion: pintaFoto # Descrip: #----------------------------------------------------------------------- sub pintaFoto { my $entry = shift; my @attrs = $entry->attributes; foreach my $attr (@attrs) { my @value = $entry->get_value( $attr ); foreach my $value (@value) { #print utf8_lat1($value); print $value; } } }