epita-std
/
ACU
Archived
1
0
Fork 0

lpt: new command account add to import account information from passwd like file. Closes #22244

This commit is contained in:
Mercier Pierre-Olivier 2014-01-12 06:27:12 +01:00
parent e9ea5fc3a5
commit 6e70dc24ff
1 changed files with 47 additions and 1 deletions

View File

@ -73,6 +73,7 @@ my %cmds =
my %cmds_account =
(
"add" => \&cmd_account_add,
"alias" => \&cmd_account_alias,
"close" => \&cmd_account_close,
"cn" => \&cmd_account_cn,
@ -250,6 +251,45 @@ sub cmd_account_cn($@)
return cmd_account_vieworchange('cn', 'name', @_);
}
sub cmd_account_add($@)
{
my $login = shift;
my $passwd_path = shift // "./passwd";
if (! -f $passwd_path)
{
log(USAGE, "lpt account <login> add [./passwd] [nopass|passgen|password]");
return 1;
}
open my $fh, "<", $passwd_path;
my @passwd_cnt = <$fh>;
close($fh);
for my $line (grep { /^$login:x/ } @passwd_cnt)
{
if ($line =~ /^$login:x:([0-9]+):([0-9]+):([^ :]+) ?([^:]*):/)
{
my $uid = $1;
my $gid = $2;
my $firstname = ucfirst $3;
my $lastname = ucfirst $4;
if (! $noconfirm)
{
say "Add user: ", YELLOW, BOLD, "$login", RESET, ":\n\tFirstname: ", BOLD, $firstname, RESET, "\n\tLastname: ", BOLD, $lastname, RESET, "\n\tUID:\t", BOLD, $uid, RESET, "\n\tGroup:\t", BOLD, $gid, RESET;
print "Would you like to add this user? [", GREEN, "y", RESET, "/", RED, "N", RESET, "] ";
my $go = <STDIN>;
chomp $go;
next if ($go ne "y" and $go ne "yes");
}
cmd_account_create($login, $gid, $uid, $firstname, $lastname, @_);
}
}
}
sub cmd_account_create($@)
{
my $login = shift;
@ -299,7 +339,7 @@ sub cmd_account_create($@)
if ($mesg->code == 0)
{
log(INFO, "Account added: $login");
my $pass = shift;
my $pass = shift // "nopass";
return cmd_account($login, $pass, @_) if ($pass ne "nopass");
return 0;
}
@ -1950,6 +1990,12 @@ B<lpt account> <login> [I<view> [I<attribute> [I<attribute> [...]]]]
If <attribute> are given, display only those attributes.
B<lpt account> <login> I<add> [./passwd] [nopass|password|passgen]
This is used to create a new Epita account, base for intra and/or lab account.
This will use the passwd file given in argument to import information about the login.
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.