diff --git a/report_acl.pl b/report_acl.pl index b1b7161..2bdb1d0 100644 --- a/report_acl.pl +++ b/report_acl.pl @@ -1 +1,67 @@ -init +#!/usr/bin/perl -w +use strict; +use esmith::AccountsDB; + +my $a = esmith::AccountsDB->open_ro() || die "Couldn't open the accounts database"; + +sub uniq { + my %seen; + grep !$seen{$_}++, @_; +} + +print "\n\n\n" . '================================' . "\n\n\n"; +print "\n" . '^ Dossier partagés ^ Accès en ecriture ^ Accès en lecture seule ^' . "\n"; + +foreach my $share ($a->get_all_by_prop(type => 'share')) { + print "\n\n" . '---------' . "\n\n"; + my $name = $share->key; + my $wu = $share->prop('WriteUsers'); + my $wg = $share->prop('WriteGroups'); + my $ru = $share->prop('ReadUsers'); + my $rg = $share->prop('ReadGroups'); + foreach my $wgroup (split(/,/, $wg)) { + my $rec_wg = $a->get($wgroup); + my $wg_members = $rec_wg->prop('Members'); + my @acces_members_rw = split(/,/, $wg_members . "," . $wu); + my @acces_members_rw_filtered = uniq(@acces_members_rw); + my @list_rw; + foreach my $user_rw (@acces_members_rw_filtered) { + my $urw = $a->get($user_rw); + my $lock_rw = $urw->prop('PasswordSet'); + if ($lock_rw eq 'no') { + push @list_rw, "" . $user_rw . ""; + } + else { + push @list_rw, $user_rw; + } + } + print "\nShare Folder : " . $name . "\n"; + print "\nListe RW :\n"; + print @list_rw; + } + + foreach my $rgroup (split(/,/, $rg)) { + my $rec_rg = $a->get($rgroup); + my $rg_members = $rec_rg->prop('Members'); + my @acces_members_ro = split(/,/, $rg_members . "," . $ru); + my @acces_members_ro_filtered = uniq(@acces_members_ro); + my @list_ro; + foreach my $user_ro (@acces_members_ro_filtered) { + my $uro = $a->get($user_ro); + my $lock_ro = $uro->prop('PasswordSet'); + if ($lock_ro eq 'no') { + push @list_ro, "" . $user_ro . ""; + } + else { + push @list_ro, $user_ro; + } + } + print "\nShare Folder : " . $name . "\n"; + print "\nListe RO :\n"; + print @list_ro; + } +} + +# print "^ " . $name . " | Accès en ecriture | Accès en lecture seule |" . "\n\n"; + +print "\n\n\n" . '================================' . "\n\n\n";