[vhffs-dev] [svn] commit: r144 - in /trunk: vhffs-api/src/Vhffs/ vhffs-api/src/Vhffs/Services/ vhffs-backend/conf/ vhffs-backend/src/pgsql/ vhffs-panel/mail/ vhffs-panel/templates/mail/ vhffs-panel/templates/user/ vhffs-panel/user/

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


Author: soda
Date: Fri Jan 27 02:37:25 2006
New Revision: 144

Log:
First fix for use spam and virus protection.
The schema has changed, only add two columns in vhffs_boxes relation. Those columns are boolean.
So, you have to change the configuration of the MTA to use it :-)

The configuration file has changed, now a <mail></mail> section exist in <services/>
For example :
<services>
	... blblabla....
	<mail>
		use_nospam = yes
		use_novirus = yes
	</mail>
</services>

MailUser has changed, so, the user accounts can use those services.

It's here for testing only.




Modified:
    trunk/vhffs-api/src/Vhffs/Conf.pm
    trunk/vhffs-api/src/Vhffs/Services/Mail.pm
    trunk/vhffs-api/src/Vhffs/Services/MailUser.pm
    trunk/vhffs-backend/conf/vhffs.conf
    trunk/vhffs-backend/src/pgsql/create_boxes.sql
    trunk/vhffs-panel/mail/prefs.pl
    trunk/vhffs-panel/templates/mail/prefs_box.tmpl
    trunk/vhffs-panel/templates/user/mailuser.tmpl
    trunk/vhffs-panel/user/prefs.pl
    trunk/vhffs-panel/user/prefs_save.pl

Modified: trunk/vhffs-api/src/Vhffs/Conf.pm
==============================================================================
--- trunk/vhffs-api/src/Vhffs/Conf.pm (original)
+++ trunk/vhffs-api/src/Vhffs/Conf.pm Fri Jan 27 02:37:25 2006
@@ -736,6 +736,22 @@
 	}
 }
 
+sub use_nospam
+{
+	return -1 if( ! defined $Config{"services"}{"mail"} );
+	return -1 if( ! defined $Config{"services"}{"mail"}{'use_nospam'} );
+	return 1 if( $Config{"services"}{"mail"}{'use_nospam'} eq "yes");
+	return 0;
+}
+
+sub use_novirus
+{
+	return -1 if( ! defined $Config{"services"}{"mail"} );
+	return -1 if( ! defined $Config{"services"}{"mail"}{'use_novirus'} );
+	return 1 if( $Config{"services"}{"mail"}{'use_novirus'} eq "yes");
+	return 0;
+}
+
 
 
 1;

Modified: trunk/vhffs-api/src/Vhffs/Services/Mail.pm
==============================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Mail.pm (original)
+++ trunk/vhffs-api/src/Vhffs/Services/Mail.pm Fri Jan 27 02:37:25 2006
@@ -159,6 +159,8 @@
 		}
 		$self->{'boxes'}{$name}{'password'} = $self->{'boxes'}{$name}{'password_hash'};
 		$self->{'boxes'}{$name}{'changed'} = 0;
+		$self->{'boxes'}{$name}{'nospam'} = 1 if( $self->{'boxes'}{$name}{'nospam'} eq 't' );
+		$self->{'boxes'}{$name}{'novirus'} = 1 if( $self->{'boxes'}{$name}{'novirus'} eq 't' );
 
 	}
 	######### End of boxes fetching ########
