Proyecto

General

Perfil

« Anterior | Siguiente » 

Revisión 292

Import inicial setgroupquota

Ver diferencias:

quotas/setgroupquota.list
%product setgroupquota
%system all
%copyright 2012 by Esteban M. Navas
%vendor Esteban M. Navas
%description Establecer quotas de disco para alumnos por grupos
%version 0.1
%readme README
%license LICENSE
%requires perl
%requires libnet-ldap-perl
%requires quota
f 0755 root root /usr/local/sbin/setgroupquota setgroupquota
quotas/README
WHAT IS setgroupquota?
setgroupquota es un paquete que nos va a permitir establecer cuotas de disco para
los usuarios de un grupo determinado. Ésto facilita el trabajo de los administradores,
ya que podemos asignar una quota de disco para alumnos, para profesores o para los
alumnos de un grupo determinado de clase.
Este script perl busca los usuarios que pertenecen al grupo en el servidor de ldap.
setgroupquota instala el script perl setgroupquota en el directorio /usr/local/sbin
setgroupquota solicita que el usuario introduzca tres datos:
* La password del administrador de ldap para consultar los datos.
* El grupo al que le queremos asignar una quota de disco: teachers, students, E-1A ...
* La quota de disco que queremos asignar (número de bloques).
El nombre del grupo que hay que introducir es cualquiera de los que tengamos creado
en ldap.
COPYRIGHT AND LICENSE INFO
setgroupquota is Copyright 2012 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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
quotas/LICENSE
License
setgroupquota 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.
setgroupquota 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.
quotas/setgroupquota
#!/usr/bin/perl
# ------------------------------------------------------------
# script: setgroupquota
# Author: Esteban M. Navas Mart?n
# Date: 06-03-2011
# Ver: 06-03-2011
# Requisito: Instalar el m?dulo de perl libnet-ldap-perl
#
# Purpose: This program set the quota for the users in a group class
#
# Copyright (c) 2012 Esteban M. Navas Mart?n <adminies.valledeljerte@edu.juntaextremadura.net>. 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 of the License, 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.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use Net::LDAP;
my $ldapserver = ldap;
my $baseGroup = "ou=Group,dc=instituto,dc=extremadura,dc=es";
my $basePeople = "ou=People,dc=instituto,dc=extremadura,dc=es";
my $groupClass;
my $groupQuota;
print "Introduce la contrase?a del administrador de ldap: ";
system "stty -echo"; # disable echo
chomp (my $pass = <STDIN>);
system "stty echo"; # enable echo
print "\n";
print "Introduce el nombre del grupo de clase: ";
chomp (my $groupClass = <STDIN>);
if (! $groupClass) {
print "$0: Debe especificar el nombre del grupo\n";
print "Ejemplos: E-1A, E-1B, B-1A, disabled...\n";
exit 1;
}
print "Introduce la quota para el grupo de clase $groupClass: ";
chomp (my $groupQuota = <STDIN>);
if (! $groupQuota) {
print "$0: Debe especificar la quota que quiere asignar al grupo\n";
exit 1;
}
$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 los miembros del grupo elegido
$mesg = $ldap->search(base=> $baseGroup, filter =>"(&(objectclass=posixGroup)(groupType=school_class)(cn=$groupClass))");
$mesg->code && die $mesg->error;
foreach $entry ($mesg->entries) {
my(@members) = $entry->get_value('memberUid');
foreach $memberUid (@members) {
$mesg2 = $ldap->search(base=> $basePeople, filter =>"(&(objectclass=posixAccount)(uid=$memberUid))");
$mesg2->code && die $mesg2->error;
@users = $mesg2->entries;
foreach $user (@users) {
$uid = $user->get_value('uid');
$uidNumber = $user->get_value('uidNumber');
print "Asignando quota de $groupQuota a $uid con uidNumber $uidNumber -> groupClass: $groupClass\n";
system ("setquota $uidNumber $groupQuota $groupQuota 0 0 /home");
}
}
}
print "Proceso concluido.\n\n";
$ldap->unbind;

Exportar a: Unified diff