1 ## $Id: checkgroups.pl 7743 2008-04-06 10:04:43Z iulius $
3 ## checkgroups control message handler.
5 ## Copyright 2001 by Marco d'Itri <md@linux.it>
7 ## Redistribution and use in source and binary forms, with or without
8 ## modification, are permitted provided that the following conditions
11 ## 1. Redistributions of source code must retain the above copyright
12 ## notice, this list of conditions and the following disclaimer.
14 ## 2. Redistributions in binary form must reproduce the above copyright
15 ## notice, this list of conditions and the following disclaimer in the
16 ## documentation and/or other materials provided with the distribution.
20 sub control_checkgroups {
21 my ($par, $sender, $replyto, $site, $action, $log, $approved,
22 $headers, $body) = @_;
23 my ($newsgrouppats) = @$par;
25 if ($action eq 'mail') {
26 my $mail = sendmail("checkgroups by $sender");
27 print $mail "$sender posted the following checkgroups message:\n";
28 print $mail map { s/^~/~~/; "$_\n" } @$headers;
31 If you want to process it, feed the body
32 of the message to docheckgroups while logged
33 in as user ID "$inn::newsuser":
35 $inn::pathbin/docheckgroups '$newsgrouppats' <<zRbJ
37 print $mail map { s/^~/~~/; "$_\n" } @$body;
39 close $mail or logdie("Cannot send mail: $!");
40 } elsif ($action eq 'log') {
42 logger($log, "checkgroups by $sender", $headers, $body);
44 logmsg("checkgroups by $sender");
46 } elsif ($action eq 'doit') {
47 if (defined &local_docheckgroups) {
48 local_docheckgroups($body, $newsgrouppats, $log, $sender);
50 docheckgroups($body, $newsgrouppats, $log, $sender);
56 my ($body, $newsgrouppats, $log, $sender) = @_;
58 my $tempfile = "$inn::tmpdir/checkgroups.$$";
59 open(TEMPART, ">$tempfile.art")
60 or logdie("Cannot open $tempfile.art: $!");
61 print TEMPART map { s/^~/~~/; "$_\n" } @$body;
64 open(OLDIN, '<&STDIN') or die $!;
65 open(OLDOUT, '>&STDOUT') or die $!;
66 open(STDIN, "$tempfile.art") or die $!;
67 open(STDOUT, ">$tempfile") or die $!;
68 my $st = system("$inn::pathbin/docheckgroups", $newsgrouppats);
69 logdie('Cannot run docheckgroups: ' . $!) if $st == -1;
70 logdie('docheckgroups returned status ' . ($st & 255)) if $st > 0;
73 open(STDIN, '<&OLDIN') or die $!;
74 open(STDOUT, '>&OLDOUT') or die $!;
76 open(TEMPFILE, $tempfile) or logdie("Cannot open $tempfile: $!");
77 my @output = <TEMPFILE>;
79 # There is no need to send an empty mail.
81 logger($log || 'mail', "checkgroups by $sender", \@output);
83 logmsg("checkgroups by $sender processed (no change)");
86 unlink($tempfile, "$tempfile.art");