Subversion Repositories camp_sysinfo_client_3

Rev

Rev 244 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
26 rodolico 1
#! /usr/bin/env perl
2 rodolico 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
 
26 rodolico 11
use warnings;
12
use strict;
13
 
28 rodolico 14
our $VERSION = '1.1';
26 rodolico 15
 
2 rodolico 16
sub doit {
13 rodolico 17
   my ( $parameters, $message ) = @_;
2 rodolico 18
   my %CLIParams ;
19
   $CLIParams{'-f'}  = qq/$$parameters{'mailFrom'}/    if $$parameters{'mailFrom'};
20
   $CLIParams{'-t'}  = qq/$$parameters{'mailTo'}/      if $$parameters{'mailTo'};
21
   $CLIParams{'-u'}  = qq/$$parameters{'mailSubject'}/ if $$parameters{'mailSubject'};
22
   $CLIParams{'-s'}  = qq/$$parameters{'mailServer'}/  if $$parameters{'mailServer'};
23
   $CLIParams{'-xu'} = qq/$$parameters{'smtpUser'}/    if $$parameters{'smtpUser'};
5 rodolico 24
   $CLIParams{'-xp'} = qq/$$parameters{'smtpPass'}/    if $$parameters{'smtpPass'};
2 rodolico 25
   $CLIParams{'-cc'} = qq/$$parameters{'mailCC'}/      if $$parameters{'mailCC'};
26
   $CLIParams{'-bcc'}= qq/$$parameters{'mailBCC'}/     if $$parameters{'mailBCC'};
27
   $CLIParams{'-l'}  = qq/$$parameters{'logFile'}/     if $$parameters{'logFile'};
5 rodolico 28
   $CLIParams{'-a'}  = qq/$$parameters{'attachment'}/     if $$parameters{'attachment'};
29
   $CLIParams{'-o tls='} = qq/$$parameters{'tls'}/     if $$parameters{'tls'};
2 rodolico 30
 
5 rodolico 31
 
28 rodolico 32
   my $commandLine = $$parameters{'sendEmailScriptLocation'};
2 rodolico 33
   die "Could not find executable $commandLine in sendEmailScript\n" unless -x $commandLine;
34
   foreach my $key ( keys %CLIParams ) {
5 rodolico 35
      # depending on whether the key ends in an = or not, we will or will not use a space
36
      # between the key and the parameter
37
      $commandLine .= $key =~ m/=$/ ? " $key'$CLIParams{$key}'" : " $key '$CLIParams{$key}'";
2 rodolico 38
   }
39
   $commandLine .= ' ' . $$parameters{'otherCLParams'} if $$parameters{'otherCLParams'};
5 rodolico 40
#   print "$commandLine\n\n";
41
#   print $message;
42
#   return;
2 rodolico 43
   open SENDMAIL, "|$commandLine" or die "Could not open [$commandLine]: $!\n";
44
   print SENDMAIL $message;
15 rodolico 45
   if ( close SENDMAIL ) { # we got an error return from SENDMAIL
46
      my $error = $? >> 8;
47
      print "Error sending report; code was [$error]\n";
48
      return $error;
49
   } else {
50
      return 1;
51
   }
2 rodolico 52
}
53
 
13 rodolico 54
1;