[vhffs-dev] [850] deleted user directive of mailuser and mailgroup which were not used, complete rewrite of MailUser and MailGroup service

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


Revision: 850
Author:   gradator
Date:     2007-08-31 17:13:11 +0000 (Fri, 31 Aug 2007)

Log Message:
-----------
deleted user directive of mailuser and mailgroup which were not used, complete rewrite of MailUser and MailGroup service

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Services/MailGroup.pm
    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/lost_ack.pl
    trunk/vhffs-panel/user/prefs.pl


Modified: trunk/vhffs-api/src/Vhffs/Services/MailGroup.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/MailGroup.pm	2007-08-31 16:55:58 UTC (rev 849)
+++ trunk/vhffs-api/src/Vhffs/Services/MailGroup.pm	2007-08-31 17:13:11 UTC (rev 850)
@@ -38,27 +38,13 @@
 #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
 {
@@ -66,30 +52,20 @@
 	my $vhffs = shift;
 	my $group = shift;
 
-	my $this = {};
-
+	return undef unless ( defined $vhffs  &&  defined  $group  &&  $vhffs->get_config->get_service_availability('mailgroup') );
 	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;
+	# Fetches the mail domain defined in config
+	my $mail_service = Vhffs::Services::Mail::get_by_mxdomain( $vhffs, $config->{domain} );
+	return undef unless defined $mail_service;
 
-	return -2 unless( defined $config->{domain} );
+	my $this = {};
+	$this->{main} = $vhffs;
+	$this->{config} = $config;
+	$this->{group} = $group;
+	$this->{localpart} = $group->get_groupname;
 	$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;
 }
@@ -97,76 +73,74 @@
 sub exists
 {
 	my $self = shift;
-	return $self->{mail_service}->exists( $self->{part} );
+	return $self->{mail_service}->exists( $self->{localpart} );
 }
 
 sub exists_forward
 {
 	my $self = shift;
-	return $self->{mail_service}->exists_forward( $self->{part} );
+	return $self->{mail_service}->exists_forward( $self->{localpart} );
 }
 
-
 sub exists_box
 {
 	my $self = shift;
-	return $self->{mail_service}->exists_box( $self->{part} );
+	return $self->{mail_service}->exists_box( $self->{localpart} );
 }
 
 sub use_nospam
 {
 	my $self = shift;
-	return $self->{mail_service}->use_nospam( $self->{part} );
+	return $self->{mail_service}->use_nospam( $self->{localpart} );
 }
 
 sub use_novirus
 {
 	my $self = shift;
-	return $self->{mail_service}->use_novirus( $self->{part} );
+	return $self->{mail_service}->use_novirus( $self->{localpart} );
 }
 
 sub change_spam_status
 {
 	my $self = shift;
-	$self->{mail_service}->change_spam_status( $self->{part} );
+	$self->{mail_service}->change_spam_status( $self->{localpart} );
 	return 1;
 }
 
 sub change_virus_status
 {
 	my $self = shift;
-	$self->{mail_service}->change_virus_status( $self->{part} );
+	$self->{mail_service}->change_virus_status( $self->{localpart} );
 	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);
+	
+	$self->{mail_service}->delforward( $self->{localpart} ) if( $self->exists_forward == 1 );
+	$self->{mail_service}->delbox( $self->{localpart} ) if( $self->exists_box == 1 );
+	return -1 if ( $self->{mail_service}->addforward( $self->{localpart} , $remote ) < 0);
 }
 
-sub delforward
+sub getforward
 {
 	my $self = shift;
-	$self->{mail_service}->delforward( $self->{part} );
+	return undef unless $self->{mail_service}->{'forward'}->{$self->{localpart}};
+	return $self->{mail_service}->{'forward'}->{$self->{localpart}}->{'remote_name'};
 }
 
-sub getforward
+sub delforward
 {
 	my $self = shift;
-	return undef unless $self->{mail_service}->{'forward'}->{$self->{part}};
-	return $self->{mail_service}->{'forward'}->{$self->{part}}->{'remote_name'};
+	$self->{mail_service}->delforward( $self->{localpart} );
 }
 
 sub delbox
 {
 	my $self = shift;
-	$self->{mail_service}->delbox( $self->{part} );
+	$self->{mail_service}->delbox( $self->{localpart} );
 }
 
 sub addbox
@@ -174,14 +148,14 @@
 	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);
