ports/103319: Update: mail/mailrep

Marcelo Araujo araujo at bsdmail.org
Sun Sep 17 04:10:26 UTC 2006


>Number:         103319
>Category:       ports
>Synopsis:       Update: mail/mailrep
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Sun Sep 17 04:10:24 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Marcelo Araujo
>Release:        FreeBSD 6.1-STABLE i386
>Organization:
BSD Experience 
>Environment:


System: FreeBSD 6.1-STABLE #5: Sun Sep  3 08:49:25 BRT 2006
    root at nagazaki.freebsd.org:/usr/src/sys/i386/compile/NAGAZAKI



>Description:


Update MailRep v1.1
- Add Scheduling report from Crontab support.
- Add check variable in Crontab mailrep.


>How-To-Repeat:





>Fix:


--- diff.makefile begins here ---
--- /usr/ports/mail/mailrep/Makefile	Tue Apr 25 16:50:25 2006
+++ Makefile	Sat Sep 16 21:37:25 2006
@@ -6,7 +6,7 @@
 #
 
 PORTNAME=	mailrep
-PORTVERSION=	1.0
+PORTVERSION=	1.1
 CATEGORIES=	mail sysutils
 MASTER_SITES=	http://cs.bon.matrix.com.br/araujo/pub/mailrep/
 
--- diff.makefile ends here ---
--- diff.mailrep.conf begins here ---
--- /usr/local/etc/mailrep/mailrep.conf	Sat Sep 16 21:36:10 2006
+++ mailrep.conf	Sat Sep 16 21:34:00 2006
@@ -26,3 +26,7 @@
 # Delivered Local
 ## relay=local status=sent
 RELAY_LOCAL	= 1 
+# Scheduling in CRONTAB
+# Send-to RBL and ERRORS
+CRON_SET        = 1 
+MAILADDR        = "example at domain"
--- diff.mailrep.conf ends here ---
--- diff.mailrep.pl begins here ---
--- /usr/local/sbin/mailrep.pl	Thu Aug 17 20:26:02 2006
+++ mailrep.pl	Sat Sep 16 21:38:46 2006
@@ -1,10 +1,13 @@
 #!/usr/bin/perl 
 ##
-# This is mailrep.pl v1.0
+# This is mailrep.pl v1.1
 # By - Marcelo Araujo (araujo at bsdmail.org) - http://experience.bsdnetwork.org
 #
-use strict;
+# Add 16 Setember 2006:
+# Scheduling Crontab support
+# By - araujo
 
+use strict;
 my @conf;
 my @setting;
 my $set;
@@ -38,9 +41,12 @@
 my $mail_to_ok;
 my $mail_to_nok;
 my $from_mail;
-
+my @email;
+my @cron_storage;
+my @crontab;
+my $cron_fluxo;
 my $date = localtime time;
-
+my $sendmail = "/usr/sbin/sendmail -t";
 my @stg = ("");
 
 sub conf()
@@ -63,6 +69,11 @@
 			push(@setting, $_);
 			}
 		}	
+		if (/MAILADDR/)
+		{
+			 $_ =~ s/=(..)|\n|#| |\t||:(..)|\|(..)|\"|MAILADDR//g;
+                        @email = $_;
+		}
 	}
 }
 
@@ -442,13 +453,100 @@
 			} 
 }	
 
