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.
- #
- #######################CONFIGURE HERE
- #
- # Pathname of working directory (all files relative to here)
- $cfv_dir="/home/dave/news/cfv/sec";
- #
- # Group you are running a vote for
- $group = "comp.security.misc";
- #
- # Pathnames of some files (shouldn't need to change these)
- $mass_ack = "$cfv_dir/mass_acknowledge"; # Where the currently voted people go
- $votes = "$cfv_dir/votes"; # Where the votes go
- $single_ack = "$cfv_dir/acknowledge"; # Canned vote acknowledgement
- $refused = "$cfv_dir/refused"; # Canned vote refusal
- #
- # Other things
- $start_date = "4/13/92 06:00"; # Voting starts
- $end_date = "5/13/92 18:00"; # Voting ends
- $moderator = "dave@elxr"; # Who to send errors to
- $backup_err = "$cfv_dir/errors"; # Where to send errors to if above fails
- #
- # Regexp definitions.
- # The software looks for a match such that one of the below regexps
- preceeds one of the
- # above newsgroups. Note the "\\" used to denote a "\", thus a PERL token of "\n"
- # should be written as "\\n" below.
- #
- # Valid YES vote substrings
- @yesvotes = (
- "yes.*$group",
- "in.*favo[ur].*$group"
- );
- #
- # Valid NO vote regexps
- @novotes = (
- "no.*$group",
- "against.*$group"
- );
- #
- #####################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 that we have a valid subject
- foreach $sub (@subjects) {
- $found = 1 if ($subject =~ /$sub/i);
- }
- if (!defined($found)) {
- &mailwarn("Invalid subject. (@subjects) Message follows:");
- print ERRLOG $message;
- &maildie("EOT.",0);
- }
- #
- # 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 $yv (@yesvotes) {
- if ($message =~ /$yv/i) {
- #
- # A YES vote
- #
- open(MASS,">>$mass_ack") || &mailwarn("Couldn't open
- '$mass_ack': YES vote from '$from' : ($<,$>) $!");
- print MASS "$from\n";
- close(MASS);
- open(VOTES,">>$votes") || &mailwarn("Couldn't open '$votes':
- YES vote from '$from' : ($<,$>) $!");
- print VOTES "[Y] $from\n";
- close(VOTES);
- 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 YES vote was recorded successfully.\n";
- close(MAIL); close(ACK);
- &maildie("",0);
- }
- }
- foreach $nv (@novotes) {
- if ($message =~ /$nv/i) {
- #
- # A NO vote
- #
- open(MASS,">>$mass_ack") || &mailwarn("Couldn't open
- '$mass_ack': NO vote from '$from' : $!");
- print MASS "$from\n";
- close(MASS);
- open(VOTES,">>$votes") || &mailwarn("Couldn't open '$votes': NO
- vote from '$from' : $! ");
- print VOTES "[N] $from\n";
- close(VOTES);
- open(ACK,"<$single_ack") || &mailwarn("Couldn't open
- '$single_ack': NO 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 NO vote was recorded successfully.\n";
- &maildie("",0);
- }
- }
- #
- # If we get here this is an invalid vote
- open(ACK,"<$refused") || &mailwarn("Couldn't open '$refused': INVALID
- 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 "\nNo valid vote could be found in your message.\n\nValid
- YES votes are of the wildcard form:\n\n";
- print MAIL join("\n",@yesvotes);
- print MAIL "\n\nValid NO votes are of the wildcard form:\n\n";
- print MAIL join("\n",@novotes);
- close(ACK); close(MAIL);
- $message =~ s/^/>>>/g;
- &mailwarn("Invalid vote. Message follows:\n\n$message");
- &maildie("EOT",0);
-
- ######
- ###### SUBROUTINES GO HERE
- ######
- 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;
- }
-