@@ -211,11 +213,16 @@
 	#COMMIT THE BOX PART
 	foreach $name ( keys %{$self->{'boxes'}} )
 	{
-		next if( ! defined $self->{'boxes'}{$name}{'password'} );
 		next if( ( defined $self->{'boxes'}{'changed'}{'changed'} ) && ( $self->{'boxes'}{'changed'}{'changed'} == 0 ) );
 		
     	$request = $self->{'db'}->{'DB_READ'}->prepare("SELECT * FROM vhffs_boxes WHERE domain='" . $self->{'domain'} . "' AND local_part='".$name."'");
 	    $rows = $request->execute;
+
+		#If boxes does not have nospam or novirus attribute
+		#so, we set t to 0
+		# This will create the attribute and initialize it
+		$self->{'boxes'}{$name}{'novirus'} = 0 if( ! defined( $self->{'boxes'}{$name}{'novirus'} ));
+		$self->{'boxes'}{$name}{'nospam'} = 0 if( ! defined( $self->{'boxes'}{$name}{'nospam'} ));
 
 		if( $rows == 0 ) #PopBox NOT created, we must create it
 		{
@@ -223,13 +230,14 @@
 			my $userhash = Vhffs::Functions::hash_popuser( $name );
 			my $passwordhash = "";
 
-			$query = "INSERT INTO vhffs_boxes VALUES('". $self->{'domain'} ."' , '". $name ."' , '". $domainhash ."' , '".$self->{'boxes'}{$name}{'password'}."' , '".$userhash."' , '')";
+			$query = "INSERT INTO vhffs_boxes(domain,local_part,domain_hash,password_hash,mbox_name,password,nospam,novirus) VALUES('". $self->{'domain'} ."' , '". $name ."' , '". $domainhash ."' , '".$self->{'boxes'}{$name}{'password'}."' , '".$userhash."' , '' ,'".$self->{'boxes'}{$name}{'nospam'}."' , '".$self->{'boxes'}{$name}{'novirus'}."')";
 			$request = $self->{'db'}->{'DB_WRITE'}->prepare( $query );
 			$request->execute;
 		}
 		else	#Popbox already created
 		{
-			$query = "UPDATE vhffs_boxes SET password_hash='".$self->{'boxes'}{$name}{'password'}."' WHERE local_part='".$self->{'boxes'}{$name}{'local_part'}."' AND domain='".$self->{'domain'}."'";
+
+			$query = "UPDATE vhffs_boxes SET nospam='".$self->{'boxes'}{$name}{'nospam'}."', novirus='".$self->{'boxes'}{$name}{'novirus'}."', password_hash='".$self->{'boxes'}{$name}{'password'}."' WHERE local_part='".$self->{'boxes'}{$name}{'local_part'}."' AND domain='".$self->{'domain'}."'";
 			$request = $self->{'db'}->{'DB_WRITE'}->prepare( $query );
 			$request->execute;
 		}
@@ -297,6 +305,45 @@
 	return 1;
 }
 
+# The change_spam_status function change the status of a box 
+# on the mail domain given in parmeter
+# If the spam removal was enable, it will be disable at next commit() on object
+sub change_spam_status
+{
+	my $self = shift;
+	my $local_part = shift;
+
+	return -1 if( ! defined $self->{'boxes'}{$local_part} );
+
+	if( ! defined( $self->{'boxes'}{$local_part}{'nospam'} ) )
+	{
+		$self->{'boxes'}{$local_part}{'nospam'} = 0;
+	}
+
+	$self->{'boxes'}{$local_part}{'nospam'} = ( ( $self->{'boxes'}{$local_part}{'nospam'} + 1 ) % 2 );
+	$self->{'boxes'}{$local_part}{'changed'} = 1;
+	return 1;
+}
+
+
+#work as change_spam_status
+sub change_virus_status
+{
+	my $self = shift;
+	my $local_part = shift;
+
+	return -1 if( ! defined $self->{'boxes'}{$local_part} );
+
+	if( ! defined( $self->{'boxes'}{$local_part}{'novirus'} ) )
+	{
+		$self->{'boxes'}{$local_part}{'novirus'} = 0;
+	}
+
+	$self->{'boxes'}{$local_part}{'novirus'} = ( ( $self->{'boxes'}{$local_part}{'novirus'} + 1 ) % 2 );
+	$self->{'boxes'}{$local_part}{'changed'} = 1;
+	return 1;
+}
+
 
 
 sub addforward
@@ -409,6 +456,7 @@
 
 
 
+
 #Following functions is needed by courier to fetch accounts
 
 sub crypt_pwd
@@ -437,6 +485,37 @@
 	my $self = shift;
 	return $self->{'domain'};
 }
