manage multiple groups

pull/1/head
Paolo Asperti 6 years ago
parent b731b3382d
commit ebcd35d691
  1. 10
      README.md
  2. 20
      importa_utenti.pl
  3. 11
      test.csv

@ -2,18 +2,16 @@
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.
Beware that Microsoft Excel uses the semicolon (;) as a separator instead the comma (,) for a CSV file (COMMA separated value).
Beware that Microsoft Excel uses the semicolon (;) as a separator instead the comma (,) for a CSV file (COMMA separated value).
To import, simply call the script, by passing the CSV file as a parameter and the separator as the second parameter.
./importa_utenti.pl test.CSV
./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,8 +79,10 @@ 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');
print $pfh $password;

@ -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

1 utente1 utente1 Nome1 Cognome1 alsdlajsd utonti1 lusers1 everybody Nome1 Cognome1 utonti1 alsdlajsd
2 utente2 utente2 Nome2 Cognome2 alsdlajsd utonti1 everybody Nome2 Cognome2 utonti1 alsdlajsd
3 utente3 utente3 Nome3 Cognome3 alsdlajsd lusers1 everybody Nome3 Cognome3 lusers1 alsdlajsd
4 utente4 utente4 Nome4 Cognome4 alsdlajsd lusers4 lusers1 everybody Nome4 Cognome4 lusers4 alsdlajsd
5 utente5 utente5 Nome5 Cognome5 alsdlajsd lusers4 everybody Nome5 Cognome5 lusers4 alsdlajsd
Loading…
Cancel
Save