home *** CD-ROM | disk | FTP | other *** search
/ zipcon.net / www.zipcon.net.tar / www.zipcon.net / pub / cgi / guestbook / guestbook.pl < prev    next >
Perl Script  |  2000-09-26  |  11KB  |  378 lines

  1. #!/usr/bin/perl
  2. ##############################################################################
  3. # Guestbook                     Version 2.3.1                                #
  4. # Copyright 1996 Matt Wright    mattw@worldwidemart.com                      #
  5. # Created 4/21/95               Last Modified 10/29/95                       #
  6. # Scripts Archive at:           http://www.worldwidemart.com/scripts/        #
  7. ##############################################################################
  8. # COPYRIGHT NOTICE                                                           #
  9. # Copyright 1996 Matthew M. Wright  All Rights Reserved.                     #
  10. #                                                                            #
  11. # Guestbook may be used and modified free of charge by anyone so long as     #
  12. # this copyright notice and the comments above remain intact.  By using this #
  13. # code you agree to indemnify Matthew M. Wright from any liability that      #  
  14. # might arise from it's use.                                                 #  
  15. #                                                                            #
  16. # Selling the code for this program without prior written consent is         #
  17. # expressly forbidden.  In other words, please ask first before you try and  #
  18. # make money off of my program.                                              #
  19. #                                                                            #
  20. # Obtain permission before redistributing this software over the Internet or #
  21. # in any other medium.    In all cases copyright and header must remain intact.#
  22. ##############################################################################
  23. # Set Variables
  24.  
  25. $guestbookurl = "http://www.zipcon.net/~LOGIN/guestbook.html";
  26. $guestbookreal = "/home/LETTER/LOGIN/public_html/guestbook.html";
  27. $guestlog = "/home/LETTER/LOGIN/public_html/guestlog.html";
  28. $cgiurl = "http://www.zipcon.net/~LOGIN/cgi-bin/guestbook.pl";
  29. $date_command = "/bin/date";
  30.  
  31. # Set Your Options:
  32. $mail = 1;              # 1 = Yes; 0 = No
  33. $uselog = 1;            # 1 = Yes; 0 = No
  34. $linkmail = 1;          # 1 = Yes; 0 = No
  35. $separator = 1;         # 1 = <hr>; 0 = <p>
  36. $redirection = 0;       # 1 = Yes; 0 = No
  37. $entry_order = 1;       # 1 = Newest entries added first;
  38.                         # 0 = Newest Entries added last.
  39. $remote_mail = 0;       # 1 = Yes; 0 = No
  40. $allow_html = 0;        # 1 = Yes; 0 = No
  41. $line_breaks = 0;    # 1 = Yes; 0 = No
  42.  
  43. # If you answered 1 to $mail or $remote_mail you will need to fill out 
  44. # these variables below:
  45. $mailprog = '/usr/lib/sendmail';
  46. $recipient = 'LOGIN@zipcon.net';
  47.  
  48. # Done
  49. ##############################################################################
  50.  
  51. # Get the Date for Entry
  52. $date = `$date_command +"%A, %B %d, %Y at %T (%Z)"`; chop($date);
  53. $shortdate = `$date_command +"%D %T %Z"`; chop($shortdate);
  54.  
  55. # Get the input
  56. read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  57.  
  58. # Split the name-value pairs
  59. @pairs = split(/&/, $buffer);
  60.  
  61. foreach $pair (@pairs) {
  62.    ($name, $value) = split(/=/, $pair);
  63.  
  64.    # Un-Webify plus signs and %-encoding
  65.    $value =~ tr/+/ /;
  66.    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  67.    $value =~ s/<!--(.|\n)*-->//g;
  68.  
  69.    if ($allow_html != 1) {
  70.       $value =~ s/<([^>]|\n)*>//g;
  71.    }
  72.  
  73.    $FORM{$name} = $value;
  74. }
  75.  
  76. # Print the Blank Response Subroutines
  77. &no_comments unless $FORM{'comments'};
  78. &no_name unless $FORM{'realname'};
  79.  
  80. # Begin the Editing of the Guestbook File
  81. open (FILE,"$guestbookreal") || die "Can't Open $guestbookreal: $!\n";
  82. @LINES=<FILE>;
  83. close(FILE);
  84. $SIZE=@LINES;
  85.  
  86. # Open Link File to Output
  87. open (GUEST,">$guestbookreal") || die "Can't Open $guestbookreal: $!\n";
  88.  
  89. for ($i=0;$i<=$SIZE;$i++) {
  90.    $_=$LINES[$i];
  91.    if (/<!--begin-->/) { 
  92.  
  93.       if ($entry_order eq '1') {
  94.          print GUEST "<!--begin-->\n";
  95.       }
  96.    
  97.       if ($line_breaks == 1) {
  98.          $FORM{'comments'} =~ s/\cM\n/<br>\n/g;
  99.       }
  100.  
  101.       print GUEST "<b>$FORM{'comments'}</b><br>\n";
  102.  
  103.       if ($FORM{'url'}) {
  104.          print GUEST "<a href=\"$FORM{'url'}\">$FORM{'realname'}</a>";
  105.       }
  106.       else {
  107.          print GUEST "$FORM{'realname'}";
  108.       }
  109.  
  110.       if ( $FORM{'username'} ){
  111.          if ($linkmail eq '1') {
  112.             print GUEST " \<<a href=\"mailto:$FORM{'username'}\">";
  113.             print GUEST "$FORM{'username'}</a>\>";
  114.          }
  115.          else {
  116.             print GUEST " <$FORM{'username'}>";
  117.          }
  118.       }
  119.  
  120.       print GUEST "<br>\n";
  121.  
  122.       if ( $FORM{'city'} ){
  123.          print GUEST "$FORM{'city'},";
  124.       }
  125.      
  126.       if ( $FORM{'state'} ){
  127.          print GUEST " $FORM{'state'}";
  128.       }
  129.  
  130.       if ( $FORM{'country'} ){
  131.          print GUEST " $FORM{'country'}";
  132.       }
  133.  
  134.       if ($separator eq '1') {
  135.          print GUEST " - $date<hr>\n\n";
  136.       }
  137.       else {
  138.          print GUEST " - $date<p>\n\n";
  139.       }
  140.  
  141.       if ($entry_order eq '0') {
  142.          print GUEST "<!--begin-->\n";
  143.       }
  144.  
  145.    }
  146.    else {
  147.       print GUEST $_;
  148.    }
  149. }
  150.  
  151. close (GUEST);
  152.  
  153. # Log The Entry
  154.  
  155. if ($uselog eq '1') {
  156.    &log('entry');
  157. }
  158.  
  159.  
  160. #########
  161. # Options
  162.  
  163. # Mail Option
  164. if ($mail eq '1') {
  165.    open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
  166.  
  167.    print MAIL "Reply-to: $FORM{'username'} ($FORM{'realname'})\n";
  168.    print MAIL "From: $FORM{'username'} ($FORM{'realname'})\n";
  169.    print MAIL "Subject: Entry to Guestbook\n\n";
  170.    print MAIL "You have a new entry in your guestbook:\n\n";
  171.    print MAIL "------------------------------------------------------\n";
  172.    print MAIL "$FORM{'comments'}\n";
  173.    print MAIL "$FORM{'realname'}";
  174.  
  175.    if ( $FORM{'username'} ){
  176.       print MAIL " <$FORM{'username'}>";
  177.    }
  178.  
  179.    print MAIL "\n";
  180.  
  181.    if ( $FORM{'city'} ){
  182.       print MAIL "$FORM{'city'},";
  183.    }
  184.  
  185.    if ( $FORM{'state'} ){
  186.       print MAIL " $FORM{'state'}";
  187.    }
  188.  
  189.    if ( $FORM{'country'} ){
  190.       print MAIL " $FORM{'country'}";
  191.    }
  192.  
  193.    print MAIL " - $date\n";
  194.    print MAIL "------------------------------------------------------\n";
  195.  
  196.    close (MAIL);
  197. }
  198.  
  199. if ($remote_mail eq '1' && $FORM{'username'}) {
  200.    open (MAIL, "|$mailprog -t") || die "Can't open $mailprog!\n";
  201.  
  202.    print MAIL "To: $FORM{'username'}\n";
  203.    print MAIL "From: $recipient\n";
  204.    print MAIL "Subject: Entry to Guestbook\n\n";
  205.    print MAIL "Thank you for adding to my guestbook.\n\n";
  206.    print MAIL "------------------------------------------------------\n";
  207.    print MAIL "$FORM{'comments'}\n";
  208.    print MAIL "$FORM{'realname'}";
  209.  
  210.    if ( $FORM{'username'} ){
  211.       print MAIL " <$FORM{'username'}>";
  212.    }
  213.  
  214.    print MAIL "\n";
  215.  
  216.    if ( $FORM{'city'} ){
  217.       print MAIL "$FORM{'city'},";
  218.    }
  219.  
  220.    if ( $FORM{'state'} ){
  221.       print MAIL " $FORM{'state'}";
  222.    }
  223.  
  224.    if ( $FORM{'country'} ){
  225.      print MAIL " $FORM{'country'}";
  226.    }
  227.  
  228.    print MAIL " - $date\n";
  229.    print MAIL "------------------------------------------------------\n";
  230.  
  231.    close (MAIL);
  232. }
  233.  
  234. # Print Out Initial Output Location Heading
  235. if ($redirection eq '1') {
  236.    print "Location: $guestbookurl\n\n";
  237. }
  238. else { 
  239.    &no_redirection;
  240. }
  241.  
  242. #######################
  243. # Subroutines
  244.  
  245. sub no_comments {
  246.    print "Content-type: text/html\n\n";
  247.    print "<html><head><title>No Comments</title></head>\n";
  248.    print "<body><h1>Your Comments appear to be blank</h1>\n";
  249.    print "The comment section in the guestbook fillout form appears\n";
  250.    print "to be blank and therefore the Guestbook Addition was not\n";
  251.    print "added.  Please enter your comments below.<p>\n";
  252.    print "<form method=POST action=\"$cgiurl\">\n";
  253.    print "Your Name:<input type=text name=\"realname\" size=30 ";
  254.    print "value=\"$FORM{'realname'}\"><br>\n";
  255.    print "E-Mail: <input type=text name=\"username\""; 
  256.    print "value=\"$FORM{'username'}\" size=40><br>\n";
  257.    print "City: <input type=text name=\"city\" value=\"$FORM{'city'}\" ";
  258.    print "size=15>, State: <input type=text name=\"state\" "; 
  259.    print "value=\"$FORM{'state'}\" size=15> Country: <input type=text "; 
  260.    print "name=\"country\" value=\"$FORM{'country'}\" size=15><p>\n";
  261.    print "Comments:<br>\n";
  262.    print "<textarea name=\"comments\" COLS=60 ROWS=4></textarea><p>\n";
  263.    print "<input type=submit> * <input type=reset></form><hr>\n";
  264.    print "Return to the <a href=\"$guestbookurl\">Guestbook</a>.";
  265.    print "\n</body></html>\n";
  266.  
  267.    # Log The Error
  268.    if ($uselog eq '1') {
  269.       &log('no_comments');
  270.    }
  271.  
  272.    exit;
  273. }
  274.  
  275. sub no_name {
  276.    print "Content-type: text/html\n\n";
  277.    print "<html><head><title>No Name</title></head>\n";
  278.    print "<body><h1>Your Name appears to be blank</h1>\n";
  279.    print "The Name Section in the guestbook fillout form appears to\n";
  280.    print "be blank and therefore your entry to the guestbook was not\n";
  281.    print "added.  Please add your name in the blank below.<p>\n";
  282.    print "<form method=POST action=\"$cgiurl\">\n";
  283.    print "Your Name:<input type=text name=\"realname\" size=30><br>\n";
  284.    print "E-Mail: <input type=text name=\"username\"";
  285.    print " value=\"$FORM{'username'}\" size=40><br>\n";
  286.    print "City: <input type=text name=\"city\" value=\"$FORM{'city'}\" ";
  287.    print "size=15>, State: <input type=text name=\"state\" ";
  288.    print "value=\"$FORM{'state'}\" size=2> Country: <input type=text ";
  289.    print "value=USA name=\"country\" value=\"$FORM{'country'}\" ";
  290.    print "size=15><p>\n";
  291.    print "Comments have been retained.<p>\n";
  292.    print "<input type=hidden name=\"comments\" ";
  293.    print "value=\"$FORM{'comments'}\">\n";
  294.    print "<input type=submit> * <input type=reset><hr>\n";
  295.    print "Return to the <a href=\"$guestbookurl\">Guestbook</a>.";
  296.    print "\n</body></html>\n";
  297.  
  298.    # Log The Error
  299.    if ($uselog eq '1') {
  300.       &log('no_name');
  301.    }
  302.  
  303.    exit;
  304. }
  305.  
  306. # Log the Entry or Error
  307. sub log {
  308.    $log_type = $_[0];
  309.    open (LOG, ">>$guestlog");
  310.    if ($log_type eq 'entry') {
  311.       print LOG "$ENV{'REMOTE_HOST'} - [$shortdate]<br>\n";
  312.    }
  313.    elsif ($log_type eq 'no_name') {
  314.       print LOG "$ENV{'REMOTE_HOST'} - [$shortdate] - ERR: No Name<br>\n";
  315.    }
  316.    elsif ($log_type eq 'no_comments') {
  317.       print LOG "$ENV{'REMOTE_HOST'} - [$shortdate] - ERR: No ";
  318.       print LOG "Comments<br>\n";
  319.    }
  320. }
  321.  
  322. # Redirection Option
  323. sub no_redirection {
  324.  
  325.    # Print Beginning of HTML
  326.    print "Content-Type: text/html\n\n";
  327.    print "<html><head><title>Thank You</title></head>\n";
  328.    print "<body><h1>Thank You For Signing The Guestbook</h1>\n";
  329.  
  330.    # Print Response
  331.    print "Thank you for filling in the guestbook.  Your entry has\n";
  332.    print "been added to the guestbook.<hr>\n";
  333.    print "Here is what you submitted:<p>\n";
  334.    print "<b>$FORM{'comments'}</b><br>\n";
  335.  
  336.    if ($FORM{'url'}) {
  337.       print "<a href=\"$FORM{'url'}\">$FORM{'realname'}</a>";
  338.    }
  339.    else {
  340.       print "$FORM{'realname'}";
  341.    }
  342.  
  343.    if ( $FORM{'username'} ){
  344.       if ($linkmail eq '1') {
  345.          print " <<a href=\"mailto:$FORM{'username'}\">";
  346.          print "$FORM{'username'}</a>>";
  347.       }
  348.       else {
  349.          print " <$FORM{'username'}>";
  350.       }
  351.    }
  352.  
  353.    print "<br>\n";
  354.  
  355.    if ( $FORM{'city'} ){
  356.       print "$FORM{'city'},";
  357.    }
  358.  
  359.    if ( $FORM{'state'} ){
  360.       print " $FORM{'state'}";
  361.    }
  362.  
  363.    if ( $FORM{'country'} ){
  364.       print " $FORM{'country'}";
  365.    }
  366.  
  367.    print " - $date<p>\n";
  368.  
  369.    # Print End of HTML
  370.    print "<hr>\n";
  371.    print "<a href=\"$guestbookurl\">Back to the Guestbook</a>\n";         print "- You may need to reload it when you get there to see your\n";
  372.    print "entry.\n";
  373.    print "</body></html>\n";
  374.  
  375.    exit;
  376. }
  377.  
  378.