+
+
+
+###########################
+# ospam function only use when the mail domain
+# if fetched
+# It can explain if a box ue antispam or not
+# for example $mail->use_nospam( 'myaccount' );
+# returns 	-1 if error
+# 			0 if nospam is used
+#			1 if spam is used
+sub use_nospam
+{
+	my $self = shift;
+	my $box = shift;
+
+	return -1 if(  ! defined( $self->{'boxes'}->{$box} ) );
+	return 1 if( $self->{'boxes'}->{$box}{'nospam'} == 1 );
+	return 0;
+}
+
+sub use_novirus
+{
+	my $self = shift;
+	my $box = shift;
+
+	return -1 if(  ! defined( $self->{'boxes'}->{$box} ) );
+	return 1 if( $self->{'boxes'}->{$box}{'novirus'} == 1 );
+	return 0;
+}
+
 
 
 sub get_boxespath

Modified: trunk/vhffs-api/src/Vhffs/Services/MailUser.pm
==============================================================================
--- trunk/vhffs-api/src/Vhffs/Services/MailUser.pm (original)
+++ trunk/vhffs-api/src/Vhffs/Services/MailUser.pm Fri Jan 27 02:37:25 2006
@@ -118,6 +118,33 @@
 	return $self->{object}->exists_box( $self->{part} );
 }
 
+sub use_nospam
+{
+	my $self = shift;
+	return $self->{object}->use_nospam( $self->{part} );
+}
+
+sub use_novirus
+{
+	my $self = shift;
+	return $self->{object}->use_novirus( $self->{part} );
+}
+
+sub change_spam_status
+{
+	my $self = shift;
+	$self->{object}->change_spam_status( $self->{part} );
+	return -2 if( $self->{object}->commit < 0 );
+	return 1;
+}
+
+sub change_virus_status
+{
+	my $self = shift;
+	$self->{object}->change_virus_status( $self->{part} );
+	return -2 if( $self->{object}->commit < 0 );
+	return 1;
+}
 
 
 sub addforward

Modified: trunk/vhffs-backend/conf/vhffs.conf
==============================================================================
--- trunk/vhffs-backend/conf/vhffs.conf (original)
+++ trunk/vhffs-backend/conf/vhffs.conf Fri Jan 27 02:37:25 2006
@@ -197,6 +197,10 @@
 		uid	=	33
 		gid	=	33
 	</subversion>
+	<mail>
+		use_nospam	=	yes
+		use_novirus	=	yes
+	</mail>
 	<mailuser>
 		activate	=	yes
 		domain		=	tuxfamily.org

Modified: trunk/vhffs-backend/src/pgsql/create_boxes.sql
==============================================================================
--- trunk/vhffs-backend/src/pgsql/create_boxes.sql (original)
+++ trunk/vhffs-backend/src/pgsql/create_boxes.sql Fri Jan 27 02:37:25 2006
@@ -6,5 +6,7 @@
 	password_hash varchar NOT NULL,
 	mbox_name varchar NOT NULL,
 	password varchar NOT NULL,
+	nospam boolean,
+	novirus boolean,
 	PRIMARY KEY (domain,local_part)
 ) WITH OIDS;

Modified: trunk/vhffs-panel/mail/prefs.pl
==============================================================================
--- trunk/vhffs-panel/mail/prefs.pl (original)
+++ trunk/vhffs-panel/mail/prefs.pl Fri Jan 27 02:37:25 2006
@@ -32,6 +32,9 @@
 my $domain = $cgi->param("name");
 my $template;
 my $subtemplate;
+my $subtemplate2;
+my $message;
+my $temp;
 
 my $templatedir = $vhffs->get_config->get_templatedir;
 
