home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
- #
- # CFV_HANDLER - Handle a CFV from usenet. Expects candidate messages on STDIN.
- #
- # Copyright (c) 1991 by Dave Hayes - dave@elxr.jpl.nasa.gov
- #
- # All rights reserved.
- #
- # Permission is given to distribute these sources, as long as the
- # copyright messages are not removed, and no monies are exchanged.
- #
- # Rev 2 - Handles multiple newsgroup votes
- #
- #####################CONFIGURE THIS STUFF!
- #
- require '/home/dave/news/cfv/ads/cfv.config';
- #
- #####################END OF CONFIGURATION STUFF!
- #
- $debug = 0; # Use this if you want verbosity on ERRLOG
- #
- # This may be a faster way to read messages. With MailMan I didn't
- # care if the message was in an array. Here I do cause I'm searching the
- # body.
- # Thanks to goehring@mentor.cc.purdue.edu (Scott Goehring)
- $* = 1;
- $save = $/; undef $/; $message = <STDIN>; $/ = $save;
- study $message;
- ($from) = $message =~ /^From: (.+)$/;
- ($subject) = $message =~ /^Subject: (.+)$/;
- $subject =~ tr/A-Z/a-z/;
- &maildebug("Message from '$from' with subject '$subject'");
- #
- # Check the date now. Must be within bounds
- ($smon,$sday,$syr,$shr,$smin) = split(/[\s\:\/]/,$start_date);
- ($emon,$eday,$eyr,$ehr,$emin) = split(/[\s\:\/]/,$end_date);
- ($x1,$cmin,$chr,$cday,$cmon,$cyr,$x2,$x3,$x4) = (localtime);
- $s = &numdate($syr,$smon,$sday,$shr,$smin);
- $e = &numdate($eyr,$emon,$eday,$ehr,$emin);
- $c = &numdate($cyr,$cmon+1,$cday,$chr,$cmin);
- if ($s > $c || $c > $e) {
- &mailwarn("Invalid date to vote. Message follows:");
- print ERRLOG $message;
- open(ACK,"<$refused") || &mailwarn("Couldn't open '$refused': out
- of date vote from '$from': $!");
- open(MAIL,"|/usr/lib/sendmail -t") || &mailwarn("Couldn't pipe to
- mail: out of date vote from '$from'");
- print MAIL <<EOT;
- From: $moderator
- To: $from
- Subject: Error in your vote
- EOT
- print MAIL <ACK>;
- print MAIL "\nYour vote is not with in the date bounds
- '$start_date' and '$end_date'.\n";
- close(MAIL);
- &maildie("EOT.",0);
- }
-
- #
- # Now check for a valid vote.
- foreach $group (@groups) {
- $got = 0;
- foreach $yv (@yesvotes) {
- if (($message =~ /$yv[^\n]*$group/i) || ($message =~ /$group[^\n]*$yv/i)) {
- #
- # A YES vote
- #
- &mass_ack;
- open(VOTES,">>$votes") || &mailwarn("Couldn't open
- '$votes': YES vote from '$from' : ($<,$>) $!");
- print VOTES "[Y] $group $from\n"; close(VOTES);
- $got = 1;
- $vote{$group} = "Y";
- }
- }
- foreach $nv (@novotes) {
- if (($message =~ /$nv[^\n]*$group/i) || ($message =~ /$group[^\n]*$nv/i)) {
- #
- # A NO vote
- #
- &mass_ack;
- open(VOTES,">>$votes") || &mailwarn("Couldn't open
- '$votes': NO vote from '$from' : $! ");
- print VOTES "[N] $group $from\n";
- close(VOTES);
- $vote{$group} = "N";
- $got = 1;
- }
- }
- if (!$got) {
- open(VOTES,">>$votes") || &mailwarn("Couldn't open '$votes': NO
- vote from '$from' : $! ");
- print VOTES "[A] $group $from\n";
- close(VOTES);
- $vote{$group} = "A";
- }
- }
-
- open(ACK,"<$single_ack") || &mailwarn("Couldn't open '$single_ack':
- YES vote from '$from': $!");
- open(MAIL,"|/usr/lib/sendmail -t") || &mailwarn("Couldn't pipe to
- mail: out of date vote from '$from'");
- print MAIL <<EOT;
- From: $moderator
- To: $from
- Subject: Your vote
- EOT
-
- print MAIL <ACK>;
- print MAIL "\nYour vote was recorded like so:\n";
- foreach $group (@groups) {
- if ($vote{$group} eq "A") { $v = "Abstain"; }
- if ($vote{$group} eq "Y") { $v = "Yes"; }
- if ($vote{$group} eq "N") { $v = "No"; }
- print MAIL "\tFor group $group: $v\n";
- }
- close(MAIL); close(ACK);
-
- ######
- ###### SUBROUTINES GO HERE
- ######
- sub mass_ack {
- return if (defined($acked));
- open(MASS,">>$mass_ack") || &mailwarn("Couldn't open '$mass_ack':
- YES vote from '$from' : ($<,$>) $!");
- print MASS "$from\n"; close(MASS);
- $acked = 1;
- }
-
- sub mailwarn {
- local($reason) = shift(@_);
- &setup_mail if (!defined($mail_is_on));
- print ERRLOG <<EOT;
- From: cfv_daemon
- To: $moderator
- Subject: CFV daemon report
-
- Warning about Mail from: '$from' with subject: '$subject':
- Reason: $reason.
- EOT
-
- }
- sub maillog {
- local($reason) = shift(@_);
-
- &setup_mail if (!defined($mail_is_on));
- print ERRLOG <<EOT;
- From: cfv_daemon
- To: $moderator
- Subject: CFV daemon report
-
- Mail from: '$from' with subject: '$subject' logged:
- Reason: $reason.
- EOT
- close(ERRLOG);
- }
- sub maildebug {
- local($reason) = shift(@_);
-
- return 0 if (!$debug);
- &setup_mail if (!defined($mail_is_on));
- print ERRLOG <<EOT;
- From: cfv_daemon
- To: $moderator
- Subject: CFV daemon report
-
- Debug Mail from: '$from' with subject: '$subject':
- Reason: $reason.
- EOT
- }
-
- sub maildie {
- local($reason) = shift(@_);
- local($exitcode) = shift(@_);
-
- exit 0 if ($exitcode == 0);
- &setup_mail if (!defined($mail_is_on));
- print ERRLOG <<EOT;
- From: cfv_daemon
- To: $moderator
- Subject: CFV daemon report
-
- Mail from: '$from' with subject: '$subject' failed:
- Reason: $reason.
- EOT
- close(ERRLOG);
- exit $exitcode;
- }
-
- sub numdate {
- local($y,$m,$d,$mn,$h) = @_;
- local($n);
-
- $n = $h + (100*$mn) + (10000*$d) + (1000000*$m) + ($y * 100000000);
- &maildebug("Converted ($y,$m,$d,$mn,$h) to $n");
- return $n;
- }
-
- sub setup_mail {
- $mail_is_on = 1;
- if (!open(ERRLOG,"| /usr/lib/sendmail -t")) {
- open(ERRLOG,">>$backup_err") || warn "Augh! Can't redirect
- ERRLOG to someplace useful!\n";
- }
- select(ERRLOG); $| = 1;
- }
-