From: root [root@pinot.cciflorida.com] Sent: Monday, July 24, 2006 11:35 AM To: hendra@cciflorida.com Subject: Emailer #!/usr/bin/perl # this is email stuff use CGI qw/:standard/; $reffile = '/var/refcode/email'; $databin = "/home/httpd/databin/" . $ENV{"HTTP_HOST"} ; $sendmailtype = 'sendmail'; $server = 'port.cciflorida.com'; $this = $0; $report = '/home/clients/hendra/emailer'; &recycle; if (param()) { $ref = &GetRefCode; foreach $i (param) { $plisa .= "$i = " . param("$i") . "\n"; $plisb .= qq($i) . param("$i") . "\n"; $l = param("$i"); print BUG "
BEFORE $i is: $l\n"; $l =~ s/bcc\:/x-c-list:/g; $cl = $l; if ($l =~ m/\n/) { $l = $`; } print BUG "
After $i is: $l\n"; if ($i =~ /^mailto/i) { $mailto = $l; $incomplete = 1 unless $l; } elsif ($i =~ /^maillist/i) { $maillist = $l; $incomplete = 1 unless $l; } elsif ($i =~ /\bbcc\:/i) { $bcc = 1; } elsif ($i =~ /^email/i) { $mailfrom = $l; $incomplete = 1 unless $l; } elsif ($i =~ /^subject/i) { $mailsubject = $l; $mailsubject =~ s/\@//g; } elsif ($i =~ /^returnto/i) { $returnto = $l; } elsif ($i =~ /^prefix/i) { $prefix = $l; $mailsubject =~ s/\@//g; } elsif ($i =~ /^receipt/i) { $receiptnote = $l; } elsif ($i =~ /^failto/i) { $failto = $l; } elsif ($i =~ /-req$/i) { if ($cl && $cl !~/^\s*$/) { ($j = $i) =~ s/-req\s*$//i; $body .= " $j\t: " . $cl . "\n"; } else { $incomplete = 1; } } else { $v = join(", ", $cl); $body .= " $i\t: $v\n"; } } if ($incomplete) { &DispIncomp; } else { $sds = ""; foreach $ve (keys %ENV) { $sds .= " $ve = $ENV{$ve}\n"; } $omailto = $mailfrom; @tto = split(/\@/, $mailto); $trep = @tto; @tfrom = split(/\@/, $mailfrom); $tbcc = @tfrom; $mybod = "Using CCI Emailer\n $trep + $tbcc recipient accounted\n$sds\n$plisa\n----\n$omailto\n"; $donotsend = 1; #&Send("sysreport\@cciflorida.com", "report\@cciflorida.com", "Report - Spam exploit", "$mybod"); $donotsend = 0; # $mailto = "hendra\@cciflorida.com"; if ($mailto) { if ($bcc) { $tbcc += 6; $body = "BCC line exist.\n" + $body; } if ($trep + $tbcc < 6) { $debug .= "

Mailto is to $mailto "; $body =~ s/[\n\r]/\n /g; &Send($mailto, $mailfrom, "$mailsubject", $body); } else { $donotsend = 1; #&Send("sysreport\@cciflorida.com", "root\@cciflorida.com", "Report - Did not sent mass email", "Total recipients: $trep + $tbcc\n"); } } elsif (opendir (DBIN, "$databin")) { $mailto = ""; undef @ccopy; $debug .= "

Found data at $databin\n"; while ($dirc = readdir(DBIN)) { $debug .= "
Found data and will open $databin/$dirc if $dirc contains $maillist"; if (open (MLIST, "$databin/$dirc") && $dirc =~ /$maillist/) { while () { next if /^\#/; next unless /(\S+@\S+)/; $xz = $1; if ($mailto) { push (@ccopy , $xz); } else { $mailto = " $xz"; } } } } if ($mailto && !$donotsend) { &Send($mailto, $mailfrom, "$mailsubject", $body); } } else { $debug .= "

