aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem.moulin@fripost.org>2012-09-05 00:08:22 +0200
committerGuilhem Moulin <guilhem.moulin@fripost.org>2012-09-05 00:09:00 +0200
commitb4f952a0e374dd02ec4cdf940a8fadf8f537f433 (patch)
tree2f40cf727374b2c3b7ed27e14587a0367a1d227f
parentd455b5b2f060ce97d5f59161bcf3e2344f1fd110 (diff)
Add aliases.
-rw-r--r--lib/FPanel/Interface.pm68
-rw-r--r--lib/FPanel/Login.pm6
-rw-r--r--template/add-alias.html84
-rw-r--r--template/list-domains.html2
-rw-r--r--template/list-locals.html6
5 files changed, 157 insertions, 9 deletions
diff --git a/lib/FPanel/Interface.pm b/lib/FPanel/Interface.pm
index 5945ea9..f9a1358 100644
--- a/lib/FPanel/Interface.pm
+++ b/lib/FPanel/Interface.pm
@@ -311,7 +311,7 @@ sub EditLocal : Runmode {
my $authzDN = "fvu=$l,fvd=$d,". $suffix;
my $ldap = $self->ldap_from_auth_user($authzDN);
- my ($null,$domainname,$localname,$crap) = (split /\//, $ENV{PATH_INFO}, 4);
+ my ($null,$domainname,$localname,$crap) = split /\//, $ENV{PATH_INFO}, 4;
my $error; # Tells wether the change submission has fails.
if (defined $self->query->param('submit')) {
@@ -453,6 +453,72 @@ sub EditLocal : Runmode {
}
+# In this Run Mode authenticated users can add mailboxes, aliases and
+# lists (if they have the permission).
+sub AddLocal : 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 $localname;
+
+ my $error;
+ my $q = $self->query;
+ if (defined $self->query->param('submit')) {
+ # A new alias has been submitted: process it
+ my %new;
+ $localname = $q->param('alias');
+ $new{objectClass} = 'FripostVirtualAlias';
+ $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;
+
+ }
+ # TODO: more checks
+ my $mesg = $ldap->add( "fva=$localname,fvd=$domainname,$suffix",
+ attrs => [ %new ] );
+ if ($mesg->code) {
+ $error = $mesg->error;
+ }
+ else {
+ return $self->redirect($q->url .'/'. $domainname .'/');
+ }
+ }
+
+ my $template = $self->load_tmpl( 'add-alias.html', cache => 1, utf8 => 1 );
+ $template->param( URL => $self->query->url );
+ $template->param( DOMAIN => $domainname );
+ $template->param( USER_LOCALPART => $l, USER_DOMAINPART => $d);
+ if (defined $error) {
+ $template->param( ALIAS => $q->param('alias') );
+ $template->param( ISACTIVE => $q->param('status') eq 'active');
+ $template->param( DESCRIPTION => join ("\n",$q->param('description')) );
+ $template->param( MAILDROP => join ("\n",$q->param('maildrop')) );
+ $template->param( ERROR => $error );
+ }
+ return $template->output;
+}
+
+
# This subroutine displays the access that the given DN has on the entry
# (long version). Possible values are :
# - "can create aliases" (a)
diff --git a/lib/FPanel/Login.pm b/lib/FPanel/Login.pm
index e21ef77..9be724a 100644
--- a/lib/FPanel/Login.pm
+++ b/lib/FPanel/Login.pm
@@ -108,7 +108,7 @@ sub setup {
unless (defined $domain and $domain ne '') {
if (defined $a) {
- return 'AddDomain' if $a eq 'AddDomain';
+ return 'AddDomain' if $a eq 'add';
}
return 'ListDomains';
}
@@ -116,9 +116,7 @@ sub setup {
unless (defined $local and $local ne '') {
if (defined $a) {
return 'EditDomain' if $a eq 'edit';
- return 'AddAccount' if $a eq 'AddAccount';
- return 'AddAlias' if $a eq 'AddAlias';
- return 'AddList' if $a eq 'AddList';
+ return 'AddLocal' if $a eq 'add';
}
return 'ListLocals';
}
diff --git a/template/add-alias.html b/template/add-alias.html
new file mode 100644
index 0000000..38193c6
--- /dev/null
+++ b/template/add-alias.html
@@ -0,0 +1,84 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
+ <title>Edit alias <TMPL_VAR NAME=ALIAS>@<TMPL_VAR NAME=DOMAIN></title>
+ <link href="/css/style.css" media="all" rel="stylesheet" type="text/css" />
+ </head>
+ <body>
+ <div id="header">
+ <div class="left column">
+ <a href="<TMPL_VAR NAME=URL>/">Root</a> /
+ <a href="<TMPL_VAR NAME=URL>/<TMPL_VAR NAME=DOMAIN>/"><TMPL_VAR NAME=DOMAIN></a> /
+ </div>
+ <div class="right column">
+ Logged as <a href="<TMPL_VAR NAME=URL>/<TMPL_VAR NAME=USER_DOMAINPART>/<TMPL_VAR NAME=USER_LOCALPART>/?a=edit"
+ ><TMPL_VAR NAME=USER_LOCALPART>@<TMPL_VAR NAME=USER_DOMAINPART></a>
+ | <a href="<TMPL_VAR NAME=URL>/?a=logout">Log out</a>
+ </div>
+ <br/>
+ </div>
+ <hr/>
+
+ <h1>Add alias under <tt><TMPL_VAR NAME=DOMAIN></tt></h1>
+
+ <TMPL_IF NAME=ERROR>
+ <div class="fail">Error: <TMPL_VAR NAME=ERROR></div>
+ <TMPL_ELSE>
+ </br>
+ </TMPL_IF>
+
+ <br/>
+
+ <form class="editform" name="editform" method="post">
+ <div class="editform">
+ <input type="hidden" name="a" value="add" />
+ <input type="hidden" name="t" value="alias" />
+
+ <p>
+ <h4 class="label">Alias name</h4>
+ <input type="text" name="alias" size="15" value="<TMPL_VAR NAME=ALIAS>"/>@<TMPL_VAR NAME=DOMAIN>
+ </p>
+
+ <hr/>
+
+ <p>
+ <h4 class="label">Status</h4>
+ <select name="status">
+ <option value="active" <TMPL_IF NAME=ERROR><TMPL_IF NAME=ISACTIVE>selected</TMPL_IF><TMPL_ELSE>selected</TMPL_IF>>Active</option>
+ <option value="inactive" <TMPL_IF NAME=ERROR><TMPL_UNLESS NAME=ISACTIVE>selected</TMPL_UNLESS></TMPL_IF>>Inactive</option>
+ </select>
+ <div class="help">
+ <b>Warning</b>: emails are <i>not</i> delivered to inactive entries.
+ </div>
+ </p>
+
+ <hr/>
+
+ <p>
+ <h4 class="label">Description</h4>
+ <textarea type="text" name="description" cols="50" rows="3" wrap="soft"><TMPL_VAR NAME=DESCRIPTION></textarea>
+ <div class="help">
+ An optional description. (HTML tags are allowed.)
+ </div>
+ </p>
+
+ <hr/>
+
+ <p>
+ <h4 class="label">Destination(s)</h4>
+ <textarea type="text" name="maildrop" cols="50" rows="10" wrap="hard" ><TMPL_VAR NAME=MAILDROP></textarea>
+ <div class="help">
+ The list of destinations (one e-mail address per line) that
+ will receive mail for this alias.
+ </div>
+ </p>
+
+ <hr/>
+
+ <input type="hidden" name="destination" value="<TMPL_VAR NAME=DESTINATION>" />
+ <input type="submit" name="submit" value="Submit Changes" />
+ </div>
+ </form>
+ </body>
+</html>
diff --git a/template/list-domains.html b/template/list-domains.html
index 4069ba0..bb29de5 100644
--- a/template/list-domains.html
+++ b/template/list-domains.html
@@ -19,7 +19,7 @@
</div>
<hr/>
- <h1>Manage domains<span class="add">[<a href="<TMPL_VAR NAME=URL>/?a=AddDomain">add</a>]<span></h1>
+ <h1>Manage domains<span class="add">[<a href="<TMPL_VAR NAME=URL>/?a=add">add</a>]<span></h1>
<a name="domains"></a>
<table class="list">
diff --git a/template/list-locals.html b/template/list-locals.html
index aa42bfd..b0aa2e4 100644
--- a/template/list-locals.html
+++ b/template/list-locals.html
@@ -29,7 +29,7 @@
<TMPL_IF NAME=LISTMAILBOXES>
<h3>Mailboxes<TMPL_IF NAME=CANADDMAILBOX
- ><span class="add">[<a href="<TMPL_VAR NAME=URL>/<TMPL_VAR NAME=DOMAIN>/?a=AddUser">add</a>]</span
+ ><span class="add">[<a href="<TMPL_VAR NAME=URL>/<TMPL_VAR NAME=DOMAIN>/?a=add&t=mailbox">add</a>]</span
></TMPL_IF></h3>
<a name="mailboxes"></a>
@@ -64,7 +64,7 @@
<TMPL_IF NAME=LISTALIASES>
<h3>Alias<TMPL_IF NAME=CANADDALIAS
- ><span class="add">[<a href="<TMPL_VAR NAME=URL>/<TMPL_VAR NAME=DOMAIN>/?a=AddAlias">add</a>]</span
+ ><span class="add">[<a href="<TMPL_VAR NAME=URL>/<TMPL_VAR NAME=DOMAIN>/?a=add&t=alias">add</a>]</span
></TMPL_IF></h3>
<a name="aliases"></a>
@@ -109,7 +109,7 @@
<TMPL_IF NAME=LISTLISTS>
<h3>Lists<TMPL_IF NAME=CANADDLIST
- ><span class="add">[<a href="<TMPL_VAR NAME=URL>/<TMPL_VAR NAME=DOMAIN>/?a=AddList">add</a>]</span
+ ><span class="add">[<a href="<TMPL_VAR NAME=URL>/<TMPL_VAR NAME=DOMAIN>/?a=add&t=list">add</a>]</span
></TMPL_IF></h3>
<a name="lists"></a>