manage multiple groups
This commit is contained in:
parent
b731b3382d
commit
ebcd35d691
@ -2,7 +2,7 @@
|
||||
Batch import a lot of users and groups.
|
||||
You need a CSV file with this layout:
|
||||
|
||||
username Firstname Lastname group password
|
||||
username Firstname Lastname password group1 [group2] [group3] [groupN]
|
||||
|
||||
See test.csv file for a sample.
|
||||
You can use the TAB as a separator (this is the default), or whatever character you want.
|
||||
@ -14,6 +14,4 @@ To import, simply call the script, by passing the CSV file as a parameter and th
|
||||
./importa_utenti.pl test.CSV ";"
|
||||
./importa_utenti.pl test.CSV ","
|
||||
|
||||
The import process will create all non-existing groups. If the user already exists then the line is skipped (so if you specified a nonexistent group for this user, the group won't be created).
|
||||
|
||||
|
||||
The import process will create all non-existing groups. If the user already exists then the line is skipped (so if you specify a nonexistent group for this user, the group won't be created).
|
||||
|
@ -32,7 +32,7 @@ while(<FH>) {
|
||||
chomp $_;
|
||||
$_ =~ s/\s+$//;
|
||||
|
||||
my ($username, $firstName, $lastName, $group, $password) = split(/$separator/, $_);
|
||||
my ($username, $firstName, $lastName, $password, @groups) = split(/$separator/, $_);
|
||||
|
||||
if( ! $username) {
|
||||
next;
|
||||
@ -53,11 +53,13 @@ while(<FH>) {
|
||||
next;
|
||||
}
|
||||
|
||||
if(!$accountsDb->get($group)) {
|
||||
my $groupRecord = $accountsDb->new_record($group, {
|
||||
'type' => 'group'
|
||||
});
|
||||
warn "[INFO] created group $group.\n";
|
||||
foreach my $group (@groups) {
|
||||
if(!$accountsDb->get($group)) {
|
||||
my $groupRecord = $accountsDb->new_record($group, {
|
||||
'type' => 'group'
|
||||
});
|
||||
warn "[INFO] created group $group.\n";
|
||||
}
|
||||
}
|
||||
|
||||
my $record = $accountsDb->new_record($username, {
|
||||
@ -77,7 +79,9 @@ while(<FH>) {
|
||||
next;
|
||||
}
|
||||
|
||||
$accountsDb->add_user_to_groups($username, $group);
|
||||
foreach my $group (@groups) {
|
||||
$accountsDb->add_user_to_groups($username, $group);
|
||||
}
|
||||
|
||||
if($password) {
|
||||
my ($pfh, $pfilename) = tempfile('import_users_XXXXX', UNLINK=>0, DIR=>'/tmp');
|
||||
|
11
test.csv
11
test.csv
@ -1,6 +1,5 @@
|
||||
utente1 Nome1 Cognome1 utonti1 alsdlajsd
|
||||
utente2 Nome2 Cognome2 utonti1 alsdlajsd
|
||||
utente3 Nome3 Cognome3 lusers1 alsdlajsd
|
||||
utente4 Nome4 Cognome4 lusers4 alsdlajsd
|
||||
utente5 Nome5 Cognome5 lusers4 alsdlajsd
|
||||
|
||||
utente1 Nome1 Cognome1 alsdlajsd utonti1 lusers1 everybody
|
||||
utente2 Nome2 Cognome2 alsdlajsd utonti1 everybody
|
||||
utente3 Nome3 Cognome3 alsdlajsd lusers1 everybody
|
||||
utente4 Nome4 Cognome4 alsdlajsd lusers4 lusers1 everybody
|
||||
utente5 Nome5 Cognome5 alsdlajsd lusers4 everybody
|
||||
|
|
Loading…
x
Reference in New Issue
Block a user