Failed on both count"; } &DispHtml($mailfrom, "$mailsubject"); } } else { &Debug; } print BUG qq($plisb
); foreach $k (keys %ENV) { next if $k =~ /^SERVER/; print BUG "
$k: $ENV{$k}"; } sub Debug { print header, start_html('CCI Email'), "Reference code is: $ref
"; print &GetRefCode . "\n" unless $ref;; foreach $k (keys %ENV) { print "
$k: $ENV{$k}"; } print "

This page is intentionally left blank.

"; } sub GetRefCode { dbmopen (%REF, "$reffile", 0660); my $out = ""; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); my $ptcd = ($year - 100) * 1000 + $yday; if ($REF{'last'} == $ptcd) { $REF{'serial'}++; } else { $REF{'last'} = $ptcd; $REF{'serial'} = 1; } if (param('prefix')) { $out = param('prefix') . $ptcd . "-" . $REF{'serial'}; $out =~ s/\n.+//; } else { $out = "Re" . $ptcd . "-" . $REF{'serial'}; } dbmclose(%REF); $out; } sub Send { my ($mailto, $mailfrom, $mailsubject, $body, $note) = @_; # sender and receiver exist $ssnum ++; print BUG qq(Sending $ssnum
\n----
\nTo: $mailto
\n----
\nFrom: $mailfrom
\n----
\nSubject: $mailsubject
\n----Body:
\n$body
\n
\n); if ($mailto && $mailfrom) { $mailfrom = " $mailfrom "; $mailfrom =~ m/\s(\S+\@\S+)\s/; $mailfrom =$1; $mailsubject .= "(Re: $ref)" ; # send email # filter out return-to, subject, mailto if (@ccopy) { my $Cc = join (',',@ccopy); } # send to submit my($sendmail) = ('/usr/sbin/sendmail'); open MAIL, "|$sendmail $mailto" or die "Can't open sendmail: message = '$!'"; print MAIL "To: $mailto\n"; print MAIL "From: $mailfrom\n"; #print MAIL "Cc: $Cc\n" if $Cc; print MAIL "Subject: $mailsubject}\n\n"; print MAIL "Mail Ref: $ref\nFrom: $mailfrom\n\n"; print MAIL "$body\n"; close MAIL or die "Can't close sendmail: message = '$!'"; # send Receipt # unless ($note && $note =~ /noreceipt/) { unless ($donotsend) { open MAIL, "|$sendmail $mailfrom" or die "Can't open sendmail: message = '$!'"; print MAIL "To: $mailfrom\n"; print MAIL "From: $mailto\n"; print MAIL "Subject: $mailsubject}\n\n"; print MAIL "Mail Ref: $ref\nFrom: $mailfrom\n\n"; if ($receiptnote) { print MAIL $receiptnote; } else { print MAIL "Your submission will be processed in the order it was received. Please save the Reference code."; } } } } sub DispHtml { if (!$returnto) { print header; } else { print header(-location=>"$returnto"); }; print start_html('CCI emailer'), "Reference code is: $ref
"; print &GetRefCode . "\n" unless $ref; print "

Your submission will be process the in order they are received. Please observe the Reference code and you should get a receipt emailed to $mailfrom.

"; print "Back to Main Site"; } sub DispIncomp { if (!$failto) { print header; } else { print header(-location=>"$failto"); }; print start_html('Form Incomplete'); print "

Your submission is incomplete. Please hit back button and complete your submission.

"; print "Back to Main Site"; } sub recycle { my ($c, $d, $fa, $fb, $now); open (DUG, ">$report/bug.html"); $c = 6; while (--$c) { $d = $c + 1; print DUG "
$c "; if (-e "$report/$c/body.html") { $fa = "$report/$c/body.html"; $fb = "$report/$d/body.html"; print DUG "mv $fa $fb"; `mv $fa $fb`; } } open (BUG, ">$report/1/body.html"); $now = `date`; print BUG "\nThis is $0 on $now


\n"; }