@@ -111,12 +114,56 @@
 	my $boxes = $mail->get_boxes;
 	foreach( sort keys %{$boxes} )
 	{
+		$temp = "";
 		$subtemplate = new HTML::Template( filename => $templatedir."/mail/prefs_box.tmpl" );
 		$subtemplate->param( ACCOUNT => $_ . "\@" . $mail->get_domain );
 		$subtemplate->param( LOCALPART => $_ );
 		$subtemplate->param( TEXT_CHANGE_PASSWORD => gettext( "Change Password" ) );
 		$subtemplate->param( TEXT_DELETE => gettext( "Delete this mail account" ) );
 		$subtemplate->param( DOMAIN => $mail->get_domain );
+
+
+
+
+		if( $vhffs->get_config->use_nospam == 1 )
+		{
+			$subtemplate2 = new HTML::Template( filename => $templatedir."/mail/prefs_spam.tmpl" );
+			$subtemplate2->param( LOCALPART => $_ );
+			$subtemplate2->param( DOMAIN => $mail->get_domain );
+			if( $mail->use_nospam( $_ ) == 1 )
+			{
+				$message = gettext( "Disable anti-spam" );	
+			}
+			else
+			{
+				$message = gettext( "Enable anti-spam" );	
+			}
+			$subtemplate2->param( TEXT_SPAM => $message );
+			$temp .= $subtemplate2->output;
+		}
+
+
+
+		if( $vhffs->get_config->use_novirus == 1 )
+		{
+			$subtemplate2 = new HTML::Template( filename => $templatedir."/mail/prefs_virus.tmpl" );
+			$subtemplate2->param( LOCALPART => $_ );
+			$subtemplate2->param( DOMAIN => $mail->get_domain );
+			if( $boxes->{$_}{'novirus'} == 1 )
+			{
+					$message = gettext( "Disable anti-virus" );	
+			}
+			else
+			{
+				$message = gettext( "Enable anti-virus" );	
+			}
+			$subtemplate2->param( TEXT_VIRUS => $message );
+			$temp .= $subtemplate2->output;
+		}
+
+
+
+		$subtemplate->param( OTHER => $temp );
 
 		$output .= $subtemplate->output;
 	}	

Modified: trunk/vhffs-panel/templates/mail/prefs_box.tmpl
==============================================================================
--- trunk/vhffs-panel/templates/mail/prefs_box.tmpl (original)
+++ trunk/vhffs-panel/templates/mail/prefs_box.tmpl Fri Jan 27 02:37:25 2006
@@ -11,6 +11,7 @@
 			<input type="submit" value="<tmpl_var name="TEXT_CHANGE_PASSWORD">" />
 		</form>
 	</td>
+	<tmpl_var name="OTHER">
 	<td>
 		<form method="post" action="delete_box.pl">
 			<input type="hidden" name="LOCALPART" value="<tmpl_var name="LOCALPART">" />

Modified: trunk/vhffs-panel/templates/user/mailuser.tmpl
==============================================================================
--- trunk/vhffs-panel/templates/user/mailuser.tmpl (original)
+++ trunk/vhffs-panel/templates/user/mailuser.tmpl Fri Jan 27 02:37:25 2006
@@ -16,6 +16,9 @@
 					<p>
 						<input name="mail_usage" id="mail_usage_box" value="1" type="radio" <tmpl_var name="POP_CHECKED">/>
 						<label for="mail_usage_box" ><tmpl_var name="TEXT_MAILBOX"></label>
+						<ul>
+						<tmpl_var name="MAILUSER_OPTIONS">
+						</ul>
 					</p>
 					<p>
 						<input name="mail_usage" id="mail_usage_foward" value="2" type="radio" <tmpl_var name="FWD_CHECKED">/>

Modified: trunk/vhffs-panel/user/prefs.pl
==============================================================================
--- trunk/vhffs-panel/user/prefs.pl (original)
+++ trunk/vhffs-panel/user/prefs.pl Fri Jan 27 02:37:25 2006
@@ -123,8 +123,10 @@
     use Vhffs::Services::MailUser;
     
     my $subtemplate = new HTML::Template( filename => $templatedir."/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 )
 	{
@@ -137,7 +139,25 @@
     $subtemplate->param( TEXT_MAILINFO2 => gettext("There is two possible usages :") );
     $subtemplate->param( TEXT_MAILBOX => sprintf( gettext("Use VHFFS servers to manage this mail,<br>you should use use the host pop.%s or imap.%s to fetch your mails") , $config->{domain} , $config->{domain} ) );
     $subtemplate->param( TEXT_MAILFORWARD => sprintf( gettext("Forward emails from %s\@%s to %s"), $username, $config->{domain}, $usermail ) );
+
+	if( $vhffs->get_config->use_nospam == 1 )
+	{
+	    $subtemplate2 = new HTML::Template( filename => $templatedir."/user/mailuserspam.tmpl" );
+	    $subtemplate2->param( TEXT_NOSPAM => gettext("Use anti-spam protection") );
+	    $subtemplate2->param( ACTIV_CHECKED => "checked" ) if( $mu->use_nospam == 1         );
+		$tmp .= $subtemplate2->output;
+	}
+
+	if( $vhffs->get_config->use_novirus == 1 )
+	{
+    	$subtemplate2 = new HTML::Template( filename => $templatedir."/user/mailuservirus.tmpl" );
+	    $subtemplate2->param( TEXT_VIRUS => gettext("Use anti-virus protection") );
+	    $subtemplate2->param( ACTIV_CHECKED => "checked" ) if( $mu->use_novirus == 1         );
+		$tmp .= $subtemplate2->output;
+	}
+
     
+    $subtemplate->param( MAILUSER_OPTIONS => $tmp );
     $template->param( MAILUSER => $subtemplate->output );
 	}
     

Modified: trunk/vhffs-panel/user/prefs_save.pl
==============================================================================
--- trunk/vhffs-panel/user/prefs_save.pl (original)
+++ trunk/vhffs-panel/user/prefs_save.pl Fri Jan 27 02:37:25 2006
@@ -98,7 +98,7 @@
 	}
 	else
 	{
-		$message = gettext("User Successfully modified");
+		$message = gettext("User Successfully modified") . "<br>";
 	}
 	
 	if( $vhffs->get_config->use_mailuser == 1 )
