diff options
author | Guilhem Moulin <guilhem.moulin@fripost.org> | 2012-09-05 23:39:09 +0200 |
---|---|---|
committer | Guilhem Moulin <guilhem.moulin@fripost.org> | 2012-09-06 00:04:11 +0200 |
commit | 0dfeabffccf3695f5f270964aa8ef8e3460ae440 (patch) | |
tree | 62bdc5ff80984a96576827a328ab9866d2d8a7be | |
parent | b4f952a0e374dd02ec4cdf940a8fadf8f537f433 (diff) |
Factorization
-rw-r--r-- | lib/FPanel/Interface.pm | 93 |
1 files changed, 28 insertions, 65 deletions
diff --git a/lib/FPanel/Interface.pm b/lib/FPanel/Interface.pm index f9a1358..1c1f9ee 100644 --- a/lib/FPanel/Interface.pm +++ b/lib/FPanel/Interface.pm @@ -100,7 +100,7 @@ sub ListLocals : Runmode { ); die "404\n" if $domains->code; # The following is not supposed to happen. - die "Error: Multible matching entries found." if $domains->count > 1; + die "Error: Multiple matching entries found." if $domains->count > 1; my $domain = $domains->pop_entry or die "404\n"; @@ -184,7 +184,6 @@ sub ListLocals : Runmode { # Can the user add aliases? $template->param( CANADDALIAS => $perms =~ /[aop]/ ); # Should we list aliases? - $template->param( LISTMAILBOXES => $mailboxes->count || $perms =~ /p/ ); $template->param( LISTALIASES => $aliases->count || $perms =~ /[aop]/ ); $template->param( ALIASES => [ map { { ALIAS => $_->get_value('fva') @@ -246,26 +245,10 @@ sub EditDomain : Runmode { # Changes have been submitted: process them my %changes; my $q = $self->query; - if (defined $q->param('status')) { - $changes{fripostIsStatusActive} = $q->param('status') eq 'active' ? + $changes{fripostIsStatusActive} = $q->param('status') eq 'active' ? 'TRUE' : 'FALSE'; - } - if (defined $q->param('description')) { - my @desc; - foreach my $d (split /\n/, $q->param('description')) { - push @desc, $d; - } - $changes{description} = [ @desc ]; - } - if (defined $q->param('maildrop')) { - my @maildrop; - foreach my $d (split /\n/, $q->param('maildrop')) { - $d =~ s/\s//g; # lowercase and strip out the spaces - push @maildrop, (lc $d) unless $d =~ /^$/; - } - $changes{fripostOptionalMaildrop} = [ @maildrop ]; - } - + $changes{description} = [ split /\n/, $q->param('description') ]; + $changes{fripostOptionalMaildrop} = [ &form2EmailList($q->param('maildrop')) ]; my $mesg = $ldap->modify( "fvd=$domainname,$suffix", replace => \%changes ); $error = $mesg->error if $mesg->code; @@ -278,7 +261,7 @@ sub EditDomain : Runmode { ); die "404\n" if $domains->code; # The following is not supposed to happen. - die "Error: Multible matching entries found." if $domains->count > 1; + die "Error: Multiple matching entries found." if $domains->count > 1; my $domain = $domains->pop_entry or die "404\n"; $ldap->unbind; @@ -350,26 +333,12 @@ sub EditLocal : Runmode { } } - if (defined $q->param('maildrop')) { - my @maildrop; - foreach my $d (split /\n/, $q->param('maildrop')) { - $d =~ s/\s//g; # lowercase and strip out the spaces - push @maildrop, (lc $d) unless $d =~ /^$/; - } - $changes{fripostOptionalMaildrop} = [ @maildrop ]; - } + $changes{fripostOptionalMaildrop} = [ &form2EmailList($q->param('maildrop')) ]; } elsif ($t eq 'alias') { $t2 = 'fva'; - if (defined $q->param('maildrop')) { - my @maildrop; - foreach my $d (split /\n/, $q->param('maildrop')) { - $d =~ s/\s//g; # lowercase and strip out the spaces - push @maildrop, (lc $d) unless $d =~ /^$/; - } - $changes{fripostMaildrop} = [ @maildrop ]; - } + $changes{fripostMaildrop} = [ &form2EmailList($q->param('maildrop')) ]; } elsif ($t eq 'list') { @@ -381,17 +350,9 @@ sub EditLocal : Runmode { } # Global parameters - if (defined $q->param('status')) { - $changes{fripostIsStatusActive} = $q->param('status') eq 'active' ? + $changes{fripostIsStatusActive} = $q->param('status') eq 'active' ? 'TRUE' : 'FALSE'; - } - if (defined $q->param('description')) { - my @desc; - foreach my $d (split /\n/, $q->param('description')) { - push @desc, $d; - } - $changes{description} = [ @desc ]; - } + $changes{description} = [ split /\n/, $q->param('description') ]; unless (defined $error) { my $mesg = $ldap->modify( "$t2=$localname,fvd=$domainname,$suffix", @@ -420,7 +381,7 @@ sub EditLocal : Runmode { ); die "404\n" if $locals->code; # The following is not supposed to happen. - die "Error: Multible matching entries found." if $locals->count > 1; + die "Error: Multiple matching entries found." if $locals->count > 1; my $local = $locals->pop_entry or die "404\n"; my $template; @@ -477,22 +438,11 @@ sub AddLocal : Runmode { $new{fripostIsStatusActive} = $q->param('status') eq 'active' ? 'TRUE' : 'FALSE'; $new{fripostOwner} = $authzDN; - if (defined $q->param('description')) { - my @desc; - foreach my $d (split /\n/, $q->param('description')) { - push @desc, $d; - } - $new{description} = [ @desc ] if @desc; - } - if (defined $q->param('maildrop')) { - my @maildrop; - foreach my $d (split /\n/, $q->param('maildrop')) { - $d =~ s/\s//g; # lowercase and strip out the spaces - push @maildrop, (lc $d) unless $d =~ /^$/; - } - $new{fripostMaildrop} = [ @maildrop ] if @maildrop; + my @desc = split /\n/, $q->param('description'); + $new{description} = [ @desc ] if @desc; + my @maildrop = &form2EmailList($q->param('maildrop')); + $new{fripostMaildrop} = [ @maildrop ] if @maildrop; - } # TODO: more checks my $mesg = $ldap->add( "fva=$localname,fvd=$domainname,$suffix", attrs => [ %new ] ); @@ -530,7 +480,7 @@ sub list_perms_long { my $perms = &list_perms(@_); if ( $perms =~ /a/) { - return 'can create aliases & lists' if ( $perms =~ /l/); + return 'can create aliases & lists' if $perms =~ /l/; return 'can create aliases'; } elsif ( $perms eq 'l' ) { @@ -596,6 +546,19 @@ sub dn2email { } +# Produces an e-mail list from a form: split the new lines and strip out +# the spaces. +sub form2EmailList { + my $str = shift; + my @list; + foreach my $e (split /\n/, $str) { + $e =~ s/\s//g; + push @list, $e unless $e =~ /^$/; + } + return @list; +} + + =head1 AUTHOR Guilhem Moulin C<< <guilhem at fripost.org> >> |