#!/usr/bin/perl -w # (C) 1998-2001 Julian Haight, GPL License # http://www.julianhaight.com/ use CGI; use strict; use Mail::Sendmail; package sendsecure; doit(); sub doit { my $query = new CGI; my($from) = $query->param('from'); my($msg) = $query->param('message'); my($to) = $query->param('to'); my($subject) = $query->param('subject'); my($key, $pid, $cmd, $tmpfile, %mail); $key = undef(); print "Content-type: text/html\n\n"; if ($to eq 'user1') { $to = 'user1@example.com'; # email $key = '0xffffffff'; # keyid } if ($key) { $_ = `/bin/date`; chop; %mail = ('To' => $to, 'From' => $from, 'Subject' => 'Feedback www.julianhaight.com:' . $subject, 'Received'=> ('from ' . $ENV{REMOTE_ADDR} . ' by www.julianhaight.com with HTTP; ' . $_) ); if ($query->param('encrypt')) { $msg = encrypt($msg, $key); } if ($msg) { $mail{'Body'} = $msg; if (Mail::Sendmail::sendmail(%mail)) { print "Message sent:
\n"; print '
From:   ' . $from . "\n".
		    "To:     $to\nSubject:$subject\nMessage:\n$msg\n
\n"; } else { print "Can't send message. " . $Mail::Sendmail::error . "
\n"; print "Trying with no return address: (julian will not be able to reply!)
\n"; $mail{'From'} = 'nobody@julianhaight.com'; if (Mail::Sendmail::sendmail(%mail)) { print "Message sent:
\n"; print '
From:   ' . $from . "\n".
			"To:     $to\nSubject:$subject\nMessage:\n$msg\n
\n"; } else { print "Still can't send."; } } } } else { print "Don't know recipient: $to\n"; } print 'Return.'; } sub encrypt { my($msg, $key) = @_; my($tmpfile) = '/tmp/sendsecure' . getppid(); my($pubring) = '/root/.pgp/pubring.pkr'; my($cmd) = ("|/usr/local/bin/pgpe -r $key -o $tmpfile -atf --pubring=$pubring 2>/dev/null"); # print $cmd . "
\n"; if (open(PGP, $cmd) || die $!) { print PGP $msg; close PGP; if ($msg = `/bin/cat $tmpfile`) { unlink $tmpfile; print "Message encrypted with PGP public key $key.
\n"; } else { print "Can't read tempfile $tmpfile $! - try without encryption
\n"; } #print $msg; } else { print "Can't open temporary file $tmpfile.
\n"; $msg = ''; } return $msg; }