#!/usr/local/bin/perl # set the line above this to your perl path. Usually fine as is # or /usr/local/bin/perl /sbin/perl # make certain that the first line stays the first line! # CONFIRMER.CGI - Modification of the BigNoseBird script cardcgi v2.0 # to add confirmation functionality. # You can download card.cgi and other great scripts from http://www.bignosebird.com # Richard Still - http://www.oakbox.com # I am going to use Bruce's disclaimer too : ) # (C)-Oakbox Productions 2000 # This software is FREEWARE! Do with it as you wish. It is yours # to share and enjoy. Modify it, improve it, and have fun with it! # It is distributed strictly as a learning aid and oakbox.com # disclaims all warranties- including but not limited to: # fitness for a particular purpose, merchantability, loss of # business, harm to your system, etc... ALWAYS BACK UP YOUR # SYSTEM BEFORE INSTALLING ANY SCRIPT OR PROGRAM FROM ANY # SOURCE! # I'm going to use the same mailer program that card.cgi uses. You will # need to change these variables to match those used in card.cgi! # USE EITHER SMTP OR SEND_MAIL DEPENDING ON YOUR SYSTEM- # BUT NOT BOTH! $SMTP_SERVER="localhost"; #$SEND_MAIL="/usr/lib/sendmail -t"; # The FROM address on the confirmation message. You must place a \ before # the AT symbol $ADMIN_EMAIL="admin\@server.com"; # You need to add ONE LINE to card.cgi to make this function work. # We will add a little img tag in the HTML page we create for # the user. This img tag will call this script when it is viewed # and this script will tell the sender that his/her card was picked # up. Open up the card.cgi (around line 226) and make this change: # # Look for this: # # # # # # __END_OF_CARD_BODY__ # # Change it to look like this: # # # # # # __END_OF_CARD_BODY__ # # Recognize that these changes make the confirmation an automatic function. And that # the sender will get a message EVERY TIME THE CARD HTML FILE IS VIEWED. # If you think that your cards are being picked up over and over again, a small # tracking modification will have to be made to this script to keep track of # which cards have been confirmed. $|=1; # Look at the comments below (everything with a #-sign) to see where you # need to make modifications. $REFID=$ENV{'QUERY_STRING'}; $REFID=~s/%(..)/pack("c",hex($1))/ge; #this was left out of 1st script! @information=split(/-=-/,$REFID); # The confirmation message to the sender $SUBJECT=" Your card has been picked up!"; $message=<<_END_; Your card to $information[1] entitled $information[2] has been viewed! Thank you again for using our web site! _END_ &sendmail($ADMIN_EMAIL, $ADMIN_EMAIL, $information[0], $SMTP_SERVER, $SUBJECT, $message); # send something to the browser. print "Content-type: image/gif\n\n"; print "F"; exit; ################################################################### #Sendmail.pm routine below by Milivoj Ivkovic ################################################################### sub sendmail { # error codes below for those who bother to check result codes # 1 success # -1 $smtphost unknown # -2 socket() failed # -3 connect() failed # -4 service not available # -5 unspecified communication error # -6 local user $to unknown on host $smtp # -7 transmission of message failed # -8 argument $to empty # # Sample call: # # &sendmail($from, $reply, $to, $smtp, $subject, $message ); # # Note that there are several commands for cleaning up possible bad inputs - if you # are hard coding things from a library file, so of those are unnecesssary # my ($fromaddr, $replyaddr, $to, $smtp, $subject, $message) = @_; $to =~ s/[ \t]+/, /g; # pack spaces and add comma $fromaddr =~ s/.*<([^\s]*?)>/$1/; # get from email address $replyaddr =~ s/.*<([^\s]*?)>/$1/; # get reply email address $replyaddr =~ s/^([^\s]+).*/$1/; # use first address $message =~ s/^\./\.\./gm; # handle . as first character $message =~ s/\r\n/\n/g; # handle line ending $message =~ s/\n/\r\n/g; $smtp =~ s/^\s+//g; # remove spaces around $smtp $smtp =~ s/\s+$//g; if (!$to) { return(-8); } if ($SMTP_SERVER ne "") { my($proto) = (getprotobyname('tcp'))[2]; my($port) = (getservbyname('smtp', 'tcp'))[2]; my($smtpaddr) = ($smtp =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/) ? pack('C4',$1,$2,$3,$4) : (gethostbyname($smtp))[4]; if (!defined($smtpaddr)) { return(-1); } if (!socket(MAIL, AF_INET, SOCK_STREAM, $proto)) { return(-2); } if (!connect(MAIL, pack('Sna4x8', AF_INET, $port, $smtpaddr))) { return(-3); } my($oldfh) = select(MAIL); $| = 1; select($oldfh); $_ = ; if (/^[45]/) { close(MAIL); return(-4); } print MAIL "helo $SMTP_SERVER\r\n"; $_ = ; if (/^[45]/) { close(MAIL); return(-5); } print MAIL "mail from: <$fromaddr>\r\n"; $_ = ; if (/^[45]/) { close(MAIL); return(-5); } foreach (split(/, /, $to)) { print MAIL "rcpt to: <$_>\r\n"; $_ = ; if (/^[45]/) { close(MAIL); return(-6); } } print MAIL "data\r\n"; $_ = ; if (/^[45]/) { close MAIL; return(-5); } } if ($SEND_MAIL ne "") { open (MAIL,"| $SEND_MAIL"); } print MAIL "To: $to\n"; print MAIL "From: $fromaddr\n"; print MAIL "Reply-to: $replyaddr\n" if $replyaddr; print MAIL "X-Mailer: Perl Powered Socket Mailer\n"; print MAIL "Subject: $subject\n\n"; print MAIL "$message"; print MAIL "\n.\n"; if ($SMTP_SERVER ne "") { $_ = ; if (/^[45]/) { close(MAIL); return(-7); } print MAIL "quit\r\n"; $_ = ; } close(MAIL); return(1); }