+	$self->{mail_service}->delforward( $self->{localpart} ) if( $self->exists_forward == 1 );
+	return -1 if( $self->{mail_service}->addbox( $self->{localpart} , $password ) < 0);
 }
 
 sub changepassword
 {
 	my ($self, $newpass) = @_;
-	return -1 if( $self->{mail_service}->change_box_password( $self->{part}, $newpass ) < 0 );
+	return -1 if( $self->{mail_service}->change_box_password( $self->{localpart}, $newpass ) < 0 );
 }
 
 1;

Modified: trunk/vhffs-api/src/Vhffs/Services/MailUser.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/MailUser.pm	2007-08-31 16:55:58 UTC (rev 849)
+++ trunk/vhffs-api/src/Vhffs/Services/MailUser.pm	2007-08-31 17:13:11 UTC (rev 850)
@@ -38,20 +38,6 @@
 #This module helps you to manage a simple maildomain
 #for all hosted people
 
-#Be careful, you have to defined in your config:
-# <services>
-#    ....
-#    ....
-#    <mailuser>
-#       activate = [yes|no]
-#       domain = domain_to_share_with_hosted
-#       user = vhffs_user_who_own_the_domain
-#    </mailuser>
-# </services>
-
-# This module wrap user on the specified user
-# and commit changes on the domain
-
 package Vhffs::Services::MailUser;
 
 use strict;
@@ -66,113 +52,97 @@
 	my $vhffs = shift;
 	my $user = shift;
 
-	my $this = {};
-
+	return undef unless ( defined $vhffs  &&  defined  $user  &&  $vhffs->get_config->get_service_availability('mailuser') );
 	my $config = $vhffs->get_config->get_service('mailuser');
-	return -1 unless( defined $config && (defined $config->{activate} && $config->{activate} eq 'yes' ) );
-    $this->{main} = $vhffs;
-    $this->{config} = $config;
 
-	return -1 unless( defined $user );
-    $this->{part} = $user->get_username;
+	return undef if( $config->{groupneeded} eq 'yes'  &&  $user->have_activegroups <= 0 );
 
-	return -2 unless( defined $config->{domain} );
-	$this->{domain} = $config->{domain};
+	# Fetches the mail domain defined in config
+	my $mail_service = Vhffs::Services::Mail::get_by_mxdomain( $vhffs, $config->{domain} );
+	return undef unless defined $mail_service;
 
-    # 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);
+	my $this = {};
+	$this->{main} = $vhffs;
+	$this->{config} = $config;
+	$this->{user} = $user;
+	$this->{localpart} = $user->get_username;
+	$this->{domain} = $config->{domain};
 	$this->{mail_service} = $mail_service;
-
-    bless( $this , $class );
-
+	bless( $this , $class );
 	return $this;
 }
 
-sub available
-{
-	my $self = shift;
-	my $user = Vhffs::User::get_by_username( $self->{main} , $self->{part} );
-	return 0 unless( defined $user );
-	return 1 if( ( ! defined $self->{config}->{groupneeded} ) || ( $self->{config}->{groupneeded} ne "yes" ) || ( $user->have_activegroups > 0 ) );
-	return 0;
-}
-
 sub exists
 {
 	my $self = shift;
-	return $self->{mail_service}->exists( $self->{part} );
+	return $self->{mail_service}->exists( $self->{localpart} );
 }
 
 sub exists_forward
 {
 	my $self = shift;
-	return $self->{mail_service}->exists_forward( $self->{part} );
+	return $self->{mail_service}->exists_forward( $self->{localpart} );
 }
 
-
 sub exists_box
 {
 	my $self = shift;
-	return $self->{mail_service}->exists_box( $self->{part} );
+	return $self->{mail_service}->exists_box( $self->{localpart} );
 }
 
 sub use_nospam
 {
 	my $self = shift;
-	return $self->{mail_service}->use_nospam( $self->{part} );
+	return $self->{mail_service}->use_nospam( $self->{localpart} );
 }
 
 sub use_novirus
 {
 	my $self = shift;
-	return $self->{mail_service}->use_novirus( $self->{part} );
+	return $self->{mail_service}->use_novirus( $self->{localpart} );
 }
 
 sub change_spam_status
 {
 	my $self = shift;
-	$self->{mail_service}->change_spam_status( $self->{part} );
+	$self->{mail_service}->change_spam_status( $self->{localpart} );
 	return 1;
 }
 
 sub change_virus_status
 {
 	my $self = shift;
-	$self->{mail_service}->change_virus_status( $self->{part} );
+	$self->{mail_service}->change_virus_status( $self->{localpart} );
 	return 1;
 }
 
