From fa54d2e280094036f7554b525a2765b8caa4ca42 Mon Sep 17 00:00:00 2001 From: Thomas Constans Date: Thu, 24 Oct 2019 22:08:21 +0200 Subject: [PATCH] support csv en utf8 remplacement phonenumber par attribut standard telephoneNumber verification definition mot de passe --- add_attribute.pl | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/add_attribute.pl b/add_attribute.pl index 13fe671..d62cbb7 100644 --- a/add_attribute.pl +++ b/add_attribute.pl @@ -29,14 +29,15 @@ if( $file =~ /entreprise/i ) { else{ die "Unknown branch\n" ; } -open(my $data, '<', $file) or die "Could not open '$file' $!\n"; +open(my $data, '<:encoding(utf8)', $file) or die "Could not open '$file' $!\n"; my @cols = @{$csv->getline ($data)}; my $row = {} ; $csv->bind_columns (\@{$row}{@cols}); +foreach my $c( @cols) { print ">".$c."<\n" ; } while ($csv->getline ($data)) { my $dn = $row->{dn} ; - if ( $dn =~ /^dn / ) { next ; } - my $idTechnique = $row->{idTechnique} ? $row->{idTechnique} : "UNDEFINED" ; + if ( $dn =~ /^dn/ ) { warn "next" ; next ; } + my $idTechnique = $row->{idTechnique} ? $row->{idTechnique} : "" ; my $question1 = $row->{question1} ? $row->{question1} : "UNDEFINED" ; my $question2 = $row->{question2} ? $row->{question2} : "UNDEFINED" ; my $question3 = $row->{question3} ? $row->{question3} : "UNDEFINED" ; @@ -45,18 +46,22 @@ while ($csv->getline ($data)) { my $reponse3 = $row->{reponse3} ? $row->{reponse3} : "UNDEFINED" ; my $siren = $row->{siren} ? $row->{siren} : "UNDEFINED" ; my $civilite = $row->{civilite} ? $row->{civilite} : "UNDEFINED" ; - my $phoneNumber = $row->{phoneNumber} ? $row->{phoneNumber} : "UNDEFINED" ; + my $phoneNumber = $row->{telephoneNumber} ? $row->{telephoneNumber} : "UNDEFINED" ; my $birthDate = $row->{birthDate} ? $row->{birthDate} : "UNDEFINED" ; my $userPassword = $row->{userPassword} ; - my $userPassword = `slappasswd -n -s $userPassword` ; + if ( $userPassword ) { $userPassword= `slappasswd -n -s $userPassword` ; } + warn "$dn\n" ; my $mesg = $ldap -> search( scope => 'base', attrs => ['1.1'], filter => '(objectClass=klesiaentreprise)', base => $dn, ); + $mesg->code and warn $dn."\t".$mesg->error; + if( $mesg-> count() == 0 ) { + warn "Add klesia OC\n" ; my $mesg = $ldap-> modify( $dn, add => { objectClass => 'klesiaentreprise', @@ -64,6 +69,7 @@ while ($csv->getline ($data)) { } # add common attributes + warn "Add common attributes\n" ; my $mesg = $ldap-> modify( $dn, changes=> [ replace => [ 'idTechnique' => $idTechnique ], @@ -81,6 +87,7 @@ while ($csv->getline ($data)) { # add entreprise specific attributes if( $isEnt ){ + warn "Add enterprise specific attributes\n" ; my $mesg = $ldap-> modify( $dn, changes=> [ replace => [ 'siren' => $siren], @@ -90,10 +97,11 @@ while ($csv->getline ($data)) { } # add people specific attributes if( $isPeople ){ + warn "Add people specific attributes\n" ; my $mesg = $ldap-> modify( $dn, changes=> [ replace => [ 'birthDate' => $birthDate], - replace => [ 'phoneNumber' => $phoneNumber], + replace => [ 'telephoneNumber' => $phoneNumber], ] ) ; $mesg->code and warn $dn."\t".$mesg->error;