chiark / gitweb /
Commit 2.4.5-5 as unpacked
[innduct.git] / control / modules / senduuname.pl
1 ##  $Id: senduuname.pl 4932 2001-07-19 00:32:56Z rra $
2 ##
3 ##  senduuname control message handler.
4 ##
5 ##  Copyright 2001 by Marco d'Itri <md@linux.it>
6 ##
7 ##  Redistribution and use in source and binary forms, with or without
8 ##  modification, are permitted provided that the following conditions
9 ##  are met:
10 ##
11 ##   1. Redistributions of source code must retain the above copyright
12 ##      notice, this list of conditions and the following disclaimer.
13 ##
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.
17
18 use strict;
19
20 sub control_senduuname {
21     my ($par, $sender, $replyto, $site, $action, $log, $approved,
22         $headers, $body) = @_;
23     my ($where) = @$par;
24
25     if ($action eq 'mail') {
26         my $mail = sendmail("senduuname $sender");
27         print $mail <<END;
28 $sender has requested information about your UUCP name.
29
30 If this is acceptable, type:
31   uuname | $inn::mailcmd -s "senduuname reply from $inn::pathhost" $replyto
32
33 The control message follows:
34
35 END
36         print $mail map { s/^~/~~/; "$_\n" } @$headers;
37         print $mail "\n";
38         print $mail map { s/^~/~~/; "$_\n" } @$body;
39         close $mail or logdie("Cannot send mail: $!");
40     } elsif ($action eq 'log') {
41         if ($log) {
42             logger($log, "senduuname $sender", $headers, $body);
43         } else {
44             logmsg("senduuname $sender");
45         }
46     } elsif ($action =~ /^(doit|doifarg)$/) {
47         if ($action eq 'doifarg' and $where ne $inn::pathhost) {
48             logmsg("skipped senduuname $sender");
49             return;
50         }
51         my $mail = sendmail("senduuname reply from $inn::pathhost", $replyto);
52         open(UUNAME, 'uuname|') or logdie("Cannot run uuname: $!");
53         print $mail $_ while <UUNAME>;
54         close UUNAME or logdie("Cannot run uuname: $!");
55         close $mail or logdie("Cannot send mail: $!");
56
57         logger($log, "senduuname $sender to $replyto", $headers, $body) if $log;
58     }
59 }
60
61 1;