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 --- css/style.css | 16 ++++++ lib/FPanel/Interface.pm | 130 +++++++++++++++++++++++++++++++++++++++++++-- template/edit-domain.html | 3 +- template/error.html | 18 +++---- template/list-domains.html | 8 ++- template/list-locals.html | 125 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 280 insertions(+), 20 deletions(-) create mode 100644 template/list-locals.html diff --git a/css/style.css b/css/style.css index 390a634..465a7b1 100644 --- a/css/style.css +++ b/css/style.css @@ -160,3 +160,19 @@ div.editform { font-weight: bold; color: #32CD32; } +.description { + text-align: justify; + font-style: italic; + margin: auto; + width: 600px; +} +.edit { + font-weight: normal; + font-size: 11pt; + margin: 10pt; +} +.add { + font-weight: normal; + font-size: 11pt; + margin: 10pt; +} 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; diff --git a/template/edit-domain.html b/template/edit-domain.html index 38abc62..5be62dd 100644 --- a/template/edit-domain.html +++ b/template/edit-domain.html @@ -8,7 +8,8 @@