Subversion Repositories camp_sysinfo_client_3

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 rodolico 1
#! /usr/bin/perl -w
2
 
15 rodolico 3
# sendEmailScript
4
# Retrieves info from sysinfo-client and sends it to the server via 
5
# smtp. It uses {sendEmailScriptLocation} to send the file (assumed
6
# to be Brandon Zehm's sendEmail.pl, dotconf.net), and utilizes
7
# the rest of $$parameters to figure out where things go.
8
#
9
# returns 1 on success, something other than 1 on failure
10
 
2 rodolico 11
sub doit {
13 rodolico 12
   my ( $parameters, $message ) = @_;
2 rodolico 13
   my %CLIParams ;
14
   $CLIParams{'-f'}  = qq/$$parameters{'mailFrom'}/    if $$parameters{'mailFrom'};
15
   $CLIParams{'-t'}  = qq/$$parameters{'mailTo'}/      if $$parameters{'mailTo'};
16
   $CLIParams{'-u'}  = qq/$$parameters{'mailSubject'}/ if $$parameters{'mailSubject'};
17
   $CLIParams{'-s'}  = qq/$$parameters{'mailServer'}/  if $$parameters{'mailServer'};
18
   $CLIParams{'-xu'} = qq/$$parameters{'smtpUser'}/    if $$parameters{'smtpUser'};
5 rodolico 19
   $CLIParams{'-xp'} = qq/$$parameters{'smtpPass'}/    if $$parameters{'smtpPass'};
2 rodolico 20
   $CLIParams{'-cc'} = qq/$$parameters{'mailCC'}/      if $$parameters{'mailCC'};
21
   $CLIParams{'-bcc'}= qq/$$parameters{'mailBCC'}/     if $$parameters{'mailBCC'};
22
   $CLIParams{'-l'}  = qq/$$parameters{'logFile'}/     if $$parameters{'logFile'};
5 rodolico 23
   $CLIParams{'-a'}  = qq/$$parameters{'attachment'}/     if $$parameters{'attachment'};
24
   $CLIParams{'-o tls='} = qq/$$parameters{'tls'}/     if $$parameters{'tls'};
2 rodolico 25
 
5 rodolico 26
 
13 rodolico 27
   $commandLine = $$parameters{'sendEmailScriptLocation'};
2 rodolico 28
   die "Could not find executable $commandLine in sendEmailScript\n" unless -x $commandLine;
29
   foreach my $key ( keys %CLIParams ) {
5 rodolico 30
      # depending on whether the key ends in an = or not, we will or will not use a space
31
      # between the key and the parameter
32
      $commandLine .= $key =~ m/=$/ ? " $key'$CLIParams{$key}'" : " $key '$CLIParams{$key}'";
2 rodolico 33
   }
34
   $commandLine .= ' ' . $$parameters{'otherCLParams'} if $$parameters{'otherCLParams'};
5 rodolico 35
#   print "$commandLine\n\n";
36
#   print $message;
37
#   return;
2 rodolico 38
   open SENDMAIL, "|$commandLine" or die "Could not open [$commandLine]: $!\n";
39
   print SENDMAIL $message;
15 rodolico 40
   if ( close SENDMAIL ) { # we got an error return from SENDMAIL
41
      my $error = $? >> 8;
42
      print "Error sending report; code was [$error]\n";
43
      return $error;
44
   } else {
45
      return 1;
46
   }
2 rodolico 47
}
48
 
13 rodolico 49
1;