From b4e2151a91eb827bc90a44a906f7a7c40fde95c7 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Tue, 4 Sep 2012 01:29:39 +0200 Subject: List mailboxes, aliases, and lists --- lib/FPanel/Interface.pm | 130 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 126 insertions(+), 4 deletions(-) (limited to 'lib/FPanel/Interface.pm') diff --git a/lib/FPanel/Interface.pm b/lib/FPanel/Interface.pm index b1b7fe5..f73b5de 100644 --- a/lib/FPanel/Interface.pm +++ b/lib/FPanel/Interface.pm @@ -35,6 +35,9 @@ sub ListDomains : StartRunmode { , scope => 'one' , filter => 'objectClass=FripostVirtualDomain' , deref => 'never' + , attrs => [ qw/fvd description fripostIsStatusActive + fripostCanCreateAlias fripostCanCreateList + fripostOwner fripostPostmaster/ ] ); die $domains->error if $domains->code; $ldap->unbind; @@ -57,6 +60,120 @@ sub ListDomains : StartRunmode { return $template->output; } + +# This Run Mode lists the known aliases, users and lists in the current +# domain. +sub ListLocals : Runmode { + my $self = shift; + my %CFG = $self->cfg; + my $suffix = join ',', @{$CFG{ldap_suffix}}; + + my ($l,$d) = split /@/, $self->authen->username, 2; + my $authzDN = "fvu=$l,fvd=$d,". $suffix; + my $ldap = $self->ldap_from_auth_user($authzDN); + + my $domainname = (split /\//, $ENV{PATH_INFO}, 3)[1]; + + my $answer = $ldap->search( base => "fvd=$domainname,$suffix" + , scope => 'base' + , filter => 'objectClass=FripostVirtualDomain' + , deref => 'never' + , attrs => [ qw/fvd description fripostIsStatusActive + fripostOptionalMaildrop + fripostOwner fripostPostmaster/ ] + ); + die $answer->error if $answer->code; + my $domain = $answer->entry('0'); + + my $canedit = 0; + foreach (qw/fripostOwner fripostPostmaster/) { + my $x = $domain->get_value($_, asref=>1); + if (defined $x and grep { $_ eq $authzDN} @$x) { + $canedit = 1; + last; + } + } + + + my $mailboxes = $ldap->search( base => "fvd=$domainname,$suffix" + , scope => 'one' + , filter => 'objectClass=FripostVirtualMailbox' + , deref => 'never' + , attrs => [ qw/fvu description + fripostIsStatusActive + fripostOptionalMaildrop + fripostMailboxQuota/ ] + ); + die $mailboxes->error if $mailboxes->code; + + my $aliases = $ldap->search( base => "fvd=$domainname,$suffix" + , scope => 'one' + , filter => 'objectClass=FripostVirtualAlias' + , deref => 'never' + , attrs => [ qw/fva description + fripostIsStatusActive + fripostOwner + fripostMaildrop/ ] + ); + die $aliases->error if $aliases->code; + + my $lists = $ldap->search( base => "fvd=$domainname,$suffix" + , scope => 'one' + , filter => 'objectClass=FripostVirtualList' + , deref => 'never' + , attrs => [ qw/fvl description + fripostIsStatusActive + fripostOwner + fripostListManager/ ] + ); + die $lists->error if $lists->code; + + $ldap->unbind; + + my $template = $self->load_tmpl( 'list-locals.html', cache => 1, utf8 => 1 + , loop_context_vars => 1 + , global_vars => 1 ); + $template->param( URL => $self->query->url ); + $template->param( DOMAIN => $domainname ); + $template->param( USER_LOCALPART => $l, USER_DOMAINPART => $d); + $template->param( DESCRIPTION => join ("\n", $domain->get_value('description')) ); + $template->param( ISACTIVE => $domain->get_value('fripostIsStatusActive') eq 'TRUE' ? 1 : 0 ); + $template->param( CANEDIT => $canedit ); + $template->param( MAILBOXES => [ + map { { USER => $_->get_value('fvu') + , DESCRIPTION => join ("\n", $_->get_value('description')) + , ISACTIVE => $_->get_value('fripostIsStatusActive') eq 'TRUE' ? 1 : 0 + , FORWARDS => [ map { {FORWARD => $_} } $_->get_value('fripostOptionalMaildrop') ] + , QUOTA => $_->get_value('fripostMailboxQuota') // '' + }; + } + $mailboxes->sorted('fvu') + ]); + $template->param( ALIASES => [ + map { { ALIAS => $_->get_value('fva') + , DESCRIPTION => join ("\n", $_->get_value('description')) + , ISACTIVE => $_->get_value('fripostIsStatusActive') eq 'TRUE' ? 1 : 0 + , OWNERS => [ map { {OWNER => &dn2email($_)} } $_->get_value('fripostOwner') ] + , DESTINATIONS => [ map { {DESTINATION => $_} } $_->get_value('fripostMaildrop') ] + }; + } + $aliases->sorted('fva') + ]); + $template->param( CATCHALLS => [ map { {CATCHALL => $_} } $domain->get_value('fripostOptionalMaildrop') ] ); + $template->param( LISTS => [ + map { { LIST => $_->get_value('fvl') + , DESCRIPTION => join ("\n", $_->get_value('description')) + , ISACTIVE => $_->get_value('fripostIsStatusActive') eq 'TRUE' ? 1 : 0 + , OWNERS => [ map { {OWNER => &dn2email($_)} } $_->get_value('fripostOwner') ] + , TRANSPORT => $_->get_value('fripostListManager') + }; + } + $lists->sorted('fvl') + ]); + return $template->output; +} + + # This is the page used to edit domains. sub EditDomain : Runmode { my $self = shift; @@ -67,7 +184,7 @@ sub EditDomain : Runmode { my $authzDN = "fvu=$l,fvd=$d,". $suffix; my $ldap = $self->ldap_from_auth_user($authzDN); - my $domain = (split /\//, $ENV{PATH_INFO}, 3)[1]; + my $domainname = (split /\//, $ENV{PATH_INFO}, 3)[1]; if (defined $self->query->param('submit') or defined $self->query->param('active')) { @@ -92,11 +209,11 @@ sub EditDomain : Runmode { $changes{fripostOptionalMaildrop} = [ @maildrop ]; } - my $mesg = $ldap->modify( "fvd=$domain,$suffix", replace => \%changes ); + my $mesg = $ldap->modify( "fvd=$domainname,$suffix", replace => \%changes ); die $mesg->error if $mesg->code; } - my $answer = $ldap->search( base => 'fvd='.$domain .','. $suffix + my $answer = $ldap->search( base => "fvd=$domainname,$suffix" , scope => 'base' , filter => 'objectClass=FripostVirtualDomain' , deref => 'never' @@ -110,7 +227,7 @@ sub EditDomain : Runmode { , global_vars => 1 ); $template->param( URL => $self->query->url ); $template->param( USER_LOCALPART => $l, USER_DOMAINPART => $d); - $template->param( DOMAIN => $domain ); + $template->param( DOMAIN => $domainname ); $template->param( DESCRIPTION => join ("\n",$answer->get_value('description')) ); $template->param( MAILDROP => join ("\n",$answer->get_value('fripostOptionalMaildrop')) ); $template->param( ISACTIVE => $answer->get_value('fripostIsStatusActive') eq 'TRUE' ? 1 : 0 ); @@ -184,5 +301,10 @@ sub ldap_from_auth_user { return $ldap; } +sub dn2email { + my $dn = shift; + $dn =~ /^fv[ual]=([^,]+),fvd=([^,]+),/ or return ''; + return "$1\@$2"; +} 1; -- cgit v1.2.3