Proyecto

General

Perfil

292 enavas
#!/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;