[vhffs-dev] [792] MailGroup is here !, users can now select a group contact email in group preferences

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 792
Author:   gradator
Date:     2007-08-29 01:25:07 +0000 (Wed, 29 Aug 2007)

Log Message:
-----------
MailGroup is here !, users can now select a group contact email in group preferences
Fixed some bugs in MailUser

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Conf.pm
    trunk/vhffs-api/src/Vhffs/Makefile.am
    trunk/vhffs-api/src/Vhffs/Services/MailUser.pm
    trunk/vhffs-backend/conf/vhffs.conf.dist.in
    trunk/vhffs-panel/group/prefs.pl
    trunk/vhffs-panel/templates/group/prefs.tmpl
    trunk/vhffs-panel/user/prefs.pl

Added Paths:
-----------
    trunk/vhffs-api/src/Vhffs/Services/MailGroup.pm


Modified: trunk/vhffs-api/src/Vhffs/Conf.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Conf.pm	2007-08-28 21:13:35 UTC (rev 791)
+++ trunk/vhffs-api/src/Vhffs/Conf.pm	2007-08-29 01:25:07 UTC (rev 792)
@@ -267,7 +267,15 @@
 }
 
 
+sub use_mailgroup
+{
+	return -1 if( ! defined $Config{"global"}{"modules"}{'use_mailgroup'} );
+	return 1 if( $Config{"global"}{"modules"}{'use_mailgroup'} eq "yes");
+	return 0;
+}
 
