Proyecto

General

Perfil

« Anterior | Siguiente » 

Revisión 30

Primera carga de código

Ver diferencias:

fotos-ldap/trunk/fotostoldap/LICENSE
License
fotostoldap is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3, or (at your option)
any later version.
fotostoldap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
fotos-ldap/trunk/fotostoldap/fotostoldap.list
%product fotostoldap
%copyright 2010 by Esteban M. Navas
%vendor Esteban M. Navas
%description Incorpora a cada usuario de ldap su foto, si se encuentra disponible.
%version 0.3
%readme README
%license LICENSE
%requires perl
%requires libnet-ldap-perl
%requires libarchive-zip-perl
%requires perlmagick
%replaces fotostoldap
f 755 root root /usr/bin/fotostoldap fotostoldap
fotos-ldap/trunk/fotostoldap/README
WHAT IS FOTOSTOLDAP?
fotostoldap es un script perl que comprueba qué usuarios no tienen foto
en ldap e inserta dicha foto desde el fichero de exportación de alumnos
obtenido de Rayuela, si se encuentra disponible.
El atribujo jpegPhoto de ldap sirve para almacenar una o varias
imágenes de un usuario usando el formato JPEG File Interchange Format [JFIF].
El tamaño límite de este atributo es de 250000 bytes. No obstante, se
debería guardar lo más pequeño que sea posible, puesto que el tamaño puede influir
en el rendimiento. Por este motivo, en la versión 0.3 incorporamos el
ajuste de tamaño.
CHANGELOG
* fotostoldap-0.2 -- Versión inicial.
* fotostoldap-0.3 -- Esta versión convierte la foto del alumno a .jpg y
la redimensiona a 80x80 pixeles.
REQUIREMENTS.
Requiere tener instalados los siguientes paquetes:
* perl.
* libnet-ldap-perl.
* libarchive-zip-perl.
* perlmagick.
HOW DO I USE FOTOSTOLDAP?
Uso: fotostoldap <path archivo Exportacion Datos Alumnado>
COPYRIGHT AND LICENSE INFO
fotostoldap is Copyright 2010 by Esteban M Navas Martín, All Rights Reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
fotos-ldap/trunk/fotostoldap/fotostoldap
#!/usr/bin/perl
#
# Programa perl para subir las fotos de los alumnos al servidor ldap del centro
# Toma como parámetro el fichero de exportación de datos de alumnado.
# Sube a ldap las fotos que se encuentran en el fichero de exportación de datos
# de aquellos alumnos que no tengan foto en ldap.
#
# Esteban M. Navas
# IES Valle del Jerte
# Fecha creación: 30/09/2010
# Fecha última modificación: 05/11/2010
# Requisito: Instalar los módulos de perl libnet-ldap-perl,
# libarchive-zip-perl y perlmagick
use Archive::Extract;
use Net::LDAP;
use Image::Magick;
# Declaramos las funciones
sub trim($);
my $ldapserver = "ldap";
my $archivo;
if ($#ARGV != 0) {
print "Uso: fotostoldap <Path Archivo Exportacion Datos Alumnado.zip>\n\n";
print "Ejemplo: fotostoldap ExportacionDatosAlumnado.zip\n";
exit;
}
if ( -e $ARGV[0] ) {
$archivo = $ARGV[0];
}
else {
print "El archivo $ARGV[0] no existe\n";
exit;
}
print "Descomprimiendo $archivo...\n";
my $ae = Archive::Extract->new(archive => $archivo);
my $ok = $ae->extract( to => '/tmp' ) or die $ae->error;
my $outdir = $ae->extract_path;
my $files = $ae->files;
print "$archivo descomprimido en $outdir\n\n";
print "Introduce la contraseña del administrador de ldap: ";
system "stty -echo"; # disable echo
chomp (my $pass = <STDIN>);
system "stty echo"; # enable echo
$ldap = Net::LDAP->new("$ldapserver") or die "$@";
# Abrimos una conexión
$ldap->bind("cn=admin,ou=People,dc=instituto,dc=extremadura,dc=es", password=>$pass);
# Obtenemos la lista de usuarios sin foto
$mesg = $ldap->search(filter=>"(&(objectClass=inetOrgPerson)(!(jpegPhoto=*)))", base=>"ou=People,dc=instituto,dc=extremadura,dc=es");
@entries = $mesg->entries;
# Procesamos cada usuario sin foto
foreach $entry (@entries) {
my $employeeNumber = $entry->get_value(employeeNumber);
my $cn = $entry->get_value(cn);
# Obtenemos el nombre del fichero
my $fichero = qx{ls $outdir | grep -iE '^$employeeNumber.[a-z]{3}'};
# Importante: Quitar los espacios que nos da la salida del qx{}
$fichero = trim($fichero);
# Si hay una foto para el alumno ...
if ( $fichero ) {
my $tmp;
my $photo;
my $imagen = $outdir . "/" . $fichero;
# Cambiamos el tamaño y el formato de la imagen
my $nuevaimagen = Image::Magick->new;
$nuevaimagen->Read( filename => $imagen );
$nuevaimagen->Set( Gravity => 'Center' );
$nuevaimagen->Resize( geometry => '80x80' );
$nuevaimagen->Extent( geometry => '80x80' );
my $imagenretocada = $outdir . "/" . $employeeNumber . ".jpg";
$nuevaimagen->Write( "$imagenretocada" );
open(FILE, "$imagenretocada");
binmode(FILE);
$photo .= $tmp while (sysread FILE, $tmp, 1024);
close(FILE);
$mesg = $ldap->modify($entry->dn(), add => {'jpegPhoto'=>$photo});
print "Foto $imagenretocada añadida a $cn\n";
# Borramos la image retocada
unlink $imagenretocada;
}
}
# Cerramos la conexión
$ldap->unbind;
# Borramos los archivos extraidos en el directorio $outdir
foreach $file (@$files) {
unlink "$outdir/$file";
}
print "Proceso concluido.\n\n";
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
fotos-ldap/trunk/updatefotosldap/updatefotosldap.list
%product updatefotosldap
%copyright 2010 by Esteban M. Navas
%vendor Esteban M. Navas
%description Incorpora a cada usuario de ldap su foto desde el fichero ExportacionDatosAlumnado.zip, si se encuentra disponible.
%version 0.1
%readme README
%license LICENSE
%requires perl
%requires libnet-ldap-perl
%requires libarchive-zip-perl
%requires perlmagick
%replaces updatefotosldap
f 755 root root /usr/bin/updatefotosldap updatefotosldap
fotos-ldap/trunk/updatefotosldap/README
WHAT IS UPDATEFOTOSLDAP?
updatefotosldap es un script perl que cambia las fotos de los alumnos
en ldap por las que se encuentran en el fichero ExportacionDatosAlumnado.zip,
ajustando su tamaño a 80x80 px y modificando el formato a .jpg
El atribujo jpegPhoto de ldap sirve para almacenar una o varias
imágenes de un usuario usando el formato JPEG File Interchange Format [JFIF].
El tamaño límite de este atributo es de 250000 bytes. No obstante, se
debería guardar lo más pequeño que sea posible, puesto que el tamaño puede influir
en el rendimiento. Por este motivo, en la versión 0.3 incorporamos el
ajuste de tamaño.
CHANGELOG
* updatefotosldap-0.1 -- Versión inicial. Convierte la foto del alumno a .jpg y
la redimensiona a 80x80 pixeles.
REQUIREMENTS.
Requiere tener instalados los siguientes paquetes:
* perl.
* libnet-ldap-perl.
* libarchive-zip-perl.
* perlmagick.
HOW DO I USE UPDATEFOTOSLDAP?
Uso: updatefotosldap <path archivo Exportacion Datos Alumnado>
COPYRIGHT AND LICENSE INFO
updatefotosldap is Copyright 2010 by Esteban M Navas Martín, All Rights Reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
fotos-ldap/trunk/updatefotosldap/updatefotosldap
#!/usr/bin/perl
#
# Programa perl para subir y/o actualizar las fotos de los alumnos en servidor ldap del centro.
# Toma como parámetro el fichero de exportación de datos de alumnado.
# Actualiza las fotos de los alumnos en el servidor de ldap desde el fichero ExportacionDatosAlumnado.zip
#
#
# Esteban M. Navas
# IES Valle del Jerte
# Fecha creación: 09/11/2010
# Fecha última modificación: 12/11/2010
# Requisito: Instalar los módulos de perl libnet-ldap-perl,
# libarchive-zip-perl y perlmagick
use Archive::Extract;
use Net::LDAP;
use Image::Magick;
# Declaramos las funciones
sub trim($);
my $ldapserver = "ldap";
my $archivo;
if ($#ARGV != 0) {
print "Uso: updatefotosldap <Path Archivo Exportacion Datos Alumnado.zip>\n\n";
print "Ejemplo: updatefotosldap ExportacionDatosAlumnado.zip\n";
exit;
}
if ( -e $ARGV[0] ) {
$archivo = $ARGV[0];
}
else {
print "El archivo $ARGV[0] no existe\n";
exit;
}
print "Descomprimiendo $archivo...\n";
my $ae = Archive::Extract->new(archive => $archivo);
my $ok = $ae->extract( to => '/tmp' ) or die $ae->error;
my $outdir = $ae->extract_path;
my $files = $ae->files;
print "$archivo descomprimido en $outdir\n\n";
print "Introduce la contraseña del administrador de ldap: ";
system "stty -echo"; # disable echo
chomp (my $pass = <STDIN>);
system "stty echo"; # enable echo
$ldap = Net::LDAP->new("$ldapserver") or die "$@";
# Abrimos una conexión
$ldap->bind("cn=admin,ou=People,dc=instituto,dc=extremadura,dc=es", password=>$pass);
# Obtenemos la lista de usuarios
$mesg = $ldap->search(filter=>"(&(objectClass=inetOrgPerson))", base=>"ou=People,dc=instituto,dc=extremadura,dc=es");
@entries = $mesg->entries;
# Procesamos cada usuario
foreach $entry (@entries) {
my $employeeNumber = $entry->get_value(employeeNumber);
my $cn = $entry->get_value(cn);
# Obtenemos el nombre del fichero
my $fichero = qx{ls $outdir | grep -iE '^$employeeNumber.[a-z]{3}'};
# Importante: Quitar los espacios que nos da la salida del qx{}
$fichero = trim($fichero);
# Si hay una foto para el alumno ...
if ( $fichero ) {
my $tmp;
my $photo;
# Y si el alumno tiene foto en el servidor ldap...
if ( $entry->get_value( jpegPhoto ) ne '') {
# ...la borramos de allí
$mesg = $ldap->modify($entry->dn(), replace => {'jpegPhoto' => ''});
}
my $imagen = $outdir . "/" . $fichero;
# Cambiamos el tamaño y el formato de la imagen
my $nuevaimagen = Image::Magick->new;
$nuevaimagen->Read( filename => $imagen );
$nuevaimagen->Set( Gravity => 'Center' );
$nuevaimagen->Resize( geometry => '80x80' );
$nuevaimagen->Extent( geometry => '80x80' );
my $imagenretocada = $outdir . "/" . $employeeNumber . ".jpg";
$nuevaimagen->Write( "$imagenretocada" );
open(FILE, "$imagenretocada");
binmode(FILE);
$photo .= $tmp while (sysread FILE, $tmp, 1024);
close(FILE);
$mesg = $ldap->modify($entry->dn(), replace => {'jpegPhoto'=>$photo});
print "Foto $imagenretocada de $cn actualizada.\n";
# Borramos la image retocada
unlink $imagenretocada;
}
}
# Cerramos la conexión
$ldap->unbind;
# Borramos los archivos extraidos en el directorio $outdir
foreach $file (@$files) {
unlink "$outdir/$file";
}
print "Proceso concluido.\n\n";
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
fotos-ldap/trunk/updatefotosldap/LICENSE
License
updatefotosldap is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3, or (at your option)
any later version.
updatefotosldap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

Exportar a: Unified diff