Start a module to log
This commit is contained in:
parent
114e661761
commit
d0420fe9f3
43
ACU/Log.pm
Normal file
43
ACU/Log.pm
Normal file
@ -0,0 +1,43 @@
|
||||
#! /usr/bin/env perl
|
||||
|
||||
package ACU::Log;
|
||||
|
||||
use v5.10.1;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Term::ANSIColor qw(:constants);
|
||||
|
||||
our $verbosity = 1;
|
||||
our $debug = 0;
|
||||
|
||||
sub do_err(@)
|
||||
{
|
||||
say BOLD, RED, ">>>", RESET, " ", BOLD, @_, RESET;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sub do_usage(@)
|
||||
{
|
||||
say BOLD, MAGENTA, " * ", RESET, " ", BOLD, @_, RESET;
|
||||
}
|
||||
|
||||
sub do_warn(@)
|
||||
{
|
||||
say BOLD, YELLOW, ">>>", RESET, " ", BOLD, @_, RESET;
|
||||
}
|
||||
|
||||
sub do_info(@)
|
||||
{
|
||||
if ($verbosity) {
|
||||
say BOLD, CYAN, " * ", RESET, " ", @_, RESET;
|
||||
}
|
||||
}
|
||||
|
||||
sub do_debug(@)
|
||||
{
|
||||
if ($debug) {
|
||||
say BOLD, BLUE, " * ", RESET, " ", @_, RESET;
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
275
utils/lpt
275
utils/lpt
@ -23,6 +23,7 @@ BEGIN {
|
||||
}
|
||||
|
||||
use ACU::LDAP;
|
||||
use ACU::Log;
|
||||
|
||||
###########################################################
|
||||
# #
|
||||
@ -42,46 +43,6 @@ my %dev_quota = ( home => "/dev/mapper/acu-nfs--accounts",
|
||||
my %def_quota = ( block => { home => 2306866, sgoinfre => 5242880 },
|
||||
file => { home => 50000, sgoinfre => 60000 } );
|
||||
|
||||
###########################################################
|
||||
# #
|
||||
# Messages subroutines #
|
||||
# #
|
||||
###########################################################
|
||||
|
||||
my $verbosity = 1;
|
||||
my $debug = 0;
|
||||
|
||||
sub do_err($)
|
||||
{
|
||||
say BOLD, RED, ">>>", RESET, " ", BOLD, @_, RESET;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sub do_usage($)
|
||||
{
|
||||
say BOLD, MAGENTA, " * ", RESET, " ", BOLD, @_, RESET;
|
||||
}
|
||||
|
||||
sub do_warn($)
|
||||
{
|
||||
say BOLD, YELLOW, ">>>", RESET, " ", BOLD, @_, RESET;
|
||||
}
|
||||
|
||||
sub do_info($)
|
||||
{
|
||||
if ($verbosity) {
|
||||
say BOLD, CYAN, " * ", RESET, " ", @_, RESET;
|
||||
}
|
||||
}
|
||||
|
||||
sub do_debug($)
|
||||
{
|
||||
if ($debug) {
|
||||
say BOLD, BLUE, " * ", RESET, " ", @_, RESET;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
###########################################################
|
||||
# #
|
||||
# Main Program #
|
||||
@ -119,7 +80,8 @@ my %cmds_account =
|
||||
"view" => \&cmd_account_view,
|
||||
"view" => \&cmd_account_view,
|
||||
|
||||
"open" => \&cmd_account_open,
|
||||
"grant-intra" => \&cmd_account_grantintra,
|
||||
"grant-lab" => \&cmd_account_grantlab,
|
||||
);
|
||||
|
||||
my %cmds_group =
|
||||
@ -148,10 +110,8 @@ my %cmds_list =
|
||||
sub ldap_get_password()
|
||||
{
|
||||
my $bindsecret;
|
||||
if (defined($ENV{'LDAP_PASSWORD'}) && $ENV{'LDAP_PASSWORD'} ne "")
|
||||
{
|
||||
$bindsecret = $ENV{'LDAP_PASSWORD'};
|
||||
return;
|
||||
if (defined($ENV{'LDAP_PASSWORD'}) && $ENV{'LDAP_PASSWORD'} ne "") {
|
||||
return $ENV{'LDAP_PASSWORD'};
|
||||
}
|
||||
|
||||
say "To avoid typing password everytime, set LDAP_PASSWORD in your env.";
|
||||
@ -186,7 +146,7 @@ sub cmd_account(@)
|
||||
my $login = shift;
|
||||
|
||||
if (! $login) {
|
||||
do_usage "lpt account <login> <command> [arguments ...]";
|
||||
ACU::Log::do_usage ("lpt account <login> <command> [arguments ...]");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -197,7 +157,7 @@ sub cmd_account(@)
|
||||
-sections => [ 'ACCOUNT COMMANDS' ] );
|
||||
}
|
||||
elsif (! exists $cmds_account{$subcmd}) {
|
||||
do_usage "Unknown command for account: ". $subcmd;
|
||||
ACU::Log::do_usage ("Unknown command for account: ". $subcmd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -214,7 +174,7 @@ sub cmd_account_close($@)
|
||||
my $login = shift;
|
||||
|
||||
if ($#_ > -1) {
|
||||
do_usage ("<lpt> account <login> close");
|
||||
ACU::Log::do_usage ("<lpt> account <login> close");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -227,14 +187,14 @@ sub cmd_account_close($@)
|
||||
scope => "sub"
|
||||
);
|
||||
if ($mesg->code != 0) {
|
||||
do_err $mesg->error;
|
||||
ACU::Log::do_err ($mesg->error);
|
||||
}
|
||||
if ($mesg->count != 1) {
|
||||
do_err "User $login not found or multiple presence";
|
||||
ACU::Log::do_err ("User $login not found or multiple presence");
|
||||
}
|
||||
|
||||
if (grep { "epitaAccount" } $mesg->entry(0)->get_value("objectClass")) {
|
||||
do_info "Invalidating password for $login ...";
|
||||
ACU::Log::do_info ("Invalidating password for $login ...");
|
||||
|
||||
my $passwd = $mesg->entry(0)->get_value("userPassword");
|
||||
$passwd =~ s/^(\{[^\}]+\})/$1!/ if ($passwd !~ /^\{[^\}]+\}!/);
|
||||
@ -246,11 +206,11 @@ sub cmd_account_close($@)
|
||||
$ldap->unbind or die ("couldn't disconnect correctly");
|
||||
|
||||
if (grep { "posixAccount" } $mesg->entry(0)->get_value("objectClass")) {
|
||||
do_debug "Setting shell for $login ...";
|
||||
ACU::Log::do_debug ("Setting shell for $login ...");
|
||||
cmd_account_shell($login, "/bin/false");
|
||||
}
|
||||
|
||||
do_warn "Done. Don't forget to restart nscd on servers and workstations!";
|
||||
ACU::Log::do_warn ("Done. Don't forget to restart nscd on servers and workstations!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -264,12 +224,14 @@ sub cmd_account_create($@)
|
||||
my $login = shift;
|
||||
|
||||
if ($#_ < 3) {
|
||||
do_usage "lpt account <login> create <group> <uid> <prénom> <nom> [nopass|passgen|password]";
|
||||
ACU::Log::do_usage ("lpt account <login> create <year> <uid> <prénom> <nom> [nopass|passgen|password]");
|
||||
return 1;
|
||||
}
|
||||
|
||||
my $group = shift;
|
||||
|
||||
ACU::Log::do_debug ("Adding dn: uid=$login,ou=$group,ou=users,dc=acu,dc=epita,dc=fr ...");
|
||||
|
||||
my $ldap = LDAP::ldap_connect();
|
||||
my $mesg = $ldap->add( "uid=$login,ou=$group,ou=users,dc=acu,dc=epita,dc=fr",
|
||||
attrs => [
|
||||
@ -281,19 +243,62 @@ sub cmd_account_create($@)
|
||||
]
|
||||
);
|
||||
|
||||
$ldap->unbind or die ("couldn't disconnect correctly");
|
||||
#$ldap->unbind or die ("couldn't disconnect correctly");
|
||||
|
||||
if ($mesg->code == 0) {
|
||||
do_info("Account added: $login");
|
||||
ACU::Log::do_info("Account added: $login");
|
||||
my $pass = shift;
|
||||
return cmd_account($login, $pass) if ($pass ne "nopass");
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
do_err("Unable to add: $login");
|
||||
ACU::Log::do_err ("Unable to add: $login: ", RESET, $mesg->error);
|
||||
}
|
||||
}
|
||||
|
||||
sub cmd_account_grantintra($@)
|
||||
{
|
||||
my $login = shift;
|
||||
|
||||
my $ldap = LDAP::ldap_connect();
|
||||
|
||||
my $dn = LDAP::search_dn($ldap, "ou=users", "uid=$login");
|
||||
|
||||
LDAP::add_attribute($ldap, $dn, "objectClass", "intraAccount");
|
||||
|
||||
ACU::Log::do_info ("$login now grants to use the intranet.");
|
||||
|
||||
$ldap->unbind or die ("couldn't disconnect correctly");
|
||||
}
|
||||
|
||||
sub cmd_account_grantlab($@)
|
||||
{
|
||||
my $login = shift;
|
||||
my $group = shift;
|
||||
|
||||
if ($group ne "acu" && $group ne "yaka") {
|
||||
ACU::Log::do_usage ("lpt account <login> grantlab <acu|yaka>");
|
||||
return 1;
|
||||
}
|
||||
|
||||
my $ldap = LDAP::ldap_connect();
|
||||
|
||||
my $dn = LDAP::search_dn($ldap, "ou=users", "uid=$login");
|
||||
|
||||
if (!LDAP::get_attribute($ldap, $dn, "mail")) {
|
||||
LDAP::add_attribute($ldap, $dn, "mail", "$login\@epita.fr");
|
||||
}
|
||||
|
||||
LDAP::add_attribute($ldap, $dn, "mailAlias", "$login\@$group.epita.fr");
|
||||
LDAP::update_attribute($ldap, $dn, "mailAccountActive", "yes");
|
||||
LDAP::add_attribute($ldap, $dn, "objectClass", "MailAccount");
|
||||
LDAP::add_attribute($ldap, $dn, "objectClass", "labAccount");
|
||||
|
||||
ACU::Log::do_info ("$login now grants to receive e-mail and connect in laboratory.");
|
||||
|
||||
$ldap->unbind or die ("couldn't disconnect correctly");
|
||||
}
|
||||
|
||||
sub cmd_account_mail(@)
|
||||
{
|
||||
return cmd_account_vieworchange('mail', 'mail', @_);
|
||||
@ -312,24 +317,24 @@ sub cmd_account_nopass($@)
|
||||
scope => "sub"
|
||||
);
|
||||
if ($mesg->code != 0) {
|
||||
do_err $mesg->error;
|
||||
ACU::Log::do_err ($mesg->error);
|
||||
}
|
||||
if ($mesg->count != 1) {
|
||||
do_err "User $login not found";
|
||||
ACU::Log::do_err ("User $login not found");
|
||||
}
|
||||
|
||||
my $pass = $mesg->entry(0)->get_value("userPassword");
|
||||
|
||||
if (! $pass || $pass eq "{crypt}!toto") {
|
||||
$mesg = $ldap->unbind;
|
||||
do_warn "Password already empty";
|
||||
ACU::Log::do_warn ("Password already empty");
|
||||
return 2;
|
||||
}
|
||||
else {
|
||||
printf(STDERR "Are you sure you want to reset password for $login? [y/N] ");
|
||||
if (getc(STDIN) ne "y") {
|
||||
do_debug "y response expected to continue; leaving.";
|
||||
do_warn "Password unchanged for $login.";
|
||||
ACU::Log::do_debug ("y response expected to continue; leaving.");
|
||||
ACU::Log::do_warn ("Password unchanged for $login.");
|
||||
return 2;
|
||||
}
|
||||
|
||||
@ -340,16 +345,16 @@ sub cmd_account_nopass($@)
|
||||
scope => "sub"
|
||||
);
|
||||
if ($mesg->code != 0) {
|
||||
do_err $mesg->error;
|
||||
ACU::Log::do_err ($mesg->error);
|
||||
}
|
||||
if ($mesg->count != 1) {
|
||||
do_err "User $login not found";
|
||||
ACU::Log::do_err ("User $login not found");
|
||||
}
|
||||
|
||||
$mesg->entry(0)->replace("userPassword" => "{crypt}!toto");
|
||||
$mesg->entry(0)->update($ldap);
|
||||
|
||||
do_info "$login have no more password.";
|
||||
ACU::Log::do_info ("$login have no more password.");
|
||||
|
||||
$ldap->unbind or die ("couldn't disconnect correctly");
|
||||
|
||||
@ -363,7 +368,7 @@ sub cmd_account_passgen($@)
|
||||
my $nb_char = shift // 10;
|
||||
|
||||
if ($nb_char < 10) {
|
||||
do_usage "lpt account <login> passgen [nb_char>=10]";
|
||||
ACU::Log::do_usage ("lpt account <login> passgen [nb_char>=10]");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -371,12 +376,12 @@ sub cmd_account_passgen($@)
|
||||
my $go = <STDIN>;
|
||||
chomp $go;
|
||||
if ($go ne "y" and $go ne "yes") {
|
||||
do_debug "y response expected to continue, leaving.";
|
||||
do_warn "Password unchanged for $login.";
|
||||
ACU::Log::do_debug ("y response expected to continue, leaving.");
|
||||
ACU::Log::do_warn ("Password unchanged for $login.");
|
||||
return 2;
|
||||
}
|
||||
|
||||
do_debug "Generating a $nb_char chars password...";
|
||||
ACU::Log::do_debug ("Generating a $nb_char chars password...");
|
||||
my $pass = "";
|
||||
open (HANDLE, "pwgen -s -n -c -y -1 $nb_char 1 |");
|
||||
while(<HANDLE>) {
|
||||
@ -385,7 +390,7 @@ sub cmd_account_passgen($@)
|
||||
close(HANDLE);
|
||||
chomp($pass);
|
||||
|
||||
do_debug "Setting $pass password to $login...";
|
||||
ACU::Log::do_debug ("Setting $pass password to $login...");
|
||||
if (cmd_account_password($login, $pass)) {
|
||||
return 3;
|
||||
}
|
||||
@ -400,7 +405,7 @@ sub cmd_account_password($@)
|
||||
my $login = shift;
|
||||
|
||||
if ($#_ > 0) {
|
||||
do_usage "lpt account <login> password [new_password]";
|
||||
ACU::Log::do_usage ("lpt account <login> password [new_password]");
|
||||
return 1;
|
||||
}
|
||||
my $pass = shift;
|
||||
@ -414,14 +419,14 @@ sub cmd_account_password($@)
|
||||
ReadMode("restore");
|
||||
print "\n";
|
||||
|
||||
do_debug "Read passwords: $pass1 and $pass2";
|
||||
ACU::Log::do_debug ("Read passwords: $pass1 and $pass2");
|
||||
|
||||
$pass1 eq $pass2 || do_err "Passwords did not match.";
|
||||
$pass1 eq $pass2 || ACU::Log::do_err ("Passwords did not match.");
|
||||
$pass = $pass1;
|
||||
}
|
||||
|
||||
if ($pass eq "") {
|
||||
do_err "Empty password refused.";
|
||||
ACU::Log::do_err ("Empty password refused.");
|
||||
}
|
||||
|
||||
chomp($pass);
|
||||
@ -442,10 +447,10 @@ sub cmd_account_password($@)
|
||||
scope => "sub"
|
||||
);
|
||||
if ($mesg->code != 0) {
|
||||
do_err $mesg->error;
|
||||
ACU::Log::do_err $mesg->error;
|
||||
}
|
||||
if ($mesg->count != 1) {
|
||||
do_err "User $login not found";
|
||||
ACU::Log::do_err ("User $login not found");
|
||||
}
|
||||
|
||||
$mesg->entry(0)->replace("userPassword" => $enc_password);
|
||||
@ -464,7 +469,7 @@ sub cmd_account_reopen(@)
|
||||
my $login = shift;
|
||||
|
||||
if ($#_ != -1) {
|
||||
do_usage ("<lpt> account <login> reopen");
|
||||
ACU::Log::do_usage ("<lpt> account <login> reopen");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -477,17 +482,17 @@ sub cmd_account_reopen(@)
|
||||
scope => "sub"
|
||||
);
|
||||
if ($mesg->code != 0) {
|
||||
do_err $mesg->error;
|
||||
ACU::Log::do_err ($mesg->error);
|
||||
}
|
||||
if ($mesg->count != 1) {
|
||||
do_err "User $login not found or multiple presence";
|
||||
ACU::Log::do_err ("User $login not found or multiple presence");
|
||||
}
|
||||
|
||||
if (grep { "epitaAccount" } $mesg->entry(0)->get_value("objectClass")) {
|
||||
# update password
|
||||
my $passwd = $mesg->entry(0)->get_value("userPassword");
|
||||
if ($passwd =~ /^\{[^\}]+\}!/) {
|
||||
do_info "Restoring password for $login ...";
|
||||
ACU::Log::do_info ("Restoring password for $login ...");
|
||||
|
||||
$passwd =~ s/^(\{[^\}]+\})!/$1/;
|
||||
|
||||
@ -499,11 +504,11 @@ sub cmd_account_reopen(@)
|
||||
$ldap->unbind or die ("couldn't disconnect correctly");
|
||||
|
||||
if (grep { "posixAccount" } $mesg->entry(0)->get_value("objectClass")) {
|
||||
do_debug "Setting shell for $login ...";
|
||||
ACU::Log::do_debug ("Setting shell for $login ...");
|
||||
cmd_account_shell($login, $shellValid);
|
||||
}
|
||||
|
||||
do_warn "Done. Don't forget to restart nscd on servers and workstations!";
|
||||
ACU::Log::do_warn ("Done. Don't forget to restart nscd on servers and workstations!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -531,7 +536,7 @@ sub cmd_account_multiple_vieworchange($$$@)
|
||||
my $change = shift;
|
||||
|
||||
if (($action ne "list" and $action ne "add" and $action ne "del" and $action ne "flush") or (!$change and $action ne "list" and $action ne "flush")) {
|
||||
do_usage "<lpt> account <login> $typeName [list|add|del|flush] [string]";
|
||||
ACU::Log::do_usage ("<lpt> account <login> $typeName [list|add|del|flush] [string]");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -545,14 +550,14 @@ sub cmd_account_multiple_vieworchange($$$@)
|
||||
scope => "sub"
|
||||
);
|
||||
if ($mesg->code != 0) {
|
||||
do_err $mesg->error;
|
||||
ACU::Log::do_err ($mesg->error);
|
||||
}
|
||||
if ($mesg->count != 1) {
|
||||
do_err "User $login not found or multiple presence";
|
||||
ACU::Log::do_err ("User $login not found or multiple presence");
|
||||
}
|
||||
|
||||
if ($action eq "add") {
|
||||
do_info "Adding $change as ".$typeName."s for $login ...";
|
||||
ACU::Log::do_info ("Adding $change as ".$typeName."s for $login ...");
|
||||
|
||||
my @data = $mesg->entry(0)->get_value($type);
|
||||
if (! grep(/^$change$/, @data)) {
|
||||
@ -560,42 +565,42 @@ sub cmd_account_multiple_vieworchange($$$@)
|
||||
$mesg->entry(0)->replace($type => \@data) or die $!;
|
||||
$mesg->entry(0)->update($ldap) or die $!;
|
||||
|
||||
do_info "Done!";
|
||||
ACU::Log::do_info ("Done!");
|
||||
}
|
||||
else {
|
||||
do_warn "$login has already $change $typeName.";
|
||||
ACU::Log::do_warn ("$login has already $change $typeName.");
|
||||
}
|
||||
}
|
||||
elsif ($action eq "del") {
|
||||
do_info "Checking if $change is a ".$typeName."s of $login ...";
|
||||
ACU::Log::do_info ("Checking if $change is a ".$typeName."s of $login ...");
|
||||
my @data = $mesg->entry(0)->get_value($type);
|
||||
if (grep(/^$change$/, @data)) {
|
||||
do_info "Deleting $change as $typeName for $login ...";
|
||||
ACU::Log::do_info ("Deleting $change as $typeName for $login ...");
|
||||
|
||||
@data = grep(!/$change$/, @data);
|
||||
|
||||
$mesg->entry(0)->replace($type => \@data) or die $!;
|
||||
$mesg->entry(0)->update($ldap) or die $!;
|
||||
|
||||
do_info "Done!";
|
||||
ACU::Log::do_info ("Done!");
|
||||
}
|
||||
else {
|
||||
do_warn "$change is not a $typeName for $login.";
|
||||
ACU::Log::do_warn ("$change is not a $typeName for $login.");
|
||||
}
|
||||
}
|
||||
elsif ($action eq "flush") {
|
||||
$ldap->modify($mesg->entry(0)->dn, delete => [$type]);
|
||||
do_info "$login have no more $typeName.";
|
||||
ACU::Log::do_info ("$login have no more $typeName.");
|
||||
}
|
||||
else {
|
||||
if ($mesg->entry(0)->get_value($type)) {
|
||||
do_info $login."'s ".$typeName."s are:";
|
||||
ACU::Log::do_info ($login."'s ".$typeName."s are:");
|
||||
for my $val ($mesg->entry(0)->get_value($type)) {
|
||||
say " - $val";
|
||||
}
|
||||
}
|
||||
else {
|
||||
do_info "$login have no $typeName.";
|
||||
ACU::Log::do_info ("$login have no $typeName.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -610,7 +615,7 @@ sub cmd_account_vieworchange($$@)
|
||||
my $login = shift;
|
||||
|
||||
if ($#_ > 0) {
|
||||
do_usage ("<lpt> account <login> $typeName [new_string]");
|
||||
ACU::Log::do_usage ("<lpt> account <login> $typeName [new_string]");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -627,22 +632,22 @@ sub cmd_account_vieworchange($$@)
|
||||
scope => "sub"
|
||||
);
|
||||
if ($mesg->code != 0) {
|
||||
do_err $mesg->error;
|
||||
ACU::Log::do_err ($mesg->error);
|
||||
}
|
||||
if ($mesg->count != 1) {
|
||||
do_err "User $login not found or multiple presence";
|
||||
ACU::Log::do_err ("User $login not found or multiple presence");
|
||||
}
|
||||
|
||||
if ($change) {
|
||||
do_info "Setting $typeName to $change for $login ...";
|
||||
ACU::Log::do_info ("Setting $typeName to $change for $login ...");
|
||||
|
||||
$mesg->entry(0)->replace($type => $change) or die $!;
|
||||
$mesg->entry(0)->update($ldap) or die $!;
|
||||
|
||||
do_info ("Done!");
|
||||
ACU::Log::do_info ("Done!");
|
||||
}
|
||||
else {
|
||||
do_info $login."'s $typeName is ".$mesg->entry(0)->get_value($type).".";
|
||||
ACU::Log::do_info ($login."'s $typeName is ".$mesg->entry(0)->get_value($type).".");
|
||||
}
|
||||
|
||||
$ldap->unbind or die ("couldn't disconnect correctly");
|
||||
@ -659,12 +664,12 @@ sub cmd_account_view($@)
|
||||
filter => "uid=$login",
|
||||
attrs => ['objectClass']);
|
||||
|
||||
$mesg->code && do_err $mesg->error;
|
||||
$mesg->code && ACU::Log::do_err ($mesg->error);
|
||||
if ($mesg->count <= 0) {
|
||||
do_err "No such account!";
|
||||
ACU::Log::do_err ("No such account!");
|
||||
}
|
||||
|
||||
do_debug "objectClasses:\t" . join(', ', $mesg->entry(0)->get_value("objectClass"));
|
||||
ACU::Log::do_debug ("objectClasses:\t" . join(', ', $mesg->entry(0)->get_value("objectClass")));
|
||||
|
||||
my @attrs = ['dn', 'ou'];
|
||||
if ($#_ >= 0) {
|
||||
@ -688,7 +693,7 @@ sub cmd_account_view($@)
|
||||
}
|
||||
}
|
||||
|
||||
do_debug "attrs to get: " . join(', ', @attrs);
|
||||
ACU::Log::do_debug ("attrs to get: " . join(', ', @attrs));
|
||||
$mesg = $ldap->search(base => "ou=users,dc=acu,dc=epita,dc=fr",
|
||||
filter => "uid=$login",
|
||||
attrs => \@attrs);
|
||||
@ -730,7 +735,7 @@ sub cmd_group(@)
|
||||
my $gname = shift;
|
||||
|
||||
if (! $gname) {
|
||||
do_usage "lpt group <group-name> <command> [arguments ...]";
|
||||
ACU::Log::do_usage ("lpt group <group-name> <command> [arguments ...]");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -741,7 +746,7 @@ sub cmd_group(@)
|
||||
-sections => [ 'GROUP COMMANDS' ] );
|
||||
}
|
||||
elsif (! exists $cmds_group{$subcmd}) {
|
||||
do_usage "Unknown command for group: ". $subcmd;
|
||||
ACU::Log::do_usage ("Unknown command for group: ". $subcmd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -752,7 +757,7 @@ sub cmd_group_list(@)
|
||||
{
|
||||
if ($#ARGV > 0)
|
||||
{
|
||||
do_usage ("<lpt> group list [group]");
|
||||
ACU::Log::do_usage ("<lpt> group list [group]");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -802,7 +807,7 @@ sub cmd_group_add(@)
|
||||
{
|
||||
if ($#ARGV < 1)
|
||||
{
|
||||
do_usage ("<lpt> group add <group> <login>");
|
||||
ACU::Log::do_usage ("<lpt> group add <group> <login>");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -852,7 +857,7 @@ sub cmd_group_remove(@)
|
||||
{
|
||||
if ($#ARGV < 1)
|
||||
{
|
||||
do_usage ("<lpt> group remove <group> <login>");
|
||||
ACU::Log::do_usage ("<lpt> group remove <group> <login>");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -908,7 +913,7 @@ sub cmd_group_create($$)
|
||||
{
|
||||
if ($#_ != 1)
|
||||
{
|
||||
do_usage ("<lpt> group create <yaka|acu> <year>");
|
||||
ACU::Log::do_usage ("<lpt> group create <yaka|acu> <year>");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -923,7 +928,7 @@ sub cmd_group_create($$)
|
||||
$gid = $year - 1000;
|
||||
}
|
||||
else {
|
||||
do_err "Error: type must be acu or yaka!";
|
||||
ACU::Log::do_err ("Error: type must be acu or yaka!");
|
||||
}
|
||||
|
||||
my $ldap = LDAP::ldap_connect();
|
||||
@ -939,14 +944,14 @@ sub cmd_group_create($$)
|
||||
|
||||
$ldap->unbind or die ("couldn't disconnect correctly");
|
||||
|
||||
do_info "group added: $cn";
|
||||
ACU::Log::do_info ("group added: $cn");
|
||||
}
|
||||
|
||||
sub cmd_group_delete(@)
|
||||
{
|
||||
if ($#ARGV != 1)
|
||||
{
|
||||
do_usage ("<lpt> group delete <yaka|acu> <year>");
|
||||
ACU::Log::do_usage ("<lpt> group delete <yaka|acu> <year>");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -971,7 +976,7 @@ sub cmd_list(@)
|
||||
-sections => [ 'LIST COMMANDS' ] );
|
||||
}
|
||||
elsif (! exists $cmds_list{$subcmd}) {
|
||||
do_usage "Unknown command for list: ". $subcmd;
|
||||
ACU::Log::do_usage ("Unknown command for list: ". $subcmd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -982,7 +987,7 @@ sub cmd_list_accounts(@)
|
||||
{
|
||||
if ($#_ > 1)
|
||||
{
|
||||
do_usage ("<lpt> list account [open|close|services]");
|
||||
ACU::Log::do_usage ("<lpt> list account [open|close|services]");
|
||||
exit(1);
|
||||
}
|
||||
my $action = shift;
|
||||
@ -997,7 +1002,7 @@ sub cmd_list_accounts(@)
|
||||
attrs => [ 'dn', 'userPassword' ]);
|
||||
$mesg->code && die $mesg->error;
|
||||
if ($mesg->count == 0) {
|
||||
do_warn "No account found";
|
||||
ACU::Log::do_warn ("No account found");
|
||||
}
|
||||
else {
|
||||
for my $entry ($mesg->entries) {
|
||||
@ -1017,7 +1022,7 @@ sub cmd_list_accounts(@)
|
||||
attrs => [ 'userPassword' ]);
|
||||
$mesg->code && die $mesg->error;
|
||||
if ($mesg->count == 0) {
|
||||
do_warn "No account found";
|
||||
ACU::Log::do_warn ("No account found");
|
||||
}
|
||||
else {
|
||||
for my $entry ($mesg->entries) {
|
||||
@ -1039,7 +1044,7 @@ sub cmd_list_accounts(@)
|
||||
attrs => [ 'uid', 'labService' ]);
|
||||
$mesg->code && die $mesg->error;
|
||||
if ($mesg->count == 0) {
|
||||
do_warn "No account found!";
|
||||
ACU::Log::do_warn ("No account found!");
|
||||
}
|
||||
else {
|
||||
for my $entry ($mesg->entries) {
|
||||
@ -1114,7 +1119,7 @@ sub cmd_account_quota_set($@)
|
||||
|
||||
if ($#_ > 2)
|
||||
{
|
||||
do_usage ("<lpt> account <login> quota <volume> <type> <value>");
|
||||
ACU::Log::do_usage ("<lpt> account <login> quota <volume> <type> <value>");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1124,10 +1129,10 @@ sub cmd_account_quota_set($@)
|
||||
|
||||
# check args
|
||||
if (!($volume eq "home" || $volume eq "sgoinfre")) {
|
||||
do_err("Volume must be home or sgoinfre; given: $volume");
|
||||
ACU::Log::do_err("Volume must be home or sgoinfre; given: $volume");
|
||||
}
|
||||
if (!($type eq "file" || $type eq "block")) {
|
||||
do_err("Type must be file or block; given: $type");
|
||||
ACU::Log::do_err("Type must be file or block; given: $type");
|
||||
}
|
||||
|
||||
# generate quotaName
|
||||
@ -1146,8 +1151,8 @@ sub cmd_account_quota_set($@)
|
||||
attrs => [ $quotaName ],
|
||||
scope => "sub"
|
||||
);
|
||||
if ($mesg->code != 0) { do_err($mesg->error); }
|
||||
if ($mesg->count != 1) { do_err("user $login not found or multiple presence"); }
|
||||
if ($mesg->code != 0) { ACU::Log::do_err($mesg->error); }
|
||||
if ($mesg->count != 1) { ACU::Log::do_err("user $login not found or multiple presence"); }
|
||||
|
||||
my $old_value = $mesg->entry(0)->get_value($quotaName);
|
||||
if (!$old_value) {
|
||||
@ -1177,17 +1182,17 @@ sub cmd_account_quota_set($@)
|
||||
$value = $old_value - $t;
|
||||
}
|
||||
elsif ($value !~ /^[0-9]+$/) {
|
||||
do_err "Value must be an integer or +i or -i";
|
||||
ACU::Log::do_err ("Value must be an integer or +i or -i");
|
||||
}
|
||||
|
||||
do_info "Changing quota of $quotaName of $login to $value...";
|
||||
ACU::Log::do_info ("Changing quota of $quotaName of $login to $value...");
|
||||
|
||||
$mesg->entry(0)->replace($quotaName => $value) or die $!;
|
||||
$mesg->entry(0)->update($ldap) or die $!;
|
||||
|
||||
$ldap->unbind;
|
||||
|
||||
do_info "Done!";
|
||||
ACU::Log::do_info ("Done!");
|
||||
}
|
||||
|
||||
sub cmd_account_quota_sync($;$)
|
||||
@ -1204,7 +1209,7 @@ sub cmd_account_quota_sync($;$)
|
||||
'quotaSgoinfreBlock', 'quotaSgoinfreFile' ]
|
||||
);
|
||||
$mesg->code && die $mesg->error;
|
||||
$mesg->count == 1 || do_err "User $login not found or multiple presence";
|
||||
$mesg->count == 1 || ACU::Log::do_err ("User $login not found or multiple presence");
|
||||
|
||||
my $quotaHomeBlock = $mesg->entry(0)->get_value("quotaHomeBlock") // $def_quota{block}{home};
|
||||
my $quotaHomeFile = $mesg->entry(0)->get_value("quotaHomeFile") // $def_quota{file}{home};
|
||||
@ -1213,10 +1218,10 @@ sub cmd_account_quota_sync($;$)
|
||||
|
||||
if (Quota::setqlim($dev_quota{home}, $mesg->entry(0)->get_value("uidNumber"), int(0.9 * $quotaHomeBlock), $quotaHomeBlock, int(0.9 * $quotaHomeFile), $quotaHomeFile, 1, 0) == 0 and
|
||||
Quota::setqlim($dev_quota{sgoinfre}, $mesg->entry(0)->get_value("uidNumber"), int(0.9 * $quotaHomeBlock), $quotaHomeBlock, int(0.9 * $quotaHomeFile), $quotaHomeFile, 1, 0) == 0) {
|
||||
do_info $login."'s quota synchronized!";
|
||||
ACU::Log::do_info ($login."'s quota synchronized!");
|
||||
}
|
||||
else {
|
||||
do_err "An error occurs during quota synchronization:";
|
||||
ACU::Log::do_err ("An error occurs during quota synchronization:");
|
||||
Quota::strerr();
|
||||
return 2;
|
||||
}
|
||||
@ -1500,18 +1505,18 @@ if ($#ARGV == -1) {
|
||||
my $cmd = shift;
|
||||
|
||||
if ($cmd eq "-v" or $cmd eq "--verbose" or $cmd eq "--debug") {
|
||||
$debug = 1;
|
||||
$ACU::Log::debug = 1;
|
||||
$cmd = shift;
|
||||
}
|
||||
elsif ($cmd eq "-f" or $cmd eq "--force") {
|
||||
$verbosity = 0;
|
||||
$ACU::Log::verbosity = 0;
|
||||
$cmd = shift;
|
||||
}
|
||||
|
||||
if (! exists $cmds{$cmd})
|
||||
{
|
||||
say BOLD, "Usage: ", RESET, "$0 ", GREEN, "command", RESET, " <arguments>";
|
||||
do_err("Uknown command : $cmd");
|
||||
ACU::Log::do_err("Uknown command : $cmd");
|
||||
}
|
||||
|
||||
exit ($cmds{$cmd}(@ARGV));
|
||||
@ -1552,10 +1557,12 @@ B<lpt account> <login> [I<view>]
|
||||
|
||||
<login> can be a globbing string.
|
||||
|
||||
B<lpt account> <login> I<create> <group> <uid> <Prenom> <Nom> [nopass|password|passgen]
|
||||
B<lpt account> <login> I<create> <promo> <uid> <Prenom> <Nom> [nopass|password|passgen]
|
||||
|
||||
This is used to create a new Epita account, base for intra and/or lab account.
|
||||
|
||||
Promo for professor are professors, other people are guests.
|
||||
|
||||
B<lpt account> <login> I<nopass>
|
||||
|
||||
This is used to erase the userPassword.
|
||||
|
Reference in New Issue
Block a user