+
+
 sub use_mailing
 {
 	return -1 if( ! defined $Config{"global"}{"modules"}{'use_mailing'} );

Modified: trunk/vhffs-api/src/Vhffs/Makefile.am
===================================================================
--- trunk/vhffs-api/src/Vhffs/Makefile.am	2007-08-28 21:13:35 UTC (rev 791)
+++ trunk/vhffs-api/src/Vhffs/Makefile.am	2007-08-29 01:25:07 UTC (rev 792)
@@ -59,6 +59,7 @@
 	Services/Mail.pm \
 	Services/Mailing.pm \
 	Services/MailUser.pm \
+	Services/MailGroup.pm \
 	Services/Mysql.pm \
 	Services/Postgres.pm \
 	Services/Repository.pm \

Added: trunk/vhffs-api/src/Vhffs/Services/MailGroup.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/MailGroup.pm	                        (rev 0)
+++ trunk/vhffs-api/src/Vhffs/Services/MailGroup.pm	2007-08-29 01:25:07 UTC (rev 792)
@@ -0,0 +1,187 @@
+#!%PERL%
+# Copyright (c) vhffs project and its contributors
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without 
+# modification, are permitted provided that the following conditions 
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright 
+#   notice, this list of conditions and the following disclaimer.
+#2. Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in 
+#   the documentation and/or other materials provided with the 
+#   distribution.
+#3. Neither the name of vhffs nor the names of its contributors 
+#   may be used to endorse or promote products derived from this 
+#   software without specific prior written permission.
+#
+#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
+#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
+#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
+#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
+#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
+# POSSIBILITY OF SUCH DAMAGE.
+
+
+# This file is a part of VHFFS4 software, a hosting platform suite
+# Please respect the licence of this file and whole program
+
+# Author : Sylvain Rochet < gradator at gradator dot net >
+
+#This module helps you to manage a simple maildomain
+#for all hosted people
+
+#Be careful, you have to define the following part in your configuration file :
+# <services>
+#    ....
+#    ....
+#    <mailgroup>
+#       activate = [yes|no]
+#       domain = domain_to_share_with_hosted
+#       user = vhffs_user_who_own_the_domain
+#    </mailgroup>
+# </services>
+
+# This module wrap group on the specified user
+# and commit changes on the domain
+
+package Vhffs::Services::MailGroup;
+
+use strict;
+use DBI;
+use Vhffs::User;
+use Vhffs::Group;
+
+# Create a new instance of the current class
+sub init
+{
+	my $class = shift;
+	my $vhffs = shift;
+	my $group = shift;
+
+	my $this = {};
+
+	my $config = $vhffs->get_config->get_service('mailgroup');
+	return -1 unless( defined $config && (defined $config->{activate} && $config->{activate} eq 'yes' ) );
+	$this->{main} = $vhffs;
+	$this->{config} = $config;
+
+	return -1 unless( defined $group );
+	$this->{part} = $group->get_groupname;
+
+	return -2 unless( defined $config->{domain} );
+	$this->{domain} = $config->{domain};
+
+	# Fetches the owner of the mail domain
+	return -3 unless( defined $config->{user} );
+	my $wuser = Vhffs::User::get_by_username( $vhffs , $config->{user} );
+	return -4 unless( defined $wuser );
+	$this->{wuser} = $wuser;
+
+	# Fetches the mail domain defined in config
+	my $mail_service = Vhffs::Services::Mail::get_by_mxdomain($vhffs, $this->{domain});
+	return -5 unless(defined $mail_service);
+	$this->{mail_service} = $mail_service;
+
+	bless( $this , $class );
+	return $this;
+}
+
+sub exists
+{
+	my $self = shift;
+	return $self->{mail_service}->exists( $self->{part} );
+}
+
+sub exists_forward
+{
+	my $self = shift;
+	return $self->{mail_service}->exists_forward( $self->{part} );
+}
+
+
+sub exists_box
+{
+	my $self = shift;
+	return $self->{mail_service}->exists_box( $self->{part} );
+}
+
+sub use_nospam
+{
+	my $self = shift;
+	return $self->{mail_service}->use_nospam( $self->{part} );
+}
+
+sub use_novirus
+{
+	my $self = shift;
+	return $self->{mail_service}->use_novirus( $self->{part} );
+}
+
+sub change_spam_status
+{
+	my $self = shift;
+	$self->{mail_service}->change_spam_status( $self->{part} );
+	return 1;
+}
+
+sub change_virus_status
+{
+	my $self = shift;
+	$self->{mail_service}->change_virus_status( $self->{part} );
+	return 1;
+}
+
+
+sub addforward
+{
+	my $self = shift;
+	my $remote = shift;
+
+	$self->{mail_service}->delforward( $self->{part} ) if( $self->exists_forward == 1 );
+	$self->{mail_service}->delbox( $self->{part} ) if( $self->exists_box == 1 );	
+	return -1 if ( $self->{mail_service}->addforward( $self->{part} , $remote ) < 0);
+}
+
+sub delforward
+{
+	my $self = shift;
+	$self->{mail_service}->delforward( $self->{part} );
+}
+
+sub getforward
+{
+	my $self = shift;
+	return undef unless $self->{mail_service}->{'forward'}->{$self->{part}};
+	return $self->{mail_service}->{'forward'}->{$self->{part}}->{'remote_name'};
+}
+
+sub delbox
+{
+	my $self = shift;
+	$self->{mail_service}->delbox( $self->{part} );
+}
+
+sub addbox
+{
+	my $self = shift;
+	my $password = shift;
+
+	$self->{mail_service}->delforward( $self->{part} ) if( $self->exists_forward == 1 );
+	return -1 if( $self->{mail_service}->addbox( $self->{part} , $password ) < 0);
+}
+
+sub changepassword
+{
+	my ($self, $newpass) = @_;
+	return -1 if( $self->{mail_service}->change_box_password( $self->{part}, $newpass ) < 0 );
+}
+
+1;

Modified: trunk/vhffs-api/src/Vhffs/Services/MailUser.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/MailUser.pm	2007-08-28 21:13:35 UTC (rev 791)
+++ trunk/vhffs-api/src/Vhffs/Services/MailUser.pm	2007-08-29 01:25:07 UTC (rev 792)
@@ -45,7 +45,7 @@
 #    <mailuser>
 #       activate = [yes|no]
 #       domain = domain_to_share_with_hosted
-#       user = vhffs_user_you_own_the_domain
+#       user = vhffs_user_who_own_the_domain
 #    </mailuser>
 # </services>
 

Modified: trunk/vhffs-backend/conf/vhffs.conf.dist.in
===================================================================
--- trunk/vhffs-backend/conf/vhffs.conf.dist.in	2007-08-28 21:13:35 UTC (rev 791)
+++ trunk/vhffs-backend/conf/vhffs.conf.dist.in	2007-08-29 01:25:07 UTC (rev 792)
@@ -71,6 +71,7 @@
 		use_dns		=	no
 		use_mailing	=	no
 		use_mailuser	=	no
+		use_mailgroup	=	no
 		use_repository	=	no
 	</modules>
 
@@ -277,17 +278,26 @@
 		use_novirus	=	yes
 	</mail>
 
-	#The mailuser service allow a user to get a mail account
-	#on a default domain
-	#With with module, ALL users get an email adress for a domain
+	#The mailuser service allow a user to get a mail account on a default domain
+	#With with module, ALL users get an email address for a domain
 	#The domain MUST exists on VHFFS, and should be owned by the user given in this configuration
 	# groupneeded : the user cannot create his mail account if it doesn't have a group
 	<mailuser>
 		activate	=	no
 		groupneeded	=	yes
-		domain		=	myhost.org
+		domain		=	users.myhost.org
 		user 		=	cat
 	</mailuser>
+
+	#The mailgroup service allow a group to get a mail account on a default domain
+	#With with module, ALL groups get an email address for a domain
+	#The domain MUST exists on VHFFS, and should be owned by the user given in this configuration
+	<mailgroup>
+		activate	=	no
+		domain		=	projects.myhost.org
+		user 		=	cat
+	</mailgroup>
+
 	<mailing>
 		default_domain = lists.vhffs.org
 	</mailing>

Modified: trunk/vhffs-panel/group/prefs.pl
===================================================================
--- trunk/vhffs-panel/group/prefs.pl	2007-08-28 21:13:35 UTC (rev 791)
+++ trunk/vhffs-panel/group/prefs.pl	2007-08-29 01:25:07 UTC (rev 792)
@@ -44,11 +44,10 @@
 use Vhffs::Main;
 use Vhffs::Panel::Main;
 use Vhffs::Panel::Group;
+use Vhffs::Functions;
 
 my $panel = new Vhffs::Panel::Main();
-if(!$panel)  {
-        exit 0;
-}
+exit 0 unless $panel;
 
 my $vhffs = $panel->{'vhffs'};
 my $session = $panel->{'session'};
@@ -170,6 +169,26 @@
                 } 
             }
         }
