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