-
 sub addforward
 {
 	my $self = shift;
 	my $remote = shift;
 	
-	if( $self->exists_box == 1 )
-	{
-		$self->{mail_service}->delbox( $self->{part} );
-	}
-	
-	return -1 if ( $self->{mail_service}->addforward( $self->{part} , $remote ) < 0);
+	$self->{mail_service}->delforward( $self->{localpart} ) if( $self->exists_forward == 1 );
+	$self->{mail_service}->delbox( $self->{localpart} ) if( $self->exists_box == 1 );
+	return -1 if ( $self->{mail_service}->addforward( $self->{localpart} , $remote ) < 0);
 }
 
+sub getforward
+{
+	my $self = shift;
+	return undef unless $self->{mail_service}->{'forward'}->{$self->{localpart}};
+	return $self->{mail_service}->{'forward'}->{$self->{localpart}}->{'remote_name'};
+}
+
 sub delforward
 {
 	my $self = shift;
-    $self->{mail_service}->delforward( $self->{part} );
+	$self->{mail_service}->delforward( $self->{localpart} );
 }
 
 sub delbox
 {
 	my $self = shift;
-    $self->{mail_service}->delbox( $self->{part} );
+	$self->{mail_service}->delbox( $self->{localpart} );
 }
 
 sub addbox
@@ -180,21 +150,14 @@
 	my $self = shift;
 	my $password = shift;
 
-
-	if( $self->exists_forward == 1 )
-	{
-		$self->{mail_service}->delforward( $self->{part} );
-	}
-
-	return -1 if( $self->{mail_service}->addbox( $self->{part} , $password ) < 0);
+	$self->{mail_service}->delforward( $self->{localpart} ) if( $self->exists_forward == 1 );
+	return -1 if( $self->{mail_service}->addbox( $self->{localpart} , $password ) < 0);
 }
 
 sub changepassword
 {
-    my ($self, $newpass) = @_;
-    return -1 if( $self->{mail_service}->change_box_password( $self->{part}, $newpass ) < 0 );
+	my ($self, $newpass) = @_;
+	return -1 if( $self->{mail_service}->change_box_password( $self->{localpart}, $newpass ) < 0 );
 }
 
-
-
 1;

Modified: trunk/vhffs-backend/conf/vhffs.conf.dist.in
===================================================================
--- trunk/vhffs-backend/conf/vhffs.conf.dist.in	2007-08-31 16:55:58 UTC (rev 849)
+++ trunk/vhffs-backend/conf/vhffs.conf.dist.in	2007-08-31 17:13:11 UTC (rev 850)
@@ -317,7 +317,6 @@
 
 		domain		=	users.myhost.org
 		groupneeded	=	yes
-		user 		=	cat
 
 		# URL to the documentation (optional)
 		url_doc		=	http://help.myhoster.net/mailuser
@@ -330,7 +329,6 @@
 		activate	=	no
 
 		domain		=	projects.myhost.org
-		user 		=	cat
 
 		# URL to the documentation (optional)
 		url_doc			=	http://help.myhoster.net/mailgroup

Modified: trunk/vhffs-panel/group/prefs.pl
===================================================================
--- trunk/vhffs-panel/group/prefs.pl	2007-08-31 16:55:58 UTC (rev 849)
+++ trunk/vhffs-panel/group/prefs.pl	2007-08-31 17:13:11 UTC (rev 850)
@@ -45,6 +45,7 @@
 use Vhffs::Panel::Main;
 use Vhffs::Panel::Group;
 use Vhffs::Functions;
+use Vhffs::Services::MailGroup;
 
 my $panel = new Vhffs::Panel::Main();
 exit 0 unless $panel;
@@ -177,14 +178,15 @@
             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( defined $mg )
 		{
 			if( $forward eq "" )  {
 				$mg->delforward( $forward );
+				$panel->add_info( gettext('Forward deleted') );
 			}else {
 				$mg->addforward( $forward );
+				$panel->add_info( gettext('Forward added') );
 			}
 		}
             }
@@ -208,21 +210,18 @@
 	$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->get_service_availability('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 );
+	my $mg = init Vhffs::Services::MailGroup( $vhffs , $group );
+	if( defined $mg )
+	{
+		$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 );
 
-			if( defined ( my $url = $mg->{config}->{'url_doc'} ) )  {
-				$template->param( HELP_TEXT => gettext('Help') );
-				$template->param( HELP_URL => $url );
-			}
+		if( defined ( my $url = $mg->{config}->{'url_doc'} ) )  {
+			$template->param( HELP_TEXT => gettext('Help') );
+			$template->param( HELP_URL => $url );
 		}
 	}
 	