+    } elsif( defined( $cgi->param('contact_email_submit') ) ) {
+        if( $vhffs->get_config->use_mailgroup == 0  ||  ( $access_level < Vhffs::Constants::ACL_MODIFY  &&  $user->is_admin != 1 ) ) {
+            $panel->add_error( gettext( 'You\'re not allowed to do this (ACL rights)' ) );
+        } else {
+            my $forward = $cgi->param( 'contact_email' );
+            if( ! defined $forward  ||  ( $forward ne ""  &&  Vhffs::Functions::valid_mail( $forward ) != 1 )  ) {
+                $panel->add_error( gettext('The email you entered fails syntax check') );
+            } else {
+		use Vhffs::Services::MailGroup;
+		my $mg = init Vhffs::Services::MailGroup( $vhffs , $group );
+		if( defined $mg && $mg >= 0 )
+		{
+			if( $forward eq "" )  {
+				$mg->delforward( $forward );
+			}else {
+				$mg->addforward( $forward );
+			}
+		}
+            }
+        }
     }
 
 
@@ -188,6 +207,19 @@
 	$template->param( YES => gettext("Yes I'm sure of what I do") );
 	$template->param( NO => gettext("No, I'm not sure, I prefer to keep this project.") );
 	$template->param( TEXT_DELETE => gettext("Delete") );
+
+	if( $vhffs->get_config->use_mailgroup == 1 )  {
+		use Vhffs::Services::MailGroup;
+		my $mg = init Vhffs::Services::MailGroup( $vhffs , $group );
+		if( defined $mg && $mg >= 0 )
+		{
+			$template->param( CONTACT_EMAIL_TITLE => gettext('Project contact') );
+			$template->param( CONTACT_EMAIL_TEXT => sprintf( gettext('We offer you the possibility to forward emails from %s@%s.') , $group->{'groupname'} , $mg->{config}->{domain} ) );
+			$template->param( CONTACT_EMAIL => $group->{'groupname'}.'@'.$mg->{config}->{domain} );
+			$template->param( CONTACT_EMAIL_MODIFY => gettext('Modify') );
+			$template->param( CONTACT_EMAIL_FORWARD => $mg->getforward );
+		}
+	}
 	
 	$template->param( TEXT_USERNAME => gettext("Username") );
 	$template->param( TEXT_JOIN_GROUP => gettext("Add a user in this group") );

Modified: trunk/vhffs-panel/templates/group/prefs.tmpl
===================================================================
--- trunk/vhffs-panel/templates/group/prefs.tmpl	2007-08-28 21:13:35 UTC (rev 791)
+++ trunk/vhffs-panel/templates/group/prefs.tmpl	2007-08-29 01:25:07 UTC (rev 792)
@@ -14,6 +14,17 @@
     </p>
 </form>
 
+<tmpl_if name="CONTACT_EMAIL_TITLE">
+<h2><tmpl_var name="CONTACT_EMAIL_TITLE"></h2>
+<p>
+<tmpl_var name="CONTACT_EMAIL_TEXT">
+<form action="#" method="post">
+Forward emails from <tmpl_var name="CONTACT_EMAIL"> to
+<input type="text" name="contact_email" id="contact_email" value="<tmpl_var name="CONTACT_EMAIL_FORWARD">"/> <input type="submit" value="<tmpl_var name="CONTACT_EMAIL_MODIFY">" name="contact_email_submit"/>
+</form>
+</p>
+</tmpl_if>
+
 <h2><tmpl_var name="USERS_TEXT"></h2>
 <h3><tmpl_var name="CURRENT_USERS"></h3>
 <tmpl_unless name="USERS">

Modified: trunk/vhffs-panel/user/prefs.pl
===================================================================
--- trunk/vhffs-panel/user/prefs.pl	2007-08-28 21:13:35 UTC (rev 791)
+++ trunk/vhffs-panel/user/prefs.pl	2007-08-29 01:25:07 UTC (rev 792)
@@ -247,14 +247,6 @@
 }
 } # if($submitted)
 
-my $mailuser;
-
-if( $vhffs->get_config->use_mailuser == 1 ) {
-    $mailuser = 1;
-} else {
-    $mailuser = 0;
-}
-
 my $username = $user->get_username();
 my $usermail = $user->get_mail();
 
@@ -367,7 +359,7 @@
 }
 
 
-if( $mailuser == 1 )
+if( $vhffs->get_config->use_mailuser == 1 )
 {
 	use Vhffs::Services::MailUser;
     


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/