aboutsummaryrefslogtreecommitdiffstats
path: root/lib/FPanel
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem.moulin@fripost.org>2012-09-04 01:29:39 +0200
committerGuilhem Moulin <guilhem.moulin@fripost.org>2012-09-04 01:29:39 +0200
commitb4e2151a91eb827bc90a44a906f7a7c40fde95c7 (patch)
tree7eb01feffc46421b0c38e2f42978a1580f06c635 /lib/FPanel
parent3c8b9dba04da6d66f7e592c3c1367a2367e1c5a5 (diff)
List mailboxes, aliases, and lists
Diffstat (limited to 'lib/FPanel')
-rw-r--r--lib/FPanel/Interface.pm130
1 files changed, 126 insertions, 4 deletions
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;