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

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

\n"; print " *


\n"; print "Return to the Guestbook."; print "\n\n"; # Log The Error if ($uselog eq '1') { &log('no_comments'); } exit; } sub no_name { print "Content-type: text/html\n\n"; print "No Name\n"; print "

Your Name appears to be blank

\n"; print "The Name Section in the guestbook fillout form appears to\n"; print "be blank and therefore your entry to the guestbook was not\n"; print "added. Please add your name in the blank below.

\n"; print "

\n"; print "Your Name:
\n"; print "E-Mail:
\n"; print "City: , State: Country:

\n"; print "Comments have been retained.

\n"; print "\n"; print " *


\n"; print "Return to the Guestbook."; print "\n\n"; # Log The Error if ($uselog eq '1') { &log('no_name'); } exit; } # Log the Entry or Error sub log { $log_type = $_[0]; open (LOG, ">>$guestlog"); if ($log_type eq 'entry') { print LOG "$ENV{'REMOTE_HOST'} - [$shortdate]
\n"; } elsif ($log_type eq 'no_name') { print LOG "$ENV{'REMOTE_HOST'} - [$shortdate] - ERR: No Name
\n"; } elsif ($log_type eq 'no_comments') { print LOG "$ENV{'REMOTE_HOST'} - [$shortdate] - ERR: No "; print LOG "Comments
\n"; } } # Redirection Option sub no_redirection { # Print Beginning of HTML print "Content-Type: text/html\n\n"; print "Thank You\n"; print "

Thank You For Signing The Guestbook

\n"; # Print Response print "Thank you for filling in the guestbook. Your entry has\n"; print "been added to the guestbook.
\n"; print "Here is what you submitted:

\n"; print "$FORM{'comments'}
\n"; if ($FORM{'url'}) { print "$FORM{'realname'}"; } else { print "$FORM{'realname'}"; } if ( $FORM{'username'} ){ if ($linkmail eq '1') { print " <"; print "$FORM{'username'}>"; } else { print " <$FORM{'username'}>"; } } print "
\n"; if ( $FORM{'city'} ){ print "$FORM{'city'},"; } if ( $FORM{'state'} ){ print " $FORM{'state'}"; } if ( $FORM{'country'} ){ print " $FORM{'country'}"; } print " - $date

\n"; # Print End of HTML print "


\n"; print "Back to the Guestbook\n"; print "- You may need to reload it when you get there to see your\n"; print "entry.\n"; print "\n"; exit; }

Login or Register to edit or fork this paste. It's free.