+sub cron_mailrep()
+{
+        &conf();
+        for($fluxo=0; $fluxo < scalar(@setting); $fluxo++)
+        {
+                if($setting[$fluxo] eq "CRON_SET")
+                {
+                        ##print ("@email\n");
+			@cron_storage = `mailrep.pl --rbl && mailrep.pl --errors`;
+			open(CRON, "</etc/crontab") || die "No crontab scheduling conf\n";
+			while(<CRON>)
+			{
+				push(@crontab,$_);
+			}
+			close(CRON);
+			for(@crontab)
+			{
+				if(/mailrep.pl/)
+				{
+					if(/-cron/)
+					{
+						$cron_fluxo = 0;
+					} else { $cron_fluxo = 1; }
+				} else { $cron_fluxo = 1; }
+			}
+
+		}
+	}
+	if($cron_fluxo == 1)
+	{
+		print("NO SCHEDULING\n");
+		print("Please: ./mailrep.pl --cronsetting <MINUTE> <HOUR>\n");
+	}
+	elsif($cron_fluxo == 0)
+                {
+			my $subject = "Subject: MailReport Daily Scheduling";
+			my $reply_to = "@email";
+			my $to = "@email";
+			open(LOG,">/tmp/log.mailrep");
+			print LOG @cron_storage;
+			close(LOG);
+			open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
+			print SENDMAIL "From: $reply_to\n";
+			print SENDMAIL "To: $to\n";
+			print SENDMAIL "$subject\n";
+			print SENDMAIL "Content-type: text/plain\n\n";
+			print SENDMAIL @cron_storage;
+			close(SENDMAIL);
+			system("rm -f /tmp/log.mailrep");
+                }
+}
+
+sub cron_remove()
+{
+	open(CRON, "/etc/crontab") || die "No crontab scheduling conf\n";
+	while(<CRON>)
+	{
+		unless($_ =~ s/mailrep.pl -cron//g)
+		{
+			push(@crontab,$_);
+		}
+	}
+	close(CRON);	
+	open(CRON, ">/etc/crontab");
+	print CRON @crontab;
+	close(CRON);	
+}
+
+sub cron_setting()
+{
+			if ($ARGV[1] eq "" & $ARGV[2] eq "")
+                        {
+                                print("Usage: ./mailrep.pl --cronsetting <MINUTE> <HOUR>\n");
+                                print("Example: ./mailrep.pl --cronsetting 15 22\n");
+                        }
+                        elsif ($ARGV[2] eq "")
+                        {
+                                print("Usage: ./mailrep.pl --cronsetting $ARGV[1] <HOUR>\n");
+                        } else {
+				open(CRON,">>/etc/crontab");
+                                print ("$ARGV[1] \t$ARGV[2] \t* \t* \t* \tmailrep.pl -cron\n");
+				print CRON "$ARGV[1] \t$ARGV[2] \t* \t* \t* \troot \t/usr/local/sbin/mailrep.pl -cron\n";
+				close(CRON);
+                        }
+
+}
+
 sub help_spamrel()
 {
 	if ($ARGV[0] eq "")
 	{
 		print ("\nmailrep --help\n\n");
 	} 
-	elsif ($ARGV[0] ne "--help" & $ARGV[0] ne "--conf" & $ARGV[0] ne "--rbl" & $ARGV[0] ne "--errors" & $ARGV[0] ne "--license" & $ARGV[0] ne "--mail-to" & $ARGV[0] ne "--mail-from") 
+	elsif ($ARGV[0] ne "--help" & $ARGV[0] ne "--conf" & $ARGV[0] ne "--rbl" & $ARGV[0] ne "--errors" & $ARGV[0] ne "--license" & $ARGV[0] ne "--mail-to" & $ARGV[0] ne "--mail-from" & $ARGV[0] ne "-cron" & $ARGV[0] ne "--cronsetting") 
 	{
 		print("\nmailrep --help\n\n");
 	} 
@@ -459,7 +557,8 @@
 			print("mailrep --mail-to --with user\@domain [Number of emails sent for determined account]\n");
 			print("mailrep --mail-from --with user\@domain [Number of email of who external sends\n");
 			print("mailrep --rbl [To report the number of blockades in the RBLS]\n");
-			print("mailrep --errors [Errors in agreement the configuration archive]\n\n");
+			print("mailrep --errors [Errors in agreement the configuration archive]\n");
+			print("mailrep --cronsetting [Setting Minute and Hour for Scheduling in crontab]\n\n"); 
 		}
 		if ($ARGV[0] eq "--conf")
 		{
@@ -497,6 +596,45 @@
 		if ($ARGV[0] eq "--mail-from")
 		{
 			&mail_from();
+		}
+		if ($ARGV[0] eq "-cron")
+		{
+			&conf();
+        		for($fluxo=0; $fluxo < scalar(@setting); $fluxo++)
+        		{
+                		if($setting[$fluxo] eq "CRON_SET")
+                		{
+					&cron_mailrep();
+					$cron_fluxo = 3;
+				} else {
+					$cron_fluxo = 2;
+				}
+			}
+			if($cron_fluxo == 2)
+			{
+				&cron_remove();
+				print("Please set CRON_SET = 1 in /usr/local/etc/mailrep/mailrep.conf\n");
+			}
+		}
+		if ($ARGV[0] eq "--cronsetting")
+		{
+			&conf();
+                        for($fluxo=0; $fluxo < scalar(@setting); $fluxo++)
+                        {
+                                if($setting[$fluxo] eq "CRON_SET")
+                                {
+					&cron_setting();
+                                        $cron_fluxo = 3;
+                                } else {
+                                        $cron_fluxo = 2;
+                                }
+                        }
+                        if($cron_fluxo == 2)
+                        {
+				&cron_remove();
+				print("Please set CRON_SET = 1 in /usr/local/etc/mailrep/mailrep.conf\n");
+                        }
+
 		}
 }	
 
--- diff.mailrep.pl ends here ---
--- distinfo begins here ---
+MD5 (mailrep-1.1.tar.gz) = dc09675eb1b4342f962a1e57a24f8204
+SHA256 (mailrep-1.1.tar.gz) = 8b8cd3d3a2ef68367760ddabe4490dab+211207b464f812de5c39a6c310cee544
+SIZE (mailrep-1.1.tar.gz) = 23552
--- distinfo ends here ---




>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list