[vhffs-dev] [986] Added an option to select allowed catchall, fixing functionnality request |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 986
Author: beuss
Date: 2007-10-14 16:56:33 +0000 (Sun, 14 Oct 2007)
Log Message:
-----------
Added an option to select allowed catchall, fixing functionnality request
#223.
Modified Paths:
--------------
trunk/vhffs-api/src/Vhffs/Panel/Template.pm
trunk/vhffs-api/src/Vhffs/Services/Mail.pm
trunk/vhffs-backend/conf/vhffs.conf.dist.in
trunk/vhffs-panel/mail/prefs.pl
trunk/vhffs-panel/templates/mail/prefs.tmpl
Modified: trunk/vhffs-api/src/Vhffs/Panel/Template.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Template.pm 2007-10-14 15:39:05 UTC (rev 985)
+++ trunk/vhffs-api/src/Vhffs/Panel/Template.pm 2007-10-14 16:56:33 UTC (rev 986)
@@ -67,6 +67,8 @@
} else {
$options{filter} = \&i18n_filter;
}
+
+ $options{default_escape} = 'HTML' unless(exists $options{default_escape});
return $class->SUPER::new(%options);
}
Modified: trunk/vhffs-api/src/Vhffs/Services/Mail.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Mail.pm 2007-10-14 15:39:05 UTC (rev 985)
+++ trunk/vhffs-api/src/Vhffs/Services/Mail.pm 2007-10-14 16:56:33 UTC (rev 986)
@@ -355,10 +355,11 @@
delete $self->{boxes}{$name};
- my $query = "DELETE FROM vhffs_boxes WHERE local_part='".$name."' AND domain='".$self->{'domain'}."'";
- my $request = $self->{'db'}->prepare( $query );
-
- $request->execute;
+ my $dbh = $self->get_db_object;
+ my $sql = 'DELETE FROM vhffs_boxes WHERE local_part = ? AND domain = ?';
+ $dbh->do($sql, undef, $name, $self->{domain});
+ $sql = 'UPDATE vhffs_mxdomain SET catchall = \'\' WHERE catchall = ?';
+ $dbh->do($sql, undef, $name.'@'.$self->{domain});
}
@@ -370,9 +371,12 @@
return -1 unless( defined $name && ( $name =~ /^[a-z0-9\_\-\.]+$/ ) );
delete $self->{forward}{$name};
- my $query = "DELETE FROM vhffs_forward WHERE local_part='".$name."' AND domain='".$self->{'domain'}."'";
- my $request = $self->{'db'}->prepare( $query );
- $request->execute;
+ my $dbh = $self->get_db_object;
+ my $sql = 'DELETE FROM vhffs_forwards WHERE local_part = ? AND domain = ?';
+ $dbh->do($sql, undef, $name, $self->{domain});
+ $sql = 'UPDATE vhffs_mxdomain SET catchall = \'\' WHERE catchall = ?';
+ warn $name.'@'.$self->{domain};
+ $dbh->do($sql, undef, $name.'@'.$self->{domain});
}
# Returns a hashref with all forwards
Modified: trunk/vhffs-backend/conf/vhffs.conf.dist.in
===================================================================
--- trunk/vhffs-backend/conf/vhffs.conf.dist.in 2007-10-14 15:39:05 UTC (rev 985)
+++ trunk/vhffs-backend/conf/vhffs.conf.dist.in 2007-10-14 16:56:33 UTC (rev 986)
@@ -352,6 +352,12 @@
# URL to the documentation (optional)
url_doc = http://help.myhoster.net/mail
+
+ # kind of catchall addresses allowed (none|domain|open)
+ # none: no catchall allowed
+ # domain: only on the concerned domain
+ # open: any address
+ allowed_catchall = domain
</mail>
# The mailuser service allows a user to get a mail account on a default domain
Modified: trunk/vhffs-panel/mail/prefs.pl
===================================================================
--- trunk/vhffs-panel/mail/prefs.pl 2007-10-14 15:39:05 UTC (rev 985)
+++ trunk/vhffs-panel/mail/prefs.pl 2007-10-14 16:56:33 UTC (rev 986)
@@ -87,9 +87,11 @@
my $message = gettext("You're not allowed to do this (ACL rights)");
$template->param( MESSAGE => $message );
} else {
+ my $catchall_type = lc($mail_config->{allowed_catchall});
+ $catchall_type = 'domain' unless(defined $catchall_type);
if( defined $cgi->param('modify_catchall_submit') ) {
- update_catchall();
+ update_catchall($catchall_type);
} elsif( defined $cgi->param('update_box_submit') ) {
update_box();
} elsif(defined $cgi->param('delete_box_submit')) {
@@ -109,12 +111,14 @@
$panel->set_title( gettext("Mail Administration for domain ") );
$template->param( VALUE_DOMAIN => $mail->get_domain );
-
+
+ $template->param( CATCHALL_TYPE => $catchall_type );
$template->param( SUBTITLE_CATCHALL => gettext("Catchall address") );
$template->param( VALUE_CATCHALL => $mail->get_catchall );
$template->param( TEXT_CATCHALL_EXPLAIN => gettext("Enter a mail address to catch all email for this domain") );
$template->param( TEXT_CATCHALL => gettext("Catchall mail") );
+
$template->param( SUBTITLE_ACCOUNTS => gettext("Accounts") );
$template->param( TEXT_ACCOUNTS_LIST => gettext("List all accounts") );
$template->param( TEXT_ACCOUNTS_ADD => gettext("Add an account") );
@@ -171,19 +175,33 @@
# Action handling subs
sub update_catchall {
+ my $type = shift;
# User wants to modify catchall address.
if(!$user->can_modify($mail)) {
$panel->add_error( gettext('You are not allowed to modify this object') );
} else {
+ if($type eq 'none') {
+ $panel->add_error( gettext('Catchall isn\'t enabled on this platform') );
+ return;
+ }
my $catchall = $cgi->param('catchall');
if(!defined($catchall)) {
$panel->add_error( gettext('CGI error') );
- } elsif($mail->set_catchall($catchall) < 0) {
- $panel->add_error( sprintf( gettext('%s is not a correct mail address'), $catchall) );
- } elsif($mail->commit() < 0) {
- $panel->add_error( gettext("An error occured while updating the mail domain") );
} else {
- $panel->add_info(gettext('Catchall address successfully changed'));
+ if($type eq 'domain' && $catchall ne '') {
+ if( ! $mail->exists_box($catchall) ) {
+ $panel->add_error( gettext('Selected mailbox doesn\'t exist for this mail domain') );
+ return;
+ }
+ $catchall .= "\@$domain";
+ }
+ if($mail->set_catchall($catchall) < 0) {
+ $panel->add_error( sprintf( gettext('%s is not a correct mail address'), $catchall) );
+ } elsif($mail->commit() < 0) {
+ $panel->add_error( gettext("An error occured while updating the mail domain") );
+ } else {
+ $panel->add_info(gettext('Catchall address successfully changed'));
+ }
}
}
}
Modified: trunk/vhffs-panel/templates/mail/prefs.tmpl
===================================================================
--- trunk/vhffs-panel/templates/mail/prefs.tmpl 2007-10-14 15:39:05 UTC (rev 985)
+++ trunk/vhffs-panel/templates/mail/prefs.tmpl 2007-10-14 16:56:33 UTC (rev 986)
@@ -1,3 +1,4 @@
+<tmpl_unless expr="CATCHALL_TYPE eq 'none'">
<h2><tmpl_var name="SUBTITLE_CATCHALL"></h2>
<form method="post" action="/mail/prefs.pl">
@@ -7,13 +8,23 @@
<label for="catchall">
<tmpl_var name="TEXT_CATCHALL"> :
</label>
+ <tmpl_if expr="CATCHALL_TYPE eq 'open'">
<input type="text" name="catchall" id="catchall" value="<tmpl_var name="VALUE_CATCHALL">" />
+ <tmpl_else>
+ <select name="catchall" id="catchall">
+ <option value="">---</option>
+ <tmpl_loop name="boxes">
+ <option <tmpl_if expr="VALUE_CATCHALL eq (sprintf('%s@%s', LOCAL_PART, DOMAIN))">selected="selected"</tmpl_if> value="<TMPL_VAR NAME="LOCAL_PART">"><TMPL_VAR NAME="LOCAL_PART">@<TMPL_VAR NAME="DOMAIN"></option>
+ </tmpl_loop>
+ </select>
+ </tmpl_if>
</p>
<p class="button" id="buttonModify">
<input type="hidden" name="name" value="<tmpl_var name="VALUE_DOMAIN">" />
<input type="submit" name="modify_catchall_submit" value="<tmpl_var name="TEXT_CHANGE_CATCHALL">"/>
</p>
</form>
+</tmpl_unless>
<h2><tmpl_var name="SUBTITLE_ACCOUNTS"></h2>