Modified: trunk/vhffs-panel/lost_ack.pl
===================================================================
--- trunk/vhffs-panel/lost_ack.pl	2007-08-31 16:55:58 UTC (rev 849)
+++ trunk/vhffs-panel/lost_ack.pl	2007-08-31 17:13:11 UTC (rev 850)
@@ -42,6 +42,7 @@
 use Vhffs::User;
 use Vhffs::Main;
 use Vhffs::Panel::Main;
+use Vhffs::Services::MailUser;
 
 my $panel = new_light Vhffs::Panel::Main();
 my $vhffs = $panel->{'vhffs'};
@@ -58,16 +59,11 @@
 {
     #create a new password for this user
     my $plainpassword = $user->generate_password;
-    my $mu;
-    if( $vhffs->get_config->get_service_availability('mailuser') == 1 ) {
-        use Vhffs::Services::MailUser;
-        $mu = init Vhffs::Services::MailUser( $vhffs , $user );
-        if( defined $mu  &&  ref($mu)  &&  $mu->available > 0 && $mu->exists_box) {
-            $mu->changepassword( $plainpassword);
-        } 
-    }
-
-    
+    my $mu = init Vhffs::Services::MailUser( $vhffs , $user );
+    if( defined $mu  &&  $mu->exists_box) {
+        $mu->changepassword( $plainpassword );
+    } 
+  
     # Send a mail with plain password inside
     my $subject = "Password changed";
     my $content = sprintf("Hello %s %s,\n\nYou asked for a new password, here are your new login information:\nUser: %s\nPassword: %s\n\nVHFFS Administrators\n", $user->get_firstname, $user->get_lastname, $user->get_username, $plainpassword );

Modified: trunk/vhffs-panel/user/prefs.pl
===================================================================
--- trunk/vhffs-panel/user/prefs.pl	2007-08-31 16:55:58 UTC (rev 849)
+++ trunk/vhffs-panel/user/prefs.pl	2007-08-31 17:13:11 UTC (rev 850)
@@ -44,6 +44,7 @@
 use Vhffs::Panel::Main;
 use Vhffs::Panel::Menu;
 use Vhffs::Panel::User;
+use Vhffs::Services::MailUser;
 
 my $panel = new Vhffs::Panel::Main();
 my $cgi = $panel->{cgi};
@@ -136,6 +137,11 @@
             $pwd_change = 1;
             $user->set_password( $pass1 );
             $panel->add_info( gettext('Password changed') );
+
+	    my $mu = init Vhffs::Services::MailUser( $vhffs , $user );
+	    if( defined $mu  &&  $mu->exists_box) {
+	        $mu->changepassword( $pass1 );
+	    }
         }
 
         my $prevmail = $user->get_mail();
@@ -153,14 +159,10 @@
             $panel->add_error( gettext("An error occured while updating the user account") );
         }
 
-        my $mu; 
-        if( $vhffs->get_config->get_service_availability('mailuser') == 1 ) {
-            use Vhffs::Services::MailUser;
-            $mu = init Vhffs::Services::MailUser( $vhffs , $user );
-        }
 
-    # check if mu is not a negative integer
-        if( defined $mu  &&  $mu >= 0  &&  $mu->available > 0 )  {
+	# -- Mail User
+	my $mu = init Vhffs::Services::MailUser( $vhffs , $user );
+        if( defined $mu )  {
 
             my $mail_activate = $cgi->param( "mail_activate" );
             my $nospam = $cgi->param( "mail_nospam" );
@@ -359,18 +361,14 @@
 }
 
 
-if( $vhffs->get_config->get_service_availability('mailuser') == 1 )
-{
-	use Vhffs::Services::MailUser;
+
+my $mu = init Vhffs::Services::MailUser( $vhffs , $user );
+if( defined $mu )  {
     
 	my $subtemplate = new HTML::Template( filename => $templatedir."/panel/user/mailuser.tmpl" );
 	my $subtemplate2;
 	my $config = $vhffs->get_config->get_service( "mailuser" );
-	my $mu  = init Vhffs::Services::MailUser( $vhffs , $user );
 	my $tmp = "";
-
-	if( defined $mu  &&  $mu >= 0  &&  $mu->available > 0 )
-	{
     
     $subtemplate->param( ACTIV_CHECKED => 1 ) if( $mu->exists == 1         );
     $subtemplate->param( POP_CHECKED => 1 )   if( $mu->exists_box == 1     );
@@ -405,8 +403,7 @@
     
     $subtemplate->param( MAILUSER_OPTIONS => $tmp );
     $template->param( MAILUSER => $subtemplate->output );
-	}
-    
 }
+    
 
 display Vhffs::Panel::Main($panel, $template->output);


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