home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume30 / netvote / part01 / multi / cfv_handler.pl < prev    next >
Encoding:
Perl Script  |  1992-06-19  |  5.2 KB  |  208 lines

  1. #!/usr/bin/perl
  2. #
  3. # CFV_HANDLER - Handle a CFV from usenet. Expects candidate messages on STDIN.
  4. # Copyright (c) 1991 by    Dave Hayes - dave@elxr.jpl.nasa.gov
  5. #
  6. # All rights reserved.
  7. #
  8. # Permission is given to distribute these sources, as long as the
  9. # copyright messages are not removed, and no monies are exchanged.
  10. #
  11. # Rev 2 - Handles multiple newsgroup votes
  12. #
  13. #####################CONFIGURE THIS STUFF!
  14. #
  15. require '/home/dave/news/cfv/ads/cfv.config';
  16. #
  17. #####################END OF CONFIGURATION STUFF!
  18. #
  19. $debug = 0;     # Use this if you want verbosity on ERRLOG
  20. #
  21. # This may be a faster way to read messages. With MailMan I didn't
  22. # care if the message was in an array. Here I do cause I'm searching the
  23. # body.
  24. # Thanks to goehring@mentor.cc.purdue.edu (Scott Goehring)
  25. $* = 1;
  26. $save = $/; undef $/; $message = <STDIN>; $/ = $save;
  27. study $message;
  28. ($from) = $message =~ /^From: (.+)$/;
  29. ($subject) = $message =~ /^Subject: (.+)$/;
  30. $subject =~ tr/A-Z/a-z/;
  31. &maildebug("Message from '$from' with subject '$subject'");
  32. #
  33. # Check the date now. Must be within bounds
  34. ($smon,$sday,$syr,$shr,$smin) = split(/[\s\:\/]/,$start_date);
  35. ($emon,$eday,$eyr,$ehr,$emin) = split(/[\s\:\/]/,$end_date);
  36. ($x1,$cmin,$chr,$cday,$cmon,$cyr,$x2,$x3,$x4) = (localtime);
  37. $s = &numdate($syr,$smon,$sday,$shr,$smin);
  38. $e = &numdate($eyr,$emon,$eday,$ehr,$emin);
  39. $c = &numdate($cyr,$cmon+1,$cday,$chr,$cmin);
  40. if ($s > $c || $c > $e) {
  41.     &mailwarn("Invalid date to vote. Message follows:");
  42.     print ERRLOG $message;
  43.     open(ACK,"<$refused") || &mailwarn("Couldn't open '$refused': out
  44. of date vote from '$from': $!"); 
  45.     open(MAIL,"|/usr/lib/sendmail -t") || &mailwarn("Couldn't pipe to
  46. mail: out of date vote from '$from'"); 
  47.     print MAIL <<EOT;
  48. From: $moderator
  49. To: $from
  50. Subject: Error in your vote
  51. EOT
  52.     print MAIL <ACK>;
  53.     print MAIL "\nYour vote is not with in the date bounds
  54. '$start_date' and '$end_date'.\n";
  55.     close(MAIL);
  56.     &maildie("EOT.",0);
  57. }
  58.  
  59. #
  60. # Now check for a valid vote.
  61. foreach $group (@groups) {
  62.     $got = 0;
  63.     foreach $yv (@yesvotes) {
  64.     if (($message =~ /$yv[^\n]*$group/i) || ($message =~ /$group[^\n]*$yv/i))  {
  65.         #
  66.         # A YES vote
  67.         #
  68.         &mass_ack;
  69.         open(VOTES,">>$votes") || &mailwarn("Couldn't open
  70. '$votes': YES vote from '$from' : ($<,$>) $!");
  71.         print VOTES "[Y] $group $from\n"; close(VOTES);
  72.         $got = 1;
  73.         $vote{$group} = "Y";
  74.     }
  75.     }
  76.     foreach $nv (@novotes) {
  77.     if (($message =~ /$nv[^\n]*$group/i) || ($message =~ /$group[^\n]*$nv/i))  {
  78.         #
  79.         # A NO vote
  80.         #
  81.         &mass_ack;
  82.         open(VOTES,">>$votes") || &mailwarn("Couldn't open
  83. '$votes': NO vote from '$from' : $! ");
  84.         print VOTES "[N] $group $from\n";
  85.         close(VOTES);
  86.         $vote{$group} = "N";
  87.         $got = 1;
  88.     }
  89.     }
  90.     if (!$got) {
  91.     open(VOTES,">>$votes") || &mailwarn("Couldn't open '$votes': NO
  92. vote from '$from' : $! ");
  93.     print VOTES "[A] $group $from\n";
  94.     close(VOTES);
  95.     $vote{$group} = "A";
  96.     }
  97. }
  98.  
  99. open(ACK,"<$single_ack") || &mailwarn("Couldn't open '$single_ack':
  100. YES vote from '$from': $!"); 
  101. open(MAIL,"|/usr/lib/sendmail -t") || &mailwarn("Couldn't pipe to
  102. mail: out of date vote from '$from'");
  103. print MAIL <<EOT;
  104. From: $moderator
  105. To: $from
  106. Subject: Your vote
  107. EOT
  108.  
  109. print MAIL <ACK>;
  110. print MAIL "\nYour vote was recorded like so:\n";
  111. foreach $group (@groups) {
  112.     if ($vote{$group} eq "A") { $v = "Abstain"; }
  113.     if ($vote{$group} eq "Y") { $v = "Yes"; }
  114.     if ($vote{$group} eq "N") { $v = "No"; }
  115.     print MAIL "\tFor group $group: $v\n";
  116. }
  117. close(MAIL); close(ACK);
  118.  
  119. ######
  120. ###### SUBROUTINES GO HERE
  121. ######
  122. sub mass_ack {
  123.     return if (defined($acked));
  124.     open(MASS,">>$mass_ack") || &mailwarn("Couldn't open '$mass_ack':
  125. YES vote from '$from' : ($<,$>) $!");
  126.     print MASS "$from\n"; close(MASS);
  127.     $acked = 1;
  128. }
  129.  
  130. sub mailwarn {
  131.     local($reason) = shift(@_);
  132.     &setup_mail if (!defined($mail_is_on));
  133.     print ERRLOG <<EOT;
  134. From: cfv_daemon
  135. To: $moderator
  136. Subject: CFV daemon report
  137.  
  138. Warning about Mail from: '$from' with subject: '$subject':
  139. Reason: $reason.
  140. EOT
  141.  
  142. }
  143. sub maillog {
  144.     local($reason) = shift(@_);
  145.  
  146.     &setup_mail if (!defined($mail_is_on));
  147.     print ERRLOG <<EOT;
  148. From: cfv_daemon
  149. To: $moderator
  150. Subject: CFV daemon report
  151.  
  152. Mail from: '$from' with subject: '$subject' logged:
  153. Reason: $reason.
  154. EOT
  155.     close(ERRLOG);
  156. }
  157. sub maildebug {
  158.     local($reason) = shift(@_);
  159.     
  160.     return 0 if (!$debug);
  161.     &setup_mail if (!defined($mail_is_on));
  162.     print ERRLOG <<EOT;
  163. From: cfv_daemon
  164. To: $moderator
  165. Subject: CFV daemon report
  166.  
  167. Debug Mail from: '$from' with subject: '$subject':
  168. Reason: $reason.
  169. EOT
  170. }
  171.  
  172. sub maildie {    
  173.     local($reason) = shift(@_);
  174.     local($exitcode) = shift(@_);
  175.  
  176.     exit 0 if ($exitcode == 0);
  177.     &setup_mail if (!defined($mail_is_on));
  178.     print ERRLOG <<EOT;
  179. From: cfv_daemon
  180. To: $moderator
  181. Subject: CFV daemon report
  182.  
  183. Mail from: '$from' with subject: '$subject' failed:
  184. Reason: $reason.
  185. EOT
  186.     close(ERRLOG);
  187.     exit $exitcode;
  188. }
  189.  
  190. sub numdate {
  191.     local($y,$m,$d,$mn,$h) = @_;
  192.     local($n);
  193.  
  194.     $n = $h + (100*$mn) + (10000*$d) + (1000000*$m) + ($y * 100000000);
  195.     &maildebug("Converted ($y,$m,$d,$mn,$h) to $n");
  196.     return $n;
  197. }
  198.     
  199. sub setup_mail {
  200.     $mail_is_on = 1;
  201.     if (!open(ERRLOG,"| /usr/lib/sendmail -t")) {
  202.     open(ERRLOG,">>$backup_err") || warn "Augh! Can't redirect
  203. ERRLOG to someplace useful!\n";
  204.    }
  205.     select(ERRLOG); $| = 1; 
  206. }
  207.