@@ -106,6 +106,26 @@
 		use Vhffs::Services::MailUser;
 		my $mu = init Vhffs::Services::MailUser( $vhffs , $user );
 		my $mail_activate = $cgi->param( "mail_activate" );
+		my $nospam = $cgi->param( "mail_nospam" );
+		my $novirus = $cgi->param( "mail_novirus" );
+		if( ( defined $nospam ) && ( $nospam eq "on" ) )
+		{
+			$nospam = 1;
+		}
+		else
+		{
+			$nospam = 0;
+		}
+		if( ( defined $novirus ) && ( $novirus eq "on" ) )
+		{
+			$novirus = 1;
+		}
+		else
+		{
+			$novirus = 0;
+		}
+
+		
 		if( ( defined $mail_activate ) && ( $mail_activate eq "on" ) )
 		{
 			my $usage = $cgi->param( "mail_usage" );
@@ -127,6 +147,14 @@
 					{
 						$message = gettext("An error occured while adding the box");
 					}
+					elsif( ( $nospam == 1 ) && ( $mu->change_spam_status < 0 ) )
+					{
+						$message = gettext("An error occured while adding the box (anti-spam adding)");
+					}
+					elsif( ( $novirus == 1 ) && ( $mu->change_virus_status < 0 ) )
+					{
+						$message = gettext("An error occured while adding the box (anti-virus adding)");
+					}
 					else
 					{
 						$message .= "<br>";
@@ -140,6 +168,61 @@
 					{
 						$mu->delbox;
 						$mu->addbox( $pass1 );
+					}
+
+					#We change  the spam status. if the pam status change
+					if( $vhffs->get_config->use_nospam == 1 )
+					{
+						if( ( $nospam == 1 ) && ( $mu->use_nospam == 0 ) )
+						{
+							if( $mu->change_spam_status == 1 )
+							{
+								$message .= gettext( "Change spam protection status for your account\n" );
+							}
+							else
+							{
+								$message .= gettext( "Error for spam protection\n" );
+							}
+						}
+						if( ( $nospam == 0 ) && ( $mu->use_nospam == 1 ) )
+						{
+							if( $mu->change_spam_status == 1 )
+							{
+								$message .= gettext( "Change spam protection status for your account\n" );
+							}
+							else
+							{
+								$message .= gettext( "Error for spam protection\n" );
+							}
+						}
+					}
+
+					#As spam, the virus status changes only if the user changed values
+					if( $vhffs->get_config->use_novirus == 1 )
+					{
+						if( ( $novirus == 1 ) && ( $mu->use_novirus == 0 ) )
+						{
+							if( $mu->change_virus_status == 1 )
+							{
+								$message .= gettext( "Change anti-virus status for your account\n" );
+							}
+							else
+							{
+								$message .= gettext( "Error for virus protection\n" );
+							}
+						}
+
+						if( ( $novirus == 0 ) && ( $mu->use_novirus == 1 ) )
+						{
+							if( $mu->change_virus_status  == 1 )
+							{
+								$message .= gettext( "Change anti-virus status for your account\n" );
+							}
+							else
+							{
+								$message .= gettext( "Error for virus protection\n" );
+							}
+						}
 					}
 				}
 			}




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